Added comments, moved EntityHandlerIface, and cleaned up old codes.
Change-Id: I1a182b6ecd3dfeea4af08f3accd72fbce9af0f9c
diff --git a/full/src/main/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManager.java b/full/src/main/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManager.java
index 0f75d84..73728a4 100644
--- a/full/src/main/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManager.java
+++ b/full/src/main/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManager.java
@@ -36,9 +36,9 @@
import de.ids_mannheim.korap.interfaces.AuthenticationIface;
import de.ids_mannheim.korap.interfaces.AuthenticationManagerIface;
import de.ids_mannheim.korap.interfaces.EncryptionIface;
+import de.ids_mannheim.korap.interfaces.EntityHandlerIface;
import de.ids_mannheim.korap.interfaces.ValidatorIface;
import de.ids_mannheim.korap.interfaces.db.AuditingIface;
-import de.ids_mannheim.korap.interfaces.db.EntityHandlerIface;
import de.ids_mannheim.korap.interfaces.db.UserDataDbIface;
import de.ids_mannheim.korap.interfaces.defaults.ApacheValidator;
import de.ids_mannheim.korap.user.DemoUser;
diff --git a/full/src/main/java/de/ids_mannheim/korap/authentication/http/AuthorizationData.java b/full/src/main/java/de/ids_mannheim/korap/authentication/http/AuthorizationData.java
index 32c9c7b..a1ad185 100644
--- a/full/src/main/java/de/ids_mannheim/korap/authentication/http/AuthorizationData.java
+++ b/full/src/main/java/de/ids_mannheim/korap/authentication/http/AuthorizationData.java
@@ -4,6 +4,11 @@
import lombok.Getter;
import lombok.Setter;
+/** Describes the values stored in Authorization header of HTTP requests.
+ *
+ * @author margaretha
+ *
+ */
@Getter
@Setter
public class AuthorizationData {
diff --git a/full/src/main/java/de/ids_mannheim/korap/config/AuthenticationMethod.java b/full/src/main/java/de/ids_mannheim/korap/config/AuthenticationMethod.java
index afd81ed..b44d0a0 100644
--- a/full/src/main/java/de/ids_mannheim/korap/config/AuthenticationMethod.java
+++ b/full/src/main/java/de/ids_mannheim/korap/config/AuthenticationMethod.java
@@ -1,5 +1,14 @@
package de.ids_mannheim.korap.config;
+/** Lists possible actual authentication methods. Multiple
+ * {@link AuthenticationScheme} may use an identical
+ * authentication method.
+ *
+ * @author margaretha
+ *
+ * @see AuthenticationScheme
+ *
+ */
public enum AuthenticationMethod {
LDAP, SHIBBOLETH, DATABASE;
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/config/AuthenticationScheme.java b/full/src/main/java/de/ids_mannheim/korap/config/AuthenticationScheme.java
index 6d9c58e..4459e56 100644
--- a/full/src/main/java/de/ids_mannheim/korap/config/AuthenticationScheme.java
+++ b/full/src/main/java/de/ids_mannheim/korap/config/AuthenticationScheme.java
@@ -2,12 +2,18 @@
import org.apache.commons.lang.WordUtils;
+/** Lists possible authentication schemes used in the Authorization header
+ * of HTTP requests.
+ *
+ * @author margaretha
+ *
+ */
public enum AuthenticationScheme {
// standard http
BASIC, BEARER,
// custom
SESSION, API;
-
+
public String displayName () {
return WordUtils.capitalizeFully(name());
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/constant/GroupMemberStatus.java b/full/src/main/java/de/ids_mannheim/korap/constant/GroupMemberStatus.java
index 59c1154..c9b5229 100644
--- a/full/src/main/java/de/ids_mannheim/korap/constant/GroupMemberStatus.java
+++ b/full/src/main/java/de/ids_mannheim/korap/constant/GroupMemberStatus.java
@@ -1,5 +1,16 @@
package de.ids_mannheim.korap.constant;
+/** Defines the status of a user-group member
+ *
+ * @author margaretha
+ *
+ */
public enum GroupMemberStatus {
- ACTIVE, PENDING, DELETED;
+ ACTIVE,
+ // membership invitation was sent and has not been accepted
+ // or rejected yet
+ PENDING,
+ // either membership invitation was rejected or the member was
+ // deleted by a user-group admin
+ DELETED;
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/constant/PredefinedRole.java b/full/src/main/java/de/ids_mannheim/korap/constant/PredefinedRole.java
index 65b0fad..d784cb0 100644
--- a/full/src/main/java/de/ids_mannheim/korap/constant/PredefinedRole.java
+++ b/full/src/main/java/de/ids_mannheim/korap/constant/PredefinedRole.java
@@ -1,5 +1,10 @@
package de.ids_mannheim.korap.constant;
+/** Defines some predefined roles used in the system.
+ *
+ * @author margaretha
+ *
+ */
public enum PredefinedRole {
USER_GROUP_ADMIN(1), USER_GROUP_MEMBER(2), VC_ACCESS_ADMIN(3), VC_ACCESS_MEMBER(4);
diff --git a/full/src/main/java/de/ids_mannheim/korap/constant/PrivilegeType.java b/full/src/main/java/de/ids_mannheim/korap/constant/PrivilegeType.java
index ad05f18..f9900b3 100644
--- a/full/src/main/java/de/ids_mannheim/korap/constant/PrivilegeType.java
+++ b/full/src/main/java/de/ids_mannheim/korap/constant/PrivilegeType.java
@@ -1,5 +1,15 @@
package de.ids_mannheim.korap.constant;
+import de.ids_mannheim.korap.entity.Privilege;
+import de.ids_mannheim.korap.entity.Role;
+
+/** Defines the privilege or permissions of users or admins
+ * based on their roles.
+ *
+ * @author margaretha
+ * @see Privilege
+ * @see Role
+ */
public enum PrivilegeType {
READ, WRITE, DELETE;
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/constant/UserGroupStatus.java b/full/src/main/java/de/ids_mannheim/korap/constant/UserGroupStatus.java
index 5cb939e..a1507ed 100644
--- a/full/src/main/java/de/ids_mannheim/korap/constant/UserGroupStatus.java
+++ b/full/src/main/java/de/ids_mannheim/korap/constant/UserGroupStatus.java
@@ -1,5 +1,12 @@
package de.ids_mannheim.korap.constant;
+import de.ids_mannheim.korap.entity.UserGroup;
+
+/** Defines possible statuses of {@link UserGroup}s
+ *
+ * @author margaretha
+ *
+ */
public enum UserGroupStatus {
ACTIVE, DELETED,
// group members cannot see the group
diff --git a/full/src/main/java/de/ids_mannheim/korap/constant/VirtualCorpusAccessStatus.java b/full/src/main/java/de/ids_mannheim/korap/constant/VirtualCorpusAccessStatus.java
index 381ae4c..0b0ab0d 100644
--- a/full/src/main/java/de/ids_mannheim/korap/constant/VirtualCorpusAccessStatus.java
+++ b/full/src/main/java/de/ids_mannheim/korap/constant/VirtualCorpusAccessStatus.java
@@ -1,8 +1,17 @@
package de.ids_mannheim.korap.constant;
+import de.ids_mannheim.korap.entity.VirtualCorpusAccess;
+
+/** Defines possible statusess of {@link VirtualCorpusAccess}
+ *
+ * @author margaretha
+ * @see VirtualCorpusAccess
+ *
+ */
public enum VirtualCorpusAccessStatus {
ACTIVE, DELETED,
+ // has not been used yet
PENDING,
// access for hidden group
// maybe not necessary?
diff --git a/full/src/main/java/de/ids_mannheim/korap/constant/VirtualCorpusType.java b/full/src/main/java/de/ids_mannheim/korap/constant/VirtualCorpusType.java
index 0072c67..5abd54c 100644
--- a/full/src/main/java/de/ids_mannheim/korap/constant/VirtualCorpusType.java
+++ b/full/src/main/java/de/ids_mannheim/korap/constant/VirtualCorpusType.java
@@ -1,5 +1,12 @@
package de.ids_mannheim.korap.constant;
+import de.ids_mannheim.korap.entity.VirtualCorpus;
+
+/** Defines types of {@link VirtualCorpus}
+ *
+ * @author margaretha
+ *
+ */
public enum VirtualCorpusType {
// available for all
PREDEFINED,
diff --git a/full/src/main/java/de/ids_mannheim/korap/dao/PrivilegeDao.java b/full/src/main/java/de/ids_mannheim/korap/dao/PrivilegeDao.java
index 874850a..8bd533d 100644
--- a/full/src/main/java/de/ids_mannheim/korap/dao/PrivilegeDao.java
+++ b/full/src/main/java/de/ids_mannheim/korap/dao/PrivilegeDao.java
@@ -18,6 +18,16 @@
import de.ids_mannheim.korap.entity.Role;
import de.ids_mannheim.korap.entity.Role_;
+/** Manages database transactions regarding {@link Privilege} entity or
+ * database table.
+ *
+ * @see Privilege
+ * @see PrivilegeType
+ * @see Role
+ *
+ * @author margaretha
+ *
+ */
@Transactional
@Repository
public class PrivilegeDao {
diff --git a/full/src/main/java/de/ids_mannheim/korap/dao/RoleDao.java b/full/src/main/java/de/ids_mannheim/korap/dao/RoleDao.java
index 6cbfaa1..b02a283 100644
--- a/full/src/main/java/de/ids_mannheim/korap/dao/RoleDao.java
+++ b/full/src/main/java/de/ids_mannheim/korap/dao/RoleDao.java
@@ -20,6 +20,12 @@
import de.ids_mannheim.korap.entity.UserGroupMember;
import de.ids_mannheim.korap.entity.UserGroupMember_;
+/** Manages database transactions regarding {@link Role} entity or database table.
+ *
+ * @author margaretha
+ * @see Role
+ * @see PrivilegeDao
+ */
@Transactional
@Repository
public class RoleDao {
@@ -28,7 +34,7 @@
private EntityManager entityManager;
@Autowired
- PrivilegeDao privilegeDao;
+ private PrivilegeDao privilegeDao;
public void createRole (String name, List<PrivilegeType> privilegeTypes) {
Role r = new Role();
diff --git a/full/src/main/java/de/ids_mannheim/korap/dao/UserGroupDao.java b/full/src/main/java/de/ids_mannheim/korap/dao/UserGroupDao.java
index 72c856a..43eee36 100644
--- a/full/src/main/java/de/ids_mannheim/korap/dao/UserGroupDao.java
+++ b/full/src/main/java/de/ids_mannheim/korap/dao/UserGroupDao.java
@@ -35,6 +35,14 @@
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.utils.ParameterChecker;
+/** Manages database transactions regarding {@link UserGroup} entity and
+ * database table.
+ *
+ * @author margaretha
+ *
+ * @see UserGroup
+ *
+ */
@Transactional
@Repository
public class UserGroupDao {
diff --git a/full/src/main/java/de/ids_mannheim/korap/dao/UserGroupMemberDao.java b/full/src/main/java/de/ids_mannheim/korap/dao/UserGroupMemberDao.java
index d2ffe28..ae58ec6 100644
--- a/full/src/main/java/de/ids_mannheim/korap/dao/UserGroupMemberDao.java
+++ b/full/src/main/java/de/ids_mannheim/korap/dao/UserGroupMemberDao.java
@@ -24,6 +24,13 @@
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.utils.ParameterChecker;
+/** Manages database transactions regarding {@link UserGroupMember} entity and
+ * database table.
+ *
+ * @author margaretha
+ * @see UserGroupMember
+ *
+ */
@Transactional
@Repository
public class UserGroupMemberDao {
diff --git a/full/src/main/java/de/ids_mannheim/korap/dao/VirtualCorpusAccessDao.java b/full/src/main/java/de/ids_mannheim/korap/dao/VirtualCorpusAccessDao.java
index 82678cf..00eb460 100644
--- a/full/src/main/java/de/ids_mannheim/korap/dao/VirtualCorpusAccessDao.java
+++ b/full/src/main/java/de/ids_mannheim/korap/dao/VirtualCorpusAccessDao.java
@@ -25,6 +25,14 @@
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.utils.ParameterChecker;
+/** Manages database transactions regarding {@link VirtualCorpusAccess} entity
+ * and its corresponding database table.
+ *
+ * @author margaretha
+ *
+ * @see VirtualCorpusAccess
+ * @see VirtualCorpus
+ */
@Transactional
@Repository
public class VirtualCorpusAccessDao {
diff --git a/full/src/main/java/de/ids_mannheim/korap/dto/UserGroupDto.java b/full/src/main/java/de/ids_mannheim/korap/dto/UserGroupDto.java
index 82f05eb..8d64c09 100644
--- a/full/src/main/java/de/ids_mannheim/korap/dto/UserGroupDto.java
+++ b/full/src/main/java/de/ids_mannheim/korap/dto/UserGroupDto.java
@@ -8,6 +8,12 @@
import lombok.Getter;
import lombok.Setter;
+/** Defines the structure of UserGroup description, e.g.
+ * to be sent as JSON objects in HTTP response.
+ *
+ * @author margaretha
+ *
+ */
@Setter
@Getter
public class UserGroupDto {
diff --git a/full/src/main/java/de/ids_mannheim/korap/dto/UserGroupMemberDto.java b/full/src/main/java/de/ids_mannheim/korap/dto/UserGroupMemberDto.java
index 1a5eda3..bf3cfea 100644
--- a/full/src/main/java/de/ids_mannheim/korap/dto/UserGroupMemberDto.java
+++ b/full/src/main/java/de/ids_mannheim/korap/dto/UserGroupMemberDto.java
@@ -6,6 +6,11 @@
import lombok.Getter;
import lombok.Setter;
+/** Defines UserGroupMember description, e.g. to be sent as
+ * JSON objects in HTTP Responses.
+ * @author margaretha
+ *
+ */
@Setter
@Getter
public class UserGroupMemberDto {
diff --git a/full/src/main/java/de/ids_mannheim/korap/dto/VirtualCorpusAccessDto.java b/full/src/main/java/de/ids_mannheim/korap/dto/VirtualCorpusAccessDto.java
index 93875ee..74d0df6 100644
--- a/full/src/main/java/de/ids_mannheim/korap/dto/VirtualCorpusAccessDto.java
+++ b/full/src/main/java/de/ids_mannheim/korap/dto/VirtualCorpusAccessDto.java
@@ -3,6 +3,10 @@
import lombok.Getter;
import lombok.Setter;
+/**
+ * @author margaretha
+ *
+ */
@Getter
@Setter
public class VirtualCorpusAccessDto {
diff --git a/full/src/main/java/de/ids_mannheim/korap/dto/VirtualCorpusDto.java b/full/src/main/java/de/ids_mannheim/korap/dto/VirtualCorpusDto.java
index f69f19d..d44ade7 100644
--- a/full/src/main/java/de/ids_mannheim/korap/dto/VirtualCorpusDto.java
+++ b/full/src/main/java/de/ids_mannheim/korap/dto/VirtualCorpusDto.java
@@ -1,8 +1,15 @@
package de.ids_mannheim.korap.dto;
+import de.ids_mannheim.korap.entity.VirtualCorpus;
import lombok.Getter;
import lombok.Setter;
+/** Defines the structure of {@link VirtualCorpus} description to be
+ * sent as JSON objects in HTTP responses.
+ *
+ * @author margaretha
+ *
+ */
@Getter
@Setter
public class VirtualCorpusDto {
diff --git a/full/src/main/java/de/ids_mannheim/korap/dto/converter/UserGroupConverter.java b/full/src/main/java/de/ids_mannheim/korap/dto/converter/UserGroupConverter.java
index 0d61db3..9dd4df9 100644
--- a/full/src/main/java/de/ids_mannheim/korap/dto/converter/UserGroupConverter.java
+++ b/full/src/main/java/de/ids_mannheim/korap/dto/converter/UserGroupConverter.java
@@ -12,6 +12,13 @@
import de.ids_mannheim.korap.entity.UserGroup;
import de.ids_mannheim.korap.entity.UserGroupMember;
+/** Manages conversion of {@link UserGroup} objects to their data access objects (DTO),
+ * e.g. UserGroupDto. DTO structure defines controllers output, namely the structure of
+ * JSON objects in HTTP responses.
+ *
+ * @author margaretha
+ *
+ */
@Component
public class UserGroupConverter {
@@ -39,7 +46,8 @@
UserGroupMemberDto memberDto = new UserGroupMemberDto();
memberDto.setUserId(member.getUserId());
memberDto.setStatus(member.getStatus());
- List<String> memberRoles = new ArrayList<>(member.getRoles().size());
+ List<String> memberRoles =
+ new ArrayList<>(member.getRoles().size());
for (Role r : member.getRoles()) {
memberRoles.add(r.getName());
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/handlers/EntityDao.java b/full/src/main/java/de/ids_mannheim/korap/handlers/EntityDao.java
index 8577a1b..35c7cbc 100644
--- a/full/src/main/java/de/ids_mannheim/korap/handlers/EntityDao.java
+++ b/full/src/main/java/de/ids_mannheim/korap/handlers/EntityDao.java
@@ -7,7 +7,7 @@
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.exceptions.DatabaseException;
-import de.ids_mannheim.korap.interfaces.db.EntityHandlerIface;
+import de.ids_mannheim.korap.interfaces.EntityHandlerIface;
import de.ids_mannheim.korap.interfaces.db.PersistenceClient;
import de.ids_mannheim.korap.user.KorAPUser;
import de.ids_mannheim.korap.user.ShibUser;
diff --git a/full/src/main/java/de/ids_mannheim/korap/interfaces/EntityHandlerIface.java b/full/src/main/java/de/ids_mannheim/korap/interfaces/EntityHandlerIface.java
new file mode 100644
index 0000000..9bcf614
--- /dev/null
+++ b/full/src/main/java/de/ids_mannheim/korap/interfaces/EntityHandlerIface.java
@@ -0,0 +1,36 @@
+package de.ids_mannheim.korap.interfaces;
+
+import de.ids_mannheim.korap.exceptions.EmptyResultException;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.user.User;
+
+/**
+ * User: hanl
+ * Date: 8/19/13
+ * Time: 11:04 AM
+ */
+public interface EntityHandlerIface {
+
+ User getAccount (String username) throws EmptyResultException,
+ KustvaktException;
+
+
+ int updateAccount (User user) throws KustvaktException;
+
+
+ int createAccount (User user) throws KustvaktException;
+
+
+ int deleteAccount (Integer userid) throws KustvaktException;
+
+
+ int truncate () throws KustvaktException;
+
+
+ int resetPassphrase (String username, String uriToken, String passphrase)
+ throws KustvaktException;
+
+
+ int activateAccount (String username, String uriToken)
+ throws KustvaktException;
+}
diff --git a/full/src/main/java/de/ids_mannheim/korap/rewrite/FullRewriteHandler.java b/full/src/main/java/de/ids_mannheim/korap/rewrite/FullRewriteHandler.java
index c65d89f..a353064 100644
--- a/full/src/main/java/de/ids_mannheim/korap/rewrite/FullRewriteHandler.java
+++ b/full/src/main/java/de/ids_mannheim/korap/rewrite/FullRewriteHandler.java
@@ -6,6 +6,11 @@
import de.ids_mannheim.korap.resource.rewrite.IdWriter;
import de.ids_mannheim.korap.resource.rewrite.RewriteHandler;
+/** Defines rewrite handling methods relevant only in full version.
+ *
+ * @author margaretha
+ *
+ */
public class FullRewriteHandler extends RewriteHandler{
public FullRewriteHandler (FullConfiguration config) {
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/controller/AnnotationController.java b/full/src/main/java/de/ids_mannheim/korap/web/controller/AnnotationController.java
index 8af6516..a49c276 100644
--- a/full/src/main/java/de/ids_mannheim/korap/web/controller/AnnotationController.java
+++ b/full/src/main/java/de/ids_mannheim/korap/web/controller/AnnotationController.java
@@ -39,9 +39,6 @@
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public class AnnotationController {
- private static Logger jlog =
- LoggerFactory.getLogger(AnnotationController.class);
-
@Autowired
CoreResponseHandler responseHandler;
diff --git a/full/src/main/resources/default-config.xml b/full/src/main/resources/default-config.xml
index 1ef5429..e901b2a 100644
--- a/full/src/main/resources/default-config.xml
+++ b/full/src/main/resources/default-config.xml
@@ -261,7 +261,7 @@
<bean id="kustvakt_authenticationmanager"
class="de.ids_mannheim.korap.authentication.KustvaktAuthenticationManager">
<constructor-arg
- type="de.ids_mannheim.korap.interfaces.db.EntityHandlerIface" ref="kustvakt_userdb" />
+ type="de.ids_mannheim.korap.interfaces.EntityHandlerIface" ref="kustvakt_userdb" />
<constructor-arg type="de.ids_mannheim.korap.interfaces.EncryptionIface"
ref="kustvakt_encryption" />
<constructor-arg ref="kustvakt_config" />
diff --git a/full/src/test/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManagerTest.java b/full/src/test/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManagerTest.java
similarity index 75%
rename from full/src/test/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManagerTest.java
rename to full/src/test/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManagerTest.java
index efdb76e..d29960b 100644
--- a/full/src/test/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManagerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManagerTest.java
@@ -1,6 +1,5 @@
-package de.ids_mannheim.korap.security.auth;
+package de.ids_mannheim.korap.authentication;
-import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.After;
@@ -10,11 +9,9 @@
import de.ids_mannheim.korap.config.Attributes;
import de.ids_mannheim.korap.config.BeanConfigTest;
-import de.ids_mannheim.korap.config.KustvaktBaseDaoInterface;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.interfaces.AuthenticationManagerIface;
-import de.ids_mannheim.korap.interfaces.db.EntityHandlerIface;
import de.ids_mannheim.korap.user.KorAPUser;
import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.user.UserDetails;
@@ -45,20 +42,6 @@
catch (KustvaktException e) {}
}
-
- @Test
- @Ignore
- public void testCreateUser () throws KustvaktException {
- User user = authManager
- .createUserAccount(KustvaktConfiguration.KUSTVAKT_USER, false);
-
- EntityHandlerIface dao = helper().getContext().getUserDBHandler();
- assertNotEquals(0, ((KustvaktBaseDaoInterface) dao).size());
- User check = dao.getAccount(user.getUsername());
- assertNotNull(check);
- }
-
-
@Test
public void testBatchStore () {
int i = 6;
@@ -73,8 +56,6 @@
@Test
@Ignore
public void testUserdetailsGet () throws KustvaktException {
- testCreateUser();
-
User user = authManager
.getUser((String) KustvaktConfiguration.KUSTVAKT_USER
.get(Attributes.USERNAME));
@@ -87,8 +68,6 @@
@Test
@Ignore
public void testUsersettingsGet () throws KustvaktException {
- testCreateUser();
-
User user = authManager
.getUser((String) KustvaktConfiguration.KUSTVAKT_USER
.get(Attributes.USERNAME));
@@ -100,8 +79,6 @@
@Test(expected = KustvaktException.class)
public void testUserDetailsGetNonExistent () throws KustvaktException {
- testCreateUser();
-
User user = new KorAPUser(10, "random");
authManager.getUserData(user, UserDetails.class);
}
@@ -109,19 +86,10 @@
@Test(expected = KustvaktException.class)
public void testUserSettingsGetNonExistent () throws KustvaktException {
- testCreateUser();
-
User user = new KorAPUser(10, "random");
authManager.getUserData(user, UserSettings.class);
}
- @Test
- @Ignore
- public void testUserUpdate() throws KustvaktException {
- testCreateUser();
- // todo:
- }
-
@Override
public void initMethod () throws KustvaktException {
diff --git a/full/src/test/java/de/ids_mannheim/korap/config/TestBeans.java b/full/src/test/java/de/ids_mannheim/korap/config/TestBeans.java
index 3bbdb4f..6ef8f65 100644
--- a/full/src/test/java/de/ids_mannheim/korap/config/TestBeans.java
+++ b/full/src/test/java/de/ids_mannheim/korap/config/TestBeans.java
@@ -4,9 +4,8 @@
import de.ids_mannheim.korap.interfaces.AuthenticationManagerIface;
import de.ids_mannheim.korap.interfaces.EncryptionIface;
+import de.ids_mannheim.korap.interfaces.EntityHandlerIface;
import de.ids_mannheim.korap.interfaces.db.AuditingIface;
-import de.ids_mannheim.korap.interfaces.db.EntityHandlerIface;
-import de.ids_mannheim.korap.interfaces.db.PolicyHandlerIface;
import de.ids_mannheim.korap.interfaces.db.ResourceOperationIface;
import de.ids_mannheim.korap.interfaces.db.UserDataDbIface;
@@ -16,8 +15,6 @@
*/
public interface TestBeans {
- public PolicyHandlerIface getPolicyDao();
-
// public KustvaktConfiguration getConfig();
public EntityHandlerIface getUserDao();
@@ -32,6 +29,4 @@
public AuthenticationManagerIface getAuthManager();
-
-
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/config/TestHelper.java b/full/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
index b53cc6f..a2b9d72 100644
--- a/full/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
+++ b/full/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
@@ -33,7 +33,7 @@
import de.ids_mannheim.korap.handlers.JDBCClient;
import de.ids_mannheim.korap.handlers.ResourceDao;
import de.ids_mannheim.korap.interfaces.EncryptionIface;
-import de.ids_mannheim.korap.interfaces.db.EntityHandlerIface;
+import de.ids_mannheim.korap.interfaces.EntityHandlerIface;
import de.ids_mannheim.korap.interfaces.db.PersistenceClient;
import de.ids_mannheim.korap.resources.KustvaktResource;
import de.ids_mannheim.korap.user.User;
@@ -119,48 +119,49 @@
return this;
}
-
- public TestHelper setupSimpleAccount (String username, String password) {
- KustvaktBaseDaoInterface dao = getBean(ContextHolder.KUSTVAKT_USERDB);
- EntityHandlerIface edao = (EntityHandlerIface) dao;
- try {
- edao.getAccount(username);
- }
- catch (EmptyResultException e) {
- // do nothing
- }
- catch (KustvaktException ex) {
- assertNull("Test user could not be set up", true);
- }
-
- Map m = new HashMap<>();
- m.put(Attributes.USERNAME, username);
-
- try {
- String hash = ((EncryptionIface) getBean(ContextHolder.KUSTVAKT_ENCRYPTION))
- .secureHash(password);
- m.put(Attributes.PASSWORD, hash);
- }
- catch (NoSuchAlgorithmException | UnsupportedEncodingException
- | KustvaktException e) {
- // do nohting
- assertNotNull("Exception thrown", null);
- }
- assertNotNull("userdatabase handler must not be null", dao);
-
- try {
-
- int i = edao.createAccount(User.UserFactory.toKorAPUser(m));
- assert BeansFactory.getKustvaktContext().getUserDBHandler()
- .getAccount((String) data.get(Attributes.USERNAME)) != null;
- assertEquals(1, i);
- }
- catch (KustvaktException e) {
- // do nothing
- assertNull("Test user could not be set up", true);
- }
- return this;
- }
+ // EM
+ @Deprecated
+// public TestHelper setupSimpleAccount (String username, String password) {
+// KustvaktBaseDaoInterface dao = getBean(ContextHolder.KUSTVAKT_USERDB);
+// EntityHandlerIface edao = (EntityHandlerIface) dao;
+// try {
+// edao.getAccount(username);
+// }
+// catch (EmptyResultException e) {
+// // do nothing
+// }
+// catch (KustvaktException ex) {
+// assertNull("Test user could not be set up", true);
+// }
+//
+// Map m = new HashMap<>();
+// m.put(Attributes.USERNAME, username);
+//
+// try {
+// String hash = ((EncryptionIface) getBean(ContextHolder.KUSTVAKT_ENCRYPTION))
+// .secureHash(password);
+// m.put(Attributes.PASSWORD, hash);
+// }
+// catch (NoSuchAlgorithmException | UnsupportedEncodingException
+// | KustvaktException e) {
+// // do nohting
+// assertNotNull("Exception thrown", null);
+// }
+// assertNotNull("userdatabase handler must not be null", dao);
+//
+// try {
+//
+// int i = edao.createAccount(User.UserFactory.toKorAPUser(m));
+// assert BeansFactory.getKustvaktContext().getUserDBHandler()
+// .getAccount((String) data.get(Attributes.USERNAME)) != null;
+// assertEquals(1, i);
+// }
+// catch (KustvaktException e) {
+// // do nothing
+// assertNull("Test user could not be set up", true);
+// }
+// return this;
+// }
public User getUser () {
diff --git a/full/src/test/java/de/ids_mannheim/korap/handlers/UserDaoTest.java b/full/src/test/java/de/ids_mannheim/korap/handlers/UserDaoTest.java
deleted file mode 100644
index 48b6d5c..0000000
--- a/full/src/test/java/de/ids_mannheim/korap/handlers/UserDaoTest.java
+++ /dev/null
@@ -1,116 +0,0 @@
-package de.ids_mannheim.korap.handlers;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-import org.junit.Ignore;
-import org.junit.Test;
-
-import de.ids_mannheim.korap.config.Attributes;
-import de.ids_mannheim.korap.config.BeansFactory;
-import de.ids_mannheim.korap.config.BeanConfigTest;
-import de.ids_mannheim.korap.config.TestHelper;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.interfaces.db.EntityHandlerIface;
-import de.ids_mannheim.korap.interfaces.db.UserDataDbIface;
-import de.ids_mannheim.korap.user.User;
-import de.ids_mannheim.korap.user.UserDetails;
-import de.ids_mannheim.korap.user.UserSettings;
-import de.ids_mannheim.korap.user.Userdata;
-
-/** EM: To do: not implemented in the new DB yet
- *
- * @author hanl
- * @date 13/02/2015
- */
-@Ignore
-public class UserDaoTest extends BeanConfigTest {
-
- @Test
- public void userput () throws KustvaktException {
- User user1 = helper().getContext().getUserDBHandler()
- .getAccount((String) TestHelper.getUserCredentials().get(Attributes.USERNAME));
- assertEquals("user creation failed", true, user1.getId() != -1);
- }
-
-
- @Test
- public void userputBatch () {
- //todo:
- }
-
-
- @Test
- public void userget () throws KustvaktException {
- User user1 = helper().getContext().getUserDBHandler()
- .getAccount((String) TestHelper.getUserCredentials().get(Attributes.USERNAME));
- assertEquals("User Retrieval does not work",
- TestHelper.getUserCredentials().get(Attributes.USERNAME), user1.getUsername());
- }
-
-
- @Test
- @Ignore
- public void testUserdetailsGetNonExistent () throws KustvaktException {
- helper().setupSimpleAccount("userdbtest", "userdbTest");
- User user = helper().getContext().getUserDBHandler()
- .getAccount("userdbtest");
- UserDataDbIface dao = BeansFactory.getTypeFactory()
- .getTypeInterfaceBean(
- helper().getContext().getUserDataProviders(),
- UserDetails.class);
- Userdata data = dao.get(user);
- assertNull(data);
- helper().dropUser("userdbtest");
- }
-
-
- @Test
- @Ignore
- public void testUserSettingsGetNonExistent () throws KustvaktException {
- helper().setupSimpleAccount("userdbtest", "userdbTest");
- User user = helper().getContext().getUserDBHandler()
- .getAccount("userdbtest");
- UserDataDbIface dao = BeansFactory.getTypeFactory()
- .getTypeInterfaceBean(
- helper().getContext().getUserDataProviders(),
- UserSettings.class);
- Userdata data = dao.get(user);
- assertNull(data);
- helper().dropUser("userdbtest");
-
- }
-
-
- // username cannot currently be changed
- @Test
- @Ignore
- public void updateUsername () throws KustvaktException {
- User user1 = helper().getContext().getUserDBHandler()
- .getAccount((String) TestHelper.getUserCredentials().get(Attributes.USERNAME));
- user1.setUsername("new_user");
- helper().getContext().getUserDBHandler().updateAccount(user1);
- User u2 = helper().getContext().getUserDBHandler()
- .getAccount("new_user");
- assertEquals("not found", user1.getUsername(), u2.getUsername());
- }
-
-
- @Test
- public void userupdate () throws KustvaktException {
- EntityHandlerIface dao = helper().getContext().getUserDBHandler();
- User user1 = dao.getAccount((String) TestHelper.getUserCredentials()
- .get(Attributes.USERNAME));
- user1.setAccountLocked(true);
- dao.updateAccount(user1);
- assertEquals("not valid", true, dao.getAccount(user1.getUsername())
- .isAccountLocked());
- }
-
-
- @Override
- public void initMethod () throws KustvaktException {
- helper().setupAccount();
-// helper().runBootInterfaces();
- }
-}
diff --git a/full/src/test/java/de/ids_mannheim/korap/security/PermissionBufferTest.java b/full/src/test/java/de/ids_mannheim/korap/security/PermissionBufferTest.java
deleted file mode 100644
index 68e874a..0000000
--- a/full/src/test/java/de/ids_mannheim/korap/security/PermissionBufferTest.java
+++ /dev/null
@@ -1,209 +0,0 @@
-package de.ids_mannheim.korap.security;
-
-import de.ids_mannheim.korap.resources.Permissions;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * @author hanl
- * @date 15/02/2016
- */
-public class PermissionBufferTest {
-
- @Test
- public void testDuplicatePermission () {
- PermissionsBuffer buffer = new PermissionsBuffer();
- assertEquals(0, buffer.addPermission(4));
- assertEquals(-1, buffer.addPermission(4));
-
- // 0 means permission was successfully added, -1 means it wasn't because it's already present
- assertEquals(0, buffer.addPermission(1));
- assertEquals(-1, buffer.addPermission(1));
-
- assertEquals(0, buffer.addPermission(8));
- assertEquals(-1, buffer.addPermission(4));
- }
-
-
- @Test
- public void testPermissionsAdd () {
- PermissionsBuffer buffer = new PermissionsBuffer();
- buffer.addPermissions(Permissions.Permission.READ);
- assertEquals(1, buffer.getPermissions().size());
-
- assertTrue(buffer.containsPByte(Permissions.Permission.READ.toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.WRITE.toByte()));
- assertFalse(buffer
- .containsPByte(Permissions.Permission.DELETE.toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.READ_POLICY
- .toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.DELETE_POLICY
- .toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.MODIFY_POLICY
- .toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.CREATE_POLICY
- .toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.ALL.toByte()));
-
- buffer = new PermissionsBuffer();
- buffer.addPermissions(Permissions.Permission.WRITE);
- buffer.addPermissions(Permissions.Permission.DELETE_POLICY);
- assertEquals(2, buffer.getPermissions().size());
- assertFalse(buffer.containsPByte(Permissions.Permission.READ.toByte()));
- assertTrue(buffer.containsPByte(Permissions.Permission.WRITE.toByte()));
- assertFalse(buffer
- .containsPByte(Permissions.Permission.DELETE.toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.READ_POLICY
- .toByte()));
- assertTrue(buffer.containsPByte(Permissions.Permission.DELETE_POLICY
- .toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.MODIFY_POLICY
- .toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.CREATE_POLICY
- .toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.ALL.toByte()));
- }
-
-
- @Test
- public void testPermissionsAddAll2 () {
- PermissionsBuffer buffer = new PermissionsBuffer();
- buffer.addPermissions(Permissions.Permission.ALL);
-
- assertEquals(Permissions.Permission.values().length, buffer
- .getPermissions().size());
- assertTrue(buffer.containsPByte(Permissions.Permission.READ.toByte()));
- assertTrue(buffer.containsPByte(Permissions.Permission.WRITE.toByte()));
- assertTrue(buffer.containsPByte(Permissions.Permission.DELETE.toByte()));
- assertTrue(buffer.containsPByte(Permissions.Permission.READ_POLICY
- .toByte()));
- assertTrue(buffer.containsPByte(Permissions.Permission.DELETE_POLICY
- .toByte()));
- assertTrue(buffer.containsPByte(Permissions.Permission.MODIFY_POLICY
- .toByte()));
- assertTrue(buffer.containsPByte(Permissions.Permission.CREATE_POLICY
- .toByte()));
- assertTrue(buffer.containsPByte(Permissions.Permission.ALL.toByte()));
- }
-
-
- @Test
- public void testPermissionsAddAll () {
- PermissionsBuffer buffer = new PermissionsBuffer();
- buffer.addPermissions(Permissions.Permission.DELETE_POLICY);
- buffer.addPermissions(Permissions.Permission.CREATE_POLICY);
- buffer.addPermissions(Permissions.Permission.READ);
- buffer.addPermissions(Permissions.Permission.MODIFY_POLICY);
- buffer.addPermissions(Permissions.Permission.DELETE);
- buffer.addPermissions(Permissions.Permission.READ_POLICY);
- buffer.addPermissions(Permissions.Permission.WRITE);
-
- assertEquals(Permissions.Permission.values().length, buffer
- .getPermissions().size());
- assertTrue(buffer.containsPByte(Permissions.Permission.READ.toByte()));
- assertTrue(buffer.containsPByte(Permissions.Permission.WRITE.toByte()));
- assertTrue(buffer.containsPByte(Permissions.Permission.DELETE.toByte()));
- assertTrue(buffer.containsPByte(Permissions.Permission.READ_POLICY
- .toByte()));
- assertTrue(buffer.containsPByte(Permissions.Permission.DELETE_POLICY
- .toByte()));
- assertTrue(buffer.containsPByte(Permissions.Permission.MODIFY_POLICY
- .toByte()));
- assertTrue(buffer.containsPByte(Permissions.Permission.CREATE_POLICY
- .toByte()));
- assertTrue(buffer.containsPByte(Permissions.Permission.ALL.toByte()));
-
- }
-
-
- @Test
- public void testPermissionsInit () {
- PermissionsBuffer buffer = new PermissionsBuffer((short) 1);
- assertEquals(1, buffer.getPermissions().size());
-
- assertTrue(buffer.containsPByte(Permissions.Permission.READ.toByte()));
- assertFalse(buffer
- .containsPByte(Permissions.Permission.DELETE.toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.WRITE.toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.READ_POLICY
- .toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.DELETE_POLICY
- .toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.MODIFY_POLICY
- .toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.CREATE_POLICY
- .toByte()));
-
- }
-
-
- @Test
- public void testPermissionsStringConversion () {
- PermissionsBuffer buffer = new PermissionsBuffer(Short.valueOf("1"));
- assertEquals(1, buffer.getPermissions().size());
-
- assertTrue(buffer.containsPByte(Permissions.Permission.READ.toByte()));
- assertFalse(buffer
- .containsPByte(Permissions.Permission.DELETE.toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.WRITE.toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.READ_POLICY
- .toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.DELETE_POLICY
- .toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.MODIFY_POLICY
- .toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.CREATE_POLICY
- .toByte()));
-
- buffer = new PermissionsBuffer(Short.valueOf("5"));
- assertTrue(buffer.containsPByte(Permissions.Permission.READ.toByte()));
- assertTrue(buffer.containsPByte(Permissions.Permission.DELETE.toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.WRITE.toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.READ_POLICY
- .toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.DELETE_POLICY
- .toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.MODIFY_POLICY
- .toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.CREATE_POLICY
- .toByte()));
-
- buffer = new PermissionsBuffer(Short.valueOf("69"));
- assertTrue(buffer.containsPByte(Permissions.Permission.READ.toByte()));
- assertTrue(buffer.containsPByte(Permissions.Permission.DELETE.toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.WRITE.toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.READ_POLICY
- .toByte()));
- assertTrue(buffer.containsPByte(Permissions.Permission.DELETE_POLICY
- .toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.MODIFY_POLICY
- .toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.CREATE_POLICY
- .toByte()));
- }
-
-
- @Test
- public void testPermissionRemovalOne () {
- PermissionsBuffer buffer = new PermissionsBuffer();
- buffer.addPermissions(Permissions.Permission.READ,
- Permissions.Permission.DELETE,
- Permissions.Permission.MODIFY_POLICY);
-
- assertTrue(buffer.containsPByte(Permissions.Permission.READ.toByte()));
- assertTrue(buffer.containsPByte(Permissions.Permission.DELETE.toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.WRITE.toByte()));
- assertTrue(buffer.containsPByte(Permissions.Permission.MODIFY_POLICY
- .toByte()));
-
- buffer.removePermission(Permissions.Permission.MODIFY_POLICY);
-
- assertTrue(buffer.containsPByte(Permissions.Permission.READ.toByte()));
- assertTrue(buffer.containsPByte(Permissions.Permission.DELETE.toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.WRITE.toByte()));
- assertFalse(buffer.containsPByte(Permissions.Permission.MODIFY_POLICY
- .toByte()));
- }
-
-}
diff --git a/full/src/test/java/de/ids_mannheim/korap/security/PolicyBenchmarkTest.java b/full/src/test/java/de/ids_mannheim/korap/security/PolicyBenchmarkTest.java
deleted file mode 100644
index 6804770..0000000
--- a/full/src/test/java/de/ids_mannheim/korap/security/PolicyBenchmarkTest.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package de.ids_mannheim.korap.security;
-
-/**
- * @author hanl
- * @date 09/02/2016
- */
-public class PolicyBenchmarkTest {
-
-
-}
diff --git a/full/src/test/java/de/ids_mannheim/korap/security/SecurityPolicyTest.java b/full/src/test/java/de/ids_mannheim/korap/security/SecurityPolicyTest.java
deleted file mode 100644
index f309543..0000000
--- a/full/src/test/java/de/ids_mannheim/korap/security/SecurityPolicyTest.java
+++ /dev/null
@@ -1,156 +0,0 @@
-package de.ids_mannheim.korap.security;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.junit.Ignore;
-import org.junit.Test;
-
-import de.ids_mannheim.korap.config.BeanConfigTest;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.interfaces.db.PolicyHandlerIface;
-import de.ids_mannheim.korap.resources.Corpus;
-import de.ids_mannheim.korap.resources.Permissions;
-
-/** EM: Not supported in the current implementation (new DB)
- *
- * @author hanl
- * @date 12/02/2016
- */
-@Deprecated
-@Ignore
-public class SecurityPolicyTest extends BeanConfigTest {
-
- @Test
- public void testConditionUpdate () {
- SecurityPolicy policy = new SecurityPolicy();
- policy.addNewCondition(new PolicyCondition("test_1"));
- policy.addNewCondition(new PolicyCondition("test_2"));
- policy.setCreator(1);
- policy.setTarget(new Corpus("WPD"));
- policy.addPermission(Permissions.Permission.READ);
-
- assertEquals(2, policy.getAdded().size());
- policy.removeCondition(new PolicyCondition("test_1"));
- assertEquals(1, policy.getAdded().size());
- }
-
-
- @Test
- public void testConditionMapping () throws KustvaktException {
- helper().setupResource(new Corpus("WPD_2"));
- SecurityPolicy policy = new SecurityPolicy();
- policy.addNewCondition(new PolicyCondition("test_1"));
- policy.addNewCondition(new PolicyCondition("test_2"));
- policy.setCreator(1);
- policy.setTarget(new Corpus("WPD_2"));
- policy.addPermission(Permissions.Permission.READ);
-
- PolicyHandlerIface dao = helper().getContext().getPolicyDbProvider();
- dao.createPolicy(policy, helper().getUser());
-
- List<SecurityPolicy>[] list = dao.getPolicies("WPD_2",
- helper().getUser(), Permissions.Permission.READ.toByte());
- assertNotNull(list);
- List<SecurityPolicy> policies = list[0];
- assertNotNull(policies);
- assertFalse(policies.isEmpty());
- assertEquals(2, policies.size());
- assertTrue(policies.get(0) instanceof SecurityPolicy.OwnerPolicy);
- policy = policies.get(1);
- assertEquals(2, policy.getConditions().size());
- policy.removeCondition(new PolicyCondition("test_1"));
- assertEquals(1, policy.getRemoved().size());
- assertTrue(policy.getAdded().isEmpty());
- }
-
-
- @Test
- public void testPersistingPermissionMapping () throws KustvaktException {
- helper().setupResource(new Corpus("WPD_3"));
- SecurityPolicy policy = new SecurityPolicy();
- policy.addNewCondition(new PolicyCondition("test_1"));
- policy.addNewCondition(new PolicyCondition("test_2"));
- policy.setCreator(1);
- policy.setTarget(new Corpus("WPD_3"));
- policy.addPermission(Permissions.Permission.READ);
- policy.addPermission(Permissions.Permission.WRITE);
-
- PolicyHandlerIface dao = helper().getContext().getPolicyDbProvider();
- dao.createPolicy(policy, helper().getUser());
-
- List<SecurityPolicy>[] list = dao.getPolicies("WPD_3",
- helper().getUser(), Permissions.Permission.READ.toByte());
-
- assertNotNull(list);
- List<SecurityPolicy> policies = list[0];
- assertNotNull(policies);
- assertFalse(policies.isEmpty());
- assertEquals(2, policies.size());
- assertTrue(policies.get(0) instanceof SecurityPolicy.OwnerPolicy);
- policy = policies.get(1);
-
- Set<Permissions.Permission> check = new HashSet<>();
- check.add(Permissions.Permission.READ);
- check.add(Permissions.Permission.WRITE);
- assertEquals(check, policy.getPermissions());
- }
-
-
- @Test
- public void testConditionRemoval () throws KustvaktException {
- helper().setupResource(new Corpus("WPD_1"));
- SecurityPolicy policy = new SecurityPolicy();
- policy.addNewCondition(new PolicyCondition("test_1"));
- policy.addNewCondition(new PolicyCondition("test_2"));
- policy.setCreator(1);
- policy.setTarget(new Corpus("WPD_1"));
- policy.addPermission(Permissions.Permission.READ);
-
- PolicyHandlerIface dao = helper().getContext().getPolicyDbProvider();
- dao.createPolicy(policy, helper().getUser());
-
- Object[] list = dao.getPolicies("WPD_1", helper().getUser(),
- Permissions.Permission.READ.toByte());
- assertNotNull(list);
- List<SecurityPolicy> policies = (List<SecurityPolicy>) list[0];
- assertNotNull(policies);
- assertFalse(policies.isEmpty());
- policy = policies.get(1);
-
- assertEquals(2, policy.getConditions().size());
- policy.removeCondition(new PolicyCondition("test_1"));
- assertEquals(1, policy.getRemoved().size());
- assertTrue(policy.getAdded().isEmpty());
-
- dao.updatePolicy(policy, helper().getUser());
- policies = dao.getPolicies("WPD_1", helper().getUser(),
- Permissions.Permission.READ.toByte())[0];
- policy = policies.get(1);
- assertEquals(1, policy.getConditions().size());
- }
-
-
- @Test
- public void testPermissionConversion () {
- SecurityPolicy policy = new SecurityPolicy();
- policy.setPOSIX("3");
- Set<Permissions.Permission> perms = new HashSet<>();
- perms.add(Permissions.Permission.READ);
- perms.add(Permissions.Permission.WRITE);
- assertEquals(perms, policy.getPermissions());
- }
-
-
- @Override
- public void initMethod () throws KustvaktException {
- // helper().runBootInterfaces();
- helper().setupAccount();
- }
-}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/PolicyServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/PolicyServiceTest.java
deleted file mode 100644
index 708259a..0000000
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/PolicyServiceTest.java
+++ /dev/null
@@ -1,175 +0,0 @@
-package de.ids_mannheim.korap.web.controller;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.UUID;
-
-import org.junit.Ignore;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import com.sun.jersey.api.client.ClientResponse;
-
-import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
-import de.ids_mannheim.korap.config.Attributes;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.interfaces.db.PolicyHandlerIface;
-import de.ids_mannheim.korap.interfaces.db.ResourceOperationIface;
-import de.ids_mannheim.korap.resources.Corpus;
-import de.ids_mannheim.korap.resources.Foundry;
-import de.ids_mannheim.korap.resources.KustvaktResource;
-import de.ids_mannheim.korap.resources.Permissions;
-import de.ids_mannheim.korap.resources.Permissions.Permission;
-import de.ids_mannheim.korap.resources.VirtualCollection;
-import de.ids_mannheim.korap.security.PolicyCondition;
-import de.ids_mannheim.korap.security.SecurityPolicy;
-import de.ids_mannheim.korap.user.User;
-import de.ids_mannheim.korap.user.User.UserFactory;
-import de.ids_mannheim.korap.web.FastJerseyTest;
-
-/** Not in the new DB
- * @author margaretha
- */
-@Ignore
-@Deprecated
-public class PolicyServiceTest extends FastJerseyTest {
-
- @Autowired
- HttpAuthorizationHandler handler;
-
- private User user = UserFactory.getDemoUser();
-
-
- @Test
- public void testCreatePolicyForVirtualCollection ()
- throws IOException, KustvaktException {
- String id = UUID.randomUUID().toString();
- ClientResponse response = resource().path(getAPIVersion()).path("admin")
- .path("createPolicies").path(id)
- .queryParam("type", "virtualcollection")
- .queryParam("name", "Goethe VC")
- .queryParam("description", "Goethe corpus")
- .queryParam("group", "public")
- .queryParam("perm", Permission.READ.name())
- .queryParam("expire", "")
- .header(Attributes.AUTHORIZATION,
- handler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015"))
- .post(ClientResponse.class);
-
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
- response.getStatus());
-
- // Check the policies
- PolicyHandlerIface dao = helper().getContext().getPolicyDbProvider();
- List<SecurityPolicy> policies = dao.getPolicies(
- new PolicyCondition("public"), VirtualCollection.class,
- Permissions.Permission.READ.toByte());
- assertEquals(2, policies.size());
-
- policies = dao.getPoliciesByPersistentId(
- new PolicyCondition("public"), VirtualCollection.class,
- Permissions.Permission.READ.toByte(),id);
- assertEquals(1, policies.size());
- assertEquals(id, policies.get(0).getTarget());
-
- // Check the resource
- List<ResourceOperationIface> providers = (List<ResourceOperationIface>) helper()
- .getContext().getResourceProviders();
- ResourceOperationIface resourceDao = providers.get(0);
-
- User user = UserFactory.getDemoUser();
- KustvaktResource resource = resourceDao.findbyId(id, user);
- assertEquals("Goethe VC", resource.getName());
-
- }
-
-
- @Test
- public void testCreatePolicyForFoundry ()
- throws IOException, KustvaktException {
- String id = UUID.randomUUID().toString();
- ClientResponse response = resource().path(getAPIVersion()).path("admin")
- .path("createPolicies").path(id).queryParam("type", "foundry")
- .queryParam("name", "stanford")
- .queryParam("description", "stanford parser")
- .queryParam("group", "public")
- .queryParam("perm", Permission.READ.name())
- .queryParam("loc", "255.255.255.0")
- .queryParam("expire", "30D")
- .header(Attributes.AUTHORIZATION,
- handler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015"))
- .post(ClientResponse.class);
-
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
- response.getStatus());
-
- // Check the resource store
- List<ResourceOperationIface> providers = (List<ResourceOperationIface>) helper()
- .getContext().getResourceProviders();
- ResourceOperationIface resourceDao = providers.get(0);
- KustvaktResource resource = resourceDao.findbyId(id, user);
- assertEquals("stanford", resource.getName());
-
- // Check the policies
- PolicyHandlerIface dao = helper().getContext().getPolicyDbProvider();
- List<SecurityPolicy> policies = dao.getPoliciesByPersistentId(
- new PolicyCondition("public"), Foundry.class,
- Permissions.Permission.READ.toByte(),id);
- assertEquals(1, policies.size());
- assertEquals("255.255.255.0",policies.get(0).getContext().getIpmask());
-
- }
-
-
- @Test
- public void testCreatePolicyForMultiplePermissions ()
- throws IOException, KustvaktException {
- String id = UUID.randomUUID().toString();
- ClientResponse response = resource().path(getAPIVersion()).path("admin")
- .path("createPolicies").path(id).queryParam("type", "corpus")
- .queryParam("name", "Brown")
- .queryParam("description", "Brown corpus")
- .queryParam("group", "public")
- .queryParam("perm", Permission.READ.name())
- .queryParam("perm", Permission.WRITE.name())
- .queryParam("perm", Permission.DELETE.name())
- .queryParam("expire", "30D")
- .header(Attributes.AUTHORIZATION,
- handler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015"))
- .post(ClientResponse.class);
-
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
- response.getStatus());
-
- // Check resource store
- List<ResourceOperationIface> providers = (List<ResourceOperationIface>) helper()
- .getContext().getResourceProviders();
- ResourceOperationIface resourceDao = providers.get(0);
-
- KustvaktResource resource = resourceDao.findbyId(id, user);
- assertEquals("Brown", resource.getName());
-
- // Check the policies
- PolicyHandlerIface dao = helper().getContext().getPolicyDbProvider();
- List<SecurityPolicy> policies = dao.getPoliciesByPersistentId(
- new PolicyCondition("public"), Corpus.class,
- Permissions.Permission.WRITE.toByte(),id);
- assertEquals(1, policies.size());
- assertEquals(id, policies.get(0).getTarget());
-
- policies = dao.getPoliciesByPersistentId(
- new PolicyCondition("public"), Corpus.class,
- Permissions.Permission.DELETE.toByte(),id);
- assertEquals(1, policies.size());
- assertEquals(id, policies.get(0).getTarget());
- }
-
-
- @Override
- public void initMethod () throws KustvaktException {
-// helper().runBootInterfaces();
- }
-}
-
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserControllerTest.java
index 3cb66f2..4ea6807 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserControllerTest.java
@@ -275,7 +275,7 @@
@Test
public void testGetUserDetailsNonExistent() throws KustvaktException {
- helper().setupSimpleAccount("userservicetest", "servicepass");
+// helper().setupSimpleAccount("userservicetest", "servicepass");
String enc = handler.createBasicAuthorizationHeaderValue("userservicetest", "servicepass");
ClientResponse response = resource().path("user").path("details")
diff --git a/full/src/test/resources/test-config.xml b/full/src/test/resources/test-config.xml
index 99b2dd7..83291a9 100644
--- a/full/src/test/resources/test-config.xml
+++ b/full/src/test/resources/test-config.xml
@@ -258,7 +258,7 @@
<bean id="kustvakt_authenticationmanager"
class="de.ids_mannheim.korap.authentication.KustvaktAuthenticationManager">
<constructor-arg
- type="de.ids_mannheim.korap.interfaces.db.EntityHandlerIface" ref="kustvakt_userdb" />
+ type="de.ids_mannheim.korap.interfaces.EntityHandlerIface" ref="kustvakt_userdb" />
<constructor-arg type="de.ids_mannheim.korap.interfaces.EncryptionIface"
ref="kustvakt_encryption" />
<constructor-arg ref="kustvakt_config" />