fixed running tests
diff --git a/src/main/java/de/ids_mannheim/korap/config/BeanConfiguration.java b/src/main/java/de/ids_mannheim/korap/config/BeanConfiguration.java
index 8702b28..a9df16b 100644
--- a/src/main/java/de/ids_mannheim/korap/config/BeanConfiguration.java
+++ b/src/main/java/de/ids_mannheim/korap/config/BeanConfiguration.java
@@ -18,6 +18,7 @@
* Date: 10/9/13
* Time: 11:20 AM
*/
+@Deprecated
public class BeanConfiguration {
private static final String CONFIG_FILE = "light-config.xml";
diff --git a/src/main/java/de/ids_mannheim/korap/config/BeansFactory.java b/src/main/java/de/ids_mannheim/korap/config/BeansFactory.java
new file mode 100644
index 0000000..b2ea511
--- /dev/null
+++ b/src/main/java/de/ids_mannheim/korap/config/BeansFactory.java
@@ -0,0 +1,128 @@
+package de.ids_mannheim.korap.config;
+
+import de.ids_mannheim.korap.interfaces.db.ResourceOperationIface;
+import de.ids_mannheim.korap.interfaces.db.UserDataDbIface;
+import de.ids_mannheim.korap.resources.KustvaktResource;
+import de.ids_mannheim.korap.user.Userdata;
+import de.ids_mannheim.korap.web.utils.KustvaktResponseHandler;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.context.support.FileSystemXmlApplicationContext;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.Collection;
+
+/**
+ * User: hanl
+ * Date: 10/9/13
+ * Time: 11:20 AM
+ */
+public class BeansFactory {
+
+ private static final String CONFIG_FILE = "light-config.xml";
+
+ private static ContextHolder beanHolder;
+
+ //todo: allow this for external plugin systems that are not kustvakt specific
+ @Deprecated
+ public static void setCustomBeansHolder(ContextHolder holder) {
+ beanHolder = holder;
+ }
+
+ public static synchronized ContextHolder getKustvaktContext() {
+ return beanHolder;
+ }
+
+ public static synchronized ContextHolder getKustvaktContext(int i) {
+ return beanHolder;
+ }
+
+ public static synchronized TypeBeanFactory getTypeFactory() {
+ return new TypeBeanFactory(beanHolder);
+ }
+
+ public static int loadClasspathContext(String... files) {
+ ApplicationContext context;
+ if (files.length == 0)
+ context = new ClassPathXmlApplicationContext(CONFIG_FILE);
+ else
+ context = new ClassPathXmlApplicationContext(files);
+ ContextHolder h = new ContextHolder(context) {
+ };
+ BeansFactory.beanHolder = h;
+ // return BeansFactory.beanHolder.indexOf(h);
+ return 0;
+ }
+
+ public static synchronized int addApplicationContext(
+ ApplicationContext context) {
+ ContextHolder h = new ContextHolder(context) {
+ };
+ BeansFactory.beanHolder = h;
+ // return BeansFactory.beanHolder.indexOf(h);
+ return 0;
+ }
+
+ public static synchronized void setKustvaktContext(ContextHolder holder) {
+ BeansFactory.beanHolder = holder;
+ }
+
+ public static synchronized int setApplicationContext(
+ ApplicationContext context) {
+ ContextHolder h = new ContextHolder(context) {
+ };
+ BeansFactory.beanHolder = h;
+ return 0;
+ }
+
+ public static synchronized int loadFileContext(String filepath) {
+ ApplicationContext context = new FileSystemXmlApplicationContext(
+ "file:" + filepath);
+ ContextHolder h = new ContextHolder(context) {
+ };
+ BeansFactory.beanHolder = h;
+ return 0;
+ }
+
+ public static void closeApplication() {
+ BeansFactory.beanHolder = null;
+ }
+
+ //todo: set response handler
+ @Deprecated
+ public static KustvaktResponseHandler getResponseHandler() {
+ return null;
+ }
+
+ public BeansFactory() {
+ }
+
+ public static class TypeBeanFactory {
+
+ private ContextHolder holder;
+
+ private TypeBeanFactory(ContextHolder holder) {
+ this.holder = holder;
+ }
+
+ public <T> T getTypedBean(Collection objs, Class type) {
+ for (Object o : objs) {
+ Type gtype = o.getClass().getGenericInterfaces()[0];
+ if (gtype instanceof ParameterizedType) {
+ ParameterizedType ptype = (ParameterizedType) gtype;
+ Object ctype = ptype.getActualTypeArguments()[0];
+ if (ctype.equals(type))
+ return (T) o;
+ }
+ }
+ throw new RuntimeException("Could not find typed bean in context for class '"+type+"'");
+ }
+
+ @Deprecated
+ public UserDataDbIface getUserDaoInstance(
+ Class<? extends Userdata> type) {
+ return getTypedBean(this.holder.getUserDataDaos(), type);
+ }
+ }
+}
diff --git a/src/main/java/de/ids_mannheim/korap/config/ContextHolder.java b/src/main/java/de/ids_mannheim/korap/config/ContextHolder.java
new file mode 100644
index 0000000..02e7232
--- /dev/null
+++ b/src/main/java/de/ids_mannheim/korap/config/ContextHolder.java
@@ -0,0 +1,115 @@
+package de.ids_mannheim.korap.config;
+
+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.db.*;
+import de.ids_mannheim.korap.web.utils.KustvaktResponseHandler;
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
+import org.springframework.context.ApplicationContext;
+
+import java.util.Collection;
+
+/**
+ * @author hanl
+ * @date 26/02/2016
+ */
+public abstract class ContextHolder {
+
+ public static final String KUSTVAKT_DB = "kustvakt_db";
+ public static final String KUSTVAKT_ENCRYPTION = "kustvakt_encryption";
+ public static final String KUSTVAKT_AUDITING = "kustvakt_auditing";
+ public static final String KUSTVAKT_CONFIG = "kustvakt_config";
+ public static final String KUSTVAKT_USERDATA = "kustvakt_userdata";
+ public static final String KUSTVAKT_RESOURCES = "kustvakt_resources";
+
+ public static final String KUSTVAKT_AUTHENTICATION_MANAGER = "kustvakt_authenticationmanager";
+ public static final String KUSTVAKT_AUTHPROVIDERS = "kustvakt_authproviders";
+ public static final String KUSTVAKT_USERDB = "kustvakt_userdb";
+ public static final String KUSTVAKT_POLICIES = "kustvakt_policies";
+
+ private ApplicationContext context = null;
+ private DefaultHandler handler;
+
+ public ContextHolder(ApplicationContext context) {
+ this.handler = new DefaultHandler();
+ this.context = context;
+ // todo: better method?!
+ KustvaktResponseHandler.init(getAuditingProvider());
+ }
+
+ protected <T> T getBean(Class<T> clazz) {
+ if (this.context != null) {
+ try {
+ return context.getBean(clazz);
+ }catch (NoSuchBeanDefinitionException e) {
+ // do nothing
+ }
+ }
+ return this.handler.getDefault(clazz);
+ }
+
+ protected <T> T getBean(String name) {
+ T bean = null;
+ if (this.context != null) {
+ try {
+ bean = (T) context.getBean(name);
+ }catch (NoSuchBeanDefinitionException e) {
+ // do nothing
+ bean = (T) this.handler.getDefault(name);
+ }
+ }
+
+ return bean;
+ }
+
+ public AuditingIface getAuditingProvider() {
+ return (AuditingIface) getBean(KUSTVAKT_AUDITING);
+ }
+
+ public <T extends KustvaktConfiguration> T getConfiguration() {
+ return (T) getBean(KUSTVAKT_CONFIG);
+ }
+
+ public PersistenceClient getPersistenceClient() {
+ return getBean(KUSTVAKT_DB);
+ }
+
+ public Collection<UserDataDbIface> getUserDataDaos() {
+ return getBean(KUSTVAKT_USERDATA);
+ }
+
+ public EncryptionIface getEncryption() {
+ return getBean(KUSTVAKT_ENCRYPTION);
+ }
+
+ public AuthenticationManagerIface getAuthenticationManager() {
+ return getBean(KUSTVAKT_AUTHENTICATION_MANAGER);
+ }
+
+ 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);
+ }
+
+ // todo: !!!!!!!!!!!!!!!!!!!!!!!!!!
+ // todo: more specific --> collection provider, document provider, etc.
+ public Collection<ResourceOperationIface> getResourceProvider() {
+ return getBean(KUSTVAKT_RESOURCES);
+ }
+
+
+ private void finish() {
+ this.getAuditingProvider().finish();
+ this.context = null;
+ }
+}
diff --git a/src/main/java/de/ids_mannheim/korap/config/KustvaktBaseDaoInterface.java b/src/main/java/de/ids_mannheim/korap/config/KustvaktBaseDaoInterface.java
index 34dd36c..cc23238 100644
--- a/src/main/java/de/ids_mannheim/korap/config/KustvaktBaseDaoInterface.java
+++ b/src/main/java/de/ids_mannheim/korap/config/KustvaktBaseDaoInterface.java
@@ -7,4 +7,7 @@
public interface KustvaktBaseDaoInterface {
int size();
+
+ int truncate();
+
}
diff --git a/src/main/java/de/ids_mannheim/korap/config/KustvaktCacheManager.java b/src/main/java/de/ids_mannheim/korap/config/KustvaktCacheManager.java
index 8d826ee..f061daa 100644
--- a/src/main/java/de/ids_mannheim/korap/config/KustvaktCacheManager.java
+++ b/src/main/java/de/ids_mannheim/korap/config/KustvaktCacheManager.java
@@ -17,17 +17,15 @@
public static void init() {
if (!loaded) {
- System.out.println("LOADING EHCACHE CONFIG FROM FILE");
InputStream in = null;
try {
in = new FileInputStream(new File("./ehcache.xml"));
}catch (FileNotFoundException e) {
- e.printStackTrace();
+ // do nothing
}
if (in == null) {
- System.out.println("LOADING EHCACHE FROM CLASSPATH");
- in = KustvaktCacheManager.class
+ in = KustvaktCacheManager.class.getClassLoader()
.getResourceAsStream("ehcache.xml");
}
CacheManager.newInstance(in);
diff --git a/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java b/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
index bbf133a..c2f3c0f 100644
--- a/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
+++ b/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
@@ -29,7 +29,7 @@
public static final Map<String, Object> KUSTVAKT_USER = new HashMap<>();
static {
- KUSTVAKT_USER.put(Attributes.ID, 1);
+ KUSTVAKT_USER.put(Attributes.ID, 1000);
KUSTVAKT_USER.put(Attributes.USERNAME, "kustvakt");
KUSTVAKT_USER.put(Attributes.PASSWORD, "kustvakt2015");
KUSTVAKT_USER.put(Attributes.EMAIL, "kustvakt@ids-mannheim.de");
@@ -95,20 +95,7 @@
throws MalformedURLException {
maxhits = new Integer(properties.getProperty("maxhits", "50000"));
returnhits = new Integer(properties.getProperty("returnhits", "50000"));
- //todo: refactor to krill.indexDir
indexDir = properties.getProperty("krill.indexDir", "");
- // URL url = KustvaktConfiguration.class.getClassLoader()
- // .getResource(idir);
- // System.out.println("LOADING FILE FROM CLASSPATH? " + url);
- // if (!new File(idir).exists() && url != null) {
- // indexDir = url.getFile();
- // }else
- // indexDir = idir;
- //
- // System.out.println(
- // "---------------------------------------------------------------");
- // System.out.println("INDEX DIR IS: " + indexDir);
- // System.out.println("FILE EXISTS? " + new File(indexDir).exists());
port = new Integer(properties.getProperty("server.port", "8095"));
// server options
serverHost = String
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 6438d67..4d7df7d 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/DocumentDao.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/DocumentDao.java
@@ -83,8 +83,7 @@
doc = new Document(
rs.getString("persistent_id"));
doc.setId(rs.getInt("id"));
- doc.setCreated(
- rs.getTimestamp("created").getTime());
+ doc.setCreated(rs.getLong("created"));
doc.setDisabled(rs.getBoolean("disabled"));
}
@@ -94,6 +93,7 @@
}catch (EmptyResultDataAccessException em) {
return null;
}catch (DataAccessException e) {
+ e.printStackTrace();
throw new KustvaktException(StatusCodes.CONNECTION_ERROR);
}
}
@@ -209,21 +209,21 @@
}
@Override
- public int deleteAll() throws KustvaktException {
+ public int size() {
+ return -1;
+ }
+
+ @Override
+ public int truncate() {
String sql = "delete from doc_store;";
try {
return this.jdbcTemplate.update(sql, new HashMap<String, Object>());
}catch (DataAccessException e) {
- throw new KustvaktException(StatusCodes.CONNECTION_ERROR);
+ return -1;
}
}
@Override
- 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 5de24a6..aa1e725 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/EntityDao.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/EntityDao.java
@@ -53,7 +53,7 @@
user = this.jdbcTemplate.queryForObject(sql, namedParameters,
new RowMapperFactory.UserMapper());
}catch (EmptyResultDataAccessException ae) {
- jlog.error("No user found for name '{}'", username);
+ jlog.warn("No user found for name '{}'", username);
throw new EmptyResultException(username);
}catch (DataAccessException e) {
jlog.error("Could not retrieve user for name: " + username, e);
@@ -139,7 +139,6 @@
np.addValue("acr", System.currentTimeMillis());
np.addValue("id", k.getId());
- System.out.println("query map " + np.getValues());
if (user.getId() != -1)
query = "INSERT INTO korap_users (id, username, account_lock, "
+
@@ -229,6 +228,16 @@
}
@Override
+ public int truncate() {
+ String sql = "DELETE FROM korap_users;";
+ try {
+ return this.jdbcTemplate.update(sql, new HashMap<String, Object>());
+ }catch (DataAccessException e) {
+ return -1;
+ }
+ }
+
+ @Override
public int resetPassphrase(String username, String uriToken,
String passphrase) throws KustvaktException {
MapSqlParameterSource np = new MapSqlParameterSource();
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 2093a13..2f62d4f 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java
@@ -42,10 +42,26 @@
return (Class<T>) KustvaktResource.class;
}
+ // todo: testing
@Override
public List<T> getResources(Collection<Object> ids, User user)
throws KustvaktException {
- return null;
+ String sql =
+ "SELECT rs.*, rt.name_path FROM resource_store as rs inner join resource_tree as rt"
+ + " on rs.id=rt.child_id WHERE rs.id IN (:ids);";
+ MapSqlParameterSource parameters = new MapSqlParameterSource();
+ parameters.addValue("ids", ids);
+ try {
+ return (List<T>) this.jdbcTemplate.query(sql, parameters,
+ new RowMapperFactory.ResourceMapper());
+ }catch (DataAccessException e) {
+ log.error(
+ "Exception during database retrieval for ids '" + ids + "'",
+ e);
+ throw new dbException(user.getId(), "resource_store",
+ StatusCodes.DB_GET_FAILED, ids.toString());
+ }
+
}
@Override
@@ -184,16 +200,6 @@
}
@Override
- public int deleteAll() throws KustvaktException {
- final String sql = "DELETE FROM resource_store;";
- try {
- return this.jdbcTemplate.update(sql, new HashMap<String, Object>());
- }catch (DataAccessException e) {
- throw new KustvaktException(StatusCodes.CONNECTION_ERROR);
- }
- }
-
- @Override
public int size() {
final String sql = "SELECT COUNT(*) FROM resource_store;";
try {
@@ -204,4 +210,14 @@
return 0;
}
}
+
+ @Override
+ public int truncate() {
+ final String sql = "DELETE FROM resource_store;";
+ try {
+ return this.jdbcTemplate.update(sql, new HashMap<String, Object>());
+ }catch (DataAccessException e) {
+ return -1;
+ }
+ }
}
diff --git a/src/main/java/de/ids_mannheim/korap/handlers/UserDetailsDao.java b/src/main/java/de/ids_mannheim/korap/handlers/UserDetailsDao.java
index e301ff5..42b0b60 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/UserDetailsDao.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/UserDetailsDao.java
@@ -58,6 +58,7 @@
try {
return this.jdbcTemplate.update(sql, source);
}catch (DataAccessException e) {
+ e.printStackTrace();
return -1;
}
}
diff --git a/src/main/java/de/ids_mannheim/korap/handlers/UserSettingsDao.java b/src/main/java/de/ids_mannheim/korap/handlers/UserSettingsDao.java
index 6b9300f..6bb8453 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/UserSettingsDao.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/UserSettingsDao.java
@@ -6,6 +6,8 @@
import de.ids_mannheim.korap.interfaces.db.UserDataDbIface;
import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.user.UserSettings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.RowMapper;
@@ -23,7 +25,10 @@
*/
public class UserSettingsDao implements UserDataDbIface<UserSettings> {
- NamedParameterJdbcTemplate jdbcTemplate;
+ private static final Logger jlog = LoggerFactory
+ .getLogger(UserSettingsDao.class);
+
+ private final NamedParameterJdbcTemplate jdbcTemplate;
public UserSettingsDao(PersistenceClient client) {
this.jdbcTemplate = (NamedParameterJdbcTemplate) client.getSource();
@@ -44,6 +49,8 @@
return id;
}catch (DataAccessException e) {
e.printStackTrace();
+ jlog.error("couldn't store data in db for user with id '{}'",
+ data.getUserID());
return -1;
}
}
diff --git a/src/main/java/de/ids_mannheim/korap/interfaces/AuthenticationManagerIface.java b/src/main/java/de/ids_mannheim/korap/interfaces/AuthenticationManagerIface.java
index 8204a4f..ca155eb 100644
--- a/src/main/java/de/ids_mannheim/korap/interfaces/AuthenticationManagerIface.java
+++ b/src/main/java/de/ids_mannheim/korap/interfaces/AuthenticationManagerIface.java
@@ -1,7 +1,9 @@
package de.ids_mannheim.korap.interfaces;
import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.user.*;
+import de.ids_mannheim.korap.user.TokenContext;
+import de.ids_mannheim.korap.user.User;
+import de.ids_mannheim.korap.user.Userdata;
import java.util.HashMap;
import java.util.Map;
@@ -63,7 +65,6 @@
public abstract void updateUserData(Userdata data) throws KustvaktException;
-
public abstract Object[] validateResetPasswordRequest(String username,
String email) throws KustvaktException;
@@ -73,8 +74,7 @@
public abstract void confirmRegistration(String uriFragment,
String username) throws KustvaktException;
- @Override
- public String toString() {
+ public String providerList() {
return "provider list: " + this.providers.toString();
}
}
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 b596b55..a844fbc 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
@@ -20,6 +20,8 @@
int deleteAccount(Integer userid) throws KustvaktException;
+ int truncate() throws KustvaktException;
+
int resetPassphrase(String username, String uriToken, String passphrase)
throws KustvaktException;
diff --git a/src/main/java/de/ids_mannheim/korap/interfaces/db/PersistenceClient.java b/src/main/java/de/ids_mannheim/korap/interfaces/db/PersistenceClient.java
index 7b8c58a..573d346 100644
--- a/src/main/java/de/ids_mannheim/korap/interfaces/db/PersistenceClient.java
+++ b/src/main/java/de/ids_mannheim/korap/interfaces/db/PersistenceClient.java
@@ -9,7 +9,7 @@
private SOURCE source;
private TYPE type;
- @Deprecated
+
protected String database;
private InputStream schema;
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 2682604..6666d49 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
@@ -39,6 +39,4 @@
// public void deleteResource(Integer id, User user) throws KorAPException;
int deleteResource(String id, User user) throws KustvaktException;
-
- int deleteAll() throws KustvaktException;
}
diff --git a/src/main/java/de/ids_mannheim/korap/interfaces/defaults/DefaultAuditing.java b/src/main/java/de/ids_mannheim/korap/interfaces/defaults/DefaultAuditing.java
index bbf895a..ef76c8c 100644
--- a/src/main/java/de/ids_mannheim/korap/interfaces/defaults/DefaultAuditing.java
+++ b/src/main/java/de/ids_mannheim/korap/interfaces/defaults/DefaultAuditing.java
@@ -1,7 +1,7 @@
package de.ids_mannheim.korap.interfaces.defaults;
import de.ids_mannheim.korap.auditing.AuditRecord;
-import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.ContextHolder;
import de.ids_mannheim.korap.config.Configurable;
import de.ids_mannheim.korap.interfaces.db.AuditingIface;
import de.ids_mannheim.korap.user.User;
@@ -18,7 +18,7 @@
* @author hanl
* @date 05/06/2015
*/
-@Configurable(BeanConfiguration.KUSTVAKT_AUDITING)
+@Configurable(ContextHolder.KUSTVAKT_AUDITING)
public class DefaultAuditing extends AuditingIface {
private FileOutputStream stream;
diff --git a/src/main/java/de/ids_mannheim/korap/interfaces/defaults/DefaultEncryption.java b/src/main/java/de/ids_mannheim/korap/interfaces/defaults/DefaultEncryption.java
index 2232c01..108188e 100644
--- a/src/main/java/de/ids_mannheim/korap/interfaces/defaults/DefaultEncryption.java
+++ b/src/main/java/de/ids_mannheim/korap/interfaces/defaults/DefaultEncryption.java
@@ -1,6 +1,6 @@
package de.ids_mannheim.korap.interfaces.defaults;
-import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.ContextHolder;
import de.ids_mannheim.korap.config.Configurable;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.interfaces.EncryptionIface;
@@ -16,7 +16,7 @@
* @author hanl
* @date 05/06/2015
*/
-@Configurable(BeanConfiguration.KUSTVAKT_ENCRYPTION)
+@Configurable(ContextHolder.KUSTVAKT_ENCRYPTION)
public class DefaultEncryption implements EncryptionIface {
private SecureRandom randomizer;
diff --git a/src/main/java/de/ids_mannheim/korap/interfaces/defaults/KustvaktEncryption.java b/src/main/java/de/ids_mannheim/korap/interfaces/defaults/KustvaktEncryption.java
index dbd3649..1707616 100644
--- a/src/main/java/de/ids_mannheim/korap/interfaces/defaults/KustvaktEncryption.java
+++ b/src/main/java/de/ids_mannheim/korap/interfaces/defaults/KustvaktEncryption.java
@@ -283,7 +283,8 @@
// todo: where applied?
@Override
- public Map<String, Object> validateMap(Map<String, Object> map) throws KustvaktException {
+ public Map<String, Object> validateMap(Map<String, Object> map)
+ throws KustvaktException {
Map<String, Object> safeMap = new HashMap<>();
KustvaktMap kmap = new KustvaktMap(map);
@@ -371,13 +372,12 @@
config.getValidationStringLength(), nullable);
}catch (ValidationException ex) {
jlog.error("Validation failed! Value '{}' with type '{}'",
- new Object[] { input, type, ex.getMessage() });
+ new Object[] { input, type });
throw new KustvaktException(StatusCodes.PARAMETER_VALIDATION_ERROR,
"invalid value of type " + type, input);
}
}
-
public void validate(Object instance) throws KustvaktException {
if (instance == null)
return;
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionCleanupFilter.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionCleanupFilter.java
index 6f12d59..f1c8500 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionCleanupFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionCleanupFilter.java
@@ -2,6 +2,8 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import de.ids_mannheim.korap.config.BeanInjectable;
+import de.ids_mannheim.korap.config.ContextHolder;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.utils.JsonUtils;
@@ -12,7 +14,8 @@
* @author hanl
* @date 28/07/2015
*/
-public class CollectionCleanupFilter implements RewriteTask.RewriteNodeAt {
+public class CollectionCleanupFilter
+ implements RewriteTask.RewriteNodeAt {
@Override
public JsonNode preProcess(KoralNode node, KustvaktConfiguration config,
@@ -43,6 +46,7 @@
return null;
}
+ // what happens to array nodes?
if (!root.equals(sub)) {
if (sub.isObject()) {
ObjectNode ob = (ObjectNode) root;
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionConstraint.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionConstraint.java
index 7c9daae..8cd37e1 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionConstraint.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionConstraint.java
@@ -1,6 +1,8 @@
package de.ids_mannheim.korap.resource.rewrite;
import com.fasterxml.jackson.databind.JsonNode;
+import de.ids_mannheim.korap.config.BeanInjectable;
+import de.ids_mannheim.korap.config.ContextHolder;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.resources.Corpus;
@@ -12,8 +14,8 @@
* @author hanl
* @date 03/07/2015
*/
-// todo: test
-public class CollectionConstraint implements RewriteTask.IterableRewriteAt {
+public class CollectionConstraint
+ implements RewriteTask.IterableRewriteAt {
@Override
public JsonNode preProcess(KoralNode node, KustvaktConfiguration config,
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/DocMatchRewrite.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/DocMatchRewrite.java
index cc58817..a15d536 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/DocMatchRewrite.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/DocMatchRewrite.java
@@ -1,7 +1,9 @@
package de.ids_mannheim.korap.resource.rewrite;
import com.fasterxml.jackson.databind.JsonNode;
-import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.BeanInjectable;
+import de.ids_mannheim.korap.config.BeansFactory;
+import de.ids_mannheim.korap.config.ContextHolder;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.handlers.DocumentDao;
@@ -15,32 +17,34 @@
* @author hanl
* @date 12/11/2015
*/
-public class DocMatchRewrite implements RewriteTask.IterableRewriteAt {
+//todo : test
+public class DocMatchRewrite
+ implements RewriteTask.IterableRewriteAt, BeanInjectable {
private DocumentDao docDao;
private Cache cache;
public DocMatchRewrite() {
- this.docDao = new DocumentDao(
- BeanConfiguration.getBeans().getPersistenceClient());
this.cache = CacheManager.getInstance().getCache("documents");
}
@Override
- public JsonNode postProcess(KoralNode node) {
+ public void insertBeans(ContextHolder beans) {
+ this.docDao = BeansFactory.getTypeFactory()
+ .getTypedBean(beans.getResourceProvider(), Document.class);
+ }
+
+ @Override
+ public JsonNode postProcess(KoralNode node) throws KustvaktException {
Document doc = null;
+ if (this.docDao == null)
+ throw new RuntimeException("Document dao must be set!");
if (node.has("docID")) {
String docID = node.get("docID");
Element e = this.cache.get(docID);
if (e == null) {
- try {
- doc = docDao.findbyId(docID, null);
- }catch (KustvaktException ex) {
- ex.printStackTrace();
- // todo: what to do here?!
- }
-
+ doc = docDao.findbyId(docID, null);
if (doc != null)
this.cache.put(new Element(docID, doc));
}else
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/FoundryInject.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/FoundryInject.java
index e7961f9..1bb0174 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/FoundryInject.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/FoundryInject.java
@@ -1,26 +1,42 @@
package de.ids_mannheim.korap.resource.rewrite;
import com.fasterxml.jackson.databind.JsonNode;
-import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.BeanInjectable;
+import de.ids_mannheim.korap.config.BeansFactory;
+import de.ids_mannheim.korap.config.ContextHolder;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.interfaces.db.UserDataDbIface;
import de.ids_mannheim.korap.resource.LayerMapper;
+import de.ids_mannheim.korap.resources.Foundry;
import de.ids_mannheim.korap.user.User;
+import de.ids_mannheim.korap.user.UserSettings;
+import edu.emory.mathcs.backport.java.util.Collections;
+
+import java.util.Collection;
/**
* @author hanl
* @date 30/06/2015
*/
-public class FoundryInject implements RewriteTask.IterableRewriteAt {
+public class FoundryInject
+ implements RewriteTask.IterableRewriteAt, BeanInjectable {
+
+ private Collection userdaos;
+
+ public FoundryInject() {
+ this.userdaos = Collections.emptyList();
+ }
+
@Override
public JsonNode preProcess(KoralNode node, KustvaktConfiguration config,
User user) throws KustvaktException {
LayerMapper mapper;
- if (user != null && BeanConfiguration.hasContext()) {
- UserDataDbIface dao = BeanConfiguration.getBeans()
- .getUserSettingsDao();
+
+ if (user != null && !userdaos.isEmpty()) {
+ UserDataDbIface dao = BeansFactory.getTypeFactory()
+ .getTypedBean(userdaos, UserSettings.class);
mapper = new LayerMapper(config, dao.get(user));
}else
mapper = new LayerMapper(config);
@@ -46,4 +62,9 @@
public JsonNode postProcess(KoralNode node) {
return null;
}
+
+ @Override
+ public <T extends ContextHolder> void insertBeans(T beans) {
+ this.userdaos = beans.getUserDataDaos();
+ }
}
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/IdWriter.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/IdWriter.java
index 737cbe4..66c2e53 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/IdWriter.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/IdWriter.java
@@ -1,6 +1,8 @@
package de.ids_mannheim.korap.resource.rewrite;
import com.fasterxml.jackson.databind.JsonNode;
+import de.ids_mannheim.korap.config.BeanInjectable;
+import de.ids_mannheim.korap.config.ContextHolder;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.user.User;
@@ -8,7 +10,8 @@
* @author hanl
* @date 25/09/2015
*/
-public class IdWriter implements RewriteTask.RewriteKoralToken {
+public class IdWriter
+ implements RewriteTask.RewriteKoralToken {
private int counter;
@@ -34,5 +37,4 @@
return wrap.path("key").asText();
return null;
}
-
}
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/MetaConstraint.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/MetaConstraint.java
index 00aa844..4899fcf 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/MetaConstraint.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/MetaConstraint.java
@@ -1,6 +1,7 @@
package de.ids_mannheim.korap.resource.rewrite;
import com.fasterxml.jackson.databind.JsonNode;
+import de.ids_mannheim.korap.config.BeanInjectable;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.user.User;
@@ -8,7 +9,8 @@
* @author hanl
* @date 04/07/2015
*/
-public class MetaConstraint implements RewriteTask.RewriteNodeAt {
+public class MetaConstraint
+ implements RewriteTask.RewriteNodeAt {
@Override
@@ -33,4 +35,5 @@
public String at() {
return "/meta";
}
+
}
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/PublicCollection.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/PublicCollection.java
index 4cdd1a6..f6a847e 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/PublicCollection.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/PublicCollection.java
@@ -1,6 +1,7 @@
package de.ids_mannheim.korap.resource.rewrite;
import com.fasterxml.jackson.databind.JsonNode;
+import de.ids_mannheim.korap.config.BeanInjectable;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.resources.Corpus;
@@ -14,7 +15,8 @@
* @author hanl
* @date 04/07/2015
*/
-public class PublicCollection implements RewriteTask.RewriteNodeAt {
+public class PublicCollection
+ implements RewriteTask.RewriteNodeAt {
public PublicCollection() {
super();
@@ -59,4 +61,5 @@
public String at() {
return "/collection";
}
+
}
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandler.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandler.java
index b6f7785..90bebd4 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandler.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandler.java
@@ -1,6 +1,8 @@
package de.ids_mannheim.korap.resource.rewrite;
import com.fasterxml.jackson.databind.JsonNode;
+import de.ids_mannheim.korap.config.BeanInjectable;
+import de.ids_mannheim.korap.config.ContextHolder;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.user.User;
@@ -18,7 +20,7 @@
*/
// todo: do post processing!
//todo: load rewritenode and rewritequery automatically from classpath by default, but namespaced from package
-public class RewriteHandler {
+public class RewriteHandler implements BeanInjectable {
private static Logger jlog = LoggerFactory.getLogger(RewriteHandler.class);
private Collection<RewriteTask.IterableRewriteAt> node_processors;
@@ -26,15 +28,33 @@
private Collection<RewriteTask> query_processors;
private Set<Class> failed_task_registration;
-
private KustvaktConfiguration config;
+ private ContextHolder beans;
public RewriteHandler(KustvaktConfiguration config) {
+ this();
this.config = config;
+ }
+
+ public RewriteHandler() {
this.node_processors = new HashSet<>();
this.token_node_processors = new HashSet<>();
this.query_processors = new HashSet<>();
this.failed_task_registration = new HashSet<>();
+ this.beans = null;
+ }
+
+
+ public void defaultRewriteConstraints() {
+ this.add(FoundryInject.class);
+ this.add(PublicCollection.class);
+ this.add(IdWriter.class);
+ this.add(DocMatchRewrite.class);
+ this.add(CollectionCleanupFilter.class);
+ }
+
+ public Set getFailedProcessors() {
+ return this.failed_task_registration;
}
public boolean addProcessor(RewriteTask rewriter) {
@@ -123,12 +143,14 @@
private JsonNode process(JsonNode root, User user, boolean post) {
jlog.debug("Running rewrite process on query {}", root);
- Iterator<Map.Entry<String, JsonNode>> it = root.fields();
- while (it.hasNext()) {
- Map.Entry<String, JsonNode> next = it.next();
- process(next.getKey(), next.getValue(), user, post);
+ if (root!= null) {
+ Iterator<Map.Entry<String, JsonNode>> it = root.fields();
+ while (it.hasNext()) {
+ Map.Entry<String, JsonNode> next = it.next();
+ process(next.getKey(), next.getValue(), user, post);
+ }
+ processFixedNode(root, user, this.query_processors, post);
}
- processFixedNode(root, user, this.query_processors, post);
return root;
}
@@ -157,10 +179,17 @@
// todo: integrate notifications into system!
private boolean processNode(String rootNode, KoralNode node, User user,
Collection<? extends RewriteTask> tasks, boolean post) {
+ if (this.config == null)
+ throw new RuntimeException(
+ "KustvaktConfiguration must be set!");
+
for (RewriteTask task : tasks) {
jlog.debug("running processor on node: " + node);
jlog.debug("on processor: " + task.getClass().toString());
+ if (this.beans != null && task instanceof BeanInjectable)
+ ((BeanInjectable) task).insertBeans(this.beans);
+
if (task instanceof RewriteTask.IterableRewriteAt) {
RewriteTask.IterableRewriteAt rw = (RewriteTask.IterableRewriteAt) task;
if (rw.path() != null && !rw.path().equals(rootNode)) {
@@ -212,4 +241,9 @@
}
}
+ @Override
+ public <T extends ContextHolder> void insertBeans(T beans) {
+ this.beans = beans;
+ this.config = beans.getConfiguration();
+ }
}
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteTask.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteTask.java
index 8166961..308f524 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteTask.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteTask.java
@@ -20,6 +20,7 @@
*/
JsonNode preProcess(KoralNode node, KustvaktConfiguration config,
User user) throws KustvaktException;
+
}
/**
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/TreeConstraint.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/TreeConstraint.java
index 2e56999..d569223 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/TreeConstraint.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/TreeConstraint.java
@@ -1,6 +1,7 @@
package de.ids_mannheim.korap.resource.rewrite;
import com.fasterxml.jackson.databind.JsonNode;
+import de.ids_mannheim.korap.config.BeanInjectable;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.user.User;
@@ -42,7 +43,8 @@
* @author hanl
* @date 02/07/2015
*/
-public class TreeConstraint implements RewriteTask.RewriteNodeAt {
+public class TreeConstraint
+ implements RewriteTask.RewriteNodeAt {
private String pointer;
diff --git a/src/main/java/de/ids_mannheim/korap/resources/Corpus.java b/src/main/java/de/ids_mannheim/korap/resources/Corpus.java
old mode 100755
new mode 100644
diff --git a/src/main/java/de/ids_mannheim/korap/resources/Permissions.java b/src/main/java/de/ids_mannheim/korap/resources/Permissions.java
index c6fc6ec..0cdb37e 100644
--- a/src/main/java/de/ids_mannheim/korap/resources/Permissions.java
+++ b/src/main/java/de/ids_mannheim/korap/resources/Permissions.java
@@ -10,23 +10,22 @@
//fixme: add read_policy permission to allow read policy permissions
READ(Permissions.READ),
-
WRITE(Permissions.WRITE),
+ DELETE(Permissions.DELETE),
- DELETE(Permissions.READ),
READ_POLICY(Permissions.READ_POLICY),
CREATE_POLICY(Permissions.CREATE_POLICY),
MODIFY_POLICY(Permissions.MODIFY_POLICY),
DELETE_POLICY(Permissions.DELETE_POLICY),
ALL(Permissions.ALL);
- private final Byte b;
+ private final byte b;
- Permission(Byte b) {
+ Permission(byte b) {
this.b = b;
}
- public Byte toByte() {
+ public byte toByte() {
return this.b;
}
}
@@ -40,28 +39,4 @@
private static final byte DELETE_POLICY = 64;
private static final byte ALL = 127;
- @Deprecated
- public static Byte getByte(Permission perm) {
- switch (perm) {
- case READ:
- return READ;
- case WRITE:
- return WRITE;
- case DELETE:
- return DELETE;
- case READ_POLICY:
- return READ_POLICY;
- case DELETE_POLICY:
- return DELETE_POLICY;
- case MODIFY_POLICY:
- return MODIFY_POLICY;
- case CREATE_POLICY:
- return CREATE_POLICY;
- case ALL:
- return ALL;
- default:
- return 0;
- }
- }
-
-}
+}
\ No newline at end of file
diff --git a/src/main/java/de/ids_mannheim/korap/resources/ResourceFactory.java b/src/main/java/de/ids_mannheim/korap/resources/ResourceFactory.java
old mode 100755
new mode 100644
index 231017b..48e4747
--- a/src/main/java/de/ids_mannheim/korap/resources/ResourceFactory.java
+++ b/src/main/java/de/ids_mannheim/korap/resources/ResourceFactory.java
@@ -28,7 +28,7 @@
try {
return (KustvaktResource) clazz.newInstance();
}catch (InstantiationException | IllegalAccessException e) {
- e.printStackTrace();
+ // do nothing
}
return null;
}
diff --git a/src/main/java/de/ids_mannheim/korap/resources/VirtualCollection.java b/src/main/java/de/ids_mannheim/korap/resources/VirtualCollection.java
old mode 100755
new mode 100644
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 88f433e..5f775ad 100644
--- a/src/main/java/de/ids_mannheim/korap/security/Parameter.java
+++ b/src/main/java/de/ids_mannheim/korap/security/Parameter.java
@@ -6,9 +6,8 @@
/**
* @author hanl@ids-mannheim.de
- * @date 09/11/13
+ * @date 09/11/14
*/
-//todo:
@Getter
public class Parameter extends KustvaktResource {
diff --git a/src/main/java/de/ids_mannheim/korap/security/PermissionsBuffer.java b/src/main/java/de/ids_mannheim/korap/security/PermissionsBuffer.java
index 96f1e72..9c63a15 100644
--- a/src/main/java/de/ids_mannheim/korap/security/PermissionsBuffer.java
+++ b/src/main/java/de/ids_mannheim/korap/security/PermissionsBuffer.java
@@ -34,7 +34,7 @@
}
public boolean containsPermission(Permissions.Permission p) {
- return containsPByte(Permissions.getByte(p));
+ return containsPByte(p.toByte());
}
public boolean containsPByte(byte perm) {
@@ -44,7 +44,7 @@
public int addPermission(int b) {
short r = (short) (bytes[1] & b);
if ((bytes[1] & b) != b)
- bytes[1] += (b - r);
+ bytes[1] += b;
else
return -1;
return 0;
@@ -121,6 +121,10 @@
return b.getShort();
}
+ public byte[] getByteArray() {
+ return bytes;
+ }
+
public Byte getPbyte() {
return this.bytes[1];
}
@@ -131,18 +135,6 @@
if (containsPByte(p.toByte()))
pe.add(p);
}
- // if (containsPByte(Permissions.READ))
- // pe.add(Permissions.Permission.READ);
- // if (containsPByte(Permissions.WRITE))
- // pe.add(Permissions.Permission.WRITE);
- // if (containsPByte(Permissions.DELETE))
- // pe.add(Permissions.Permission.DELETE);
- // if (containsPByte(Permissions.CREATE_POLICY))
- // pe.add(Permissions.Permission.CREATE_POLICY);
- // if (containsPByte(Permissions.MODIFY_POLICY))
- // pe.add(Permissions.Permission.MODIFY_POLICY);
- // if (containsPByte(Permissions.DELETE_POLICY))
- // pe.add(Permissions.Permission.DELETE_POLICY);
return pe;
}
diff --git a/src/main/java/de/ids_mannheim/korap/security/SecurityPolicy.java b/src/main/java/de/ids_mannheim/korap/security/SecurityPolicy.java
index dfaece7..9539cb8 100644
--- a/src/main/java/de/ids_mannheim/korap/security/SecurityPolicy.java
+++ b/src/main/java/de/ids_mannheim/korap/security/SecurityPolicy.java
@@ -22,6 +22,7 @@
// 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;
@@ -86,9 +87,9 @@
// todo ???????
@Deprecated
- public SecurityPolicy setOverride(Permissions.Permission... perms) {
+ private SecurityPolicy setOverride(Permissions.Permission... perms) {
for (Permissions.Permission p : perms)
- this.permissions.addOverride(Permissions.getByte(p));
+ this.permissions.addOverride(p.toByte());
return this;
}
@@ -155,11 +156,16 @@
if (this.addedidx.contains(idx))
this.addedidx.remove(idx);
else
- this.removedidx.add(this.conditions.indexOf(constraint));
+ 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;
diff --git a/src/main/java/de/ids_mannheim/korap/security/ac/PolicyBuilder.java b/src/main/java/de/ids_mannheim/korap/security/ac/PolicyBuilder.java
index 7e65b7c..8fff53c 100644
--- a/src/main/java/de/ids_mannheim/korap/security/ac/PolicyBuilder.java
+++ b/src/main/java/de/ids_mannheim/korap/security/ac/PolicyBuilder.java
@@ -151,7 +151,7 @@
}else if (rel.equals(Relation.OR)) {
for (PolicyCondition c : this.conditions) {
SecurityPolicy policy = new SecurityPolicy()
- .addCondition(c).setTarget(resources[idx])
+ .addNewCondition(c).setTarget(resources[idx])
.addPermission(permissions)
.setCreator(this.user.getId());
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 75d2e8a..57d4658 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
@@ -79,10 +79,10 @@
MapSqlParameterSource np = new MapSqlParameterSource();
np.addValue("target", policy.getTarget());
if (policy.getContext().getEnd() != 0L)
- np.addValue("exp", new Timestamp(policy.getContext().getEnd()));
+ np.addValue("exp", policy.getContext().getEnd());
else
np.addValue("exp", null);
- np.addValue("en", new Timestamp(policy.getContext().getStart()));
+ np.addValue("en", policy.getContext().getStart());
np.addValue("posix", policy.getPermissionByte());
np.addValue("cr", new Timestamp(TimeUtils.getNow().getMillis()));
np.addValue("creator", user.getId());
@@ -95,6 +95,7 @@
this.mapConstraints(policy);
return policy.getID();
}catch (DataAccessException e) {
+ e.printStackTrace();
jlog.error("Operation (INSERT) not possible for '{}' for user '{}'",
policy.toString(), user.getId());
throw new dbException(user.getId(), "policy_store",
@@ -146,6 +147,7 @@
}
policy.clear();
}catch (DataAccessException e) {
+ e.printStackTrace();
jlog.error(
"Operation (MAPPING POLICY CONDITIONS) not possible for '{}' for user '{}'",
policy.toString(), policy.getCreator());
@@ -249,7 +251,6 @@
param.addValue("perm", perm);
param.addValue("type", ResourceFactory.getResourceMapping(clazz));
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 "
@@ -258,7 +259,7 @@
"where " +
"pv.enable <= :en and (pv.expire > :en or pv.expire is NULL) and "
+
- "pv.group_id=:cond and pv.typeand " +
+ "pv.group_id=:cond and pv.type=:type 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)"
@@ -276,8 +277,7 @@
}
});
}catch (DataAccessException e) {
- e.printStackTrace();
- jlog.error("Permission Denied for policy retrieval for '{}'",
+ jlog.error("Permission Denied: policy retrieval for '{}'",
condition.getSpecifier());
return Collections.emptyList();
}
@@ -308,7 +308,6 @@
"(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 in (select g.group_id from group_users "
+
"as g where g.user_id=:userid) 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>[]>() {
@@ -316,12 +315,14 @@
@Override
public List<SecurityPolicy>[] extractData(ResultSet rs)
throws SQLException, DataAccessException {
- return SecurityRowMappers.mapResourcePolicies(rs);
+ List<SecurityPolicy>[] pol = SecurityRowMappers
+ .mapResourcePolicies(rs);
+ return pol;
}
});
}catch (DataAccessException e) {
jlog.error(
- "Permission Denied for policy retrieval for '{}' for user '{}'",
+ "Permission Denied: policy retrieval for '{}' for user '{}'",
target, user.getId());
return new List[2];
}
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
old mode 100755
new mode 100644
index bc3bcb4..232c5eb
--- a/src/main/java/de/ids_mannheim/korap/security/ac/ResourceFinder.java
+++ b/src/main/java/de/ids_mannheim/korap/security/ac/ResourceFinder.java
@@ -1,6 +1,7 @@
package de.ids_mannheim.korap.security.ac;
-import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.ContextHolder;
+import de.ids_mannheim.korap.config.BeansFactory;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.interfaces.db.PolicyHandlerIface;
import de.ids_mannheim.korap.interfaces.db.ResourceOperationIface;
@@ -12,6 +13,7 @@
import de.ids_mannheim.korap.security.SecurityPolicy;
import de.ids_mannheim.korap.user.Attributes;
import de.ids_mannheim.korap.user.User;
+import lombok.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -20,12 +22,13 @@
/**
* Created by hanl on 3/20/14.
*/
+//todo: use factory pattern to init resourcefinder
public class ResourceFinder {
private static final Logger jlog = LoggerFactory
.getLogger(ResourceFinder.class);
private static PolicyHandlerIface policydao;
- private static ResourceOperationIface resourcedao;
+ private static Map<Class, ResourceOperationIface> resourcedaos = new HashMap<>();
private List<KustvaktResource.Container> containers;
private User user;
@@ -37,17 +40,18 @@
private ResourceFinder() {
this.containers = new ArrayList<>();
- checkProviders();
+ overrideProviders(null);
}
- private static void checkProviders() {
- if (BeanConfiguration.hasContext() && policydao == null) {
- ResourceFinder.policydao = BeanConfiguration.getBeans()
- .getPolicyDbProvider();
- ResourceFinder.resourcedao = BeanConfiguration.getBeans()
- .getResourceProvider();
+ public static void overrideProviders(ContextHolder beans) {
+ if (beans == null)
+ beans = BeansFactory.getKustvaktContext();
+ if (policydao == null | resourcedaos == null) {
+ ResourceFinder.policydao = beans.getPolicyDbProvider();
+ for (ResourceOperationIface iface : beans.getResourceProvider())
+ resourcedaos.put(iface.type(), iface);
}
- if (policydao == null | resourcedao == null)
+ if (policydao == null | resourcedaos.isEmpty())
throw new RuntimeException("provider not set!");
}
@@ -71,8 +75,8 @@
}
//todo: needs to be much faster!
- public static <T extends KustvaktResource> ResourceFinder init(User user,
- Class<T> clazz) throws KustvaktException {
+ public static <T extends KustvaktResource> ResourceFinder init(
+ @NonNull User user, Class<T> clazz) throws KustvaktException {
return init(null, true, user, clazz, Permissions.Permission.READ);
}
@@ -85,15 +89,25 @@
public static <T extends KustvaktResource> Set<T> searchPublic(
Class<T> clazz) throws KustvaktException {
- checkProviders();
+ return searchPublicFiltered(clazz);
+ }
+
+ public static <T extends KustvaktResource> Set<T> searchPublicFiltered(
+ Class<T> clazz, String ...ids) throws KustvaktException {
+ overrideProviders(null);
Set<T> sets = new HashSet<>();
List<SecurityPolicy> policies = policydao
.getPolicies(new PolicyCondition(Attributes.PUBLIC_GROUP),
clazz, Permissions.Permission.READ.toByte());
- for (SecurityPolicy policy : policies)
- sets.add((T) resourcedao.findbyId(policy.getTarget(),
- User.UserFactory.getDemoUser()));
+ List<String> id_set = Arrays.asList(ids);
+ for (SecurityPolicy policy : policies) {
+ T r = (T) resourcedaos.get(KustvaktResource.class)
+ .findbyId(policy.getTarget(),
+ User.UserFactory.getDemoUser());
+ if (id_set.isEmpty() || id_set.contains(r.getPersistentID()))
+ sets.add(r);
+ }
return sets;
}
@@ -123,10 +137,8 @@
Set<T> resources = new HashSet<>();
if (this.containers != null) {
for (KustvaktResource.Container c : this.containers) {
- ResourceOperationIface<T> iface = BeanConfiguration.getBeans()
- .getResourceProvider();
try {
- T resource = (T) iface
+ T resource = (T) resourcedaos.get(KustvaktResource.class)
.findbyId(c.getPersistentID(), this.user);
if (resource != null) {
PolicyEvaluator e = PolicyEvaluator
diff --git a/src/main/java/de/ids_mannheim/korap/security/ac/ResourceHandler.java b/src/main/java/de/ids_mannheim/korap/security/ac/ResourceHandler.java
index 7510e23..840461b 100644
--- a/src/main/java/de/ids_mannheim/korap/security/ac/ResourceHandler.java
+++ b/src/main/java/de/ids_mannheim/korap/security/ac/ResourceHandler.java
@@ -20,6 +20,8 @@
* @date 23/03/2014
*/
+//todo: use interface (maybe a cachable interface?) and bean instanceing
+// todo: if cachable, data integrity needs to be checked! either remove caching or check integrity!
@SuppressWarnings("all")
public class ResourceHandler {
@@ -56,7 +58,7 @@
try {
p = SecurityManager.findbyId(id, user);
} catch (EmptyResultException e) {
- throw new NotAuthorizedException(StatusCodes.PERMISSION_DENIED);
+ throw new NotAuthorizedException(StatusCodes.EMPTY_RESULTS, String.valueOf(id));
}
return p.getResource();
}
@@ -64,22 +66,17 @@
public <T extends KustvaktResource> T findbyStrId(String persistent_id,
User user, String type)
throws KustvaktException, NotAuthorizedException {
- T cache = (T) getCache(persistent_id, ResourceFactory
- .getResourceClass(type));
- if (cache != null)
- return cache;
- else
- return (T) findbyStrId(persistent_id, user,
- ResourceFactory.getResourceClass(type));
+ return (T) findbyStrId(persistent_id, user,
+ ResourceFactory.getResourceClass(type));
}
public <T extends KustvaktResource> T findbyStrId(String persistent_id,
User user, Class<T> type)
throws KustvaktException, NotAuthorizedException {
- T cache = (T) getCache(persistent_id, type);
- if (cache != null)
- return cache;
- else {
+ //T cache = (T) getCache(persistent_id, type);
+ //if (cache != null)
+ // return cache;
+ //else {
SecurityManager<T> p;
try {
p = SecurityManager.findbyId(persistent_id, user, type);
@@ -87,7 +84,7 @@
throw new NotAuthorizedException(StatusCodes.EMPTY_RESULTS, persistent_id);
}
return p.getResource();
- }
+ //}
}
public <T extends KustvaktResource> Collection<T> findbyPath(String path, Class type, User user)
@@ -136,14 +133,14 @@
public <T extends KustvaktResource> void deleteResources(User user, T... resources)
throws KustvaktException, NotAuthorizedException {
for (T r : resources) {
- SecurityManager policies;
+ SecurityManager manager;
try {
- policies = SecurityManager.findbyId(r.getPersistentID(), user, r.getClass(),
+ manager = SecurityManager.findbyId(r.getPersistentID(), user, r.getClass(),
Permissions.Permission.DELETE);
} catch (EmptyResultException e) {
return;
}
- policies.deleteResource();
+ manager.deleteResource();
}
}
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 b05d810..b66fe62 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
@@ -1,6 +1,7 @@
package de.ids_mannheim.korap.security.ac;
-import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.ContextHolder;
+import de.ids_mannheim.korap.config.BeansFactory;
import de.ids_mannheim.korap.exceptions.EmptyResultException;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.NotAuthorizedException;
@@ -54,20 +55,20 @@
this.policies[0] = new ArrayList<>();
this.silent = true;
this.user = user;
- checkProviders();
+ overrideProviders(null);
}
- private static void checkProviders() {
- if (BeanConfiguration.hasContext() && (policydao == null
- | crypto == null)) {
- SecurityManager.policydao = BeanConfiguration.getBeans()
- .getPolicyDbProvider();
- SecurityManager.crypto = BeanConfiguration.getBeans()
- .getEncryption();
+ public static void overrideProviders(ContextHolder beans) {
+ if (beans == null)
+ beans = BeansFactory.getKustvaktContext();
+ if (policydao == null | crypto == null) {
+ SecurityManager.policydao = beans.getPolicyDbProvider();
+ SecurityManager.crypto = beans.getEncryption();
SecurityManager.handlers = new HashMap<>();
- ResourceOperationIface rprovider = BeanConfiguration.getBeans()
+ Collection<ResourceOperationIface> providers = beans
.getResourceProvider();
- SecurityManager.handlers.put(rprovider.type(), rprovider);
+ for (ResourceOperationIface op : providers)
+ SecurityManager.handlers.put(op.type(), op);
}
if (policydao == null && crypto == null)
throw new RuntimeException("providers not set!");
@@ -214,9 +215,6 @@
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]);
this.evaluator = new PolicyEvaluator(this.user, this.policies);
if (this.policies == null) {
@@ -242,7 +240,8 @@
iface = handlers.get(KustvaktResource.class);
T resource = (T) iface
.findbyId(this.evaluator.getResourceID(), this.user);
- // todo: fix this
+ // fixme: this
+ // fixme: deprecated!
resource.setManaged(this.evaluator.isManaged());
resource.setShared(this.evaluator.isShared());
return resource;
@@ -257,7 +256,7 @@
public static SecurityManager register(KustvaktResource resource, User user)
throws KustvaktException, NotAuthorizedException {
SecurityManager p = new SecurityManager(user);
- if (!user.isDemo()) {
+ if (!User.UserFactory.isDemo(user.getUsername())) {
if (resource.getParentID() != null) {
try {
// the owner has all rights per default, in order to be able derivate from a parent resource, he needs all permissions as well
@@ -408,6 +407,7 @@
}
}
+ // todo:
public void deletePolicy(SecurityPolicy policy)
throws KustvaktException, NotAuthorizedException {
// todo: get rid of this: use sql to match policy id and target according to evaluator!
@@ -492,5 +492,4 @@
return false;
}
}
-
}
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 efcc95c..0ab9cbd 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
@@ -26,9 +26,10 @@
@Override
public SecurityPolicy mapRow(ResultSet rs, int rowNum)
throws SQLException {
+ String perms = rs.getString("perm");
SecurityPolicy p = new SecurityPolicy();
p.setID(rs.getInt("pid")).setTarget(rs.getString("persistent_id"))
- .setPOSIX(rs.getString("perm"));
+ .setPOSIX(perms);
PolicyContext context = new PolicyContext();
context.setIPMask(rs.getString("iprange"));
@@ -70,14 +71,16 @@
}
}
+ @SuppressWarnings(value = "all")
public static List<SecurityPolicy>[] mapResourcePolicies(ResultSet rs)
throws SQLException {
List<SecurityPolicy>[] policyArray = null;
List<Integer>[] idx = null;
+ loop:
while (rs.next()) {
- // user has no permission here --> thus skip
+ // user has no permission here, thus skip
if (rs.getInt("allowed") == 0)
- continue;
+ continue loop;
if (policyArray == null) {
int v = rs.getInt("max_depth") + 1;
@@ -86,7 +89,6 @@
}
int depth = rs.getInt("depth");
-
if (policyArray[depth] == null) {
policyArray[depth] = new ArrayList<>();
idx[depth] = new ArrayList<>();
@@ -142,7 +144,7 @@
PolicyCondition c = new PolicyCondition(rs.getString("group_id"));
if (!policy.contains(c))
- policy.addCondition(c);
+ policy.addNewCondition(c);
}
return new ArrayList<>(policyMap.values());
}
@@ -172,7 +174,7 @@
PolicyCondition c = new PolicyCondition(rs.getString("group_id"));
if (!policy.contains(c))
- policy.addCondition(c);
+ policy.addNewCondition(c);
}
List<SecurityPolicy>[] results;
diff --git a/src/main/java/de/ids_mannheim/korap/security/auth/BasicHttpAuth.java b/src/main/java/de/ids_mannheim/korap/security/auth/BasicHttpAuth.java
index aa7b28b..c93d6ec 100644
--- a/src/main/java/de/ids_mannheim/korap/security/auth/BasicHttpAuth.java
+++ b/src/main/java/de/ids_mannheim/korap/security/auth/BasicHttpAuth.java
@@ -1,6 +1,6 @@
package de.ids_mannheim.korap.security.auth;
-import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.BeansFactory;
import de.ids_mannheim.korap.config.Scopes;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
@@ -47,8 +47,8 @@
@Override
public TokenContext getUserStatus(String authToken)
throws KustvaktException {
- EncryptionIface crypto = BeanConfiguration.getBeans().getEncryption();
- EntityHandlerIface dao = BeanConfiguration.getBeans()
+ EncryptionIface crypto = BeansFactory.getKustvaktContext().getEncryption();
+ EntityHandlerIface dao = BeansFactory.getKustvaktContext()
.getUserDBHandler();
String[] values = decode(authToken);
if (values != 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 29c3641..fe33683 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
@@ -1,6 +1,7 @@
package de.ids_mannheim.korap.security.auth;
import de.ids_mannheim.korap.auditing.AuditRecord;
+import de.ids_mannheim.korap.config.BeansFactory;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.config.URIParam;
import de.ids_mannheim.korap.exceptions.*;
@@ -23,6 +24,7 @@
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
+import java.util.Collection;
import java.util.Map;
/**
@@ -40,18 +42,20 @@
private EntityHandlerIface entHandler;
private AuditingIface auditing;
private KustvaktConfiguration config;
- private final LoginCounter counter;
+ private Collection userdatadaos;
+ private LoginCounter counter;
private Cache user_cache;
public KustvaktAuthenticationManager(EntityHandlerIface userdb,
EncryptionIface crypto, KustvaktConfiguration config,
- AuditingIface auditer) {
+ AuditingIface auditer, Collection<UserDataDbIface> userdatadaos) {
+ this.user_cache = CacheManager.getInstance().getCache("users");
this.entHandler = userdb;
this.config = config;
this.crypto = crypto;
this.auditing = auditer;
this.counter = new LoginCounter(config);
- this.user_cache = CacheManager.getInstance().getCache("users");
+ this.userdatadaos = userdatadaos;
}
/**
@@ -485,8 +489,11 @@
}
KorAPUser user = User.UserFactory.getUser(username);
- user.setAccountLocked(confirmation_required);
+ Object id = attributes.get(Attributes.ID);
+ if (id != null && id instanceof Integer)
+ user.setId((Integer) id);
+ user.setAccountLocked(confirmation_required);
if (confirmation_required) {
URIParam param = new URIParam(crypto.createToken(),
TimeUtils.plusSeconds(config.getExpiration()).getMillis());
@@ -505,10 +512,15 @@
settings.readDefaults(safeMap);
settings.checkRequired();
- UserdataFactory.getDaoInstance(UserDetails.class).store(details);
- UserdataFactory.getDaoInstance(UserSettings.class).store(settings);
+ UserDataDbIface dao = BeansFactory.getTypeFactory()
+ .getTypedBean(userdatadaos, UserDetails.class);
+ assert dao != null;
+ dao.store(details);
+ dao = BeansFactory.getTypeFactory()
+ .getTypedBean(userdatadaos, UserSettings.class);
+ assert dao != null;
+ dao.store(settings);
}catch (KustvaktException e) {
- e.printStackTrace();
throw new WrappedException(e, StatusCodes.CREATE_ACCOUNT_FAILED,
user.toString());
}
@@ -538,12 +550,19 @@
d.readDefaults(attributes);
d.checkRequired();
- UserdataFactory.getDaoInstance(d.getClass()).store(d);
+ UserDataDbIface dao = BeansFactory.getTypeFactory()
+ .getTypedBean(userdatadaos, UserDetails.class);
+ assert dao != null;
+ dao.store(d);
UserSettings s = new UserSettings(user.getId());
s.readDefaults(attributes);
s.checkRequired();
- UserdataFactory.getDaoInstance(s.getClass()).store(s);
+
+ dao = BeansFactory.getTypeFactory()
+ .getTypedBean(userdatadaos, UserSettings.class);
+ assert dao != null;
+ dao.store(d);
return user;
}
@@ -681,13 +700,16 @@
throws WrappedException {
try {
- UserDataDbIface<T> dao = UserdataFactory.getDaoInstance(clazz);
- T data = dao.get(user);
+ UserDataDbIface<T> dao = BeansFactory.getTypeFactory()
+ .getTypedBean(BeansFactory.getKustvaktContext().getUserDataDaos(), clazz);
+ T data = null;
+ if (dao != null)
+ data = dao.get(user);
+
if (data == null)
throw new WrappedException(user.getId(),
- StatusCodes.EMPTY_RESULTS, clazz.getSimpleName());
-
- return data;
+ StatusCodes.EMPTY_RESULTS, clazz.getSimpleName());
+ return data;
}catch (KustvaktException e) {
jlog.error("Error ", e);
throw new WrappedException(e, StatusCodes.GET_ACCOUNT_FAILED);
@@ -698,10 +720,12 @@
@Override
public void updateUserData(Userdata data) throws WrappedException {
try {
+
data.validate(this.crypto);
- UserDataDbIface dao = UserdataFactory
- .getDaoInstance(data.getClass());
- dao.update(data);
+ UserDataDbIface dao = BeansFactory.getTypeFactory()
+ .getTypedBean(BeansFactory.getKustvaktContext().getUserDataDaos(), data.getClass());
+ if (dao != null)
+ dao.update(data);
}catch (KustvaktException e) {
jlog.error("Error ", e);
throw new WrappedException(e, StatusCodes.UPDATE_ACCOUNT_FAILED);
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 e266f1f..8161254 100644
--- a/src/main/java/de/ids_mannheim/korap/user/User.java
+++ b/src/main/java/de/ids_mannheim/korap/user/User.java
@@ -123,10 +123,6 @@
return true;
}
- public boolean isDemo() {
- return this.getUsername().equalsIgnoreCase(DemoUser.DEMOUSER_NAME);
- }
-
public boolean isAdmin() {
return this.getUsername().equals(ADMINISTRATOR_ID);
}
diff --git a/src/main/java/de/ids_mannheim/korap/user/Userdata.java b/src/main/java/de/ids_mannheim/korap/user/Userdata.java
index 616857d..7b88f00 100644
--- a/src/main/java/de/ids_mannheim/korap/user/Userdata.java
+++ b/src/main/java/de/ids_mannheim/korap/user/Userdata.java
@@ -57,8 +57,11 @@
return this.fields.get(key);
}
+ /**
+ *
+ * @return
+ */
public boolean isValid() {
- // return this.missing(this.fields).isEmpty() && this.userID != -1;
return missing().length == 0;
}
@@ -111,7 +114,7 @@
return JsonUtils.toJSON(this.fields);
}
- public void addField(String key, Object value) {
+ public void setField(String key, Object value) {
this.fields.put(key, value);
}
diff --git a/src/main/java/de/ids_mannheim/korap/user/UserdataFactory.java b/src/main/java/de/ids_mannheim/korap/user/UserdataFactory.java
index 85e8046..3e899b2 100644
--- a/src/main/java/de/ids_mannheim/korap/user/UserdataFactory.java
+++ b/src/main/java/de/ids_mannheim/korap/user/UserdataFactory.java
@@ -1,6 +1,6 @@
package de.ids_mannheim.korap.user;
-import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.BeansFactory;
import de.ids_mannheim.korap.config.KustvaktClassLoader;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
@@ -11,6 +11,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -19,6 +20,7 @@
* @author hanl
* @date 27/01/2016
*/
+@Deprecated
public class UserdataFactory {
private static final Map<Class<? extends Userdata>, UserDataDbIface> instances = new HashMap<>();
@@ -26,7 +28,23 @@
private UserdataFactory() {
}
- public static Class<? extends UserDataDbIface> getClass(
+ public static UserDataDbIface getDaoInstanceFromBean(
+ Class<? extends Userdata> type) {
+ Collection<UserDataDbIface> daos = BeansFactory.getKustvaktContext()
+ .getUserDataDaos();
+ for (UserDataDbIface o : daos) {
+ Type gtype = o.getClass().getGenericInterfaces()[0];
+ if (gtype instanceof ParameterizedType) {
+ ParameterizedType ptype = (ParameterizedType) gtype;
+ Class ctype = (Class) ptype.getActualTypeArguments()[0];
+ if (ctype.equals(type))
+ return o;
+ }
+ }
+ return null;
+ }
+
+ public static Class<? extends UserDataDbIface> getClassFromAnno(
Class<? extends Userdata> data) {
Set<Class<? extends UserDataDbIface>> c = KustvaktClassLoader
.loadSubTypes(UserDataDbIface.class);
@@ -42,15 +60,17 @@
return null;
}
- public static UserDataDbIface getDaoInstance(
- Class<? extends Userdata> data) throws KustvaktException {
+ // todo: remove and load userdata via bean context
+ @Deprecated
+ public static UserDataDbIface getDaoInstance(Class<? extends Userdata> data)
+ throws KustvaktException {
if (instances.get(data) == null) {
- Class<? extends UserDataDbIface> cl = getClass(data);
- if (BeanConfiguration.hasContext() && cl != null) {
+ Class<? extends UserDataDbIface> cl = getClassFromAnno(data);
+ if (cl != null) {
try {
Constructor c = cl.getConstructor(PersistenceClient.class);
UserDataDbIface iface = (UserDataDbIface) c.newInstance(
- BeanConfiguration.getBeans()
+ BeansFactory.getKustvaktContext()
.getPersistenceClient());
instances.put(data, iface);
return iface;
@@ -59,7 +79,8 @@
}
}
throw new KustvaktException(StatusCodes.NOT_SUPPORTED,
- "No database handler found for type " + data.getSimpleName());
+ "No database handler found for type " + data
+ .getSimpleName());
}else
return instances.get(data);
}
diff --git a/src/main/java/de/ids_mannheim/korap/utils/IPNetMask.java b/src/main/java/de/ids_mannheim/korap/utils/IPNetMask.java
old mode 100755
new mode 100644
diff --git a/src/main/java/de/ids_mannheim/korap/utils/PropertyReader.java b/src/main/java/de/ids_mannheim/korap/utils/PropertyReader.java
index 292b019..9d953b5 100644
--- a/src/main/java/de/ids_mannheim/korap/utils/PropertyReader.java
+++ b/src/main/java/de/ids_mannheim/korap/utils/PropertyReader.java
@@ -1,5 +1,7 @@
package de.ids_mannheim.korap.utils;
+import de.ids_mannheim.korap.config.BeanInjectable;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -13,7 +15,6 @@
*/
public abstract class PropertyReader {
-
protected Map<String, Properties> read(String path) throws IOException {
Map<String, Properties> res = new HashMap<>();
Properties s = new Properties();
@@ -30,7 +31,6 @@
return res;
}
-
public abstract void load();
}
diff --git a/src/main/java/de/ids_mannheim/korap/utils/ServiceVersion.java b/src/main/java/de/ids_mannheim/korap/utils/ServiceVersion.java
deleted file mode 100755
index 1233c15..0000000
--- a/src/main/java/de/ids_mannheim/korap/utils/ServiceVersion.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package de.ids_mannheim.korap.utils;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
-/**
- * @author hanl
- * @date 23/01/2014
- */
-public class ServiceVersion {
-
- private ServiceVersion() {
- }
-
- public static String getAPIVersion() {
- String path = "/version.prop";
- InputStream stream = ServiceVersion.class.getResourceAsStream(path);
- if (stream == null)
- return "UNKNOWN";
-
- Properties props = new Properties();
- try {
- props.load(stream);
- stream.close();
- return (String) props.get("version");
- }catch (IOException e) {
- return "UNKNOWN";
- }
-
- }
-
-}
diff --git a/src/main/java/de/ids_mannheim/korap/utils/UserPropertyReader.java b/src/main/java/de/ids_mannheim/korap/utils/UserPropertyReader.java
index 3369106..be187b7 100644
--- a/src/main/java/de/ids_mannheim/korap/utils/UserPropertyReader.java
+++ b/src/main/java/de/ids_mannheim/korap/utils/UserPropertyReader.java
@@ -1,10 +1,11 @@
package de.ids_mannheim.korap.utils;
-import de.ids_mannheim.korap.config.BeanConfiguration;
+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.db.EntityHandlerIface;
+import de.ids_mannheim.korap.interfaces.db.UserDataDbIface;
import de.ids_mannheim.korap.user.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -31,8 +32,8 @@
public UserPropertyReader(String path) {
this.path = path;
- this.iface = BeanConfiguration.getBeans().getUserDBHandler();
- this.crypto = BeanConfiguration.getBeans().getEncryption();
+ this.iface = BeansFactory.getKustvaktContext().getUserDBHandler();
+ this.crypto = BeansFactory.getKustvaktContext().getEncryption();
}
@Override
@@ -100,13 +101,18 @@
UserDetails det = new UserDetails(user.getId());
det.readDefaults(vals);
det.validate(crypto);
- UserdataFactory.getDaoInstance(det.getClass()).store(det);
Userdata set = new UserSettings(user.getId());
set.readDefaults(vals);
set.validate(crypto);
- UserdataFactory.getDaoInstance(set.getClass()).store(set);
+ UserDataDbIface dao = BeansFactory.getTypeFactory()
+ .getTypedBean(BeansFactory.getKustvaktContext().getUserDataDaos(), UserDetails.class);
+ dao.store(det);
+
+ dao = BeansFactory.getTypeFactory()
+ .getTypedBean(BeansFactory.getKustvaktContext().getUserDataDaos(), UserSettings.class);
+ dao.store(set);
}
jlog.info("successfully created account for user {}",
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 4934ac8..b3fdb51 100644
--- a/src/main/java/de/ids_mannheim/korap/web/KustvaktBaseServer.java
+++ b/src/main/java/de/ids_mannheim/korap/web/KustvaktBaseServer.java
@@ -3,12 +3,12 @@
import com.sun.jersey.api.core.PackagesResourceConfig;
import com.sun.jersey.api.core.ResourceConfig;
import com.sun.jersey.spi.container.servlet.ServletContainer;
-import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.BeansFactory;
import de.ids_mannheim.korap.config.KustvaktCacheManager;
import de.ids_mannheim.korap.config.KustvaktClassLoader;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.web.service.BootupInterface;
+import de.ids_mannheim.korap.web.service.BootableBeanInterface;
import lombok.Getter;
import lombok.Setter;
import org.eclipse.jetty.server.Connector;
@@ -35,9 +35,9 @@
KustvaktArgs kargs = server.readAttributes(args);
if (kargs.config != null)
- BeanConfiguration.loadFileContext(kargs.config);
+ BeansFactory.loadFileContext(kargs.config);
else
- BeanConfiguration.loadClasspathContext();
+ BeansFactory.loadClasspathContext();
KustvaktCacheManager.init();
@@ -60,9 +60,6 @@
case "--port":
kargs.setPort(Integer.valueOf(args[i + 1]));
break;
- case "--props":
- kargs.setProperties(args[+1]);
- break;
case "--help":
StringBuffer b = new StringBuffer();
@@ -83,14 +80,14 @@
}
public void runPreStart() {
- Set<Class<? extends BootupInterface>> set = KustvaktClassLoader
- .loadSubTypes(BootupInterface.class);
+ Set<Class<? extends BootableBeanInterface>> set = KustvaktClassLoader
+ .loadSubTypes(BootableBeanInterface.class);
- List<BootupInterface> list = new ArrayList<>(set.size());
+ List<BootableBeanInterface> list = new ArrayList<>(set.size());
for (Class cl : set) {
- BootupInterface iface;
+ BootableBeanInterface iface;
try {
- iface = (BootupInterface) cl.newInstance();
+ iface = (BootableBeanInterface) cl.newInstance();
list.add(iface);
}catch (InstantiationException | IllegalAccessException e) {
continue;
@@ -99,10 +96,9 @@
System.out.println("Found boot loading interfaces: " + list);
int track = list.size();
while (!list.isEmpty()) {
- System.out.println("ITERATING LIST IS " + list);
- for (BootupInterface iface : new ArrayList<>(list)) {
+ for (BootableBeanInterface iface : new ArrayList<>(list)) {
try {
- iface.load();
+ iface.load(BeansFactory.getKustvaktContext());
}catch (KustvaktException e) {
// don't do anything!
System.out.println(
@@ -124,8 +120,7 @@
runPreStart();
if (kargs.port == -1)
- kargs.setPort(
- BeanConfiguration.getBeans().getConfiguration().getPort());
+ kargs.setPort(BeansFactory.getKustvaktContext().getConfiguration().getPort());
System.out.println(
"Starting Kustvakt Service on port '" + kargs.port + "'");
@@ -175,9 +170,6 @@
private boolean debug;
@Getter
private String config;
- @Getter
- @Deprecated
- private String properties;
private int port;
private SslContextFactory sslContext;
private String[] rootPackages;
@@ -188,7 +180,6 @@
this.sslContext = null;
this.debug = false;
this.config = null;
- this.properties = null;
this.init = false;
}
diff --git a/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java b/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
index 69a843e..18440a2 100644
--- a/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
+++ b/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
@@ -45,7 +45,7 @@
if (!f.exists()) {
KustvaktLogger.ERROR_LOGGER.error("Index not found!");
System.exit(-1);
- };
+ }
this.index = new KrillIndex(new MMapDirectory(Paths.get(path)));
};
} catch (IOException e) {
diff --git a/src/main/java/de/ids_mannheim/korap/web/filter/AuthFilter.java b/src/main/java/de/ids_mannheim/korap/web/filter/AuthFilter.java
index cb419fd..cc4e68c 100644
--- a/src/main/java/de/ids_mannheim/korap/web/filter/AuthFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/web/filter/AuthFilter.java
@@ -4,7 +4,7 @@
import com.sun.jersey.spi.container.ContainerRequestFilter;
import com.sun.jersey.spi.container.ContainerResponseFilter;
import com.sun.jersey.spi.container.ResourceFilter;
-import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.BeansFactory;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.interfaces.AuthenticationManagerIface;
import de.ids_mannheim.korap.user.TokenContext;
@@ -23,7 +23,7 @@
private AuthenticationManagerIface userController;
public AuthFilter() {
- this.userController = BeanConfiguration.getBeans()
+ this.userController = BeansFactory.getKustvaktContext()
.getAuthenticationManager();
}
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 30e8961..2626349 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
@@ -4,7 +4,7 @@
import com.sun.jersey.spi.container.ContainerRequestFilter;
import com.sun.jersey.spi.container.ContainerResponseFilter;
import com.sun.jersey.spi.container.ResourceFilter;
-import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.BeansFactory;
import de.ids_mannheim.korap.user.TokenContext;
import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.utils.TimeUtils;
@@ -54,7 +54,7 @@
c.setHostAddress(host);
c.setUserAgent(agent);
c.setExpirationTime(TimeUtils.plusSeconds(
- BeanConfiguration.getBeans().getConfiguration()
+ BeansFactory.getKustvaktContext().getConfiguration()
.getShortTokenTTL()).getMillis());
return c;
}
diff --git a/src/main/java/de/ids_mannheim/korap/web/filter/PiwikFilter.java b/src/main/java/de/ids_mannheim/korap/web/filter/PiwikFilter.java
index 9c9cd9c..3fdec88 100644
--- a/src/main/java/de/ids_mannheim/korap/web/filter/PiwikFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/web/filter/PiwikFilter.java
@@ -10,7 +10,7 @@
import com.sun.jersey.spi.container.ContainerRequestFilter;
import com.sun.jersey.spi.container.ContainerResponseFilter;
import com.sun.jersey.spi.container.ResourceFilter;
-import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.BeansFactory;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.interfaces.AuthenticationManagerIface;
import de.ids_mannheim.korap.user.*;
@@ -40,7 +40,7 @@
private AuthenticationManagerIface controller;
public PiwikFilter() {
- controller = BeanConfiguration.getBeans().getAuthenticationManager();
+ controller = BeansFactory.getKustvaktContext().getAuthenticationManager();
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
if (jlog.isDebugEnabled())
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 b676f88..aaf5146 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
@@ -1,12 +1,14 @@
package de.ids_mannheim.korap.web.service;
-import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.ContextHolder;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.resources.Permissions;
import de.ids_mannheim.korap.resources.VirtualCollection;
import de.ids_mannheim.korap.security.ac.PolicyBuilder;
+import de.ids_mannheim.korap.security.ac.ResourceFinder;
+import de.ids_mannheim.korap.security.ac.SecurityManager;
import de.ids_mannheim.korap.user.Attributes;
import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.utils.CollectionQueryBuilder3;
@@ -16,54 +18,54 @@
* @author hanl
* @date 12/01/2016
*/
-public class CollectionLoader implements BootupInterface {
+public class CollectionLoader implements BootableBeanInterface {
@Override
- public void load() throws KustvaktException {
- if (BeanConfiguration.hasContext()) {
- User user = User.UserFactory
- .toUser(KustvaktConfiguration.KUSTVAKT_USER);
+ public void load(ContextHolder beans) throws KustvaktException {
+ SecurityManager.overrideProviders(beans);
+ ResourceFinder.overrideProviders(beans);
- //todo: load default collections!
- CollectionQueryBuilder3 bui = new CollectionQueryBuilder3();
- bui.addQuery("creationDate since 1775");
+ User user = User.UserFactory
+ .toUser(KustvaktConfiguration.KUSTVAKT_USER);
- VirtualCollection c1 = new VirtualCollection();
- c1.setName("Weimarer Werke");
- c1.addField(Attributes.QUERY, bui.toJSON());
+ CollectionQueryBuilder3 bui = new CollectionQueryBuilder3();
+ bui.addQuery("creationDate since 1775");
- c1.setDescription("Goethe-Werke in Weimar (seit 1775)");
+ VirtualCollection c1 = new VirtualCollection();
+ c1.setName("Weimarer Werke");
+ c1.addField(Attributes.QUERY, bui.toJSON());
- bui = new CollectionQueryBuilder3();
- bui.addQuery("textType = Aphorismus");
+ c1.setDescription("Goethe-Werke in Weimar (seit 1775)");
- VirtualCollection c2 = new VirtualCollection();
- c2.setName("Aphorismen");
- c2.addField(Attributes.QUERY, bui.toJSON());
- c2.setDescription("Aphorismentexte Goethes");
+ bui = new CollectionQueryBuilder3();
+ bui.addQuery("textType = Aphorismus");
- bui = new CollectionQueryBuilder3();
- bui.addQuery("title ~ \"Werther\"");
+ VirtualCollection c2 = new VirtualCollection();
+ c2.setName("Aphorismen");
+ c2.addField(Attributes.QUERY, bui.toJSON());
+ c2.setDescription("Aphorismentexte Goethes");
- VirtualCollection c3 = new VirtualCollection();
- c3.setName("Werther");
- c3.addField(Attributes.QUERY, bui.toJSON());
- c3.setDescription("Goethe - Die Leiden des jungen Werther");
+ bui = new CollectionQueryBuilder3();
+ bui.addQuery("title ~ \"Werther\"");
- PolicyBuilder b = new PolicyBuilder(user);
- b.setPermissions(Permissions.Permission.READ);
- b.setResources(c1, c2, c3);
- b.setConditions("public");
- String result = b.create();
+ VirtualCollection c3 = new VirtualCollection();
+ c3.setName("Werther");
+ c3.addField(Attributes.QUERY, bui.toJSON());
+ c3.setDescription("Goethe - Die Leiden des jungen Werther");
- if (JsonUtils.readTree(result).size() > 0)
- throw new KustvaktException(StatusCodes.REQUEST_INVALID,
- "creating collections caused errors", result);
- }
+ PolicyBuilder b = new PolicyBuilder(user);
+ b.setPermissions(Permissions.Permission.READ);
+ b.setResources(c1, c2, c3);
+ b.setConditions("public");
+ String result = b.create();
+
+ if (JsonUtils.readTree(result).size() > 0)
+ throw new KustvaktException(StatusCodes.REQUEST_INVALID,
+ "creating collections caused errors", result);
}
@Override
- public Class<? extends BootupInterface>[] getDependencies() {
+ public Class<? extends BootableBeanInterface>[] getDependencies() {
return new Class[] { UserLoader.class };
}
}
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 af6df90..f568c88 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
@@ -1,34 +1,54 @@
package de.ids_mannheim.korap.web.service;
-import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.ContextHolder;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.exceptions.KustvaktException;
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.security.ac.PolicyBuilder;
+import de.ids_mannheim.korap.security.ac.ResourceFinder;
+import de.ids_mannheim.korap.security.ac.SecurityManager;
import de.ids_mannheim.korap.user.User;
/**
* @author hanl
* @date 15/01/2016
*/
-public class PolicyLoader implements BootupInterface {
+public class PolicyLoader implements BootableBeanInterface {
@Override
- public void load() throws KustvaktException {
- if (BeanConfiguration.hasContext()) {
- User user = User.UserFactory
- .toUser(KustvaktConfiguration.KUSTVAKT_USER);
- PolicyBuilder builder = new PolicyBuilder(user);
- builder.addCondition("public");
- builder.setResources(new Corpus("GOE"));
- builder.setPermissions(Permissions.Permission.READ);
- builder.create();
- }
+ public void load(ContextHolder beans) throws KustvaktException {
+ SecurityManager.overrideProviders(beans);
+ ResourceFinder.overrideProviders(beans);
+
+ User user = User.UserFactory
+ .toUser(KustvaktConfiguration.KUSTVAKT_USER);
+ PolicyBuilder builder = new PolicyBuilder(user);
+ builder.addCondition("public");
+ builder.setResources(new Corpus("GOE"));
+ builder.setPermissions(Permissions.Permission.READ);
+ builder.create();
+
+ builder = new PolicyBuilder(user);
+ builder.addCondition("public");
+ builder.setResources(new Corpus("WPD"));
+ builder.setPermissions(Permissions.Permission.READ);
+ builder.create();
+
+ KustvaktResource tt = new Foundry("tt");
+ tt.setName("TreeTagger");
+ tt.setDescription("todo ...");
+ builder = new PolicyBuilder(user);
+ builder.addCondition("public");
+ builder.setResources(tt);
+ builder.setPermissions(Permissions.Permission.READ);
+ builder.create();
}
@Override
- public Class<? extends BootupInterface>[] getDependencies() {
+ public Class<? extends BootableBeanInterface>[] getDependencies() {
return new Class[] { UserLoader.class };
}
}
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 ed233a1..4ea11db 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
@@ -1,6 +1,6 @@
package de.ids_mannheim.korap.web.service;
-import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.ContextHolder;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.interfaces.AuthenticationManagerIface;
@@ -9,19 +9,18 @@
* @author hanl
* @date 12/01/2016
*/
-public class UserLoader implements BootupInterface {
+public class UserLoader implements BootableBeanInterface {
+
@Override
- public void load() throws KustvaktException {
- if (BeanConfiguration.hasContext()) {
- AuthenticationManagerIface manager = BeanConfiguration.getBeans()
- .getAuthenticationManager();
- manager.createUserAccount(KustvaktConfiguration.KUSTVAKT_USER,
- false);
- }
+ public void load(ContextHolder beans) throws KustvaktException {
+ AuthenticationManagerIface manager = beans
+ .getAuthenticationManager();
+ manager.createUserAccount(KustvaktConfiguration.KUSTVAKT_USER,
+ false);
}
@Override
- public Class<? extends BootupInterface>[] getDependencies() {
+ public Class<? extends BootableBeanInterface>[] getDependencies() {
return new Class[0];
}
}
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/full/AuthService.java b/src/main/java/de/ids_mannheim/korap/web/service/full/AuthService.java
index 490479d..27de612 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/full/AuthService.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/full/AuthService.java
@@ -2,7 +2,7 @@
import com.sun.jersey.spi.container.ContainerRequest;
import com.sun.jersey.spi.container.ResourceFilters;
-import de.ids_mannheim.korap.config.BeanConfiguration;
+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.AuthenticationManagerIface;
@@ -10,7 +10,7 @@
import de.ids_mannheim.korap.user.*;
import de.ids_mannheim.korap.utils.JsonUtils;
import de.ids_mannheim.korap.utils.KustvaktLogger;
-import de.ids_mannheim.korap.utils.ServiceVersion;
+import de.ids_mannheim.korap.utils.ServiceInfo;
import de.ids_mannheim.korap.web.KustvaktServer;
import de.ids_mannheim.korap.web.filter.AuthFilter;
import de.ids_mannheim.korap.web.filter.DefaultFilter;
@@ -44,7 +44,7 @@
// private SendMail mail;
public AuthService() {
- this.controller = BeanConfiguration.getBeans()
+ this.controller = BeansFactory.getKustvaktContext()
.getAuthenticationManager();
//todo: replace with real property values
// this.mail = new SendMail(ExtConfiguration.getMailProperties());
@@ -63,10 +63,10 @@
public Response bootstrap() {
Map m = new HashMap();
// m.put("settings", new UserSettings().toObjectMap());
- m.put("ql", BeanConfiguration.getBeans().getConfiguration()
+ m.put("ql", BeansFactory.getKustvaktContext().getConfiguration()
.getQueryLanguages());
m.put("SortTypes", null); // types of sorting that are supported!
- m.put("version", ServiceVersion.getAPIVersion());
+ m.put("version", ServiceInfo.getInfo().getVersion());
return Response.ok(JsonUtils.toJSON(m)).build();
}
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/full/OAuthService.java b/src/main/java/de/ids_mannheim/korap/web/service/full/OAuthService.java
index 5e5e2cf..463e068 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/full/OAuthService.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/full/OAuthService.java
@@ -65,11 +65,11 @@
public OAuthService() {
this.handler = new OAuth2Handler(
- BeanConfiguration.getBeans().getPersistenceClient());
- this.controller = BeanConfiguration.getBeans()
+ BeansFactory.getKustvaktContext().getPersistenceClient());
+ this.controller = BeansFactory.getKustvaktContext()
.getAuthenticationManager();
- this.crypto = BeanConfiguration.getBeans().getEncryption();
- this.config = BeanConfiguration.getBeans().getConfiguration();
+ this.crypto = BeansFactory.getKustvaktContext().getEncryption();
+ this.config = BeansFactory.getKustvaktContext().getConfiguration();
}
@POST
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 3b0691e..cd10d64 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
@@ -3,7 +3,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import com.sun.jersey.spi.container.ResourceFilters;
-import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.BeansFactory;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.exceptions.EmptyResultException;
import de.ids_mannheim.korap.exceptions.KustvaktException;
@@ -12,8 +12,7 @@
import de.ids_mannheim.korap.interfaces.AuthenticationManagerIface;
import de.ids_mannheim.korap.query.serialize.MetaQueryBuilder;
import de.ids_mannheim.korap.query.serialize.QuerySerializer;
-import de.ids_mannheim.korap.resource.rewrite.FoundryInject;
-import de.ids_mannheim.korap.resource.rewrite.RewriteHandler;
+import de.ids_mannheim.korap.resource.rewrite.*;
import de.ids_mannheim.korap.resources.*;
import de.ids_mannheim.korap.security.ac.ResourceFinder;
import de.ids_mannheim.korap.security.ac.ResourceHandler;
@@ -60,17 +59,18 @@
private RewriteHandler processor;
public ResourceService() {
- this.controller = BeanConfiguration.getBeans()
+ this.controller = BeansFactory.getKustvaktContext()
.getAuthenticationManager();
- this.config = BeanConfiguration.getBeans().getConfiguration();
+ this.config = BeansFactory.getKustvaktContext().getConfiguration();
this.resourceHandler = new ResourceHandler();
this.searchKrill = new SearchKrill(config.getIndexDir());
UriBuilder builder = UriBuilder.fromUri("http://10.0.10.13").port(9997);
this.graphDBhandler = new ClientsHandler(builder.build());
- this.processor = new RewriteHandler(config);
- this.processor.add(FoundryInject.class);
+ this.processor = new RewriteHandler();
+ this.processor.defaultRewriteConstraints();
+ this.processor.insertBeans(BeansFactory.getKustvaktContext());
}
/**
@@ -304,10 +304,20 @@
TokenContext ctx = (TokenContext) securityContext.getUserPrincipal();
QuerySerializer ss;
CollectionQueryBuilder3 cquery = new CollectionQueryBuilder3();
+ if (cq != null)
+ cquery.setBaseQuery(cq);
+
User user;
try {
user = controller.getUser(ctx.getUsername());
- Set<Corpus> resources = ResourceFinder.search(user, Corpus.class);
+ Set<Corpus> resources = new HashSet<>();
+
+ if (User.UserFactory.isDemo(ctx.getUsername()))
+ resources = ResourceFinder.searchPublic(Corpus.class);
+ else
+ resources = ResourceFinder.search(user, Corpus.class);
+ System.out.println("RESOURCES FOUND "+ resources);
+
for (KustvaktResource corpus : resources)
cquery.addQuery("corpusID=" + corpus.getPersistentID());
}catch (KustvaktException e) {
@@ -315,8 +325,7 @@
}
ss = new QuerySerializer().setQuery(q, ql, v);
- if (cq != null)
- ss.setCollection(cq);
+ ss.setCollection(cquery.toJSON());
MetaQueryBuilder meta = new MetaQueryBuilder();
if (pageIndex != null)
@@ -347,7 +356,8 @@
* @param pageIndex
* @return
*/
- // todo: test
+
+ //todo: does cq have any sensable worth here?
@TRACE
@Path("{type}/{id}/search")
public Response buildQuery(@Context Locale locale,
@@ -372,6 +382,7 @@
try {
User user = controller.getUser(ctx.getUsername());
+ //todo: instead of throwing exception, build notification and rewrites into result query
KustvaktResource resource;
if (StringUtils.isInteger(id))
resource = this.resourceHandler
@@ -387,15 +398,11 @@
}catch (KustvaktException e) {
KustvaktLogger.ERROR_LOGGER.error("Exception encountered!", e);
- throw KustvaktResponseHandler.throwit(e);
+ //throw KustvaktResponseHandler.throwit(e);
}
ss = new QuerySerializer().setQuery(q, ql, v);
- // todo: parse resources
- if (cq != null)
- ss.setCollection(cq);
-
MetaQueryBuilder meta = new MetaQueryBuilder();
if (pageIndex != null)
meta.addEntry("startIndex", pageIndex);
@@ -483,7 +490,7 @@
// meta.addEntry("itemsPerResource", 1);
serializer.setMeta(meta.raw());
- // policy rewrite!
+ //fixme: policy rewrite!
String query = this.processor.preProcess(serializer.toJSON(), user);
jlog.info("the serialized query {}", query);
@@ -567,8 +574,6 @@
.throwit(StatusCodes.ILLEGAL_ARGUMENT,
"Type parameter not supported", type);
- // functions.createQuery(id, type, user, query, ql, v);
-
meta.addEntry("startIndex", pageIndex);
meta.addEntry("startPage", pageInteger);
meta.setSpanContext(ctx);
@@ -582,6 +587,8 @@
query = s.toJSON();
// PolicyParser parser = new PolicyParser(user);
// query = parser.parse(s.toJSON());
+ //todo: 1
+
}
String result;
try {
@@ -899,7 +906,7 @@
cachetmp.setStats(JsonUtils.readSimple(stats, Map.class));
}
- if (!cache && !user.isDemo()) {
+ if (!cache && !User.UserFactory.isDemo(ctx.getUsername())) {
collection = ResourceFactory
.getPermanentCollection(cachetmp, name, description);
vals = collection.toMap();
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 973544f..45999fc 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
@@ -4,7 +4,7 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.sun.jersey.spi.container.ContainerRequest;
import com.sun.jersey.spi.container.ResourceFilters;
-import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.BeansFactory;
import de.ids_mannheim.korap.config.Scopes;
import de.ids_mannheim.korap.config.URIParam;
import de.ids_mannheim.korap.exceptions.KustvaktException;
@@ -38,8 +38,6 @@
public class UserService {
private static Logger jlog = LoggerFactory.getLogger(UserService.class);
- // private static Logger jlog = KustvaktLogger
- // .getLogger(KustvaktLogger.SECURITY_LOG);
private AuthenticationManagerIface controller;
private
@@ -47,7 +45,7 @@
UriInfo info;
public UserService() {
- this.controller = BeanConfiguration.getBeans()
+ this.controller = BeansFactory.getKustvaktContext()
.getAuthenticationManager();
}
@@ -237,7 +235,7 @@
try {
User user = controller.getUser(ctx.getUsername());
Userdata data = controller.getUserData(user, UserSettings.class);
- data.addField(Attributes.USERNAME, ctx.getUsername());
+ data.setField(Attributes.USERNAME, ctx.getUsername());
result = data.data();
}catch (KustvaktException e) {
jlog.error("Exception encountered!", e);
@@ -259,7 +257,7 @@
try {
User user = controller.getUser(ctx.getUsername());
- if (user.isDemo())
+ if (User.UserFactory.isDemo(ctx.getUsername()))
return Response.notModified().build();
Userdata data = controller.getUserData(user, UserSettings.class);
@@ -293,7 +291,7 @@
try {
User user = controller.getUser(ctx.getUsername());
Userdata data = controller.getUserData(user, UserDetails.class);
- data.addField(Attributes.USERNAME, ctx.getUsername());
+ data.setField(Attributes.USERNAME, ctx.getUsername());
result = data.data();
}catch (KustvaktException e) {
jlog.error("Exception encountered!", e);
@@ -315,7 +313,7 @@
try {
User user = controller.getUser(ctx.getUsername());
- if (user.isDemo())
+ if (User.UserFactory.isDemo(ctx.getUsername()))
return Response.notModified().build();
UserDetails new_data = new UserDetails(user.getId());
@@ -393,7 +391,7 @@
TokenContext ctx = (TokenContext) context.getUserPrincipal();
try {
User user = controller.getUser(ctx.getUsername());
- if (user.isDemo())
+ if (User.UserFactory.isDemo(ctx.getUsername()))
return Response.notModified().build();
controller.deleteAccount(user);
}catch (KustvaktException e) {
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/light/LightService.java b/src/main/java/de/ids_mannheim/korap/web/service/light/LightService.java
index fde88cd..783e7e2 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/light/LightService.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/light/LightService.java
@@ -1,7 +1,7 @@
package de.ids_mannheim.korap.web.service.light;
import com.sun.jersey.core.util.MultivaluedMapImpl;
-import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.BeansFactory;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.config.QueryBuilderUtil;
import de.ids_mannheim.korap.exceptions.KustvaktException;
@@ -44,12 +44,13 @@
private KustvaktConfiguration config;
public LightService() {
- this.config = BeanConfiguration.getBeans().getConfiguration();
+ this.config = BeansFactory.getKustvaktContext().getConfiguration();
this.searchKrill = new SearchKrill(config.getIndexDir());
UriBuilder builder = UriBuilder.fromUri("http://10.0.10.13").port(9997);
this.graphDBhandler = new ClientsHandler(builder.build());
- this.processor = new RewriteHandler(config);
+ this.processor = new RewriteHandler();
this.processor.add(FoundryInject.class);
+ this.processor.insertBeans(BeansFactory.getKustvaktContext());
}
/**
@@ -83,7 +84,8 @@
@QueryParam("count") Integer pageLength,
@QueryParam("offset") Integer pageIndex,
@QueryParam("page") Integer startPage,
- @QueryParam("ref") String reference, @QueryParam("cq") String cq) {
+ // fixme: remove cq from light service
+ @QueryParam("cq") String cq) {
QuerySerializer ss = new QuerySerializer().setQuery(q, ql, v);
MetaQueryBuilder meta = new MetaQueryBuilder();
@@ -122,6 +124,7 @@
@QueryParam("offset") Integer pageIndex,
@QueryParam("page") Integer pageInteger,
@QueryParam("fields") Set<String> fields,
+ // fixme: remove cq value from lightservice
@QueryParam("cq") String cq, @QueryParam("engine") String engine) {
KustvaktConfiguration.BACKENDS eng = this.config.chooseBackend(engine);
@@ -148,6 +151,7 @@
String.valueOf(meta.getSpanContext().getLeft_size()));
map.add("rctxs",
String.valueOf(meta.getSpanContext().getRight_size()));
+
try {
result = this.graphDBhandler.getResponse(map, "distKwic");
}catch (KustvaktException e) {
diff --git a/src/main/resources/db/mysql/V0.1__userdatabase.sql b/src/main/resources/db/mysql/V0.1__userdatabase.sql
index cfe31a1..09b1591 100644
--- a/src/main/resources/db/mysql/V0.1__userdatabase.sql
+++ b/src/main/resources/db/mysql/V0.1__userdatabase.sql
@@ -1,3 +1,4 @@
+
-- rename all columns in new way!
CREATE TABLE IF NOT EXISTS korap_users (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
diff --git a/src/main/resources/db/mysql/V0.3__securitydatabase.sql b/src/main/resources/db/mysql/V0.3__securitydatabase.sql
index c8f6816..5406156 100644
--- a/src/main/resources/db/mysql/V0.3__securitydatabase.sql
+++ b/src/main/resources/db/mysql/V0.3__securitydatabase.sql
@@ -111,25 +111,4 @@
aud_failure VARCHAR(100)
);
-
--- indices
-create trigger delete_policy after delete on resource_store
-for each row delete from policy_store where target_id=OLD.id;
-
-DELIMITER //
-CREATE TRIGGER tree_entry_insert AFTER INSERT ON resource_store FOR EACH ROW BEGIN
- INSERT INTO resource_tree (parent_id, child_id, depth, name_path)
- VALUES (NEW.id, NEW.id, 0, NEW.name);
- INSERT INTO resource_tree (parent_id, child_id, depth, name_path)
- SELECT parent_id, NEW.id, depth + 1, concat(name_path,"/",NEW.name) FROM resource_tree WHERE child_id = NEW.parent_id;
-END; //
-
-DELIMITER ;
-
--- todo: are this automatically adapted when refactoring?
-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);
-
-- foreign key constraints
diff --git a/src/main/resources/db/sqlite/V1__Initial_version.sql b/src/main/resources/db/sqlite/V1__Initial_version.sql
index 06663e7..d109779 100644
--- a/src/main/resources/db/sqlite/V1__Initial_version.sql
+++ b/src/main/resources/db/sqlite/V1__Initial_version.sql
@@ -24,13 +24,19 @@
CREATE TABLE IF NOT EXISTS user_details (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER UNIQUE NOT NULL,
-data BLOB NOT NULL
+data BLOB NOT NULL,
+foreign key (user_id)
+references korap_users (id)
+on delete cascade
);
CREATE TABLE IF NOT EXISTS user_settings (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER UNIQUE NOT NULL,
-data BLOB NOT NULL
+data BLOB NOT NULL,
+foreign key (user_id)
+references korap_users (id)
+on delete cascade
);
@@ -262,8 +268,8 @@
-- deletes a group if the group has no longer members!
create trigger if not exists group_ref_del after delete on group_ref
-when (select count(*) from group_ref where groupId=OLD.group_id) = 0
-begin delete from groupolicy_store where name=OLD.group_id; end;
+when (select count(*) from group_ref where group_id=OLD.group_id) = 0
+begin delete from group_store where name=OLD.group_id; end;
-- create trigger relCr after insert on resource_store
-- when (select count(*) from r_tree where parent_id==NEW.id and
diff --git a/src/main/resources/default-config.xml b/src/main/resources/default-config.xml
index 86a5cba..1b0c72c 100644
--- a/src/main/resources/default-config.xml
+++ b/src/main/resources/default-config.xml
@@ -76,7 +76,7 @@
<bean id="flyway" class="org.flywaydb.core.Flyway" init-method="migrate">
<property name="baselineOnMigrate" value="false"/>
<property name="locations"
- value="classpath:${jdbc.schemaPath}"/>
+ value="${jdbc.schemaPath}"/>
<property name="dataSource" ref="dataSource"/>
</bean>
@@ -161,7 +161,7 @@
ref="kustvakt_encryption"/>
</bean>
- <util:list id="auth_providers"
+ <util:list id="kustvakt_authproviders"
value-type="de.ids_mannheim.korap.interfaces.AuthenticationIface">
<ref bean="basic_auth"/>
<ref bean="session_auth"/>
@@ -169,6 +169,26 @@
<ref bean="openid_auth"/>
</util:list>
+
+ <bean id="userdata_details"
+ class="de.ids_mannheim.korap.handlers.UserDetailsDao">
+ <constructor-arg
+ type="de.ids_mannheim.korap.interfaces.db.PersistenceClient"
+ ref="kustvakt_db"/>
+ </bean>
+ <bean id="userdata_settings"
+ class="de.ids_mannheim.korap.handlers.UserDetailsDao">
+ <constructor-arg
+ type="de.ids_mannheim.korap.interfaces.db.PersistenceClient"
+ ref="kustvakt_db"/>
+ </bean>
+
+ <util:list id="kustvakt_userdata"
+ value-type="de.ids_mannheim.korap.interfaces.db.UserdataDbIface">
+ <ref bean="userdata_details"/>
+ <ref bean="userdata_settings"/>
+ </util:list>
+
<!-- specify type for constructor argument -->
<bean id="kustvakt_authenticationmanager"
class="de.ids_mannheim.korap.security.auth.KustvaktAuthenticationManager">
@@ -181,8 +201,9 @@
<constructor-arg
type="de.ids_mannheim.korap.interfaces.db.AuditingIface"
ref="kustvakt_auditing"/>
+ <constructor-arg ref="kustvakt_userdata"/>
<!-- inject authentication providers to use -->
- <property name="providers" ref="auth_providers"/>
+ <property name="providers" ref="kustvakt_authproviders"/>
</bean>
<!-- todo: if db interfaces not loaded via spring, does transaction even work then? -->
diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties
index c9186f6..39e040a 100644
--- a/src/main/resources/log4j.properties
+++ b/src/main/resources/log4j.properties
@@ -1,7 +1,7 @@
# Root logger option
#log4j.threshold=ALL
-log4j.rootLogger=DEBUG, stdout, debugLog
+log4j.rootLogger=WARN, stdout, debugLog
log4j.logger.log=ERROR, errorLog
# Direct log messages to stdout
diff --git a/src/main/resources/validation.properties b/src/main/resources/validation.properties
old mode 100755
new mode 100644
diff --git a/src/main/resources/version.prop b/src/main/resources/version.prop
deleted file mode 100644
index e5683df..0000000
--- a/src/main/resources/version.prop
+++ /dev/null
@@ -1 +0,0 @@
-version=${project.version}
\ No newline at end of file