tests
diff --git a/src/main/java/de/ids_mannheim/korap/config/KustvaktBaseDaoInterface.java b/src/main/java/de/ids_mannheim/korap/config/KustvaktBaseDaoInterface.java
new file mode 100644
index 0000000..34dd36c
--- /dev/null
+++ b/src/main/java/de/ids_mannheim/korap/config/KustvaktBaseDaoInterface.java
@@ -0,0 +1,10 @@
+package de.ids_mannheim.korap.config;
+
+/**
+ * @author hanl
+ * @date 11/02/2016
+ */
+public interface KustvaktBaseDaoInterface {
+
+ int size();
+}
diff --git a/src/main/java/de/ids_mannheim/korap/config/KustvaktClassLoader.java b/src/main/java/de/ids_mannheim/korap/config/KustvaktClassLoader.java
index 6016025..345dc77 100644
--- a/src/main/java/de/ids_mannheim/korap/config/KustvaktClassLoader.java
+++ b/src/main/java/de/ids_mannheim/korap/config/KustvaktClassLoader.java
@@ -1,8 +1,11 @@
package de.ids_mannheim.korap.config;
+import de.ids_mannheim.korap.interfaces.db.UserDataDbIface;
import org.reflections.Reflections;
import java.lang.annotation.Annotation;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
import java.util.Set;
/**
@@ -32,4 +35,19 @@
Class<? extends Annotation> annotation) {
return reflections.getTypesAnnotatedWith(annotation);
}
+
+ public static Class<? extends UserDataDbIface> getClass(Class type,
+ Class iface) {
+ Set<Class<?>> c = KustvaktClassLoader.loadSubTypes(iface);
+ for (Class o : c) {
+ Type ctype = o.getGenericInterfaces()[0];
+ if (ctype instanceof ParameterizedType) {
+ ParameterizedType ptype = (ParameterizedType) ctype;
+ Class tclass = (Class) ptype.getActualTypeArguments()[0];
+ if (tclass.equals(type))
+ return o;
+ }
+ }
+ return null;
+ }
}
diff --git a/src/main/java/de/ids_mannheim/korap/config/KustvaktTypeInterface.java b/src/main/java/de/ids_mannheim/korap/config/KustvaktTypeInterface.java
new file mode 100644
index 0000000..a5270bd
--- /dev/null
+++ b/src/main/java/de/ids_mannheim/korap/config/KustvaktTypeInterface.java
@@ -0,0 +1,10 @@
+package de.ids_mannheim.korap.config;
+
+/**
+ * @author hanl
+ * @date 11/02/2016
+ */
+public interface KustvaktTypeInterface<T> {
+
+ Class<T> type();
+}
diff --git a/src/main/java/de/ids_mannheim/korap/handlers/DocumentDao.java b/src/main/java/de/ids_mannheim/korap/handlers/DocumentDao.java
index ccc9409..6438d67 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/DocumentDao.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/DocumentDao.java
@@ -35,11 +35,6 @@
}
@Override
- public Class<Document> getType() {
- return Document.class;
- }
-
- @Override
public Document findbyId(Integer id, User user) throws KustvaktException {
MapSqlParameterSource s = new MapSqlParameterSource();
s.addValue("id", id);
@@ -224,7 +219,12 @@
}
@Override
- public int size() throws KustvaktException {
+ public int size() {
return -1;
}
+
+ @Override
+ public Class<Document> type() {
+ return Document.class;
+ }
}
diff --git a/src/main/java/de/ids_mannheim/korap/handlers/EntityDao.java b/src/main/java/de/ids_mannheim/korap/handlers/EntityDao.java
index 497b23c..5de24a6 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/EntityDao.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/EntityDao.java
@@ -1,5 +1,6 @@
package de.ids_mannheim.korap.handlers;
+import de.ids_mannheim.korap.config.KustvaktBaseDaoInterface;
import de.ids_mannheim.korap.config.ParamFields;
import de.ids_mannheim.korap.config.URIParam;
import de.ids_mannheim.korap.exceptions.EmptyResultException;
@@ -8,7 +9,6 @@
import de.ids_mannheim.korap.exceptions.dbException;
import de.ids_mannheim.korap.interfaces.db.EntityHandlerIface;
import de.ids_mannheim.korap.interfaces.db.PersistenceClient;
-import de.ids_mannheim.korap.user.DemoUser;
import de.ids_mannheim.korap.user.KorAPUser;
import de.ids_mannheim.korap.user.ShibUser;
import de.ids_mannheim.korap.user.User;
@@ -33,7 +33,7 @@
* @author hanl
* @date 13/01/2014
*/
-public class EntityDao implements EntityHandlerIface {
+public class EntityDao implements EntityHandlerIface, KustvaktBaseDaoInterface {
private static Logger jlog = LoggerFactory.getLogger(EntityDao.class);
private NamedParameterJdbcTemplate jdbcTemplate;
@@ -164,7 +164,6 @@
"VALUES (:us, :type, :ali, " +
":edu, :cn, :mail, :logs, :logft);";
np.addValue("us", s.getUsername());
- // np.addValue("ali", s.getAccountLink());
np.addValue("ali", null);
np.addValue("edu", s.getAffiliation());
np.addValue("mail", s.getMail());
@@ -172,23 +171,16 @@
np.addValue("cn", s.getCn());
np.addValue("acr", System.currentTimeMillis());
- //todo: disable after first intro
- }else if (user instanceof DemoUser) {
- query = "INSERT INTO korap_users (username, type, account_lock, account_creation "
- +
- "password, uri_fragment, " +
- "uri_expiration) VALUES (:us, :type, :alo, " +
- ":ps, :uri, :urie);";
-
- np.addValue("us", user.getUsername());
- np.addValue("type", user.getType());
- // np.addValue("ali", user.getAccountLink());
- np.addValue("ali", null);
- np.addValue("alo", user.isAccountLocked());
- np.addValue("urie", new Date(0));
- np.addValue("ps", DemoUser.PASSPHRASE);
- np.addValue("uri", "");
- np.addValue("acr", System.currentTimeMillis());
+ //todo: deprecate
+ // }else if (user instanceof DemoUser) {
+ // query = "INSERT INTO korap_users (id, username, type, account_lock, account_creation) VALUES "
+ // + "(:id, :us, :type, :alo);";
+ //
+ // np.addValue("id", user.getId());
+ // np.addValue("us", user.getUsername());
+ // np.addValue("type", user.getType());
+ // np.addValue("alo", user.isAccountLocked());
+ // np.addValue("acr", System.currentTimeMillis());
}else
return -1;
@@ -202,7 +194,6 @@
}catch (DataAccessException e) {
jlog.error("Could not create user account with username: {}",
user.getUsername());
- e.printStackTrace();
throw new dbException(user.getUsername(), "korap_users",
StatusCodes.NAME_EXISTS, user.getUsername());
}
@@ -286,7 +277,6 @@
return this.jdbcTemplate
.queryForObject(query, new HashMap<String, Object>(),
Integer.class);
-
}
//todo:
diff --git a/src/main/java/de/ids_mannheim/korap/handlers/JDBCClient.java b/src/main/java/de/ids_mannheim/korap/handlers/JDBCClient.java
index 6161cdb..18b4e87 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/JDBCClient.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/JDBCClient.java
@@ -52,7 +52,7 @@
try {
// uses flyway schema table to determine of schema was applied succesfully
size = tmp.queryForObject(
- "select count(*) from schema_version limit 10;",
+ "select count(*) from schema_version limit 5;",
new HashMap<String, Object>(), Integer.class);
}catch (Exception e) {
System.out.println("No database schema found!");
diff --git a/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java b/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java
index 0869236..2093a13 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java
@@ -38,7 +38,7 @@
}
@Override
- public Class<T> getType() {
+ public Class<T> type() {
return (Class<T>) KustvaktResource.class;
}
@@ -150,7 +150,7 @@
source.addValue("name", resource.getName());
source.addValue("pid", resource.getPersistentID());
source.addValue("parent", parid);
- source.addValue("ow", resource.getOwner());
+ source.addValue("ow", user.getId());
source.addValue("desc", resource.getDescription());
source.addValue("type",
ResourceFactory.getResourceMapping(resource.getClass()));
@@ -194,14 +194,14 @@
}
@Override
- public int size() throws KustvaktException {
+ public int size() {
final String sql = "SELECT COUNT(*) FROM resource_store;";
try {
return this.jdbcTemplate
.queryForObject(sql, new HashMap<String, Object>(),
Integer.class);
}catch (DataAccessException e) {
- return -1;
+ return 0;
}
}
}
diff --git a/src/main/java/de/ids_mannheim/korap/handlers/RowMapperFactory.java b/src/main/java/de/ids_mannheim/korap/handlers/RowMapperFactory.java
index 22c600c..9ed2524 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/RowMapperFactory.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/RowMapperFactory.java
@@ -4,7 +4,6 @@
import de.ids_mannheim.korap.config.URIParam;
import de.ids_mannheim.korap.resources.KustvaktResource;
import de.ids_mannheim.korap.resources.ResourceFactory;
-import de.ids_mannheim.korap.resources.VirtualCollection;
import de.ids_mannheim.korap.user.Attributes;
import de.ids_mannheim.korap.user.KorAPUser;
import de.ids_mannheim.korap.user.ShibUser;
@@ -106,7 +105,6 @@
KustvaktResource r = ResourceFactory.getResource(rs.getInt("type"));
if (r != null) {
r.setId(rs.getInt("id"));
- r.setOwner(rs.getInt("creator"));
r.setName(rs.getString("name"));
r.setFields(rs.getString("data"));
@@ -119,25 +117,4 @@
}
}
-
- // todo: ??!
- public static class CollectionMapper
- implements RowMapper<VirtualCollection> {
-
- @Override
- public VirtualCollection mapRow(ResultSet rs, int i)
- throws SQLException {
- VirtualCollection c = ResourceFactory
- .getCollection(rs.getInt("id"), false);
- c.setPersistentID(rs.getString("persistent_id"));
- c.setCreated(rs.getTimestamp("created").getTime());
- c.setName(rs.getString("name"));
- c.setDescription(rs.getString("description"));
- c.setOwner(rs.getInt("user_id"));
- c.setFields(rs.getString("data"));
- c.checkNull();
- return c;
- }
- }
-
}
diff --git a/src/main/java/de/ids_mannheim/korap/interfaces/db/EntityHandlerIface.java b/src/main/java/de/ids_mannheim/korap/interfaces/db/EntityHandlerIface.java
index 932c069..b596b55 100644
--- a/src/main/java/de/ids_mannheim/korap/interfaces/db/EntityHandlerIface.java
+++ b/src/main/java/de/ids_mannheim/korap/interfaces/db/EntityHandlerIface.java
@@ -25,6 +25,4 @@
int activateAccount(String username, String uriToken)
throws KustvaktException;
-
- int size();
}
diff --git a/src/main/java/de/ids_mannheim/korap/interfaces/db/PolicyHandlerIface.java b/src/main/java/de/ids_mannheim/korap/interfaces/db/PolicyHandlerIface.java
index e563f58..5b6866d 100644
--- a/src/main/java/de/ids_mannheim/korap/interfaces/db/PolicyHandlerIface.java
+++ b/src/main/java/de/ids_mannheim/korap/interfaces/db/PolicyHandlerIface.java
@@ -34,6 +34,8 @@
*/
List<SecurityPolicy>[] getPolicies(Integer target, User user, Byte perm);
+ List<SecurityPolicy>[] getPolicies(PolicyCondition condition, Byte perm);
+
/**
* @param policy
* @return
@@ -86,8 +88,7 @@
* @param id
* @param user
*/
- //todo: test
- void deleteResourcePolicies(String id, User user) throws KustvaktException;
+ int deleteResourcePolicies(String id, User user) throws KustvaktException;
/**
* @param policy
@@ -157,7 +158,7 @@
* @param param
* @throws KustvaktException
*/
- void createParamBinding(Parameter param) throws KustvaktException;
+ int createParamBinding(Parameter param) throws KustvaktException;
/**
* @param condition
@@ -171,6 +172,8 @@
* @param policy
* @throws KustvaktException
*/
- void removeParamBinding(SecurityPolicy policy) throws KustvaktException;
+ int removeParamBinding(SecurityPolicy policy) throws KustvaktException;
+
+ int size();
}
diff --git a/src/main/java/de/ids_mannheim/korap/interfaces/db/ResourceOperationIface.java b/src/main/java/de/ids_mannheim/korap/interfaces/db/ResourceOperationIface.java
index d35f924..2682604 100644
--- a/src/main/java/de/ids_mannheim/korap/interfaces/db/ResourceOperationIface.java
+++ b/src/main/java/de/ids_mannheim/korap/interfaces/db/ResourceOperationIface.java
@@ -1,5 +1,7 @@
package de.ids_mannheim.korap.interfaces.db;
+import de.ids_mannheim.korap.config.KustvaktBaseDaoInterface;
+import de.ids_mannheim.korap.config.KustvaktTypeInterface;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.resources.KustvaktResource;
import de.ids_mannheim.korap.user.User;
@@ -9,11 +11,8 @@
// todo: for transaction to work this should go into core module!?!
// todo: user instance only required for auditing pointcut operations
-public interface ResourceOperationIface<T extends KustvaktResource> {
-
- // todo: remove and use type reference!
- @Deprecated
- Class<T> getType();
+public interface ResourceOperationIface<T extends KustvaktResource>
+ extends KustvaktTypeInterface<T>, KustvaktBaseDaoInterface {
<T extends KustvaktResource> T findbyId(String id, User user)
throws KustvaktException;
@@ -42,7 +41,4 @@
int deleteResource(String id, User user) throws KustvaktException;
int deleteAll() throws KustvaktException;
-
- int size() throws KustvaktException;
-
}
diff --git a/src/main/java/de/ids_mannheim/korap/resources/Corpus.java b/src/main/java/de/ids_mannheim/korap/resources/Corpus.java
index 8dd64e6..fdd9660 100755
--- a/src/main/java/de/ids_mannheim/korap/resources/Corpus.java
+++ b/src/main/java/de/ids_mannheim/korap/resources/Corpus.java
@@ -22,12 +22,12 @@
super();
}
- public Corpus(Integer id, int creator) {
- super(id, creator);
+ public Corpus(String pers) {
+ super(pers);
}
- public Corpus(String pers_id, int creator) {
- super(pers_id, creator);
+ public Corpus(Integer id) {
+ super(id);
}
@Override
diff --git a/src/main/java/de/ids_mannheim/korap/resources/Foundry.java b/src/main/java/de/ids_mannheim/korap/resources/Foundry.java
index 51e14f0..11753d5 100644
--- a/src/main/java/de/ids_mannheim/korap/resources/Foundry.java
+++ b/src/main/java/de/ids_mannheim/korap/resources/Foundry.java
@@ -10,13 +10,12 @@
super();
}
- public Foundry(Integer id, int creator) {
- super(id, creator);
+ public Foundry(Integer id) {
+ super(id);
}
- public Foundry(String persistentID, int creator) {
- super(persistentID, creator);
- this.setName(persistentID);
+ public Foundry(String persistentID) {
+ super(persistentID);
}
}
diff --git a/src/main/java/de/ids_mannheim/korap/resources/KustvaktResource.java b/src/main/java/de/ids_mannheim/korap/resources/KustvaktResource.java
index 259b033..7c25292 100644
--- a/src/main/java/de/ids_mannheim/korap/resources/KustvaktResource.java
+++ b/src/main/java/de/ids_mannheim/korap/resources/KustvaktResource.java
@@ -24,8 +24,10 @@
private String name;
private String description;
// todo: manage creator over policies!
- @JsonIgnore
- private Integer owner;
+
+ // @JsonIgnore
+ // @Deprecated
+ // private Integer owner;
protected long created;
@Deprecated
private boolean managed;
@@ -38,26 +40,23 @@
@Getter(AccessLevel.PROTECTED)
private Map<String, Object> fields;
- // todo: redo constructors
- protected KustvaktResource() {
+ public KustvaktResource() {
this.created = TimeUtils.getNow().getMillis();
this.id = -1;
this.parentID = null;
this.fields = new HashMap<>();
}
- public KustvaktResource(Integer id, int creator) {
+ public KustvaktResource(Integer id) {
this.created = TimeUtils.getNow().getMillis();
this.id = id;
- this.owner = creator;
this.parentID = null;
this.fields = new HashMap<>();
}
// todo: move creator to builder instance for policies
- public KustvaktResource(String persistentID, int creator) {
+ public KustvaktResource(String persistentID) {
this();
- this.owner = creator;
this.persistentID = persistentID;
}
@@ -136,11 +135,11 @@
this.getCreated() :
other.getCreated());
this.setPath(this.getPath() == null ? other.getPath() : this.getPath());
- this.setOwner(
- this.getOwner() == null ? other.getOwner() : this.getOwner());
- this.setManaged(
- !this.isManaged() ? other.isManaged() : this.isManaged());
- this.setShared(!this.isShared() ? other.isShared() : this.isShared());
+ // this.setOwner(
+ // this.getOwner() == null ? other.getOwner() : this.getOwner());
+ // this.setManaged(
+ // !this.isManaged() ? other.isManaged() : this.isManaged());
+ // this.setShared(!this.isShared() ? other.isShared() : this.isShared());
}
/**
@@ -156,11 +155,6 @@
setName(this.getName() == null ? "" : this.getName());
}
- protected String createID() {
- // return utils.randomAlphanumeric(10);
- return "";
- }
-
/**
* this method is used to return field information about the class
* All subclasses should override this method
@@ -190,7 +184,6 @@
", name='" + name + '\'' +
", created=" + created +
", path=" + path +
- ", owner=" + owner +
'}';
}
@@ -198,20 +191,17 @@
@Getter
public static class Container {
private final Class type;
- // private final Integer id;
private final String persistentID;
private final boolean set;
public Container(String persistentID, Class type) {
this.type = type;
- // this.id = id;
this.set = true;
this.persistentID = persistentID;
}
public Container(Class type) {
this.type = type;
- // this.id = id;
this.set = true;
this.persistentID = null;
}
@@ -219,7 +209,6 @@
public Container() {
this.set = false;
this.type = null;
- // this.id = null;
this.persistentID = null;
}
diff --git a/src/main/java/de/ids_mannheim/korap/resources/Layer.java b/src/main/java/de/ids_mannheim/korap/resources/Layer.java
index 7203216..2dc411c 100644
--- a/src/main/java/de/ids_mannheim/korap/resources/Layer.java
+++ b/src/main/java/de/ids_mannheim/korap/resources/Layer.java
@@ -10,25 +10,24 @@
super();
}
-
public Layer(Integer id, int creator) {
- super(id, creator);
+ super(id);
}
// layer name must not be unique!
- public Layer(Integer id, String name, int creator) {
- super(id, creator);
+ public Layer(Integer id, String name) {
+ super(id);
this.setName(name);
}
- public Layer(String persistentID, String name, int creator) {
- super(persistentID, creator);
+ public Layer(String persistentID, String name) {
+ super(persistentID);
this.setPersistentID(persistentID);
this.setName(name);
}
- public Layer(String persistentID, int creator) {
- super(persistentID, creator);
+ public Layer(String persistentID) {
+ super(persistentID);
}
}
diff --git a/src/main/java/de/ids_mannheim/korap/resources/ResourceFactory.java b/src/main/java/de/ids_mannheim/korap/resources/ResourceFactory.java
index e854b49..231017b 100755
--- a/src/main/java/de/ids_mannheim/korap/resources/ResourceFactory.java
+++ b/src/main/java/de/ids_mannheim/korap/resources/ResourceFactory.java
@@ -1,5 +1,7 @@
package de.ids_mannheim.korap.resources;
+import org.apache.commons.codec.digest.DigestUtils;
+
import java.util.ArrayList;
import java.util.List;
@@ -54,6 +56,12 @@
return null;
}
+ public static <T extends KustvaktResource> T createID(T resource) {
+ if (resource.getData() != null && !resource.getData().isEmpty())
+ resource.setPersistentID(DigestUtils.sha1Hex(resource.getData()));
+ return resource;
+ }
+
public static <T extends KustvaktResource> Class<T> getResourceClass(
String type) {
for (Class value : subTypes) {
@@ -79,53 +87,50 @@
}
public static VirtualCollection getPermanentCollection(
- VirtualCollection mergable, String corpusName, String description,
- Integer owner) {
+ VirtualCollection mergable, String corpusName, String description) {
VirtualCollection v = new VirtualCollection();
v.merge(mergable);
- v.setPersistentID(v.createID());
v.setName(corpusName);
v.setDescription(description);
- v.setOwner(owner);
- return v;
+ return createID(v);
}
- public static VirtualCollection createCollection(String name, String query,
- Integer owner) {
- VirtualCollection v = new VirtualCollection(query);
- v.setName(name);
- v.setOwner(owner);
- return v;
- }
+ // public static VirtualCollection createCollection(String name, String query,
+ // Integer owner) {
+ // VirtualCollection v = new VirtualCollection(query);
+ // v.setName(name);
+ // v.setOwner(owner);
+ // return v;
+ // }
+ //
+ // public static VirtualCollection createCollection(String name,
+ // Integer owner) {
+ // VirtualCollection v = new VirtualCollection();
+ // v.setOwner(owner);
+ // v.setName(name);
+ // return v;
+ // }
+ //
+ // public static VirtualCollection getCollection(Integer collectionID,
+ // boolean cache) {
+ // VirtualCollection v = new VirtualCollection();
+ // v.setId(collectionID);
+ // v.setDescription("");
+ // v.setName("");
+ // return v;
+ // }
+ //
+ // public static VirtualCollection createContainer(String name,
+ // String description, String query, Integer owner) {
+ // VirtualCollection v = new VirtualCollection(query);
+ // v.setName(name);
+ // v.setDescription(description);
+ // v.setOwner(owner);
+ // v.setManaged(true);
+ // return v;
+ // }
- public static VirtualCollection createCollection(String name,
- Integer owner) {
- VirtualCollection v = new VirtualCollection();
- v.setOwner(owner);
- v.setName(name);
- return v;
- }
-
- public static VirtualCollection getCollection(Integer collectionID,
- boolean cache) {
- VirtualCollection v = new VirtualCollection();
- v.setId(collectionID);
- v.setDescription("");
- v.setName("");
- return v;
- }
-
- public static VirtualCollection createContainer(String name,
- String description, String query, Integer owner) {
- VirtualCollection v = new VirtualCollection(query);
- v.setName(name);
- v.setDescription(description);
- v.setOwner(owner);
- v.setManaged(true);
- return v;
- }
-
- public static VirtualCollection getIDContainer(Integer id, Integer owner) {
- return new VirtualCollection(id, owner);
+ public static VirtualCollection getIDContainer(Integer id) {
+ return new VirtualCollection(id);
}
}
diff --git a/src/main/java/de/ids_mannheim/korap/resources/VirtualCollection.java b/src/main/java/de/ids_mannheim/korap/resources/VirtualCollection.java
index 5ffbb13..74ff1c8 100755
--- a/src/main/java/de/ids_mannheim/korap/resources/VirtualCollection.java
+++ b/src/main/java/de/ids_mannheim/korap/resources/VirtualCollection.java
@@ -2,7 +2,6 @@
import lombok.Getter;
import lombok.Setter;
-import org.apache.commons.codec.digest.DigestUtils;
import java.util.Map;
@@ -17,33 +16,16 @@
@Deprecated
private Map stats;
- protected VirtualCollection() {
+ public VirtualCollection() {
super();
- this.setPersistentID(this.createID());
}
- public VirtualCollection(Integer id, int creator) {
- super(id, creator);
+ public VirtualCollection(Integer id) {
+ super(id);
}
- public VirtualCollection(String persistentID, int creator) {
- super(persistentID, creator);
- }
-
- public VirtualCollection(String query) {
- this();
- this.setFields(query);
- this.setPersistentID(this.createID());
- }
-
- // todo: redo!
- @Override
- protected String createID() {
- if (this.getData() != null) {
- String s = this.getData();
- return DigestUtils.sha1Hex(s);
- }
- return super.createID();
+ public VirtualCollection(String persistentID) {
+ super(persistentID);
}
@Override
@@ -60,9 +42,9 @@
@Override
@SuppressWarnings("unchecked")
public void checkNull() {
- super.checkNull();
this.setDescription(
this.getDescription() == null ? "" : this.getDescription());
+ super.checkNull();
}
@Override
@@ -72,7 +54,6 @@
", persistentID='" + this.getPersistentID() + '\'' +
", created=" + created +
", path=" + this.getPath() +
- ", owner=" + this.getOwner() +
", name='" + this.getName() + '\'' +
", data='" + this.getData() + '\'' +
'}';
diff --git a/src/main/java/de/ids_mannheim/korap/security/Parameter.java b/src/main/java/de/ids_mannheim/korap/security/Parameter.java
index 7eab421..88f433e 100644
--- a/src/main/java/de/ids_mannheim/korap/security/Parameter.java
+++ b/src/main/java/de/ids_mannheim/korap/security/Parameter.java
@@ -8,6 +8,7 @@
* @author hanl@ids-mannheim.de
* @date 09/11/13
*/
+//todo:
@Getter
public class Parameter extends KustvaktResource {
@@ -22,7 +23,6 @@
super.setName(identifier.toLowerCase());
this.value = value;
this.equal = equal;
- super.setOwner(user.getId());
}
@Override
diff --git a/src/main/java/de/ids_mannheim/korap/security/ac/ConditionManagement.java b/src/main/java/de/ids_mannheim/korap/security/ac/ConditionManagement.java
index c239f99..d06764f 100644
--- a/src/main/java/de/ids_mannheim/korap/security/ac/ConditionManagement.java
+++ b/src/main/java/de/ids_mannheim/korap/security/ac/ConditionManagement.java
@@ -47,8 +47,8 @@
== 1) {
policydao.addToCondition(usernames, condition, admin);
}else
- jlog.error("Users could not be added to condition '{}'",
- condition.getSpecifier());
+ jlog.error("Users '{}' could not be added to condition '{}'",
+ usernames, condition.getSpecifier());
}
public void addUser(String username, PolicyCondition condition,
diff --git a/src/main/java/de/ids_mannheim/korap/security/ac/PolicyDao.java b/src/main/java/de/ids_mannheim/korap/security/ac/PolicyDao.java
index e006d87..eb30029 100644
--- a/src/main/java/de/ids_mannheim/korap/security/ac/PolicyDao.java
+++ b/src/main/java/de/ids_mannheim/korap/security/ac/PolicyDao.java
@@ -29,6 +29,7 @@
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
/**
@@ -128,6 +129,7 @@
this.jdbcTemplate.batchUpdate(remove, sources_removed);
}
+ // todo: naming convention!
if (!policy.getAdded().isEmpty()) {
idx = 0;
MapSqlParameterSource[] sources = new MapSqlParameterSource[policy
@@ -226,7 +228,7 @@
@Override
public List<SecurityPolicy>[] extractData(ResultSet rs)
throws SQLException, DataAccessException {
- return SecurityRowMappers.mapping(rs, user);
+ return SecurityRowMappers.mapping(rs);
}
});
}catch (DataAccessException e) {
@@ -238,6 +240,47 @@
}
@Override
+ public List<SecurityPolicy>[] getPolicies(PolicyCondition condition,
+ Byte perm) {
+ MapSqlParameterSource param = new MapSqlParameterSource();
+ param.addValue("cond", condition.getSpecifier());
+ param.addValue("perm", perm);
+ param.addValue("en", new Timestamp(TimeUtils.getNow().getMillis()));
+
+ String sql_new = "select pv.*, pv.perm & :perm as allowed, " +
+ "rh.depth, (select max(depth) from resource_tree " +
+ "where child_id=rh.child_id) as max_depth from policy_view as pv "
+ +
+ "inner join resource_tree as rh on rh.parent_id=pv.id " +
+ "where " +
+ "pv.enable <= :en and (pv.expire > :en or pv.expire is NULL) and "
+ +
+ "(pv.group_id='self' or pv.group_id=:cond) and " +
+ "(select sum(distinct depth) from resource_tree where child_id=rh.child_id) = "
+ +
+ "(select sum(distinct res.depth) from policy_view as pos inner join resource_tree as res on res.parent_id=pos.id where (pos.group_id=:cond)"
+ +
+ " or pos.group_id='self') and res.child_id=rh.child_id group by child_id)";
+
+ try {
+ return this.jdbcTemplate.query(sql_new, param,
+ new ResultSetExtractor<List<SecurityPolicy>[]>() {
+
+ @Override
+ public List<SecurityPolicy>[] extractData(ResultSet rs)
+ throws SQLException, DataAccessException {
+ return SecurityRowMappers.mapping(rs);
+ }
+ });
+ }catch (DataAccessException e) {
+ e.printStackTrace();
+ jlog.error("Permission Denied for policy retrieval for '{}'",
+ condition.getSpecifier());
+ return new List[2];
+ }
+ }
+
+ @Override
public List<SecurityPolicy>[] getPolicies(String target, final User user,
Byte perm) {
MapSqlParameterSource param = new MapSqlParameterSource();
@@ -246,7 +289,6 @@
param.addValue("perm", perm);
param.addValue("en", new Timestamp(TimeUtils.getNow().getMillis()));
- // fixme: missing constraint of user group membership!
String sql_new = "select pv.*, pv.perm & :perm as allowed, " +
"rh.depth, (select max(depth) from resource_tree " +
"where child_id=rh.child_id) as max_depth from policy_view as pv "
@@ -271,7 +313,7 @@
@Override
public List<SecurityPolicy>[] extractData(ResultSet rs)
throws SQLException, DataAccessException {
- return SecurityRowMappers.mapping(rs, user);
+ return SecurityRowMappers.mapping(rs);
}
});
}catch (DataAccessException e) {
@@ -314,7 +356,7 @@
@Override
public List<SecurityPolicy>[] extractData(ResultSet rs)
throws SQLException, DataAccessException {
- return SecurityRowMappers.mapping(rs, user);
+ return SecurityRowMappers.mapping(rs);
}
});
}catch (DataAccessException e) {
@@ -505,13 +547,13 @@
}
@Override
- public void deleteResourcePolicies(String id, User user)
+ public int deleteResourcePolicies(String id, User user)
throws KustvaktException {
MapSqlParameterSource param = new MapSqlParameterSource();
param.addValue("id", id);
- String sql = "DELETE FROM policy_store WHERE target_id=:id;";
+ String sql = "DELETE FROM policy_store WHERE target_id in (SELECT id FROM resource_store WHERE persistent_id=:id);";
try {
- this.jdbcTemplate.update(sql, param);
+ return this.jdbcTemplate.update(sql, param);
}catch (DataAccessException e) {
jlog.error("Operation (DELETE) not possible for '{}' for user '{}'",
id, user.getId());
@@ -638,10 +680,16 @@
param.addValue("status", BooleanUtils.getBoolean(admin));
return this.jdbcTemplate.update(insert, param);
}catch (DataAccessException e) {
- jlog.error("Operation (INSERT) not possible for '{}' for user '{}'",
- condition.toString(), username);
- throw new dbException(null, "group_store",
- StatusCodes.DB_INSERT_FAILED, condition.toString());
+ //todo: test with mysql
+ if (!e.getMessage().toLowerCase()
+ .contains("UNIQUE".toLowerCase())) {
+ jlog.error(
+ "Operation (INSERT) not possible for '{}' for user '{}'",
+ condition.toString(), username);
+ throw new dbException(null, "group_store",
+ StatusCodes.DB_INSERT_FAILED, condition.toString());
+ }
+ return 0;
}
}
@@ -661,7 +709,7 @@
MapSqlParameterSource[] sources = new MapSqlParameterSource[usernames
.size()];
- // todo: use unique index for that! problematic though --> why?
+ // todo: use unique index for that! problematic though --> why? no special exception?
// final String select = "select count(id) from group_users where userID=" +
// "(select id from korap_users where username=:username) " +
// "AND group_id=:group;";
@@ -673,6 +721,7 @@
"WHERE username=:username), :group, :status);";
try {
for (int idx = 0; idx < usernames.size(); idx++) {
+ //todo: dont do that here
if (usernames.get(idx) == null || usernames.get(idx).isEmpty())
throw new KustvaktException(StatusCodes.ILLEGAL_ARGUMENT);
@@ -684,7 +733,6 @@
// that as checkup (may also be manageable via triggers)
// if (this.jdbcTemplate
// .queryForObject(select, param, Integer.class) == 0)
- System.out.println("PARAMETER MAP " + param.getValues());
sources[idx] = param;
}
@@ -692,12 +740,16 @@
//fixme: problem - unique constraints throws exception. skip that user entry?!
return this.jdbcTemplate.batchUpdate(insert, sources);
}catch (DataAccessException e) {
- jlog.error("Operation (INSERT) not possible for '{}' for user '{}'",
- condition.toString(), usernames, e);
- throw new KustvaktException(
- "Operation (INSERT) not possible for '" + condition
- .toString() + "' for user '" + usernames + "'", e,
- StatusCodes.CONNECTION_ERROR);
+ if (!e.getCause().toString().contains("UNIQUE")) {
+ jlog.error(
+ "Operation (INSERT) not possible for '{}' for user '{}'",
+ condition.toString(), usernames, e);
+ throw new KustvaktException(
+ "Operation (INSERT) not possible for '" + condition
+ .toString() + "' for user '" + usernames + "'",
+ e, StatusCodes.CONNECTION_ERROR);
+ }
+ return null;
}
}
@@ -728,20 +780,21 @@
}
@Override
- public void createParamBinding(Parameter param) throws KustvaktException {
+ public int createParamBinding(Parameter param) throws KustvaktException {
MapSqlParameterSource source = new MapSqlParameterSource();
source.addValue("key", param.getName());
source.addValue("policy", param.getPolicy().getID());
source.addValue("value", param.getValue());
source.addValue("flag", param.isEqual());
- if (!parameterExists(param.getName()))
- createParameter(param.getName(), "", param.getOwner());
+ //todo:
+ // if (!parameterExists(param.getName()))
+ // createParameter(param.getName(), "", param.getOwner());
final String insert =
"INSERT INTO param_map (param_id, policy_id, value, flag) VALUES ((SELECT id FROM param_store "
+ "WHERE p_key=:key), (SELECT id FROM policy_store WHERE id=:policy), :value, :flag);";
try {
- this.jdbcTemplate.update(insert, source);
+ return this.jdbcTemplate.update(insert, source);
}catch (DataAccessException e) {
jlog.error("Operation (INSERT) not possible for '{}",
param.toString());
@@ -789,16 +842,28 @@
}
@Override
- public void removeParamBinding(SecurityPolicy policy)
+ public int removeParamBinding(SecurityPolicy policy)
throws KustvaktException {
MapSqlParameterSource source = new MapSqlParameterSource();
source.addValue("id", policy.getID());
final String sql = "DELETE FROM param_map WHERE policy_id=:id";
try {
- this.jdbcTemplate.update(sql, source);
+ return this.jdbcTemplate.update(sql, source);
}catch (DataAccessException e) {
throw new KustvaktException(e, StatusCodes.CONNECTION_ERROR);
}
}
+ @Override
+ public int size() {
+ String sql = "SELECT COUNT(*) FROM policy_view;";
+ try {
+ return this.jdbcTemplate
+ .queryForObject(sql, new HashMap<String, Object>(),
+ Integer.class);
+ }catch (DataAccessException e) {
+ return 0;
+ }
+ }
+
}
diff --git a/src/main/java/de/ids_mannheim/korap/security/ac/PolicyEvaluator.java b/src/main/java/de/ids_mannheim/korap/security/ac/PolicyEvaluator.java
index 4e6508a..d76848a 100644
--- a/src/main/java/de/ids_mannheim/korap/security/ac/PolicyEvaluator.java
+++ b/src/main/java/de/ids_mannheim/korap/security/ac/PolicyEvaluator.java
@@ -147,8 +147,8 @@
public static PolicyEvaluator setFlags(User user,
KustvaktResource resource) {
PolicyEvaluator e = new PolicyEvaluator(user, resource);
- e.setFlag("managed", resource.getOwner() == KorAPUser.ADMINISTRATOR_ID);
- e.setFlag("shared", false);
+// e.setFlag("managed", resource.getOwner() == KorAPUser.ADMINISTRATOR_ID);
+// e.setFlag("shared", false);
return e;
}
diff --git a/src/main/java/de/ids_mannheim/korap/security/ac/ResourceFinder.java b/src/main/java/de/ids_mannheim/korap/security/ac/ResourceFinder.java
index 5cd0738..822c94c 100755
--- a/src/main/java/de/ids_mannheim/korap/security/ac/ResourceFinder.java
+++ b/src/main/java/de/ids_mannheim/korap/security/ac/ResourceFinder.java
@@ -8,6 +8,8 @@
import de.ids_mannheim.korap.resources.Permissions;
import de.ids_mannheim.korap.resources.ResourceFactory;
import de.ids_mannheim.korap.security.PermissionsBuffer;
+import de.ids_mannheim.korap.security.PolicyCondition;
+import de.ids_mannheim.korap.user.Attributes;
import de.ids_mannheim.korap.user.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,6 +34,11 @@
checkProviders();
}
+ private ResourceFinder() {
+ this.containers = new ArrayList<>();
+ checkProviders();
+ }
+
private static void checkProviders() {
if (BeanConfiguration.hasContext() && policydao == null) {
ResourceFinder.policydao = BeanConfiguration.getBeans()
@@ -73,6 +80,18 @@
Permissions.PERMISSIONS.READ);
}
+ public static <T extends KustvaktResource> Set<T> searchPublic(
+ Class<T> clazz) {
+ List[] list = policydao
+ .getPolicies(new PolicyCondition(Attributes.PUBLIC_GROUP),
+ Permissions.READ);
+ System.out.println("_____________________");
+ System.out.println("list 1 " + list[0]);
+ System.out.println("list 1 " + list[1]);
+ return new HashSet<>();
+
+ }
+
// todo: should this be working?
public static <T extends KustvaktResource> Set<T> search(User user,
Class<T> clazz) throws KustvaktException {
@@ -107,7 +126,7 @@
if (resource != null) {
PolicyEvaluator e = PolicyEvaluator
.setFlags(user, resource);
- resource.setManaged(e.getFlag("managed", false));
+ // resource.setManaged(e.getFlag("managed", false));
resources.add(resource);
}
}catch (KustvaktException e) {
diff --git a/src/main/java/de/ids_mannheim/korap/security/ac/SecurityManager.java b/src/main/java/de/ids_mannheim/korap/security/ac/SecurityManager.java
index d37385d..94d08e6 100644
--- a/src/main/java/de/ids_mannheim/korap/security/ac/SecurityManager.java
+++ b/src/main/java/de/ids_mannheim/korap/security/ac/SecurityManager.java
@@ -66,7 +66,7 @@
SecurityManager.handlers = new HashMap<>();
ResourceOperationIface rprovider = BeanConfiguration.getBeans()
.getResourceProvider();
- SecurityManager.handlers.put(rprovider.getType(), rprovider);
+ SecurityManager.handlers.put(rprovider.type(), rprovider);
}
if (policydao == null && crypto == null)
throw new RuntimeException("providers not set!");
@@ -79,8 +79,8 @@
SecurityManager.crypto = crypto;
SecurityManager.handlers = new HashMap<>();
jlog.info("Registering handlers: {}", Arrays.asList(ifaces));
- for (ResourceOperationIface iface : ifaces)
- handlers.put(iface.getType(), iface);
+ // for (ResourceOperationIface iface : ifaces)
+ // handlers.put(iface.getType(), iface);
}
/**
@@ -213,9 +213,9 @@
if (id instanceof Integer)
this.policies = policydao
.getPolicies((Integer) id, this.user, b.getPbyte());
- // System.out.println("-------------------------------");
- // System.out.println("LENGTH OF POLICY ARRAY " + this.policies.length);
- // System.out.println("POLICY AT 0 " + this.policies[0]);
+// System.out.println("-------------------------------");
+// System.out.println("LENGTH OF POLICY ARRAY " + this.policies.length);
+// System.out.println("POLICY AT 0 " + this.policies[0]);
this.evaluator = new PolicyEvaluator(this.user, this.policies);
if (this.policies == null) {
@@ -275,12 +275,13 @@
// create persistent identifier for the resource
if (resource.getPersistentID() == null || resource.getPersistentID()
.isEmpty()) {
+ // todo: use resource data!
resource.setPersistentID(p.crypto.createID());
newid = true;
}
if (newid | !p.checkResource(resource.getPersistentID(), user)) {
- resource.setOwner(user.getId());
+ // resource.setOwner(user.getId());
jlog.info("Creating Access Control structure for resource '"
+ resource.getPersistentID() + "@" + resource.getId()
diff --git a/src/main/java/de/ids_mannheim/korap/security/ac/SecurityRowMappers.java b/src/main/java/de/ids_mannheim/korap/security/ac/SecurityRowMappers.java
index 4dedb30..48f339a 100644
--- a/src/main/java/de/ids_mannheim/korap/security/ac/SecurityRowMappers.java
+++ b/src/main/java/de/ids_mannheim/korap/security/ac/SecurityRowMappers.java
@@ -5,7 +5,6 @@
import de.ids_mannheim.korap.security.PolicyCondition;
import de.ids_mannheim.korap.security.PolicyContext;
import de.ids_mannheim.korap.security.SecurityPolicy;
-import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.utils.PrefixTreeMap;
import lombok.Data;
import org.springframework.dao.DataAccessException;
@@ -71,7 +70,7 @@
}
}
- public static List<SecurityPolicy>[] mapping(ResultSet rs, User user)
+ public static List<SecurityPolicy>[] mapping(ResultSet rs)
throws SQLException {
List<SecurityPolicy>[] policyArray = null;
List<Integer>[] idx = null;
diff --git a/src/main/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManager.java b/src/main/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManager.java
index b3fbbed..29c3641 100644
--- a/src/main/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManager.java
+++ b/src/main/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManager.java
@@ -86,6 +86,9 @@
String key = cache_key(username);
Element e = user_cache.get(key);
+ if (User.UserFactory.isDemo(username))
+ return User.UserFactory.getDemoUser();
+
if (e != null) {
Map map = (Map) e.getObjectValue();
user = User.UserFactory.toUser(map);
@@ -491,6 +494,8 @@
}
user.setPassword(hash);
try {
+ jlog.info("Creating new user account for user {}",
+ user.getUsername());
entHandler.createAccount(user);
UserDetails details = new UserDetails(user.getId());
details.readDefaults(safeMap);
diff --git a/src/main/java/de/ids_mannheim/korap/user/Attributes.java b/src/main/java/de/ids_mannheim/korap/user/Attributes.java
index 96a80fb..3fe16bd 100644
--- a/src/main/java/de/ids_mannheim/korap/user/Attributes.java
+++ b/src/main/java/de/ids_mannheim/korap/user/Attributes.java
@@ -13,6 +13,8 @@
public static final String CLIENT_SECRET = "client_secret";
public static final String SCOPES = "scopes";
+ public static final String PUBLIC_GROUP = "public";
+
public static final String SERVICE_ACCESS = "service_access";
public static final String USER = "KorapUser";
public static final String SHIBUSER = "ShibUser";
@@ -155,7 +157,7 @@
public static final String DISABLED = "disabled";
public static final String USER_ID = "user_id";
public static final String PARENT_ID = "parent_id";
-// public static final String
+ // public static final String
}
diff --git a/src/main/java/de/ids_mannheim/korap/user/DemoUser.java b/src/main/java/de/ids_mannheim/korap/user/DemoUser.java
index b1ceef1..cdb6671 100644
--- a/src/main/java/de/ids_mannheim/korap/user/DemoUser.java
+++ b/src/main/java/de/ids_mannheim/korap/user/DemoUser.java
@@ -12,11 +12,11 @@
public static final String DEMOUSER_NAME = "demo";
public static final Integer DEMOUSER_ID = 1654234534;
private static final long ACCOUNT_CREATED = 1377102171202L;
- public static final String PASSPHRASE = "$2a$15$rGPvLWm5JJ1iYj0V61e5guYIGmSo.rjdBkAVIU1vWS/xdybmABxRa";
+ public static final String PASSPHRASE = "demo";
- // todo: test functionality!
protected DemoUser() {
super(DEMOUSER_NAME, 2);
+ this.setId(-1);
this.setAccountCreation(ACCOUNT_CREATED);
}
diff --git a/src/main/java/de/ids_mannheim/korap/user/User.java b/src/main/java/de/ids_mannheim/korap/user/User.java
index 79df7cb..e266f1f 100644
--- a/src/main/java/de/ids_mannheim/korap/user/User.java
+++ b/src/main/java/de/ids_mannheim/korap/user/User.java
@@ -167,6 +167,10 @@
return demo;
}
+ public static boolean isDemo(String username) {
+ return new DemoUser().getUsername().equalsIgnoreCase(username);
+ }
+
public static ShibUser getShibInstance(String eduPersonID, String mail,
String cn) {
ShibUser u = new ShibUser(eduPersonID);
diff --git a/src/main/java/de/ids_mannheim/korap/web/KustvaktBaseServer.java b/src/main/java/de/ids_mannheim/korap/web/KustvaktBaseServer.java
index 2a8e430..9937c3c 100644
--- a/src/main/java/de/ids_mannheim/korap/web/KustvaktBaseServer.java
+++ b/src/main/java/de/ids_mannheim/korap/web/KustvaktBaseServer.java
@@ -166,6 +166,7 @@
}
+
@Setter
public static class KustvaktArgs {
@@ -188,6 +189,6 @@
this.properties = null;
this.init = false;
}
- }
-}
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/de/ids_mannheim/korap/web/filter/DefaultFilter.java b/src/main/java/de/ids_mannheim/korap/web/filter/DefaultFilter.java
index 07108a1..30e8961 100644
--- a/src/main/java/de/ids_mannheim/korap/web/filter/DefaultFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/web/filter/DefaultFilter.java
@@ -13,6 +13,7 @@
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.ext.Provider;
+import java.security.Principal;
/**
* Created by hanl on 7/15/14.
@@ -32,12 +33,16 @@
// means that this is the public service
if (authentication == null || authentication.isEmpty()) {
+ Principal pr = null;
try {
- request.getUserPrincipal();
+ pr = request.getUserPrincipal();
}catch (UnsupportedOperationException e) {
+ // do nothing
+ }
+ if (pr == null)
request.setSecurityContext(
new KorAPContext(createShorterToken(host, ua)));
- }
+
}
return request;
}
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/CollectionLoader.java b/src/main/java/de/ids_mannheim/korap/web/service/CollectionLoader.java
index 0548cc6..5ef5ee9 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/CollectionLoader.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/CollectionLoader.java
@@ -4,7 +4,6 @@
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.resources.Permissions;
-import de.ids_mannheim.korap.resources.ResourceFactory;
import de.ids_mannheim.korap.resources.VirtualCollection;
import de.ids_mannheim.korap.security.ac.PolicyBuilder;
import de.ids_mannheim.korap.user.Attributes;
@@ -20,9 +19,6 @@
@Override
public void load() throws KustvaktException {
if (BeanConfiguration.hasContext()) {
- int uid = (Integer) KustvaktConfiguration.KUSTVAKT_USER
- .get(Attributes.ID);
-
User user = User.UserFactory
.toUser(KustvaktConfiguration.KUSTVAKT_USER);
@@ -30,22 +26,26 @@
CollectionQueryBuilder3 bui = new CollectionQueryBuilder3();
bui.addQuery("creationDate since 1775");
- VirtualCollection c1 = ResourceFactory
- .createCollection("Weimarer Werke", bui.toJSON(), uid);
+ VirtualCollection c1 = new VirtualCollection();
+ c1.setName("Weimarer Werke");
+ c1.addField(Attributes.QUERY, bui.toJSON());
+
c1.setDescription("Goethe-Werke in Weimar (seit 1775)");
bui = new CollectionQueryBuilder3();
bui.addQuery("textType = Aphorismus");
- VirtualCollection c2 = ResourceFactory
- .createCollection("Aphorismen", bui.toJSON(), uid);
+ VirtualCollection c2 = new VirtualCollection();
+ c2.setName("Aphorismen");
+ c2.addField(Attributes.QUERY, bui.toJSON());
c2.setDescription("Aphorismentexte Goethes");
bui = new CollectionQueryBuilder3();
bui.addQuery("title ~ \"Werther\"");
- VirtualCollection c3 = ResourceFactory
- .createCollection("Werther", bui.toJSON(), uid);
+ VirtualCollection c3 = new VirtualCollection();
+ c3.setName("Werther");
+ c3.addField(Attributes.QUERY, bui.toJSON());
c3.setDescription("Goethe - Die Leiden des jungen Werther");
PolicyBuilder b = new PolicyBuilder(user);
@@ -53,6 +53,10 @@
b.setResources(c1, c2, c3);
b.setConditions("public");
b.create();
+
+// ConditionManagement c = new ConditionManagement(user);
+// c.addUser(User.UserFactory.getDemoUser().getUsername(),
+// new PolicyCondition("public"), false);
}
}
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/PolicyLoader.java b/src/main/java/de/ids_mannheim/korap/web/service/PolicyLoader.java
index 3ad501c..7cf1e68 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/PolicyLoader.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/PolicyLoader.java
@@ -21,7 +21,7 @@
.toUser(KustvaktConfiguration.KUSTVAKT_USER);
PolicyBuilder builder = new PolicyBuilder(user);
builder.addCondition("public");
- builder.setResources(new Corpus("GOE", user.getId()));
+ builder.setResources(new Corpus("GOE"));
builder.setPermissions(Permissions.PERMISSIONS.ALL);
builder.create();
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/UserLoader.java b/src/main/java/de/ids_mannheim/korap/web/service/UserLoader.java
index 04ecd95..991e126 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/UserLoader.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/UserLoader.java
@@ -3,6 +3,8 @@
import de.ids_mannheim.korap.config.BeanConfiguration;
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.user.User;
/**
* @author hanl
@@ -12,9 +14,13 @@
@Override
public void load() throws KustvaktException {
if (BeanConfiguration.hasContext()) {
- BeanConfiguration.getBeans().getAuthenticationManager()
- .createUserAccount(KustvaktConfiguration.KUSTVAKT_USER,
- false);
+ AuthenticationManagerIface manager = BeanConfiguration.getBeans()
+ .getAuthenticationManager();
+
+ BeanConfiguration.getBeans().getUserDBHandler()
+ .createAccount(User.UserFactory.getDemoUser());
+ manager.createUserAccount(KustvaktConfiguration.KUSTVAKT_USER,
+ false);
}
}
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java b/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java
index d9fec47..bae4c21 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java
@@ -275,7 +275,7 @@
// }
@POST
@Path("colloc")
- public Response getCollocatioBase(@QueryParam("q") String query) {
+ public Response getCollocationBase(@QueryParam("q") String query) {
String result;
try {
result = graphDBhandler.getResponse("distCollo", "q", query);
@@ -814,8 +814,7 @@
if (!cache) {
collection = ResourceFactory
- .getPermanentCollection(cachetmp, name, description,
- user.getId());
+ .getPermanentCollection(cachetmp, name, description);
vals = collection.toMap();
try {
resourceHandler.storeResources(user, collection);
@@ -902,8 +901,7 @@
if (!cache && !user.isDemo()) {
collection = ResourceFactory
- .getPermanentCollection(cachetmp, name, description,
- user.getId());
+ .getPermanentCollection(cachetmp, name, description);
vals = collection.toMap();
try {
resourceHandler.storeResources(user, collection);
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/full/UserService.java b/src/main/java/de/ids_mannheim/korap/web/service/full/UserService.java
index 2f4e4de..973544f 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/full/UserService.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/full/UserService.java
@@ -206,7 +206,7 @@
@GET
@Path("info")
@ResourceFilters({ AuthFilter.class, DefaultFilter.class, PiwikFilter.class,
- BlockingFilter.class, BlockingFilter.class })
+ BlockingFilter.class })
public Response getStatus(@Context SecurityContext context,
@QueryParam("scopes") String scopes) {
TokenContext ctx = (TokenContext) context.getUserPrincipal();
diff --git a/src/main/java/de/ids_mannheim/korap/web/utils/KustvaktResponseHandler.java b/src/main/java/de/ids_mannheim/korap/web/utils/KustvaktResponseHandler.java
index 80cd425..bd4c675 100644
--- a/src/main/java/de/ids_mannheim/korap/web/utils/KustvaktResponseHandler.java
+++ b/src/main/java/de/ids_mannheim/korap/web/utils/KustvaktResponseHandler.java
@@ -54,7 +54,7 @@
e.getEntity());
}
- private static String buildNotification(int code, String message,
+ public static String buildNotification(int code, String message,
String entity) {
Notifications notif = new Notifications();
notif.addError(code, message, entity);
@@ -79,6 +79,9 @@
case StatusCodes.ILLEGAL_ARGUMENT:
status = Response.Status.NOT_ACCEPTABLE;
break;
+ case StatusCodes.STATUS_OK:
+ status = Response.Status.OK;
+ break;
}
return status;
}
diff --git a/src/main/resources/db/mysql/V0.3__securitydatabase.sql b/src/main/resources/db/mysql/V0.3__securitydatabase.sql
index e74b114..c8f6816 100644
--- a/src/main/resources/db/mysql/V0.3__securitydatabase.sql
+++ b/src/main/resources/db/mysql/V0.3__securitydatabase.sql
@@ -127,7 +127,7 @@
DELIMITER ;
-- todo: are this automatically adapted when refactoring?
-CREATE INDEX group_index ON group_users(user_id);
+CREATE INDEX group_index ON group_users(user_id, group_id);
CREATE INDEX policy_index ON group_ref(policy_id);
CREATE UNIQUE INDEX resource_tree_index ON resource_tree (parent_id, depth, child_id);
CREATE UNIQUE INDEX param_unique ON param_store (p_key, p_value);
diff --git a/src/main/resources/db/sqlite/V1__Initial_version.sql b/src/main/resources/db/sqlite/V1__Initial_version.sql
index 46eff5e..06663e7 100644
--- a/src/main/resources/db/sqlite/V1__Initial_version.sql
+++ b/src/main/resources/db/sqlite/V1__Initial_version.sql
@@ -1,7 +1,7 @@
CREATE TABLE IF NOT EXISTS korap_users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username VARCHAR(150) NOT NULL UNIQUE,
-password VARCHAR(100) NOT NULL,
+password VARCHAR(100),
account_lock boolean NOT NULL,
account_creation BIGINT NOT NULL,
-- deprecate this
@@ -308,7 +308,7 @@
-- indices
-- test unique index constraints
-create index group_index on group_users(user_id);
+create index group_index on group_users(user_id, group_id);
create index policy_index on group_ref(policy_id);
create index policy_target on policy_store(target_id);
create unique index r_tree_index on resource_tree (parent_id, depth, child_id);
diff --git a/src/test/java/de/ids_mannheim/korap/config/CollectionLoaderTest.java b/src/test/java/de/ids_mannheim/korap/config/CollectionLoaderTest.java
new file mode 100644
index 0000000..1b3a4ea
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/config/CollectionLoaderTest.java
@@ -0,0 +1,46 @@
+package de.ids_mannheim.korap.config;
+
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.handlers.ResourceDao;
+import de.ids_mannheim.korap.web.service.CollectionLoader;
+import de.ids_mannheim.korap.web.service.UserLoader;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author hanl
+ * @date 11/02/2016
+ */
+public class CollectionLoaderTest {
+
+ @AfterClass
+ public static void close() {
+ BeanConfiguration.closeApplication();
+ }
+
+ @BeforeClass
+ public static void create() {
+ BeanConfiguration.loadClasspathContext("default-config.xml");
+ }
+
+ @Test
+ public void testCollectionLoader() {
+ ResourceDao dao = new ResourceDao(
+ BeanConfiguration.getBeans().getPersistenceClient());
+
+ boolean error = false;
+ UserLoader u = new UserLoader();
+ CollectionLoader l = new CollectionLoader();
+ try {
+ u.load();
+ l.load();
+ }catch (KustvaktException e) {
+ error = true;
+ }
+ assert !error;
+ Assert.assertNotEquals("Is not supposed to be zero", 0, dao.size());
+
+ }
+}
diff --git a/src/test/java/de/ids_mannheim/korap/config/ConfigTest.java b/src/test/java/de/ids_mannheim/korap/config/ConfigTest.java
index d4f2ad5..9c10da4 100644
--- a/src/test/java/de/ids_mannheim/korap/config/ConfigTest.java
+++ b/src/test/java/de/ids_mannheim/korap/config/ConfigTest.java
@@ -1,13 +1,10 @@
package de.ids_mannheim.korap.config;
import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.handlers.ResourceDao;
-import de.ids_mannheim.korap.resources.VirtualCollection;
-import de.ids_mannheim.korap.security.ac.ResourceFinder;
import de.ids_mannheim.korap.user.Attributes;
-import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.utils.ServiceVersion;
import de.ids_mannheim.korap.utils.TimeUtils;
+import de.ids_mannheim.korap.web.Arg;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@@ -32,20 +29,6 @@
}
@Test
- public void testCollectionLoader() throws KustvaktException {
- TestHelper.runBootInterfaces();
- ResourceDao dao = new ResourceDao(
- BeanConfiguration.getBeans().getPersistenceClient());
- int size = dao.size();
- Assert.assertNotEquals("Is not supposed to be zero", 0, size);
-
- Set<VirtualCollection> set = ResourceFinder.search(User.UserFactory
- .toUser(KustvaktConfiguration.KUSTVAKT_USER),
- VirtualCollection.class);
- System.out.println("RESULTING SET: " + set);
- }
-
- @Test
public void testServiceVersion() {
String v = ServiceVersion.getAPIVersion();
Assert.assertNotEquals("wrong version", "UNKNOWN", v);
@@ -76,6 +59,24 @@
BeanConfiguration.getBeans().getEncryption()
.validateEntry(v, Attributes.EMAIL);
}
+
+ @Test
+ public void testArgLoader() {
+ String[] args = new String[] { "--port", "8080", "--config",
+ "local.conf", "--init" };
+ Set<Arg> s = Arg.loadArgs(args);
+ assert s.size() == 3;
+
+ for (Arg arg : s) {
+ if (arg instanceof Arg.PortArg)
+ assert ((Arg.PortArg) arg).getValue() == 8080;
+ if (arg instanceof Arg.ConfigArg)
+ assert ((Arg.ConfigArg) arg).getValue().equals("local.conf");
+ if (arg instanceof Arg.InitArg)
+ assert ((Arg.InitArg) arg).getValue();
+ }
+ }
+
}
diff --git a/src/test/java/de/ids_mannheim/korap/config/PolicyLoaderTest.java b/src/test/java/de/ids_mannheim/korap/config/PolicyLoaderTest.java
new file mode 100644
index 0000000..866a5e1
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/config/PolicyLoaderTest.java
@@ -0,0 +1,48 @@
+package de.ids_mannheim.korap.config;
+
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.security.ac.PolicyDao;
+import de.ids_mannheim.korap.web.service.CollectionLoader;
+import de.ids_mannheim.korap.web.service.PolicyLoader;
+import de.ids_mannheim.korap.web.service.UserLoader;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author hanl
+ * @date 11/02/2016
+ */
+public class PolicyLoaderTest {
+
+ @AfterClass
+ public static void close() {
+ BeanConfiguration.closeApplication();
+ }
+
+ @BeforeClass
+ public static void create() {
+ BeanConfiguration.loadClasspathContext("default-config.xml");
+ }
+
+ @Test
+ public void testUserLoader() {
+ boolean error = false;
+ UserLoader u = new UserLoader();
+ CollectionLoader c = new CollectionLoader();
+ PolicyLoader l = new PolicyLoader();
+ try {
+ u.load();
+ c.load();
+ l.load();
+ }catch (KustvaktException e) {
+ error = true;
+ }
+ assert !error;
+
+ PolicyDao dao = new PolicyDao(
+ BeanConfiguration.getBeans().getPersistenceClient());
+ Assert.assertNotEquals("Is not supposed to be zero", 0, dao.size());
+ }
+}
diff --git a/src/test/java/de/ids_mannheim/korap/config/TestHelper.java b/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
index cc180f3..faa38ac 100644
--- a/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
+++ b/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
@@ -1,8 +1,10 @@
package de.ids_mannheim.korap.config;
import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.handlers.ResourceDao;
import de.ids_mannheim.korap.interfaces.db.EntityHandlerIface;
import de.ids_mannheim.korap.interfaces.db.PersistenceClient;
+import de.ids_mannheim.korap.resources.KustvaktResource;
import de.ids_mannheim.korap.user.Attributes;
import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.web.service.BootupInterface;
@@ -29,7 +31,8 @@
public static boolean setupAccount() {
boolean r = BeanConfiguration.hasContext();
- if (r && BeanConfiguration.getBeans().getUserDBHandler().size() == 0) {
+ if (r && ((KustvaktBaseDaoInterface) BeanConfiguration.getBeans()
+ .getUserDBHandler()).size() == 0) {
EntityHandlerIface dao = BeanConfiguration.getBeans()
.getUserDBHandler();
Map m = new HashMap<>();
@@ -57,7 +60,8 @@
public static boolean setupSimpleAccount(String username, String password) {
boolean r = BeanConfiguration.hasContext();
- if (r && BeanConfiguration.getBeans().getUserDBHandler().size() == 0) {
+ if (r && ((KustvaktBaseDaoInterface) BeanConfiguration.getBeans()
+ .getUserDBHandler()).size() == 0) {
EntityHandlerIface dao = BeanConfiguration.getBeans()
.getUserDBHandler();
Map m = new HashMap<>();
@@ -184,12 +188,36 @@
iface.load();
}catch (KustvaktException e) {
// don't do anything!
+ System.out.println(
+ "Loader instance failed ... exiting programme!");
+ System.exit(-1);
}
}
}else
throw new RuntimeException("Client not setup properly!");
}
+ public static void setupResource(KustvaktResource resource, User user)
+ throws KustvaktException {
+ ResourceDao dao = new ResourceDao(
+ BeanConfiguration.getBeans().getPersistenceClient());
+ dao.storeResource(resource, user);
+ }
+
+ public static KustvaktResource getResource(String name)
+ throws KustvaktException {
+ ResourceDao dao = new ResourceDao(
+ BeanConfiguration.getBeans().getPersistenceClient());
+ return dao.findbyId(name, getUser());
+ }
+
+ public static void dropResource(String name) throws KustvaktException {
+ ResourceDao dao = new ResourceDao(
+ BeanConfiguration.getBeans().getPersistenceClient());
+ dao.deleteResource(name, null);
+
+ }
+
private TestHelper() {
}
diff --git a/src/test/java/de/ids_mannheim/korap/config/UserLoaderTest.java b/src/test/java/de/ids_mannheim/korap/config/UserLoaderTest.java
new file mode 100644
index 0000000..8b33f2f
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/config/UserLoaderTest.java
@@ -0,0 +1,42 @@
+package de.ids_mannheim.korap.config;
+
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.handlers.EntityDao;
+import de.ids_mannheim.korap.web.service.UserLoader;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author hanl
+ * @date 11/02/2016
+ */
+public class UserLoaderTest {
+
+ @AfterClass
+ public static void close() {
+ BeanConfiguration.closeApplication();
+ }
+
+ @BeforeClass
+ public static void create() {
+ BeanConfiguration.loadClasspathContext("default-config.xml");
+ }
+
+ @Test
+ public void testUserLoader() {
+ EntityDao dao = new EntityDao(
+ BeanConfiguration.getBeans().getPersistenceClient());
+
+ boolean error = false;
+ UserLoader l = new UserLoader();
+ try {
+ l.load();
+ }catch (KustvaktException e) {
+ error = true;
+ }
+ assert !error;
+ Assert.assertNotEquals("Is not supposed to be zero", 0, dao.size());
+ }
+}
diff --git a/src/test/java/de/ids_mannheim/korap/handlers/ResourceDaoTest.java b/src/test/java/de/ids_mannheim/korap/handlers/ResourceDaoTest.java
index 0b11863..83d6de7 100644
--- a/src/test/java/de/ids_mannheim/korap/handlers/ResourceDaoTest.java
+++ b/src/test/java/de/ids_mannheim/korap/handlers/ResourceDaoTest.java
@@ -1,9 +1,9 @@
+package de.ids_mannheim.korap.handlers;
+
import de.ids_mannheim.korap.config.BeanConfiguration;
import de.ids_mannheim.korap.config.TestHelper;
import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.handlers.ResourceDao;
import de.ids_mannheim.korap.resources.KustvaktResource;
-import de.ids_mannheim.korap.resources.ResourceFactory;
import de.ids_mannheim.korap.resources.VirtualCollection;
import de.ids_mannheim.korap.user.User;
import org.junit.After;
@@ -25,7 +25,7 @@
@AfterClass
public static void drop() {
-// TestHelper.dropUser();
+ // TestHelper.dropUser();
BeanConfiguration.closeApplication();
}
@@ -39,7 +39,7 @@
public void createCollection() throws KustvaktException {
ResourceDao dao = new ResourceDao(
BeanConfiguration.getBeans().getPersistenceClient());
- VirtualCollection c = ResourceFactory.createCollection("testColl", 1);
+ VirtualCollection c = new VirtualCollection("testColl");
c.addField("key_1", "this is a test");
c.addField("key_2", 2);
@@ -59,7 +59,7 @@
public void ResourceDataUpdate() throws KustvaktException {
ResourceDao dao = new ResourceDao(
BeanConfiguration.getBeans().getPersistenceClient());
- VirtualCollection c = ResourceFactory.createCollection("testColl", 1);
+ VirtualCollection c = new VirtualCollection("testColl");
c.addField("key_1", "this is a test");
c.addField("key_2", 2);
diff --git a/src/test/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManagerTest.java b/src/test/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManagerTest.java
index efcf6c0..0c2adc1 100644
--- a/src/test/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManagerTest.java
+++ b/src/test/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManagerTest.java
@@ -1,6 +1,7 @@
package de.ids_mannheim.korap.security.auth;
import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.KustvaktBaseDaoInterface;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.config.TestHelper;
import de.ids_mannheim.korap.exceptions.KustvaktException;
@@ -47,7 +48,7 @@
EntityHandlerIface dao = BeanConfiguration.getBeans()
.getUserDBHandler();
- assert dao.size() > 0;
+ assert ((KustvaktBaseDaoInterface) dao).size() > 0;
User check = dao.getAccount(user.getUsername());
assert check != null;
}
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/AuthServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/AuthServiceTest.java
index 0bed7ff..6ba0ddc 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/full/AuthServiceTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/AuthServiceTest.java
@@ -1,11 +1,6 @@
package de.ids_mannheim.korap.web.service.full;
-import de.ids_mannheim.korap.config.BeanConfiguration;
-import de.ids_mannheim.korap.config.TestHelper;
import de.ids_mannheim.korap.web.service.FastJerseyTest;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
/**
* @author hanl
@@ -15,36 +10,4 @@
//todo: test basicauth via secure connection
- @BeforeClass
- public static void setup() {
- BeanConfiguration.loadClasspathContext("default-config.xml");
- FastJerseyTest.setPackages("de.ids_mannheim.korap.web.service.full",
- "de.ids_mannheim.korap.web.filter",
- "de.ids_mannheim.korap.web.utils");
- TestHelper.setupAccount();
- }
-
- @AfterClass
- public static void close() {
- TestHelper.dropUser();
- BeanConfiguration.closeApplication();
- }
-
- @Test
- public void testKustvaktAuth() {
-
- }
-
- @Test
- public void testDemoAuth() {
-
- }
-
- @Test
- public void testUnauthorizedAuth() {
-
- }
-
-
-
}
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/FilterTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/FilterTest.java
new file mode 100644
index 0000000..4b6f118
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/FilterTest.java
@@ -0,0 +1,61 @@
+package de.ids_mannheim.korap.web.service.full;
+
+import com.sun.jersey.api.client.ClientResponse;
+import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.TestHelper;
+import de.ids_mannheim.korap.security.auth.BasicHttpAuth;
+import de.ids_mannheim.korap.user.Attributes;
+import de.ids_mannheim.korap.web.service.FastJerseyTest;
+import org.eclipse.jetty.server.Response;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author hanl
+ * @date 08/02/2016
+ */
+public class FilterTest extends FastJerseyTest {
+
+ @BeforeClass
+ public static void setup() {
+ BeanConfiguration.loadClasspathContext("default-config.xml");
+ FastJerseyTest.setPackages("de.ids_mannheim.korap.web.service.full",
+ "de.ids_mannheim.korap.web.filter",
+ "de.ids_mannheim.korap.web.utils");
+ TestHelper.setupAccount();
+ }
+
+ @AfterClass
+ public static void close() {
+ TestHelper.dropUser();
+ BeanConfiguration.closeApplication();
+ }
+
+ @Test
+ public void testTestUserAuth() {
+ ClientResponse resp = resource().path(getAPIVersion()).path("user/info")
+ .header(Attributes.AUTHORIZATION, BasicHttpAuth
+ .encode(TestHelper.getUserCredentials()[0],
+ TestHelper.getUserCredentials()[1]))
+ .get(ClientResponse.class);
+ assert resp.getStatus() == Response.SC_OK;
+ System.out.println("entity '" + resp.getEntity(String.class) + "'");
+ }
+
+ @Test
+ public void testDemoAuth() {
+ ClientResponse resp = resource().path(getAPIVersion()).path("user/info")
+ .get(ClientResponse.class);
+ assert resp.getStatus() == Response.SC_OK;
+ }
+
+ @Test
+ public void testUnauthorizedAuth() {
+ ClientResponse resp = resource().path(getAPIVersion()).path("user/info")
+ .header(Attributes.AUTHORIZATION,
+ BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
+ .get(ClientResponse.class);
+ assert resp.getStatus() == Response.SC_UNAUTHORIZED;
+ }
+}
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktResourceServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktResourceServiceTest.java
index 377b4e8..45182a6 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktResourceServiceTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/KustvaktResourceServiceTest.java
@@ -11,6 +11,7 @@
import de.ids_mannheim.korap.web.service.FastJerseyTest;
import org.junit.AfterClass;
import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.Test;
/**
@@ -63,6 +64,7 @@
}
@Test
+ @Ignore
public void testStats() {
ClientResponse response = resource().path(getAPIVersion())
.path("collection").header(Attributes.AUTHORIZATION,
@@ -77,6 +79,8 @@
System.out.println("NODE COLLECTIONS" + node);
String id = node.path(0).path("id").asText();
+ System.out.println("ID IS " + id);
+ System.out.println("FROM NODE " + node);
response = resource().path(getAPIVersion()).path("collection").path(id)
.path("stats").header(Attributes.AUTHORIZATION,
BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceRemoteApiTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceRemoteApiTest.java
new file mode 100644
index 0000000..bcf5f9a
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/ResourceRemoteApiTest.java
@@ -0,0 +1,17 @@
+package de.ids_mannheim.korap.web.service.full;
+
+import org.junit.Test;
+
+/**
+ * @author hanl
+ * @date 08/02/2016
+ */
+public class ResourceRemoteApiTest {
+
+
+
+ @Test
+ public void testResourceGetFromDemo() {
+
+ }
+}