userdetails service responses
diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml
index 7976ad5..90437df 100644
--- a/dependency-reduced-pom.xml
+++ b/dependency-reduced-pom.xml
@@ -4,7 +4,7 @@
   <groupId>de.ids_mannheim.korap</groupId>

   <artifactId>Kustvakt-core</artifactId>

   <name>Kustvakt core</name>

-  <version>0.56</version>

+  <version>0.58</version>

   <description>Kustvakt core, basic rest api for testing purposes and default

         interfaces</description>

   <build>

@@ -70,7 +70,7 @@
             <exclude>**/*APITest.java</exclude>

           </excludes>

           <includes>

-            <include>**/*.java</include>

+            <include>de.ids_mannheim.korap.**/*.java</include>

           </includes>

         </configuration>

       </plugin>

diff --git a/pom.xml b/pom.xml
index 52043a2..c0237ee 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
     <modelVersion>4.0.0</modelVersion>
     <groupId>de.ids_mannheim.korap</groupId>
     <artifactId>Kustvakt-core</artifactId>
-    <version>0.56</version>
+    <version>0.58</version>
     <packaging>jar</packaging>
     <name>Kustvakt core</name>
     <description>Kustvakt core, basic rest api for testing purposes and default
@@ -149,7 +149,7 @@
                         <exclude>**/*APITest.java</exclude>
                     </excludes>
                     <includes>
-                        <include>**/*.java</include>
+                        <include>de.ids_mannheim.korap.**/*.java</include>
                     </includes>
                 </configuration>
             </plugin>
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 ba271f0..d59c23e 100644
--- a/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
+++ b/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
@@ -34,6 +34,7 @@
         KUSTVAKT_USER.put(Attributes.PASSWORD, "kustvakt2015");
         KUSTVAKT_USER.put(Attributes.EMAIL, "kustvakt@ids-mannheim.de");
         KUSTVAKT_USER.put(Attributes.COUNTRY, "Germany");
+        KUSTVAKT_USER.put(Attributes.ADDRESS, "Mannheim");
         KUSTVAKT_USER.put(Attributes.FIRSTNAME, "Kustvakt");
         KUSTVAKT_USER.put(Attributes.LASTNAME, "KorAP");
         KUSTVAKT_USER.put(Attributes.INSTITUTION, "IDS Mannheim");
diff --git a/src/main/java/de/ids_mannheim/korap/exceptions/EmptyResultException.java b/src/main/java/de/ids_mannheim/korap/exceptions/EmptyResultException.java
index a854bc5..f510ac5 100644
--- a/src/main/java/de/ids_mannheim/korap/exceptions/EmptyResultException.java
+++ b/src/main/java/de/ids_mannheim/korap/exceptions/EmptyResultException.java
@@ -12,7 +12,7 @@
     }
 
     public EmptyResultException(String entity) {
-        super(StatusCodes.EMPTY_RESULTS, "", entity);
+        super(StatusCodes.EMPTY_RESULTS, "No entity found for id", entity);
     }
 
 }
diff --git a/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java b/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java
index 34aa013..4c40304 100644
--- a/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java
+++ b/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java
@@ -9,96 +9,96 @@
     /**
      * 100 status codes for standard system errors
      */
-    public static final Integer EMPTY_RESULTS = 100;
-    public static final Integer REQUEST_INVALID = 101;
+    public static final int EMPTY_RESULTS = 100;
+    public static final int REQUEST_INVALID = 101;
     //fixme: redundancy?!
-    public static final Integer ENTRY_EXISTS = 102;
-    public static final Integer STATUS_OK = 103;
-    public static final Integer UNSUPPORTED_OPERATION = 104;
-    public static final Integer ILLEGAL_ARGUMENT = 105;
-    public static final Integer CONNECTION_ERROR = 106;
-    public static final Integer NOTHING_CHANGED = 107;
-    public static final Integer PARAMETER_VALIDATION_ERROR = 108;
-    public static final Integer DEFAULT_ERROR = 109;
-    public static final Integer NOT_SUPPORTED = 110;
+    public static final int ENTRY_EXISTS = 102;
+    public static final int STATUS_OK = 103;
+    public static final int UNSUPPORTED_OPERATION = 104;
+    public static final int ILLEGAL_ARGUMENT = 105;
+    public static final int CONNECTION_ERROR = 106;
+    public static final int NOTHING_CHANGED = 107;
+    public static final int PARAMETER_VALIDATION_ERROR = 108;
+    public static final int DEFAULT_ERROR = 109;
+    public static final int NOT_SUPPORTED = 110;
 
     /**
      * 400 status codes for account/authentication relevant components
      */
 
-    public static final Integer ACCOUNT_DEACTIVATED = 200;
-    public static final Integer ACCOUNT_CONFIRMATION_FAILED = 201;
-    public static final Integer ALREADY_LOGGED_IN = 202;
-    public static final Integer EXPIRED = 204;
-    public static final Integer BAD_CREDENTIALS = 205;
-    public static final Integer UNCONFIRMED_ACCOUNT = 206;
-    public static final Integer NAME_EXISTS = 207;
-    public static final Integer PASSWORD_RESET_FAILED = 208;
+    public static final int ACCOUNT_DEACTIVATED = 200;
+    public static final int ACCOUNT_CONFIRMATION_FAILED = 201;
+    public static final int ALREADY_LOGGED_IN = 202;
+    public static final int EXPIRED = 204;
+    public static final int BAD_CREDENTIALS = 205;
+    public static final int UNCONFIRMED_ACCOUNT = 206;
+    public static final int NAME_EXISTS = 207;
+    public static final int PASSWORD_RESET_FAILED = 208;
     // fixme: ?!
     @Deprecated
-    public static final Integer AUTHENTICATION_DENIED = 209;
+    public static final int AUTHENTICATION_DENIED = 209;
 
-    public static final Integer LOGIN_SUCCESSFUL = 210;
-    public static final Integer LOGIN_FAILED = 211;
-    public static final Integer LOGOUT_SUCCESSFUL = 212;
-    public static final Integer LOGOUT_FAILED = 213;
+    public static final int LOGIN_SUCCESSFUL = 210;
+    public static final int LOGIN_FAILED = 211;
+    public static final int LOGOUT_SUCCESSFUL = 212;
+    public static final int LOGOUT_FAILED = 213;
 
-    public static final Integer CLIENT_REGISTRATION_FAILURE = 214;
-    public static final Integer CLIENT_REMOVAL_FAILURE = 215;
-    public static final Integer CLIENT_AUTHORIZATION_FAILURE = 216;
+    public static final int CLIENT_REGISTRATION_FAILURE = 214;
+    public static final int CLIENT_REMOVAL_FAILURE = 215;
+    public static final int CLIENT_AUTHORIZATION_FAILURE = 216;
 
     /**
      * 500 status codes for access control related components (also policy rewrite)
      */
-    public static final Integer PERMISSION_DENIED = 401;
-    public static final Integer UNSUPPORTED_RESOURCE = 402;
-    public static final Integer UNSUPPORTED_FOUNDRY = 403;
-    public static final Integer UNSUPPORTED_CORPUS = 404;
-    public static final Integer UNSUPPORTED_LAYER = 405;
+    public static final int PERMISSION_DENIED = 401;
+    public static final int UNSUPPORTED_RESOURCE = 402;
+    public static final int UNSUPPORTED_FOUNDRY = 403;
+    public static final int UNSUPPORTED_CORPUS = 404;
+    public static final int UNSUPPORTED_LAYER = 405;
     // make a distinction between no and invalid vc?
-    public static final Integer UNSUPPORTED_COLLECTION = 406;
-    public static final Integer CORPUS_REWRITE = 407;
-    public static final Integer FOUNDRY_REWRITE = 408;
-    public static final Integer FOUNDRY_INJECTION = 409;
-    public static final Integer MISSING_ARGUMENTS = 410;
-    public static final Integer MISSING_VIRTUALCOLLECTION = 411;
-    public static final Integer MISSING_POLICY_TARGET = 412;
-    public static final Integer MISSING_POLICY_CONDITIONS = 413;
-    public static final Integer MISSING_POLICY_PERMISSION = 414;
-    public static final Integer RESOURCE_NOT_FOUND = 415;
+    public static final int UNSUPPORTED_COLLECTION = 406;
+    public static final int CORPUS_REWRITE = 407;
+    public static final int FOUNDRY_REWRITE = 408;
+    public static final int FOUNDRY_INJECTION = 409;
+    public static final int MISSING_ARGUMENTS = 410;
+    public static final int MISSING_VIRTUALCOLLECTION = 411;
+    public static final int MISSING_POLICY_TARGET = 412;
+    public static final int MISSING_POLICY_CONDITIONS = 413;
+    public static final int MISSING_POLICY_PERMISSION = 414;
+    public static final int RESOURCE_NOT_FOUND = 415;
 
     // todo: extend according to policy rewrite possible!
     // policy errors
-    public static final Integer POLICY_ERROR_DEFAULT = 500;
-    public static final Integer POLICY_CREATE_ERROR = 501;
-    public static final Integer NO_POLICIES = 502;
+    public static final int POLICY_ERROR_DEFAULT = 500;
+    public static final int POLICY_CREATE_ERROR = 501;
+    public static final int NO_POLICIES = 502;
 
     // database codes
-    public static final Integer DB_GET_FAILED = 601;
-    public static final Integer DB_INSERT_FAILED = 602;
-    public static final Integer DB_DELETE_FAILED = 603;
-    public static final Integer DB_UPDATE_FAILED = 604;
+    public static final int DB_GET_FAILED = 601;
+    public static final int DB_INSERT_FAILED = 602;
+    public static final int DB_DELETE_FAILED = 603;
+    public static final int DB_UPDATE_FAILED = 604;
 
-    public static final Integer DB_GET_SUCCESSFUL = 605;
-    public static final Integer DB_INSERT_SUCCESSFUL = 606;
-    public static final Integer DB_DELETE_SUCCESSFUL = 607;
-    public static final Integer DB_UPDATE_SUCCESSFUL = 608;
+    public static final int DB_GET_SUCCESSFUL = 605;
+    public static final int DB_INSERT_SUCCESSFUL = 606;
+    public static final int DB_DELETE_SUCCESSFUL = 607;
+    public static final int DB_UPDATE_SUCCESSFUL = 608;
 
     // service status codes
-    public static final Integer CREATE_ACCOUNT_SUCCESSFUL = 700;
-    public static final Integer CREATE_ACCOUNT_FAILED = 701;
-    public static final Integer DELETE_ACCOUNT_SUCCESSFUL = 702;
-    public static final Integer DELETE_ACCOUNT_FAILED = 703;
-    public static final Integer UPDATE_ACCOUNT_SUCCESSFUL = 704;
-    public static final Integer UPDATE_ACCOUNT_FAILED = 705;
+    public static final int CREATE_ACCOUNT_SUCCESSFUL = 700;
+    public static final int CREATE_ACCOUNT_FAILED = 701;
+    public static final int DELETE_ACCOUNT_SUCCESSFUL = 702;
+    public static final int DELETE_ACCOUNT_FAILED = 703;
+    public static final int UPDATE_ACCOUNT_SUCCESSFUL = 704;
+    public static final int UPDATE_ACCOUNT_FAILED = 705;
 
-    public static final Integer GET_ACCOUNT_SUCCESSFUL = 706;
-    public static final Integer GET_ACCOUNT_FAILED = 707;
+    public static final int GET_ACCOUNT_SUCCESSFUL = 706;
+    public static final int GET_ACCOUNT_FAILED = 707;
 
     /**
      * 300 status codes for query language and serialization
      */
 
-    public static final Integer NO_QUERY = 301;
+    public static final int NO_QUERY = 301;
 
 }
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 e87b62d..c5bf551 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/EntityDao.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/EntityDao.java
@@ -53,6 +53,7 @@
             user = this.jdbcTemplate.queryForObject(sql, namedParameters,
                     new RowMapperFactory.UserMapper());
         }catch (EmptyResultDataAccessException ae) {
+            ae.printStackTrace();
             jlog.error("No user found for name '{}'", username);
             throw new EmptyResultException(username);
         }catch (DataAccessException e) {
@@ -73,20 +74,21 @@
             np.addValue("alo", k.isAccountLocked());
             if (k.getPassword() != null)
                 np.addValue("ps", k.getPassword());
-            URIParam param = k.getField(URIParam.class);
-            if (param != null) {
-                np.addValue("frag", param.getUriFragment());
-                np.addValue("exp", new Date(param.getUriExpiration()));
-            }else {
-                np.addValue("frag", null);
-                np.addValue("exp", null);
-            }
+            //            URIParam param = k.getField(URIParam.class);
+            //            if (param != null) {
+            //                np.addValue("frag", param.getUriFragment());
+            //                np.addValue("exp", new Date(param.getUriExpiration()));
+            //            }else {
+            //                np.addValue("frag", null);
+            //                np.addValue("exp", null);
+            //            }
             np.addValue("id", k.getId());
 
             query = "UPDATE korap_users SET account_lock=:alo," +
-                    "account_link=:ali, password=:ps," +
-                    "uri_fragment=:frag," +
-                    "uri_expiration=:exp WHERE id=:id";
+                    "account_link=:ali, password=:ps "
+                    //                    "uri_fragment=:frag," +
+                    //                    "uri_expiration=:exp "
+                    + "WHERE id=:id";
         }else if (user instanceof ShibUser) {
             ShibUser s = (ShibUser) user;
             //todo:
@@ -138,6 +140,7 @@
             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, "
                         +
@@ -278,6 +281,7 @@
         }
     }
 
+    @Override
     public int size() {
         final String query = "SELECT COUNT(*) FROM korap_users;";
         return this.jdbcTemplate
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 06c952f..0869236 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java
@@ -116,7 +116,9 @@
             return (T) this.jdbcTemplate.queryForObject(sql, source,
                     new RowMapperFactory.ResourceMapper());
         }catch (DataAccessException e) {
-            e.printStackTrace();
+            if (e instanceof IncorrectResultSizeDataAccessException)
+                throw new KustvaktException(StatusCodes.ILLEGAL_ARGUMENT,
+                        "invalid request id given!", String.valueOf(id));
             return null;
         }
     }
diff --git a/src/main/java/de/ids_mannheim/korap/handlers/RowMapperFactory.java b/src/main/java/de/ids_mannheim/korap/handlers/RowMapperFactory.java
index 060578c..22c600c 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/RowMapperFactory.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/RowMapperFactory.java
@@ -111,7 +111,7 @@
 
                 r.setFields(rs.getString("data"));
                 r.setDescription(rs.getString("description"));
-                r.setCreated(rs.getTimestamp("created").getTime());
+                r.setCreated(rs.getLong("created"));
                 r.setPath(rs.getString("name_path"));
                 r.setPersistentID(rs.getString("persistent_id"));
             }
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 e05386b..e301ff5 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/UserDetailsDao.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/UserDetailsDao.java
@@ -1,10 +1,13 @@
 package de.ids_mannheim.korap.handlers;
 
+import de.ids_mannheim.korap.exceptions.StatusCodes;
+import de.ids_mannheim.korap.exceptions.dbException;
 import de.ids_mannheim.korap.interfaces.db.PersistenceClient;
 import de.ids_mannheim.korap.interfaces.db.UserDataDbIface;
 import de.ids_mannheim.korap.user.User;
 import de.ids_mannheim.korap.user.UserDetails;
 import org.springframework.dao.DataAccessException;
+import org.springframework.dao.EmptyResultDataAccessException;
 import org.springframework.jdbc.core.RowMapper;
 import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
 import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
@@ -60,7 +63,7 @@
     }
 
     @Override
-    public UserDetails get(Integer id) {
+    public UserDetails get(Integer id) throws dbException {
         String sql = "SELECT * FROM user_details WHERE id=:id;";
         MapSqlParameterSource source = new MapSqlParameterSource();
         source.addValue("id", id);
@@ -80,13 +83,16 @@
                         }
                     });
 
-        }catch (DataAccessException e) {
+        }catch (EmptyResultDataAccessException ex) {
             return null;
+        }catch (DataAccessException e) {
+            throw new dbException(-1, "userDetails",
+                    StatusCodes.REQUEST_INVALID, String.valueOf(id));
         }
     }
 
     @Override
-    public UserDetails get(User user) {
+    public UserDetails get(User user) throws dbException {
         String sql = "SELECT * FROM user_details WHERE user_id=:userid;";
         MapSqlParameterSource source = new MapSqlParameterSource();
         source.addValue("userid", user.getId());
@@ -105,10 +111,11 @@
                             return details;
                         }
                     });
-
-        }catch (DataAccessException e) {
-            e.printStackTrace();
+        }catch (EmptyResultDataAccessException ex) {
             return null;
+        }catch (DataAccessException e) {
+            throw new dbException(user.getId(), "userDetails",
+                    StatusCodes.REQUEST_INVALID);
         }
     }
 
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 d343dca..6b9300f 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/UserSettingsDao.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/UserSettingsDao.java
@@ -1,10 +1,13 @@
 package de.ids_mannheim.korap.handlers;
 
+import de.ids_mannheim.korap.exceptions.StatusCodes;
+import de.ids_mannheim.korap.exceptions.dbException;
 import de.ids_mannheim.korap.interfaces.db.PersistenceClient;
 import de.ids_mannheim.korap.interfaces.db.UserDataDbIface;
 import de.ids_mannheim.korap.user.User;
 import de.ids_mannheim.korap.user.UserSettings;
 import org.springframework.dao.DataAccessException;
+import org.springframework.dao.EmptyResultDataAccessException;
 import org.springframework.jdbc.core.RowMapper;
 import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
 import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
@@ -25,6 +28,7 @@
     public UserSettingsDao(PersistenceClient client) {
         this.jdbcTemplate = (NamedParameterJdbcTemplate) client.getSource();
     }
+
     @Override
     public int store(UserSettings data) {
         String sql = "INSERT INTO user_settings (user_id, data) VALUES (:userid, :data);";
@@ -59,7 +63,7 @@
     }
 
     @Override
-    public UserSettings get(Integer id) {
+    public UserSettings get(Integer id) throws dbException {
         String sql = "SELECT * FROM user_settings WHERE id=:id;";
         MapSqlParameterSource source = new MapSqlParameterSource();
         source.addValue("id", id);
@@ -79,13 +83,16 @@
                         }
                     });
 
-        }catch (DataAccessException e) {
+        }catch (EmptyResultDataAccessException ex) {
             return null;
+        }catch (DataAccessException e) {
+            throw new dbException(-1, "userSettings",
+                    StatusCodes.REQUEST_INVALID, String.valueOf(id));
         }
     }
 
     @Override
-    public UserSettings get(User user) {
+    public UserSettings get(User user) throws dbException {
         String sql = "SELECT * FROM user_settings WHERE user_id=:userid;";
         MapSqlParameterSource source = new MapSqlParameterSource();
         source.addValue("userid", user.getId());
@@ -105,9 +112,11 @@
                         }
                     });
 
-        }catch (DataAccessException e) {
-            e.printStackTrace();
+        }catch (EmptyResultDataAccessException ex) {
             return null;
+        }catch (DataAccessException e) {
+            throw new dbException(-1, "userSettings",
+                    StatusCodes.REQUEST_INVALID);
         }
     }
 
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 c83f60d..932c069 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
@@ -26,4 +26,5 @@
     int activateAccount(String username, String uriToken)
             throws KustvaktException;
 
+    int size();
 }
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 06af664..1922433 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
@@ -11,8 +11,6 @@
 import de.ids_mannheim.korap.security.SecurityPolicy;
 import de.ids_mannheim.korap.user.User;
 
-import java.util.Arrays;
-
 /**
  * @author hanl
  * @date 14/04/2014
@@ -130,15 +128,10 @@
         if (this.rel == null)
             this.rel = Relation.AND;
 
-        System.out.println("CREATING RESOURCES " + Arrays.asList(resources));
-        System.out.println("RESOURCES LENGTH " + resources.length);
         for (int idx = 0; idx < this.resources.length; idx++) {
             try {
-                System.out.println("ITERATING OVER ARRAY " + idx);
                 if (parents[idx] != null)
                     resources[idx].setParentID(parents[idx].getPersistentID());
-                System.out.println("RUNNING REGISTERING SERVICE ON RESOURCE "
-                        + resources[idx]);
                 SecurityManager manager = SecurityManager
                         .register(resources[idx], user);
 
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 57c6fe2..12bee9f 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
@@ -602,10 +602,9 @@
         }
     }
 
-    private Integer createCondition(PolicyCondition condition, User user)
+    private void createCondition(PolicyCondition condition, User user)
             throws KustvaktException {
         MapSqlParameterSource param = new MapSqlParameterSource();
-        KeyHolder key = new GeneratedKeyHolder();
         param.addValue("name", condition.getSpecifier());
         param.addValue("ex", condition.getFlags().get(Attributes.EXPORT));
         param.addValue("qo", condition.getFlags().get(Attributes.QUERY_ONLY));
@@ -615,8 +614,7 @@
         try {
             this.jdbcTemplate
                     .update("INSERT INTO group_store (name, sym_use, export, commercial) "
-                            + "VALUES (:name, :sy, :ex, :com);", param, key);
-            return key.getKey().intValue();
+                            + "VALUES (:name, :sy, :ex, :com);", param);
         }catch (DataAccessException e) {
             jlog.error("Operation (INSERT) not possible for '{}'",
                     condition.toString());
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 0b33e68..4dedb30 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
@@ -14,7 +14,6 @@
 
 import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.sql.Timestamp;
 import java.util.*;
 
 /**
@@ -34,12 +33,12 @@
 
             PolicyContext context = new PolicyContext();
             context.setIPMask(rs.getString("iprange"));
-            Timestamp date = rs.getTimestamp("enable");
-            Timestamp date2 = rs.getTimestamp("expire");
-            if (date != null)
-                context.setEnableTime(date.getTime());
-            if (date2 != null)
-                context.setExpirationTime(date2.getTime());
+            long enable = rs.getLong("enable");
+            long expire = rs.getLong("expire");
+            if (enable != -1)
+                context.setEnableTime(enable);
+            if (expire != -1)
+                context.setExpirationTime(expire);
             //            context.addFlag("export", rs.getBoolean("export"));
             //            context.addFlag("sym_use", rs.getInt("sym_use"));
             p.setContext(context);
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 e97ea53..aa7b28b 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
@@ -50,15 +50,16 @@
         EncryptionIface crypto = BeanConfiguration.getBeans().getEncryption();
         EntityHandlerIface dao = BeanConfiguration.getBeans()
                 .getUserDBHandler();
-        TokenContext c = new TokenContext();
         String[] values = decode(authToken);
         if (values != null) {
+            TokenContext c = new TokenContext();
             User user = dao.getAccount(values[0]);
             if (user instanceof KorAPUser) {
                 boolean check = crypto
                         .checkHash(values[1], ((KorAPUser) user).getPassword());
+
                 if (!check)
-                    return c;
+                    return null;
             }
             c.setUsername(values[0]);
             c.setTokenType(Attributes.BASIC_AUTHENTICATION);
@@ -68,8 +69,9 @@
             //            fixme: you can make queries, but user sensitive data is off limits?!
             c.addContextParameter(Attributes.SCOPES,
                     Scopes.Scope.search.toString());
+            return c;
         }
-        return c;
+        return null;
     }
 
     // not supported!
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 adcb263..70b190b 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
@@ -89,14 +89,9 @@
             Map map = (Map) e.getObjectValue();
             user = User.UserFactory.toUser(map);
         }else {
-            try {
-                user = entHandler.getAccount(username);
-                user_cache.put(new Element(key, user.toCache()));
-                // todo: not valid. for the duration of the session, the host should not change!
-            }catch (EmptyResultException e1) {
-                // do nothing
-                return null;
-            }
+            user = entHandler.getAccount(username);
+            user_cache.put(new Element(key, user.toCache()));
+            // todo: not valid. for the duration of the session, the host should not change!
         }
         //todo:
         //        user.addField(Attributes.HOST, context.getHostAddress());
@@ -486,8 +481,9 @@
         }
 
         KorAPUser user = User.UserFactory.getUser(username);
+        user.setAccountLocked(confirmation_required);
+
         if (confirmation_required) {
-            user.setAccountLocked(true);
             URIParam param = new URIParam(crypto.createToken(),
                     TimeUtils.plusSeconds(config.getExpiration()).getMillis());
             user.addField(param);
@@ -679,7 +675,12 @@
 
         try {
             UserDataDbIface<T> dao = UserdataFactory.getDaoInstance(clazz);
-            return dao.get(user);
+            T data = dao.get(user);
+            if (data == null)
+                throw new WrappedException(user.getId(),
+                        StatusCodes.EMPTY_RESULTS, clazz.getSimpleName());
+
+            return data;
         }catch (KustvaktException e) {
             jlog.error("Error ", e);
             throw new WrappedException(e, StatusCodes.GET_ACCOUNT_FAILED);
diff --git a/src/main/java/de/ids_mannheim/korap/security/auth/SessionFactory.java b/src/main/java/de/ids_mannheim/korap/security/auth/SessionFactory.java
index 426d594..8004e31 100644
--- a/src/main/java/de/ids_mannheim/korap/security/auth/SessionFactory.java
+++ b/src/main/java/de/ids_mannheim/korap/security/auth/SessionFactory.java
@@ -25,6 +25,7 @@
  *
  * @author hanl
  */
+//todo: use simple ehcache!
 public class SessionFactory implements Runnable {
 
     private static Logger jlog = LoggerFactory.getLogger(SessionFactory.class);
@@ -48,10 +49,8 @@
     public boolean hasSession(TokenContext context) {
         if (context.getUsername().equalsIgnoreCase(DemoUser.DEMOUSER_NAME))
             return false;
-        if (loggedInRecord.containsKey(context.getUsername()) && !loggedInRecord
-                .get(context.getUsername()).isEmpty())
-            return true;
-        return false;
+        return loggedInRecord.containsKey(context.getUsername())
+                && !loggedInRecord.get(context.getUsername()).isEmpty();
     }
 
     @Cacheable("session")
@@ -118,8 +117,9 @@
      */
     private boolean isUserSessionValid(String token) {
         if (timeCheck.containsKey(token)) {
-            if (TimeUtils.plusSeconds(timeCheck.get(token).getMillis(),
-                    inactive).isAfterNow()) {
+            if (TimeUtils
+                    .plusSeconds(timeCheck.get(token).getMillis(), inactive)
+                    .isAfterNow()) {
                 jlog.debug("user has session");
                 return true;
             }else
@@ -144,19 +144,10 @@
                 removeSession(entry.getKey());
             }
         }
+        // fixme: not doing anything!
         if (inactive.size() > 0)
             jlog.debug("removing inactive user session for users '{}' ",
                     inactive);
-
-        //        keys:
-        //        for (String key : failedLogins.getKeySet()) {
-        //            DateTime d = new DateTime(failedLogins.get(key).get(1));
-        //            if (d.isBeforeNow()) {
-        //                failedLogins.remove(key);
-        //                jlog.info("removed failed login counts due to expiration for user {}", key);
-        //                continue keys;
-        //            }
-        //        }
     }
 
     /**
@@ -165,7 +156,7 @@
     @Override
     public void run() {
         timeoutMaintenance();
-        jlog.debug("logged users: {}", loggedInRecord.toString());
-
+        if (loggedInRecord.size() > 0)
+            jlog.debug("logged users: {}", loggedInRecord.toString());
     }
 }
diff --git a/src/main/java/de/ids_mannheim/korap/user/DemoUser.java b/src/main/java/de/ids_mannheim/korap/user/DemoUser.java
index 22da0e8..b1ceef1 100644
--- a/src/main/java/de/ids_mannheim/korap/user/DemoUser.java
+++ b/src/main/java/de/ids_mannheim/korap/user/DemoUser.java
@@ -18,7 +18,6 @@
     protected DemoUser() {
         super(DEMOUSER_NAME, 2);
         this.setAccountCreation(ACCOUNT_CREATED);
-//        this.setQueries(UserQuery.demoUserQueries());
     }
 
     protected User clone() {
diff --git a/src/main/java/de/ids_mannheim/korap/user/TokenContext.java b/src/main/java/de/ids_mannheim/korap/user/TokenContext.java
index a31beab..bdc2d36 100644
--- a/src/main/java/de/ids_mannheim/korap/user/TokenContext.java
+++ b/src/main/java/de/ids_mannheim/korap/user/TokenContext.java
@@ -109,6 +109,12 @@
         return c;
     }
 
+    public boolean isValid() {
+        return (this.username != null && !this.username.isEmpty()) && (
+                this.token != null && !this.token.isEmpty()) && (
+                this.tokenType != null && !this.tokenType.isEmpty());
+    }
+
     public String getToken() {
         return token;
     }
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 95330b1..79df7cb 100644
--- a/src/main/java/de/ids_mannheim/korap/user/User.java
+++ b/src/main/java/de/ids_mannheim/korap/user/User.java
@@ -177,6 +177,24 @@
             return u;
         }
 
+        public static KorAPUser toKorAPUser(Map<String, Object> map) {
+            KorAPUser user = UserFactory
+                    .getUser((String) map.get(Attributes.USERNAME));
+            user.setPassword((String) map.get(Attributes.PASSWORD));
+            int id = map.get(Attributes.ID) == null ?
+                    -1 :
+                    (int) map.get(Attributes.ID);
+            if (id != -1)
+                user.setId(id);
+            long cr = map.get(Attributes.ACCOUNT_CREATION) == null ?
+                    -1 :
+                    (long) map.get(Attributes.ACCOUNT_CREATION);
+            if (cr != -1)
+                user.setAccountCreation(
+                        (Long) map.get(Attributes.ACCOUNT_CREATION));
+            return user;
+        }
+
         public static User toUser(Map<String, Object> map) {
             KustvaktMap kmap = new KustvaktMap(map);
             int type = map.get(Attributes.TYPE) == null ?
@@ -184,14 +202,19 @@
                     (Integer) kmap.get(Attributes.TYPE, Integer.class);
             User user;
             long created = -1;
+            int id = kmap.get(Attributes.ID, Integer.class) == null ?
+                    -1 :
+                    (Integer) kmap.get(Attributes.ID, Integer.class);
+
             if (map.get(Attributes.ACCOUNT_CREATION) != null)
                 created = DateTime.parse(kmap.get(Attributes.ACCOUNT_CREATION))
                         .getMillis();
             switch (type) {
                 case 0:
                     user = UserFactory.getUser(kmap.get(Attributes.USERNAME));
-                    user.setId(
-                            (Integer) kmap.get(Attributes.ID, Integer.class));
+                    if (id != -1)
+                        user.setId((Integer) kmap
+                                .get(Attributes.ID, Integer.class));
                     user.setAccountLocked(
                             map.get(Attributes.ACCOUNTLOCK) == null ?
                                     false :
@@ -200,8 +223,7 @@
                     user.setAccountCreation(created);
                     break;
                 default:
-                    user = UserFactory.getDemoUser(
-                            (Integer) kmap.get(Attributes.ID, Integer.class));
+                    user = UserFactory.getDemoUser();
                     user.setAccountCreation(created);
             }
             return user;
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 353915f..85e8046 100644
--- a/src/main/java/de/ids_mannheim/korap/user/UserdataFactory.java
+++ b/src/main/java/de/ids_mannheim/korap/user/UserdataFactory.java
@@ -59,7 +59,7 @@
                 }
             }
             throw new KustvaktException(StatusCodes.NOT_SUPPORTED,
-                    "No database class 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/web/KustvaktBaseServer.java b/src/main/java/de/ids_mannheim/korap/web/KustvaktBaseServer.java
index 8bdfb7d..2a8e430 100644
--- a/src/main/java/de/ids_mannheim/korap/web/KustvaktBaseServer.java
+++ b/src/main/java/de/ids_mannheim/korap/web/KustvaktBaseServer.java
@@ -4,6 +4,7 @@
 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.KustvaktCacheManager;
 import de.ids_mannheim.korap.config.KustvaktClassLoader;
 import de.ids_mannheim.korap.config.KustvaktConfiguration;
 import de.ids_mannheim.korap.exceptions.KustvaktException;
@@ -39,6 +40,8 @@
         else
             BeanConfiguration.loadClasspathContext();
 
+        KustvaktCacheManager.init();
+
         kargs.setRootPackages(
                 new String[] { "de.ids_mannheim.korap.web.service.light" });
 
@@ -107,6 +110,7 @@
                     iface.load();
                 }catch (KustvaktException e) {
                     // don't do anything!
+                    System.out.println("An error occurred! " + 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 60a2891..cb419fd 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
@@ -40,11 +40,10 @@
                 context = userController
                         .getTokenStatus(authentication, host, ua);
             }catch (KustvaktException e) {
-                throw KustvaktResponseHandler.throwit(e);
+                throw KustvaktResponseHandler.throwAuthenticationException();
             }
-
             // fixme: give reason why access is not granted?
-            if (context != null && (
+            if (context != null && context.isValid() && (
                     (context.isSecureRequired() && request.isSecure())
                             | !context.isSecureRequired()))
                 request.setSecurityContext(new KorAPContext(context));
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 7a6b249..d9fec47 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
@@ -29,6 +29,7 @@
 import de.ids_mannheim.korap.web.SearchKrill;
 import de.ids_mannheim.korap.web.TRACE;
 import de.ids_mannheim.korap.web.filter.AuthFilter;
+import de.ids_mannheim.korap.web.filter.BlockingFilter;
 import de.ids_mannheim.korap.web.filter.DefaultFilter;
 import de.ids_mannheim.korap.web.filter.PiwikFilter;
 import de.ids_mannheim.korap.web.utils.KustvaktResponseHandler;
@@ -44,7 +45,8 @@
  * @date 29/01/2014
  */
 @Path(KustvaktServer.API_VERSION + "/")
-@ResourceFilters({ AuthFilter.class, DefaultFilter.class, PiwikFilter.class })
+@ResourceFilters({ AuthFilter.class, DefaultFilter.class, PiwikFilter.class,
+        BlockingFilter.class })
 @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
 public class ResourceService {
 
@@ -869,8 +871,8 @@
             CollectionQueryBuilder3 cquery = new CollectionQueryBuilder3();
             if (reference != null && !reference.equals("null")) {
                 try {
-                    cquery.addQuery(
-                            (String) resourceHandler.findbyStrId(reference, user,
+                    cquery.addQuery((String) resourceHandler
+                            .findbyStrId(reference, user,
                                     VirtualCollection.class).getData());
                 }catch (KustvaktException e) {
                     throw KustvaktResponseHandler.throwit(e);
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 b7a5e5e..dc65cc7 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
@@ -101,8 +101,8 @@
     @POST
     @Path("update")
     @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
-    @ResourceFilters({ AuthFilter.class, DefaultFilter.class,
-            PiwikFilter.class })
+    @ResourceFilters({ AuthFilter.class, DefaultFilter.class, PiwikFilter.class,
+            BlockingFilter.class })
     public Response updateAccount(@Context SecurityContext ctx, String json) {
         TokenContext context = (TokenContext) ctx.getUserPrincipal();
         try {
@@ -206,7 +206,7 @@
     @GET
     @Path("info")
     @ResourceFilters({ AuthFilter.class, DefaultFilter.class, PiwikFilter.class,
-            BlockingFilter.class })
+            BlockingFilter.class, BlockingFilter.class })
     public Response getStatus(@Context SecurityContext context,
             @QueryParam("scopes") String scopes) {
         TokenContext ctx = (TokenContext) context.getUserPrincipal();
@@ -228,8 +228,8 @@
 
     @GET
     @Path("settings")
-    @ResourceFilters({ AuthFilter.class, DefaultFilter.class,
-            PiwikFilter.class })
+    @ResourceFilters({ AuthFilter.class, DefaultFilter.class, PiwikFilter.class,
+            BlockingFilter.class })
     public Response getUserSettings(@Context SecurityContext context,
             @Context Locale locale) {
         TokenContext ctx = (TokenContext) context.getUserPrincipal();
@@ -250,8 +250,8 @@
     @POST
     @Path("settings")
     @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
-    @ResourceFilters({ AuthFilter.class, DefaultFilter.class,
-            PiwikFilter.class })
+    @ResourceFilters({ AuthFilter.class, DefaultFilter.class, PiwikFilter.class,
+            BlockingFilter.class })
     public Response updateSettings(@Context SecurityContext context,
             @Context Locale locale, MultivaluedMap form) {
         TokenContext ctx = (TokenContext) context.getUserPrincipal();
@@ -284,8 +284,8 @@
 
     @GET
     @Path("details")
-    @ResourceFilters({ AuthFilter.class, DefaultFilter.class,
-            PiwikFilter.class })
+    @ResourceFilters({ AuthFilter.class, DefaultFilter.class, PiwikFilter.class,
+            BlockingFilter.class })
     public Response getDetails(@Context SecurityContext context,
             @Context Locale locale) {
         TokenContext ctx = (TokenContext) context.getUserPrincipal();
@@ -299,14 +299,15 @@
             jlog.error("Exception encountered!", e);
             throw KustvaktResponseHandler.throwit(e);
         }
-        return Response.ok(result).build();
+//        return Response.ok(result).build();
+        return null;
     }
 
     @POST
     @Path("details")
     @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
-    @ResourceFilters({ AuthFilter.class, DefaultFilter.class,
-            PiwikFilter.class })
+    @ResourceFilters({ AuthFilter.class, DefaultFilter.class, PiwikFilter.class,
+            BlockingFilter.class })
     public Response updateDetails(@Context SecurityContext context,
             @Context Locale locale, MultivaluedMap form) {
         TokenContext ctx = (TokenContext) context.getUserPrincipal();
@@ -336,8 +337,8 @@
     @POST
     @Path("queries")
     @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
-    @ResourceFilters({ AuthFilter.class, DefaultFilter.class,
-            PiwikFilter.class })
+    @ResourceFilters({ AuthFilter.class, DefaultFilter.class, PiwikFilter.class,
+            BlockingFilter.class })
     public Response updateQueries(@Context SecurityContext context,
             String json) {
         TokenContext ctx = (TokenContext) context.getUserPrincipal();
@@ -387,8 +388,8 @@
     }
 
     @DELETE
-    @ResourceFilters({ AuthFilter.class, DefaultFilter.class,
-            PiwikFilter.class })
+    @ResourceFilters({ AuthFilter.class, DefaultFilter.class, PiwikFilter.class,
+            BlockingFilter.class })
     public Response deleteUser(@Context SecurityContext context) {
         TokenContext ctx = (TokenContext) context.getUserPrincipal();
         try {
@@ -405,8 +406,8 @@
 
     @GET
     @Path("queries")
-    @ResourceFilters({ AuthFilter.class, DefaultFilter.class,
-            PiwikFilter.class })
+    @ResourceFilters({ AuthFilter.class, DefaultFilter.class, PiwikFilter.class,
+            BlockingFilter.class })
     public Response getQueries(@Context SecurityContext context,
             @Context Locale locale) {
         TokenContext ctx = (TokenContext) context.getUserPrincipal();
diff --git a/src/main/java/de/ids_mannheim/korap/web/utils/KustvaktResponseHandler.java b/src/main/java/de/ids_mannheim/korap/web/utils/KustvaktResponseHandler.java
index 89ad245..80cd425 100644
--- a/src/main/java/de/ids_mannheim/korap/web/utils/KustvaktResponseHandler.java
+++ b/src/main/java/de/ids_mannheim/korap/web/utils/KustvaktResponseHandler.java
@@ -32,19 +32,19 @@
     }
 
     public static WebApplicationException throwit(KustvaktException e) {
-        return new WebApplicationException(
-                Response.status(Response.Status.BAD_REQUEST)
-                        .entity(buildNotification(e)).build());
+        Response s = Response.status(getStatus(e.getStatusCode()))
+                .entity(buildNotification(e)).build();
+        return new WebApplicationException(s);
     }
 
     public static WebApplicationException throwit(int code) {
-        return new WebApplicationException(Response.status(Response.Status.OK)
+        return new WebApplicationException(Response.status(getStatus(code))
                 .entity(buildNotification(code, "", "")).build());
     }
 
     public static WebApplicationException throwit(int code, String message,
             String entity) {
-        return new WebApplicationException(Response.status(Response.Status.OK)
+        return new WebApplicationException(Response.status(getStatus(code))
                 .entity(buildNotification(code, message, entity)).build());
     }
 
@@ -62,12 +62,24 @@
     }
 
     public static WebApplicationException throwAuthenticationException() {
-        KustvaktException e = new KustvaktException(
-                StatusCodes.BAD_CREDENTIALS);
         return new WebApplicationException(
                 Response.status(Response.Status.UNAUTHORIZED)
                         .header(HttpHeaders.WWW_AUTHENTICATE,
                                 "Basic realm=Kustvakt Authentication Service")
-                        .entity(buildNotification(e)).build());
+                        .entity(buildNotification(StatusCodes.BAD_CREDENTIALS,
+                                "Unauthorized access", "")).build());
+    }
+
+    private static Response.Status getStatus(int code) {
+        Response.Status status = Response.Status.BAD_REQUEST;
+        switch (code) {
+            case StatusCodes.EMPTY_RESULTS:
+                status = Response.Status.NO_CONTENT;
+                break;
+            case StatusCodes.ILLEGAL_ARGUMENT:
+                status = Response.Status.NOT_ACCEPTABLE;
+                break;
+        }
+        return status;
     }
 }
diff --git a/src/main/resources/db/mysql/V0.1__userdatabase.sql b/src/main/resources/db/mysql/V0.1__userdatabase.sql
index 6444651..cfe31a1 100644
--- a/src/main/resources/db/mysql/V0.1__userdatabase.sql
+++ b/src/main/resources/db/mysql/V0.1__userdatabase.sql
@@ -23,53 +23,17 @@
     account_link VARCHAR(100)
 );
 
+
 CREATE TABLE IF NOT EXISTS user_details (
-    Id INTEGER PRIMARY KEY AUTO_INCREMENT,
-    user_id INTEGER NOT NULL UNIQUE,
-    firstName VARCHAR(100),
-    lastName VARCHAR(100),
-    gender VARCHAR(100),
-    phone VARCHAR(100),
-    institution VARCHAR(100),
-    email VARCHAR(100),
-    address VARCHAR(100),
-    country VARCHAR(100),
-    privateUsage BOOLEAN,
-    foreign key (user_id)
-    references korap_users (id)
-    on delete cascade
+id INTEGER PRIMARY KEY AUTO_INCREMENT,
+user_id INTEGER UNIQUE NOT NULL,
+data BLOB NOT NULL
 );
 
 CREATE TABLE IF NOT EXISTS user_settings (
-    Id INTEGER PRIMARY KEY AUTO_INCREMENT,
-    user_id INTEGER NOT NULL UNIQUE,
-    fileNameForExport VARCHAR(100),
-    itemForSimpleAnnotation INTEGER,
-    leftContextItemForExport VARCHAR(100),
-    leftContextSizeForExport INTEGER,
-    locale VARCHAR(100),
-    leftContextItem VARCHAR(100),
-    leftContextSize INTEGER,
-    rightContextItem VARCHAR(100),
-    rightContextItemForExport VARCHAR(100),
-    rightContextSize INTEGER,
-    rightContextSizeForExport INTEGER,
-    selectedCollection VARCHAR(100),
-    queryLanguage VARCHAR(100),
-    pageLength INTEGER,
-    metadataQueryExpertModus BOOLEAN,
-    searchSettingsTab INTEGER,
-    selectedGraphType INTEGER,
-    selectedSortType VARCHAR(100),
-    selectedViewForSearchResults VARCHAR(100),
-    POSFoundry VARCHAR(100),
-    lemmaFoundry VARCHAR(100),
-    constFoundry VARCHAR(100),
-    relFoundry VARCHAR(100),
-    collectData BOOLEAN,
-    foreign key (user_id)
-    references korap_users (id)
-    on delete cascade
+id INTEGER PRIMARY KEY AUTO_INCREMENT,
+user_id INTEGER UNIQUE NOT NULL,
+data BLOB NOT NULL
 );
 
 -- deprecated
diff --git a/src/main/resources/db/mysql/V0.2__resourcesdatabase.sql b/src/main/resources/db/mysql/V0.2__resourcesdatabase.sql
index 01b8c26..cc2afa3 100644
--- a/src/main/resources/db/mysql/V0.2__resourcesdatabase.sql
+++ b/src/main/resources/db/mysql/V0.2__resourcesdatabase.sql
@@ -5,7 +5,8 @@
 name VARCHAR(100),
 description VARCHAR(300),
 parent_id Integer unsigned null,
-created BIGINT NOT NULL,
+created BIGINT null,
+data BLOB,
 type INTEGER NOT NULL,
 creator INTEGER NOT NULL
 );
@@ -24,7 +25,7 @@
 on delete cascade
 );
 
-
+-- deprecated
 CREATE TABLE IF NOT EXISTS user_queries (
     id INTEGER PRIMARY KEY,
     queryLanguage VARCHAR(100),
diff --git a/src/main/resources/db/mysql/V0.3__securitydatabase.sql b/src/main/resources/db/mysql/V0.3__securitydatabase.sql
index b7d826b..e74b114 100644
--- a/src/main/resources/db/mysql/V0.3__securitydatabase.sql
+++ b/src/main/resources/db/mysql/V0.3__securitydatabase.sql
@@ -5,8 +5,8 @@
     created TIMESTAMP,
     creator INTEGER NOT NULL,
     posix SMALLINT NOT NULL,
-    expire TIMESTAMP NULL,
-    enable TIMESTAMP NULL,
+    expire BIGINT NULL,
+    enable BIGINT NULL,
     iprange VARCHAR(200)
 );
 
diff --git a/src/main/resources/db/sqlite/V1__Initial_version.sql b/src/main/resources/db/sqlite/V1__Initial_version.sql
index 69fd635..46eff5e 100644
--- a/src/main/resources/db/sqlite/V1__Initial_version.sql
+++ b/src/main/resources/db/sqlite/V1__Initial_version.sql
@@ -45,19 +45,6 @@
 on delete cascade
 );
 
-CREATE TABLE IF NOT EXISTS coll_store (
-id INTEGER PRIMARY KEY AUTOINCREMENT,
-persistent_id VARCHAR(150) UNIQUE,
-name VARCHAR(150),
-description VARCHAR(200),
-query VARCHAR(500),
-created BIGINT NOT NULL,
-user_id INTEGER,
-foreign key(user_id)
-references korap_users(id)
-on delete cascade
-);
-
 CREATE TABLE IF NOT EXISTS audit_records (
 aud_id INTEGER PRIMARY KEY AUTOINCREMENT,
 aud_category VARCHAR(100),
@@ -161,7 +148,7 @@
 name VARCHAR(100),
 description VARCHAR(300),
 parent_id INTEGER unsigned null,
-created TIMESTAMP default current_timestamp,
+created BIGINT null,
 data BLOB,
 type INTEGER NOT NULL,
 creator INTEGER NOT NULL
diff --git a/src/main/resources/default-config.xml b/src/main/resources/default-config.xml
index cb62910..89f4bb9 100644
--- a/src/main/resources/default-config.xml
+++ b/src/main/resources/default-config.xml
@@ -10,18 +10,14 @@
                             http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
                             http://www.springframework.org/schema/tx
                             http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
-
-
                             http://www.springframework.org/schema/aop
                             http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
                             http://www.springframework.org/schema/cache
                             http://www.springframework.org/schema/cache/spring-cache-4.0.xsd
-
-
                             http://www.springframework.org/schema/util
                             http://www.springframework.org/schema/util/spring-util-4.0.xsd">
 
-    <cache:annotation-driven/>
+    <!--<cache:annotation-driven/>-->
 
     <bean id="props"
           class="org.springframework.beans.factory.config.PropertiesFactoryBean">
@@ -45,14 +41,14 @@
         </property>
     </bean>
 
-    <bean id='cacheManager'
-          class='org.springframework.cache.ehcache.EhCacheCacheManager'
-          p:cacheManager-ref='ehcache'/>
+    <!--<bean id='cacheManager'-->
+          <!--class='org.springframework.cache.ehcache.EhCacheCacheManager'-->
+          <!--p:cacheManager-ref='ehcache'/>-->
 
-    <bean id='ehcache'
-          class='org.springframework.cache.ehcache.EhCacheManagerFactoryBean'
-          p:configLocation='classpath:ehcache.xml'
-          p:shared='true'/>
+    <!--<bean id='ehcache'-->
+          <!--class='org.springframework.cache.ehcache.EhCacheManagerFactoryBean'-->
+          <!--p:configLocation='classpath:ehcache.xml'-->
+          <!--p:shared='true'/>-->
 
     <!-- props are injected from default-config.xml -->
     <bean id="kustvakt_config"
diff --git a/src/main/resources/ehcache.xml b/src/main/resources/ehcache.xml
index 4259339..1bbb213 100644
--- a/src/main/resources/ehcache.xml
+++ b/src/main/resources/ehcache.xml
@@ -17,20 +17,25 @@
            maxEntriesLocalHeap="50"
            overflowToDisk='false'/>
     <cache name='id_tokens'
-           timeToIdleSeconds="172800"
            eternal='true'
            maxElementsOnDisk="10000000"
            memoryStoreEvictionPolicy="LRU"
            maxEntriesLocalHeap="50"
            overflowToDisk='true'/>
     <cache name='id_tokens_inv'
-           timeToIdleSeconds="322800"
            eternal='true'
            maxElementsOnDisk="10000000"
            memoryStoreEvictionPolicy="LRU"
            maxEntriesLocalHeap="50"
            overflowToDisk='true'/>
 
+    <cache name='auth_sessions'
+           timeToIdleSeconds="172800"
+           eternal='false'
+           memoryStoreEvictionPolicy="LRU"
+           maxEntriesLocalHeap="100"
+           overflowToDisk='false'/>
+
     <cache name='auth_codes'
            timeToIdleSeconds="600"
            eternal='false'
diff --git a/src/test/java/UserdataTest.java b/src/test/java/UserdataTest.java
index c3cc6b8..e5b598f 100644
--- a/src/test/java/UserdataTest.java
+++ b/src/test/java/UserdataTest.java
@@ -1,5 +1,6 @@
 import de.ids_mannheim.korap.config.BeanConfiguration;
 import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.exceptions.dbException;
 import de.ids_mannheim.korap.handlers.UserDetailsDao;
 import de.ids_mannheim.korap.handlers.UserSettingsDao;
 import de.ids_mannheim.korap.interfaces.db.UserDataDbIface;
@@ -47,7 +48,7 @@
     }
 
     @Test
-    public void testDataGet() {
+    public void testDataGet() throws dbException {
         User user = new KorAPUser();
         user.setId(1);
         UserDetailsDao dao = new UserDetailsDao(
diff --git a/src/test/java/de/ids_mannheim/korap/config/TestHelper.java b/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
index c1e2cd1..2a685a8 100644
--- a/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
+++ b/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
@@ -10,6 +10,8 @@
 import org.springframework.jdbc.core.RowCallbackHandler;
 import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
 
+import java.io.UnsupportedEncodingException;
+import java.security.NoSuchAlgorithmException;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.*;
@@ -25,9 +27,9 @@
     private static final String[] credentials = new String[] { "test1",
             "testPass2015" };
 
-    public static boolean setupUser() {
+    public static boolean setupAccount() {
         boolean r = BeanConfiguration.hasContext();
-        if (r) {
+        if (r && BeanConfiguration.getBeans().getUserDBHandler().size() == 0) {
             EntityHandlerIface dao = BeanConfiguration.getBeans()
                     .getUserDBHandler();
             Map m = new HashMap<>();
@@ -45,8 +47,37 @@
                         .createUserAccount(m, false);
             }catch (KustvaktException e) {
                 // do nothing
-                System.out.println("THE EXCEPTION...");
-                e.printStackTrace();
+                Assert.assertNull("Test user could not be set up", true);
+                return false;
+            }
+        }
+        return r;
+    }
+
+    public static boolean setupSimpleAccount() {
+        boolean r = BeanConfiguration.hasContext();
+        if (r && BeanConfiguration.getBeans().getUserDBHandler().size() == 0) {
+            EntityHandlerIface dao = BeanConfiguration.getBeans()
+                    .getUserDBHandler();
+            Map m = new HashMap<>();
+            m.put(Attributes.USERNAME, credentials[0]);
+
+            try {
+                String hash = BeanConfiguration.getBeans().getEncryption()
+                        .produceSecureHash(credentials[1]);
+                m.put(Attributes.PASSWORD, hash);
+            }catch (NoSuchAlgorithmException | UnsupportedEncodingException | KustvaktException e) {
+
+            }
+            Assert.assertNotNull("userdatabase handler must not be null", dao);
+
+            try {
+                int i = dao.createAccount(User.UserFactory.toKorAPUser(m));
+                assert BeanConfiguration.getBeans().getUserDBHandler()
+                        .getAccount(credentials[0]) != null;
+                assert i == 1;
+            }catch (KustvaktException e) {
+                // do nothing
                 Assert.assertNull("Test user could not be set up", true);
                 return false;
             }
@@ -80,7 +111,18 @@
         return r;
     }
 
-    public static boolean truncateAllUsers() {
+    public static void drop() {
+        if (BeanConfiguration.hasContext()) {
+            PersistenceClient cl = BeanConfiguration.getBeans()
+                    .getPersistenceClient();
+            String sql = "drop database " + cl.getDatabase() + ";";
+            NamedParameterJdbcTemplate jdbc = (NamedParameterJdbcTemplate) cl
+                    .getSource();
+            jdbc.update(sql, new HashMap<String, Object>());
+        }
+    }
+
+    public static boolean truncateAll() {
         boolean r = BeanConfiguration.hasContext();
         if (r) {
             String sql = "SELECT Concat('TRUNCATE TABLE ', TABLE_NAME) FROM INFORMATION_SCHEMA.TABLES";
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/KustvaktResourceServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/KustvaktResourceServiceTest.java
index 62beae8..4f27150 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/KustvaktResourceServiceTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/KustvaktResourceServiceTest.java
@@ -4,6 +4,7 @@
 import com.sun.jersey.api.client.ClientResponse;
 import de.ids_mannheim.korap.config.BeanConfiguration;
 import de.ids_mannheim.korap.config.TestHelper;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.security.auth.BasicHttpAuth;
 import de.ids_mannheim.korap.user.Attributes;
 import de.ids_mannheim.korap.utils.JsonUtils;
@@ -27,7 +28,8 @@
     }
 
     @AfterClass
-    public static void close() {
+    public static void close() throws KustvaktException {
+        BeanConfiguration.getBeans().getResourceProvider().deleteAll();
         BeanConfiguration.closeApplication();
     }
 
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/OAuth2EndpointTest.java b/src/test/java/de/ids_mannheim/korap/web/service/OAuth2EndpointTest.java
index f0865b6..e1dc167 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/OAuth2EndpointTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/OAuth2EndpointTest.java
@@ -35,7 +35,7 @@
                 "de.ids_mannheim.korap.web.filter",
                 "de.ids_mannheim.korap.web.utils");
 
-        TestHelper.setupUser();
+        TestHelper.setupAccount();
         credentials = TestHelper.getUserCredentials();
     }
 
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/OAuth2HandlerTest.java b/src/test/java/de/ids_mannheim/korap/web/service/OAuth2HandlerTest.java
index a804d69..4cf5ecb 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/OAuth2HandlerTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/OAuth2HandlerTest.java
@@ -39,7 +39,7 @@
         info.setUrl("http://localhost:8080/api/v0.1");
         info.setRedirect_uri("testwebsite/login");
 
-        TestHelper.setupUser();
+        TestHelper.setupAccount();
         user = TestHelper.getUser();
         handler.registerClient(info, user);
     }