Added comments, moved EntityHandlerIface, and cleaned up old codes.
Change-Id: I1a182b6ecd3dfeea4af08f3accd72fbce9af0f9c
diff --git a/core/src/main/java/de/ids_mannheim/korap/config/BeanConfiguration.java b/core/src/main/java/de/ids_mannheim/korap/config/BeanConfiguration.java
index 1dfe134..5e8aa36 100644
--- a/core/src/main/java/de/ids_mannheim/korap/config/BeanConfiguration.java
+++ b/core/src/main/java/de/ids_mannheim/korap/config/BeanConfiguration.java
@@ -10,9 +10,7 @@
import de.ids_mannheim.korap.interfaces.EncryptionIface;
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.PersistenceClient;
-import de.ids_mannheim.korap.interfaces.db.PolicyHandlerIface;
import de.ids_mannheim.korap.interfaces.db.ResourceOperationIface;
import de.ids_mannheim.korap.interfaces.db.UserDataDbIface;
import de.ids_mannheim.korap.interfaces.defaults.ApacheValidator;
@@ -37,7 +35,6 @@
public static final String KUSTVAKT_AUTHENTICATION_MANAGER = "kustvakt_authenticationmanager";
public static final String KUSTVAKT_USERDB = "kustvakt_userdb";
- public static final String KUSTVAKT_POLICIES = "kustvakt_policies";
private static BeanHolderHelper beans;
@@ -174,15 +171,9 @@
// }
- public EntityHandlerIface getUserDBHandler () {
- return getBean(KUSTVAKT_USERDB);
- }
-
-
- public PolicyHandlerIface getPolicyDbProvider () {
- return getBean(KUSTVAKT_POLICIES);
- }
-
+// public EntityHandlerIface getUserDBHandler () {
+// return getBean(KUSTVAKT_USERDB);
+// }
public ValidatorIface getValidator() {
try {
diff --git a/core/src/main/java/de/ids_mannheim/korap/config/ContextHolder.java b/core/src/main/java/de/ids_mannheim/korap/config/ContextHolder.java
index b32bb3b..0703cb5 100644
--- a/core/src/main/java/de/ids_mannheim/korap/config/ContextHolder.java
+++ b/core/src/main/java/de/ids_mannheim/korap/config/ContextHolder.java
@@ -1,16 +1,19 @@
package de.ids_mannheim.korap.config;
-import de.ids_mannheim.korap.interfaces.EncryptionIface;
-import de.ids_mannheim.korap.interfaces.ValidatorIface;
-import de.ids_mannheim.korap.interfaces.db.*;
-import de.ids_mannheim.korap.interfaces.defaults.ApacheValidator;
-import de.ids_mannheim.korap.web.CoreResponseHandler;
+import java.io.IOException;
+import java.util.Collection;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;
-import java.io.IOException;
-import java.util.Collection;
+import de.ids_mannheim.korap.interfaces.EncryptionIface;
+import de.ids_mannheim.korap.interfaces.ValidatorIface;
+import de.ids_mannheim.korap.interfaces.db.AuditingIface;
+import de.ids_mannheim.korap.interfaces.db.PersistenceClient;
+import de.ids_mannheim.korap.interfaces.db.ResourceOperationIface;
+import de.ids_mannheim.korap.interfaces.db.UserDataDbIface;
+import de.ids_mannheim.korap.interfaces.defaults.ApacheValidator;
+import de.ids_mannheim.korap.web.CoreResponseHandler;
/**
* @author hanl
@@ -102,16 +105,10 @@
// }
- public EntityHandlerIface getUserDBHandler () {
- return getBean(KUSTVAKT_USERDB);
- }
+// public EntityHandlerIface getUserDBHandler () {
+// return getBean(KUSTVAKT_USERDB);
+// }
- public PolicyHandlerIface getPolicyDbProvider () {
- Object b = getBean(KUSTVAKT_POLICIES);
- return (PolicyHandlerIface) b;
- }
-
-
// public Collection<AuthenticationIface> getAuthProviders () {
// return getBean(KUSTVAKT_AUTHPROVIDERS);
// }
diff --git a/core/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java b/core/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
index 563e493..7198bdc 100644
--- a/core/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
+++ b/core/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
@@ -76,8 +76,6 @@
private String default_token;
private String default_dep;
private String default_const;
- @Deprecated
- private String policyConfig;
private ArrayList<String> foundries;
private ArrayList<String> layers;
diff --git a/core/src/main/java/de/ids_mannheim/korap/interfaces/db/PolicyHandlerIface.java b/core/src/main/java/de/ids_mannheim/korap/interfaces/db/PolicyHandlerIface.java
deleted file mode 100644
index fe20a25..0000000
--- a/core/src/main/java/de/ids_mannheim/korap/interfaces/db/PolicyHandlerIface.java
+++ /dev/null
@@ -1,203 +0,0 @@
-package de.ids_mannheim.korap.interfaces.db;
-
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.resources.Foundry;
-import de.ids_mannheim.korap.resources.KustvaktResource;
-import de.ids_mannheim.korap.security.Parameter;
-import de.ids_mannheim.korap.security.PolicyCondition;
-import de.ids_mannheim.korap.security.SecurityPolicy;
-import de.ids_mannheim.korap.user.User;
-
-import java.util.List;
-
-/**
- * User: hanl
- * Date: 10/31/13
- * Time: 3:01 PM
- */
-public interface PolicyHandlerIface {
-
- /**
- * @param policy
- * @param user
- * @throws KustvaktException
- */
- int createPolicy (SecurityPolicy policy, User user)
- throws KustvaktException;
-
-
- /**
- * @param target
- * @param user
- * @param perm
- * @return
- */
- List<SecurityPolicy>[] getPolicies (Integer target, User user, Byte perm);
-
-
- List<SecurityPolicy> getPolicies (PolicyCondition condition,
- Class<? extends KustvaktResource> clazz, Byte perm);
-
- List<SecurityPolicy> getPoliciesByPersistentId (PolicyCondition policyCondition,
- Class<? extends KustvaktResource> clazz, byte perm, String id);
-
- /**
- * @param policy
- * @return
- * @throws KustvaktException
- */
- void mapConstraints (SecurityPolicy policy) throws KustvaktException;
-
-
- /**
- * @param target
- * @param user
- * @param perm
- * @return
- */
- List<SecurityPolicy>[] getPolicies (String target, User user, Byte perm);
-
-
- /**
- * @param path
- * @param user
- * @param perm
- * @return
- */
- // todo: refactor
- List<SecurityPolicy>[] findPolicies (String path, User user, Byte perm);
-
-
- /**
- * @param path
- * @param user
- * @param b
- * @param clazz
- * @return
- * @throws KustvaktException
- */
- List<KustvaktResource.Container> getDescending (String path, User user,
- Byte b, Class<? extends KustvaktResource> clazz)
- throws KustvaktException;
-
-
- /**
- * @param path
- * @param user
- * @param b
- * @param clazz
- * @return
- * @throws KustvaktException
- */
- List<KustvaktResource.Container> getAscending (String path, User user,
- Byte b, Class<? extends KustvaktResource> clazz)
- throws KustvaktException;
-
-
- /**
- * @param id
- * @param user
- */
- int deleteResourcePolicies (String id, User user) throws KustvaktException;
-
-
- /**
- * @param policy
- * @param user
- * @return
- * @throws KustvaktException
- */
- int deletePolicy (SecurityPolicy policy, User user)
- throws KustvaktException;
-
-
- /**
- * @param policy
- * @param user
- * @return
- * @throws KustvaktException
- */
- int updatePolicy (SecurityPolicy policy, User user)
- throws KustvaktException;
-
-
- /**
- * checks if a similar policy already exists
- *
- * @param policy
- * @return
- * @throws KustvaktException
- */
- int checkPolicy (SecurityPolicy policy, User user) throws KustvaktException;
-
-
- /**
- * @param user
- * @param name
- * @param owner
- * @return
- * @throws KustvaktException
- */
- int matchCondition (User user, String name, boolean owner)
- throws KustvaktException;
-
-
- /**
- * @param username
- * @param condition
- * @param admin
- * @return
- * @throws KustvaktException
- */
- int addToCondition (String username, PolicyCondition condition,
- boolean admin) throws KustvaktException;
-
-
- /**
- * @param usernames
- * @param condition
- * @param status
- * @throws KustvaktException
- */
-
- //todo: add a handler user id, to skip the matching step in the corpusmanagement segment!
- int[] addToCondition (List<String> usernames, PolicyCondition condition,
- boolean status) throws KustvaktException;
-
-
- /**
- * @param usernames
- * @param condition
- * @throws KustvaktException
- */
- void removeFromCondition (List<String> usernames, PolicyCondition condition)
- throws KustvaktException;
-
-
- /**
- * @param param
- * @throws KustvaktException
- */
- int createParamBinding (Parameter param) throws KustvaktException;
-
-
- /**
- * @param condition
- * @return
- * @throws KustvaktException
- */
- List<String> getUsersFromCondition (PolicyCondition condition)
- throws KustvaktException;
-
-
- /**
- * @param policy
- * @throws KustvaktException
- */
- int removeParamBinding (SecurityPolicy policy) throws KustvaktException;
-
-
- int size ();
-
-
-}
diff --git a/core/src/main/java/de/ids_mannheim/korap/security/Parameter.java b/core/src/main/java/de/ids_mannheim/korap/security/Parameter.java
deleted file mode 100644
index c27f0cf..0000000
--- a/core/src/main/java/de/ids_mannheim/korap/security/Parameter.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package de.ids_mannheim.korap.security;
-
-import de.ids_mannheim.korap.resources.KustvaktResource;
-import de.ids_mannheim.korap.user.User;
-import lombok.Getter;
-
-/**
- * @author hanl@ids-mannheim.de
- * @date 09/11/14
- */
-@Getter
-public class Parameter extends KustvaktResource {
-
- private String value;
- private SecurityPolicy policy;
- // todo: what is this supposed to do?
- private boolean equal;
-
-
- public Parameter (String identifier, String value, boolean equal, User user) {
- super();
- super.setName(identifier.toLowerCase());
- this.value = value;
- this.equal = equal;
- }
-
-
- @Override
- public void merge (KustvaktResource resource) {}
-
-
- @Override
- public void checkNull () {}
-
-
- public String getValue () {
- if (policy == null)
- return null;
- return value;
- }
-
-
- public void setPolicy (SecurityPolicy policy) {
- this.policy = policy;
- }
-
-}
diff --git a/core/src/main/java/de/ids_mannheim/korap/security/PermissionsBuffer.java b/core/src/main/java/de/ids_mannheim/korap/security/PermissionsBuffer.java
deleted file mode 100644
index dc98264..0000000
--- a/core/src/main/java/de/ids_mannheim/korap/security/PermissionsBuffer.java
+++ /dev/null
@@ -1,176 +0,0 @@
-package de.ids_mannheim.korap.security;
-
-import de.ids_mannheim.korap.resources.Permissions;
-
-import java.nio.ByteBuffer;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * User: hanl
- * Date: 11/5/13
- * Time: 1:05 PM
- */
-public class PermissionsBuffer {
-
- private byte[] bytes;
-
-
- public PermissionsBuffer () {
- this((short) 0);
- }
-
-
- public PermissionsBuffer (short perm) {
- setByte(perm);
- }
-
-
- private void setByte (short perm) {
- ByteBuffer b = ByteBuffer.allocate(2);
- b.putShort(perm);
- bytes = b.array();
- }
-
-
- public PermissionsBuffer (byte ... bytes) {
- this.bytes = bytes;
- }
-
-
- public boolean containsPermission (Permissions.Permission p) {
- return containsPByte(p.toByte());
- }
-
-
- public boolean containsPByte (byte perm) {
- return (bytes[1] & perm) == perm;
- }
-
-
- public int addPermission (int b) {
- short r = (short) (bytes[1] & b);
- if ((bytes[1] & b) != b)
- bytes[1] += b;
- else
- return -1;
- return 0;
- }
-
-
- public void retain (int compare) {
- short f = (short) (bytes[1] & compare);
- ByteBuffer b = ByteBuffer.allocate(2);
- b.putShort(f);
- bytes = b.array();
- }
-
-
- public void addPermissions (Permissions.Permission ... perm) {
- if (perm.length > 0) {
- for (Permissions.Permission p : perm)
- addPermission(p.toByte());
- }
- }
-
-
- public void removePermission (Permissions.Permission perm) {
- this.removePermission(perm.toByte());
- }
-
-
- public int removePermission (int b) {
- if ((bytes[1] & b) != 0)
- bytes[1] -= b;
- else
- return -1;
- return 0;
- }
-
-
- @Deprecated
- public int addOverride (int b) {
- if ((bytes[0] & b) == 0)
- bytes[0] += b;
- else
- return -1;
- return 0;
- }
-
-
- public int removeOverride (int b) {
- if ((bytes[0] & b) != 0)
- bytes[0] -= b;
- else
- return -1;
- return 0;
- }
-
-
- @Deprecated
- public boolean isOverridable (int b) {
- return (bytes[0] & b) != 0;
- }
-
-
- public boolean leftShift (byte perm) {
- // return pbyte & (perm << 1);
- System.out.println("pbyte is: " + bytes[1]);
- System.out.println("bitswise operation, left shift " + (perm << 1));
- return false;
- }
-
-
- @Override
- public boolean equals (Object perm) {
- if (perm instanceof Byte)
- return (bytes[1] & (byte) perm) == bytes[1];
- else if (perm instanceof PermissionsBuffer) {
- PermissionsBuffer b = (PermissionsBuffer) perm;
- return (bytes[1] & b.bytes[1]) == bytes[1];
- }
- return false;
- }
-
-
- public short getBytes () {
- ByteBuffer b = ByteBuffer.wrap(bytes);
- return b.getShort();
- }
-
-
- public byte[] getByteArray () {
- return bytes;
- }
-
-
- public Byte getPbyte () {
- return this.bytes[1];
- }
-
-
- public Set<Permissions.Permission> getPermissions () {
- Set<Permissions.Permission> pe = new HashSet<>();
- for (Permissions.Permission p : Permissions.Permission.values()) {
- if (containsPByte(p.toByte()))
- pe.add(p);
- }
- return pe;
- }
-
-
- public byte getOverride () {
- return this.bytes[0];
- }
-
-
- public String toBinary () {
- StringBuilder sb = new StringBuilder(bytes.length * Byte.SIZE);
- for (int i = 0; i < Byte.SIZE * bytes.length; i++) {
- sb.append((bytes[i / Byte.SIZE] << i % Byte.SIZE & 0x80) == 0 ? '0'
- : '1');
- }
- return sb.toString();
- }
-
-}
diff --git a/core/src/main/java/de/ids_mannheim/korap/security/PolicyCondition.java b/core/src/main/java/de/ids_mannheim/korap/security/PolicyCondition.java
deleted file mode 100644
index a7adbf8..0000000
--- a/core/src/main/java/de/ids_mannheim/korap/security/PolicyCondition.java
+++ /dev/null
@@ -1,113 +0,0 @@
-package de.ids_mannheim.korap.security;
-
-import de.ids_mannheim.korap.config.Attributes;
-import lombok.Getter;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * User: hanl
- * Date: 10/29/13
- * Time: 4:30 PM
- */
-@Getter
-public class PolicyCondition implements Comparable<PolicyCondition> {
-
- private static Map<String, Object> stats = new HashMap<>();
-
- static {
- stats.put(Attributes.SYM_USE, -1);
- stats.put(Attributes.COMMERCIAL, false);
- //fixme: doesnt query only and export infer the same thing?
- stats.put(Attributes.QUERY_ONLY, false);
- stats.put(Attributes.EXPORT, false);
- stats.put(Attributes.LICENCE, null);
- stats.put(Attributes.RANGE, null);
- //fixme: range is valuable in this context, but time span should remain in the policy context!
- stats.put(Attributes.TIME_SPANS, null);
- }
-
- //todo: loadSubTypes these from database or configuration --> use id reference, rather than variable declaration
-
- //todo: old regex for format gr(2323): "(^[^\\(]+)\\((.*)\\)"
- // private static final Pattern p = Pattern.compile("\\((.*)\\)");
- private final String specifier;
- private String description;
- private static final String EX_PRE = "ex:";
- private Map<String, Object> flags;
-
-
- public PolicyCondition (String target) {
- // pattern to map extensionally created groups
- this.specifier = target;
- this.flags = new HashMap<>(stats);
- }
-
-
- public PolicyCondition () {
- this(EX_PRE + createGroupName());
- }
-
-
- @Deprecated
- //todo: do this in crypto bean!
- private static String createGroupName () {
- // return Base64.encodeBase64String(SecureRGenerator
- // .getNextSecureRandom(64));
- return "<new group name>";
- }
-
-
- public void setDescription (String description) {
- this.description = description;
- }
-
-
- public void setFlag (String key, Object value) {
- Object f = this.flags.get(key);
- if (f != null && f.getClass().equals(value.getClass()))
- this.flags.put(key, value);
- }
-
-
- public String getSpecifier () {
- return this.specifier;
- }
-
-
- public boolean isExtensional () {
- return getSpecifier().startsWith(EX_PRE);
- }
-
-
- @Override
- public String toString () {
- return "(" + this.specifier + ")";
- }
-
-
- @Override
- public int compareTo (PolicyCondition o) {
- return this.getSpecifier().compareTo(o.getSpecifier());
- }
-
-
- @Override
- public boolean equals (Object o) {
- if (this == o)
- return true;
- if (o == null || getClass() != o.getClass())
- return false;
-
- PolicyCondition that = (PolicyCondition) o;
- return specifier.equals(that.specifier);
- }
-
-
- @Override
- public int hashCode () {
- return specifier.hashCode();
- }
-
-}
diff --git a/core/src/main/java/de/ids_mannheim/korap/security/PolicyContext.java b/core/src/main/java/de/ids_mannheim/korap/security/PolicyContext.java
deleted file mode 100644
index 00e3067..0000000
--- a/core/src/main/java/de/ids_mannheim/korap/security/PolicyContext.java
+++ /dev/null
@@ -1,79 +0,0 @@
-package de.ids_mannheim.korap.security;
-
-import de.ids_mannheim.korap.utils.IPNetMask;
-import de.ids_mannheim.korap.utils.TimeUtils;
-import lombok.Getter;
-
-import java.net.UnknownHostException;
-
-/**
- * @author hanl
- * @date 09/01/2014
- */
-@Getter
-public class PolicyContext {
-
- // refers to a specific ip location
- private String ipmask = "";
- // this context is not like an environmental property (e.g. morning hours/ evening hours), but specifies absolute time
- // parameters (e.g. from 10.04.2014 9:00 till 14..04.2014 active for testing).
- // if the containing parameter do not meet, the policy will be deactivated. if no parameter where specified, the policy
- // remains active
- // specifies a start time for the policy to be activated
- private long start = 0L;
- // specifies a time up to which the policy stays active
- private long end = 0L;
-
-
- public PolicyContext () {
- start = TimeUtils.getNow().getMillis();
- }
-
-
- public PolicyContext setIPMask (String ip) {
- this.ipmask = ip;
- return this;
- }
-
-
- public PolicyContext setExpirationTime (long limit) {
- this.end = limit;
- return this;
- }
-
-
- public PolicyContext setEnableTime (long start) {
- this.start = start;
- return this;
- }
-
-
- protected boolean isActive (String ipaddress) {
- if (ipaddress == null)
- return false;
- if (noMask())
- return true;
- IPNetMask mask;
- try {
- mask = IPNetMask.getIPMask(this.ipmask);
- boolean f = mask.matches(ipaddress);
- return f;
- }
- catch (UnknownHostException e) {
- e.printStackTrace();
- return false;
- }
- }
-
-
- protected boolean noMask () {
- return ipmask == null || ipmask.isEmpty();
- }
-
-
- @Override
- public String toString () {
- return "PolicyContext{" + ", ipmask='" + ipmask + '\'' + ", start="
- + start + ", end=" + end + '}';
- }
-}
diff --git a/core/src/main/java/de/ids_mannheim/korap/security/SecurityPolicy.java b/core/src/main/java/de/ids_mannheim/korap/security/SecurityPolicy.java
deleted file mode 100644
index 51d73d8..0000000
--- a/core/src/main/java/de/ids_mannheim/korap/security/SecurityPolicy.java
+++ /dev/null
@@ -1,316 +0,0 @@
-package de.ids_mannheim.korap.security;
-
-import de.ids_mannheim.korap.resources.KustvaktResource;
-import de.ids_mannheim.korap.resources.Permissions;
-import de.ids_mannheim.korap.user.User;
-import lombok.Getter;
-
-import java.util.*;
-
-/**
- * User: hanl
- * Date: 10/8/13
- * Time: 5:26 PM
- */
-
-// default is deny, but deny policies are allowed, when specifying a subset that would otherwise be allowed!
-// must be implemented as a resolution mechanism, that automatically creates this kind of policy strategy (allow > deny)
-
-public class SecurityPolicy {
-
- private int id = 0;
- // a settingattribute id for instance,
- // which specifies the attribute to be protected by this policy
- private String target;
- // todo: change to set!
- private List<PolicyCondition> conditions;
- private Set<Integer> removedidx;
- private Set<Integer> addedidx;
- private PermissionsBuffer permissions;
- private PolicyContext ctx;
- private Integer creator;
-
-
- public SecurityPolicy () {
- this.setID(-1);
- this.ctx = new PolicyContext();
- this.conditions = new ArrayList<>();
- this.removedidx = new HashSet<>();
- this.addedidx = new HashSet<>();
- this.permissions = new PermissionsBuffer();
- }
-
-
- public SecurityPolicy (Integer id) {
- this();
- this.setID(id);
- }
-
-
- public SecurityPolicy setID (Integer id) {
- this.id = id;
- return this;
- }
-
-
- public Integer getID () {
- return this.id;
- }
-
-
- public Integer getCreator () {
- return this.creator;
- }
-
-
- public PolicyContext getContext () {
- return this.ctx;
- }
-
-
- public SecurityPolicy setTarget (KustvaktResource resource) {
- this.target = resource.getPersistentID();
- return this;
- }
-
-
- public SecurityPolicy setTarget (String target) {
- this.target = target;
- return this;
- }
-
-
- public String getTarget () {
- return this.target;
- }
-
-
- public SecurityPolicy setPOSIX (String posix) {
- this.permissions = new PermissionsBuffer(Short.valueOf(posix));
- return this;
- }
-
-
- public SecurityPolicy setCreator (Integer creator) {
- this.creator = creator;
- return this;
- }
-
-
- // todo ???????
- @Deprecated
- private SecurityPolicy setOverride (Permissions.Permission ... perms) {
- for (Permissions.Permission p : perms)
- this.permissions.addOverride(p.toByte());
- return this;
- }
-
-
- public SecurityPolicy setContext (PolicyContext ctx) {
- this.ctx = ctx;
- return this;
- }
-
-
- private boolean hasContext () {
- return !ctx.noMask();
- }
-
-
- //todo:
- public boolean isActive (User user) {
- System.out.println("THE POLICY " + this.toString());
- System.out.println("DOES THIS HAVE CONTEXT? " + this.hasContext());
- // String host = (String) user.getField(Attributes.HOST);
- // System.out.println("HOST IS " + host);
- // System.out.println("is active? " + ctx.isActive(host));
- // if (this.hasContext())
- // return ctx.isActive(host);
- return !this.hasContext();
- }
-
-
- public List<String> getConditionList () {
- List<String> c = new LinkedList<>();
- Collections.sort(conditions);
- for (PolicyCondition p : conditions)
- c.add(p.getSpecifier());
- return c;
- }
-
-
- public String getConditionString () {
- if (conditions.isEmpty())
- return "";
-
- Collections.sort(conditions);
- StringBuffer b = new StringBuffer();
- for (PolicyCondition c : conditions) {
- b.append(c);
- b.append(";");
- }
- b.deleteCharAt(b.lastIndexOf(";"));
- return b.toString();
- }
-
-
- public List<PolicyCondition> getConditions () {
- return this.conditions;
- }
-
-
- public SecurityPolicy setConditions (PolicyCondition ... constraints) {
- this.conditions.clear();
- this.removedidx.clear();
- this.addedidx.clear();
- for (int idx = 0; idx < constraints.length; idx++) {
- this.conditions.add(idx, constraints[idx]);
- this.addedidx.add(idx);
- }
- return this;
- }
-
-
- public SecurityPolicy removeCondition (PolicyCondition constraint) {
- int idx = this.conditions.indexOf(constraint);
- if (this.addedidx.contains(idx))
- this.addedidx.remove(idx);
- else
- this.removedidx.add(idx);
- return this;
- }
-
-
- public SecurityPolicy addCondition (PolicyCondition constraint) {
- this.conditions.add(constraint);
- return this;
- }
-
-
- public SecurityPolicy addNewCondition (PolicyCondition constraint) {
- if (this.conditions.add(constraint))
- this.addedidx.add(this.conditions.indexOf(constraint));
- return this;
- }
-
-
- public boolean contains (PolicyCondition constraint) {
- return conditions.contains(constraint);
- }
-
-
- public Collection<Integer> getRemoved () {
- return this.removedidx;
- }
-
-
- public Collection<Integer> getAdded () {
- return this.addedidx;
- }
-
-
- public void clear () {
- // clear remove, add, conditions list!
- for (Integer remove : this.removedidx)
- this.conditions.remove(remove);
- this.removedidx.clear();
- this.addedidx.clear();
- }
-
-
- public boolean hasPermission (Permissions.Permission perm) {
- return permissions != null && permissions.containsPermission(perm);
- }
-
-
- /**
- * function to add a permission byte to the collection.
- *
- * @param perms
- * @return
- */
- public SecurityPolicy addPermission (Permissions.Permission ... perms) {
- permissions.addPermissions(perms);
- return this;
- }
-
-
- public boolean equalsPermission (Permissions.Permission ... perms) {
- PermissionsBuffer b = new PermissionsBuffer();
- b.addPermissions(perms);
- return permissions != null
- && permissions.getPbyte().equals(b.getPbyte());
- }
-
-
- public void removePermission (Permissions.Permission perm) {
- if (permissions != null)
- permissions.removePermission(perm);
- }
-
-
- public Byte getPermissionByte () {
- return permissions.getPbyte();
- }
-
-
- @Override
- public String toString () {
- final StringBuffer sb = new StringBuffer("SecurityPolicy{");
- sb.append("id=").append(id);
- sb.append(", target='").append(target).append('\'');
- sb.append(", conditions=").append(conditions);
- sb.append(", permissions=").append(getPermissions());
- sb.append('}');
- return sb.toString();
- }
-
-
- public Set<Permissions.Permission> getPermissions () {
- return permissions.getPermissions();
- }
-
-
- @Override
- public boolean equals (Object o) {
- if (this == o)
- return true;
- if (o == null || getClass() != o.getClass())
- return false;
-
- SecurityPolicy policy = (SecurityPolicy) o;
-
- if (id != policy.id)
- return false;
- if (target != policy.target)
- return false;
-
- return true;
- }
-
-
- @Override
- public int hashCode () {
- int result = id;
- result = 31 * result + target.hashCode();
- return result;
- }
-
- @Getter
- public static class OwnerPolicy extends SecurityPolicy {
- private final Integer owner;
-
-
- public OwnerPolicy (String target, Integer owner) {
- this.owner = owner;
- super.setTarget(target);
- }
-
-
- @Override
- public String toString () {
- return "OwnerPolicy(" + super.getTarget() + "," + owner + ")";
- }
-
- }
-}
diff --git a/core/src/main/java/de/ids_mannheim/korap/utils/UserPropertyReader.java b/core/src/main/java/de/ids_mannheim/korap/utils/UserPropertyReader.java
deleted file mode 100644
index d98de46..0000000
--- a/core/src/main/java/de/ids_mannheim/korap/utils/UserPropertyReader.java
+++ /dev/null
@@ -1,143 +0,0 @@
-package de.ids_mannheim.korap.utils;
-
-import de.ids_mannheim.korap.config.BeansFactory;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.exceptions.StatusCodes;
-import de.ids_mannheim.korap.interfaces.EncryptionIface;
-import de.ids_mannheim.korap.interfaces.ValidatorIface;
-import de.ids_mannheim.korap.interfaces.db.EntityHandlerIface;
-import de.ids_mannheim.korap.interfaces.db.UserDataDbIface;
-import de.ids_mannheim.korap.user.*;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.security.NoSuchAlgorithmException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * @author hanl
- * @date 30/09/2014
- *
- * EM: where is this used?
- */
-public class UserPropertyReader extends PropertyReader {
-
- private static Logger jlog = LoggerFactory
- .getLogger(UserPropertyReader.class);
-
-
- private Map<String, Properties> props;
- private String path;
- private EntityHandlerIface iface;
- private EncryptionIface crypto;
- private ValidatorIface validator;
-
-
- public UserPropertyReader (String path) {
- this.path = path;
- this.iface = BeansFactory.getKustvaktContext().getUserDBHandler();
- this.crypto = BeansFactory.getKustvaktContext().getEncryption();
- this.validator = BeansFactory.getKustvaktContext().getValidator();
- }
-
-
- @Override
- public void load () {
- try {
- props = super.read(this.path);
- for (Map.Entry<String, Properties> e : props.entrySet()) {
- try {
- createUser(e.getKey(), e.getValue());
- }
- catch (KustvaktException ex) {
- jlog.error("KorAP-Exception: {} for user {}",
- ex.getStatusCode(), e.getKey());
- }
- }
- iface.createAccount(User.UserFactory.getDemoUser());
- }
- catch (IOException e) {
- jlog.error("Could not read from path {}", path);
- }
- catch (KustvaktException e) {
- jlog.error("KorAP-Exception: {}", e.getStatusCode());
- }
- }
-
-
- private User createUser (String username, Properties p)
- throws KustvaktException {
- KorAPUser user;
-// if (username.equals(User.ADMINISTRATOR_NAME)) {
-// user = User.UserFactory.getAdmin();
-//
-// String pass = p.getProperty(username + ".password", null);
-// if (pass == null)
-// throw new KustvaktException(StatusCodes.ILLEGAL_ARGUMENT);
-//
-// try {
-// pass = crypto.secureHash(pass);
-// }
-// catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
-// throw new KustvaktException(StatusCodes.REQUEST_INVALID);
-// }
-// user.setPassword(pass);
-// iface.createAccount(user);
-// }
-// else {
- user = User.UserFactory.getUser(username);
- Map<String, Object> vals = new HashMap<>();
- for (Map.Entry e : p.entrySet()) {
- String key = e.getKey().toString().split("\\.", 2)[1];
- vals.put(key, e.getValue().toString());
- }
- String pass = p.getProperty(username + ".password", null);
- if (pass == null)
- throw new KustvaktException(StatusCodes.ILLEGAL_ARGUMENT);
-
- try {
- pass = crypto.secureHash(pass);
- }
- catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
- throw new KustvaktException(StatusCodes.REQUEST_INVALID);
- }
-
- user.setPassword(pass);
- user.setAccountLocked(Boolean.valueOf(p.getProperty(username
- + ".lock", "false")));
- user.setAccountCreation(TimeUtils.getNow().getMillis());
-
- //todo: make sure uri is set to 0, so sql queries work with the null value
- // user.setURIExpiration(0L);
- iface.createAccount(user);
- UserDetails det = new UserDetails();
- det.setUserId(user.getId());
- det.read(vals, true);
- det.validate(this.validator);
-
- Userdata set = new UserSettings();
- set.setUserId(user.getId());
- set.read(vals, true);
- set.validate(this.validator);
-
- UserDataDbIface dao = BeansFactory.getTypeFactory()
- .getTypeInterfaceBean(
- BeansFactory.getKustvaktContext()
- .getUserDataProviders(), UserDetails.class);
- dao.store(det);
-
- dao = BeansFactory.getTypeFactory().getTypeInterfaceBean(
- BeansFactory.getKustvaktContext().getUserDataProviders(),
- UserSettings.class);
- dao.store(set);
-// }
-
- jlog.info("successfully created account for user {}",
- user.getUsername());
- return user;
- }
-}
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/core/src/main/java/de/ids_mannheim/korap/interfaces/db/EntityHandlerIface.java b/full/src/main/java/de/ids_mannheim/korap/interfaces/EntityHandlerIface.java
similarity index 94%
rename from core/src/main/java/de/ids_mannheim/korap/interfaces/db/EntityHandlerIface.java
rename to full/src/main/java/de/ids_mannheim/korap/interfaces/EntityHandlerIface.java
index 456b385..9bcf614 100644
--- a/core/src/main/java/de/ids_mannheim/korap/interfaces/db/EntityHandlerIface.java
+++ b/full/src/main/java/de/ids_mannheim/korap/interfaces/EntityHandlerIface.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.interfaces.db;
+package de.ids_mannheim.korap.interfaces;
import de.ids_mannheim.korap.exceptions.EmptyResultException;
import de.ids_mannheim.korap.exceptions.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" />
diff --git a/lite/pom.xml b/lite/pom.xml
index 9cc85a1..f73ba49 100644
--- a/lite/pom.xml
+++ b/lite/pom.xml
@@ -147,7 +147,7 @@
<dependency>
<groupId>de.ids_mannheim.korap</groupId>
<artifactId>Kustvakt-core</artifactId>
- <version>0.60</version>
+ <version>0.60.1</version>
</dependency>
<!-- Spring -->