user data db
diff --git a/src/main/java/de/ids_mannheim/korap/config/JWTSigner.java b/src/main/java/de/ids_mannheim/korap/config/JWTSigner.java
index 30f8e2f..d959604 100644
--- a/src/main/java/de/ids_mannheim/korap/config/JWTSigner.java
+++ b/src/main/java/de/ids_mannheim/korap/config/JWTSigner.java
@@ -41,25 +41,25 @@
this(secret, new URL(issuer), 72 * 60 * 60);
}
- public SignedJWT createJWT(User user, Map<String, String> attr) {
+ public SignedJWT createJWT(User user, Map<String, Object> attr) {
return signContent(user, attr, defaultttl);
}
- public SignedJWT signContent(User user, Map<String, String> attr, int ttl) {
+ public SignedJWT signContent(User user, Map<String, Object> attr, int ttl) {
String scopes;
JWTClaimsSet cs = new JWTClaimsSet();
cs.setIssuerClaim(this.issuer.toString());
- if ((scopes = attr.get(Attributes.SCOPES)) != null) {
- Scopes claims = Scopes.mapScopes(scopes, user.getDetails());
+ if ((scopes = (String) attr.get(Attributes.SCOPES)) != null) {
+ Scopes claims = Scopes.mapScopes(scopes, attr);
cs.setCustomClaims(claims.toMap());
}
cs.setSubjectClaim(user.getUsername());
if (attr.get(Attributes.CLIENT_ID) != null)
cs.setAudienceClaim(
- new String[] { attr.get(Attributes.CLIENT_ID) });
+ new String[] { (String) attr.get(Attributes.CLIENT_ID) });
cs.setExpirationTimeClaim(
TimeUtils.getNow().plusSeconds(ttl).getMillis());
SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.HS256),
diff --git a/src/main/java/de/ids_mannheim/korap/config/Scopes.java b/src/main/java/de/ids_mannheim/korap/config/Scopes.java
index 63a3f07..cce49e8 100644
--- a/src/main/java/de/ids_mannheim/korap/config/Scopes.java
+++ b/src/main/java/de/ids_mannheim/korap/config/Scopes.java
@@ -1,7 +1,6 @@
package de.ids_mannheim.korap.config;
import de.ids_mannheim.korap.user.Attributes;
-import de.ids_mannheim.korap.user.UserDetails;
import de.ids_mannheim.korap.utils.JsonUtils;
import java.util.ArrayList;
@@ -54,18 +53,17 @@
return s.toArray(new Scope[s.size()]);
}
- public static Scopes mapScopes(String scopes, UserDetails details) {
+ public static Scopes mapScopes(String scopes, Map<String, Object> details) {
Scopes m = new Scopes();
- Map<String, Object> det = details.toMap();
if (scopes != null && !scopes.isEmpty()) {
Scope[] scopearr = mapScopes(scopes);
for (Scope s : scopearr) {
- Object v = det.get(s.toString());
+ Object v = details.get(s.toString());
if (v != null)
m._values.put(s.toString(), v);
}
if (scopes.contains(Scope.profile.toString()))
- m._values.putAll(Scopes.getProfileScopes(det)._values);
+ m._values.putAll(Scopes.getProfileScopes(details)._values);
m._values.put(Attributes.SCOPES, scopes);
}
return m;
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 c44888f..34aa013 100644
--- a/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java
+++ b/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java
@@ -56,7 +56,7 @@
public static final Integer UNSUPPORTED_CORPUS = 404;
public static final Integer UNSUPPORTED_LAYER = 405;
// make a distinction between no and invalid vc?
- public static final Integer UNSUPPORTED_VIRTUALCOLLECTION = 406;
+ 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;
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 cab2d4c..e87b62d 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/EntityDao.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/EntityDao.java
@@ -8,23 +8,22 @@
import de.ids_mannheim.korap.exceptions.dbException;
import de.ids_mannheim.korap.interfaces.db.EntityHandlerIface;
import de.ids_mannheim.korap.interfaces.db.PersistenceClient;
-import de.ids_mannheim.korap.user.*;
+import de.ids_mannheim.korap.user.DemoUser;
+import de.ids_mannheim.korap.user.KorAPUser;
+import de.ids_mannheim.korap.user.ShibUser;
+import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.utils.BooleanUtils;
import de.ids_mannheim.korap.utils.TimeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
-import org.springframework.jdbc.core.RowMapper;
-import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import java.sql.Date;
-import java.sql.ResultSet;
-import java.sql.SQLException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -43,186 +42,6 @@
this.jdbcTemplate = (NamedParameterJdbcTemplate) client.getSource();
}
- @Override
- public UserSettings getUserSettings(Integer userid)
- throws KustvaktException {
- // TransactionDefinition def = new DefaultTransactionDefinition();
- // TransactionStatus status = transactionManager.getTransaction(def);
-
- MapSqlParameterSource np = new MapSqlParameterSource();
- np.addValue("us", userid);
- final String sql =
- "SELECT user.* FROM user_settings as user inner join korap_users as a "
- + "on a.id=user.user_id WHERE user.user_id=:us";
- try {
- Map s = this.jdbcTemplate.queryForMap(sql, np);
- return UserSettings.fromObjectMap(s);
- }catch (EmptyResultDataAccessException ex) {
- return new UserSettings();
- }catch (DataAccessException e) {
- jlog.error("Could not retrieve user settings for user: " + userid,
- e);
- throw new dbException(userid, "user_settings",
- StatusCodes.DB_GET_FAILED, userid.toString());
- }
- }
-
- //todo: uniqueness constraints on usersettings and details (every user only one entry for data and settings)
- @Override
- public int updateSettings(UserSettings settings) throws KustvaktException {
- final String sql =
- "UPDATE user_settings SET fileNameForExport=:fileNameForExport,"
- +
- "leftContextItemForExport=:leftContextItemForExport," +
- "leftContextSizeForExport=:leftContextSizeForExport,locale=:locale,leftContextItem=:leftContextItem,"
- +
- "leftContextSize=:leftContextSize," +
- "rightContextItem=:rightContextItem,rightContextItemForExport=:rightContextItemForExport,"
- +
- "rightContextSize=:rightContextSize," +
- "POSFoundry=:defaultPOSfoundry, lemmaFoundry=:defaultLemmafoundry, constFoundry=:defaultConstfoundry, "
- +
- "relFoundry=:defaultRelfoundry, " +
- "rightContextSizeForExport=:rightContextSizeForExport,selectedCollection=:selectedCollection,queryLanguage=:queryLanguage,"
- +
- "pageLength=:pageLength,metadataQueryExpertModus=:metadataQueryExpertModus,collectData=:collectData "
- +
- "WHERE user_id=:userID";
- try {
- return this.jdbcTemplate
- .update(sql, new BeanPropertySqlParameterSource(settings));
- }catch (DataAccessException e) {
- jlog.error("Could not update user settings for user: " + settings
- .getUserID(), e);
- throw new dbException(settings.getUserID(), "user_settings",
- StatusCodes.DB_UPDATE_FAILED, settings.toString());
- }
- }
-
- /**
- * @param settings
- * @throws KustvaktException
- */
-
- private void createSettings(UserSettings settings)
- throws KustvaktException {
- final String sql =
- "INSERT INTO user_settings (user_id, fileNameForExport,leftContextItemForExport,"
- +
- "leftContextSizeForExport,locale,leftContextItem,leftContextSize,"
- +
- "rightContextItem,rightContextItemForExport,rightContextSize,"
- +
- "rightContextSizeForExport,selectedCollection,queryLanguage,"
- +
- "pageLength,metadataQueryExpertModus, POSFoundry, lemmaFoundry, constFoundry, relFoundry, collectData) "
- +
- "VALUES (:userID, :fileNameForExport, :leftContextItemForExport, "
- +
- ":leftContextSizeForExport, :locale, :leftContextItem, :leftContextSize, "
- +
- ":rightContextItem,:rightContextItemForExport, :rightContextSize, "
- +
- ":rightContextSizeForExport, :selectedCollection, :queryLanguage, "
- +
- ":pageLength, :metadataQueryExpertModus, :defaultPOSfoundry, "
- +
- ":defaultLemmafoundry, :defaultConstfoundry, :defaultRelfoundry, :collectData);";
-
- try {
- if (settings == null)
- throw new KustvaktException(StatusCodes.MISSING_ARGUMENTS,
- "no settings provided", "user settings");
- this.jdbcTemplate
- .update(sql, new BeanPropertySqlParameterSource(settings));
- }catch (DataAccessException e) {
- jlog.error("Could not create user settings for user: " + settings
- .getUserID(), e);
- throw new dbException(settings.getUserID(), "userSettings",
- StatusCodes.DB_INSERT_FAILED, settings.toString());
- }
- }
-
- @Override
- public UserDetails getUserDetails(Integer userid) throws KustvaktException {
- final String sql = "SELECT us.* FROM user_details as us inner join korap_users as ku on ku.id=us.user_id WHERE us.user_id=:user";
- MapSqlParameterSource np = new MapSqlParameterSource();
- np.addValue("user", userid);
-
- try {
- return this.jdbcTemplate
- .queryForObject(sql, np, new RowMapper<UserDetails>() {
- @Override
- public UserDetails mapRow(ResultSet rs, int i)
- throws SQLException {
- UserDetails d = new UserDetails();
- d.setUserID(rs.getInt("user_id"));
- d.setAddress(rs.getString("address"));
- d.setCountry(rs.getString("country"));
- d.setEmail(rs.getString("email"));
- d.setFirstName(rs.getString("firstName"));
- d.setLastName(rs.getString("lastName"));
- d.setGender(rs.getString("gender"));
- d.setInstitution(rs.getString("institution"));
- d.setPhone(rs.getString("phone"));
- d.setPrivateUsage(rs.getBoolean("privateUsage"));
- return d;
- }
- });
- }catch (EmptyResultDataAccessException ex) {
- //todo: create audit record?
- return null;
- }catch (DataAccessException e) {
- jlog.error("Could not retrieve user details for user: " + userid,
- e);
- throw new dbException(userid, "userDetails",
- StatusCodes.DB_GET_FAILED, userid.toString());
- }
- }
-
- @Override
- public int updateUserDetails(UserDetails details) throws KustvaktException {
- final String up =
- "UPDATE user_details SET firstName=:firstName, lastName=:lastName, "
- +
- "gender=:gender, phone=:phone, institution=:institution, "
- +
- "email=:email, address=:address, country=:country, privateUsage=:privateUsage "
- +
- "WHERE user_id=:userID;";
- try {
- return this.jdbcTemplate
- .update(up, new BeanPropertySqlParameterSource(details));
- }catch (DataAccessException e) {
- jlog.error("Could not retrieve user details for user: " + details
- .getUserID(), e);
- throw new dbException(details.getUserID(), "userDetails",
- StatusCodes.DB_UPDATE_FAILED, details.toString());
- }
- }
-
- private void createUserDetails(UserDetails details)
- throws KustvaktException {
- final String up =
- "INSERT INTO user_details (user_id, firstName, lastName, gender, phone, institution, "
- +
- "email, address, country, privateUsage) VALUES (:userID, :firstName, :lastName, :gender, "
- +
- ":phone, :institution, :email, :address, :country, :privateUsage);";
- try {
- if (details == null)
- throw new KustvaktException(StatusCodes.MISSING_ARGUMENTS,
- "no details provided", "user details");
- this.jdbcTemplate
- .update(up, new BeanPropertySqlParameterSource(details));
- }catch (DataAccessException e) {
- jlog.error("Could not create user details for user: " + details
- .getUserID(), e);
- throw new dbException(details.getUserID(), "userDetails",
- StatusCodes.DB_INSERT_FAILED, details.toString());
- }
- }
-
// usersettings are fetched plus basic account info, no details, since i rarely use them anyway!
@Override
public User getAccount(String username) throws KustvaktException {
@@ -377,14 +196,6 @@
int r = this.jdbcTemplate
.update(query, np, holder, new String[] { "id" });
user.setId(holder.getKey().intValue());
-
- if (user.getDetails() == null)
- user.setDetails(new UserDetails());
- if (user.getSettings() == null)
- user.setSettings(new UserSettings());
-
- this.createUserDetails(user.getDetails());
- this.createSettings(user.getSettings());
return r;
}catch (DataAccessException e) {
jlog.error("Could not create user account with username: {}",
diff --git a/src/main/java/de/ids_mannheim/korap/interfaces/AuthenticationIface.java b/src/main/java/de/ids_mannheim/korap/interfaces/AuthenticationIface.java
index 13f29f6..82d6737 100644
--- a/src/main/java/de/ids_mannheim/korap/interfaces/AuthenticationIface.java
+++ b/src/main/java/de/ids_mannheim/korap/interfaces/AuthenticationIface.java
@@ -11,7 +11,7 @@
TokenContext getUserStatus(String authToken) throws
KustvaktException;
- TokenContext createUserSession(User user, Map<String, String> attr)
+ TokenContext createUserSession(User user, Map<String, Object> attr)
throws KustvaktException;
void removeUserSession(String token) throws KustvaktException;
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 7c0b418..8204a4f 100644
--- a/src/main/java/de/ids_mannheim/korap/interfaces/AuthenticationManagerIface.java
+++ b/src/main/java/de/ids_mannheim/korap/interfaces/AuthenticationManagerIface.java
@@ -40,18 +40,18 @@
public abstract User getUser(String username) throws KustvaktException;
public abstract User authenticate(int type, String username,
- String password, Map<String, String> attributes)
+ String password, Map<String, Object> attributes)
throws KustvaktException;
public abstract TokenContext createTokenContext(User user,
- Map<String, String> attr, String provider_key)
+ Map<String, Object> attr, String provider_key)
throws KustvaktException;
public abstract void logout(TokenContext context) throws KustvaktException;
public abstract void lockAccount(User user) throws KustvaktException;
- public abstract User createUserAccount(Map attributes,
+ public abstract User createUserAccount(Map<String, Object> attributes,
boolean confirmation_required) throws KustvaktException;
// public abstract boolean updateAccount(User user) throws KustvaktException;
@@ -63,21 +63,6 @@
public abstract void updateUserData(Userdata data) throws KustvaktException;
- @Deprecated
- public abstract UserDetails getUserDetails(User user)
- throws KustvaktException;
-
- @Deprecated
- public abstract UserSettings getUserSettings(User user)
- throws KustvaktException;
-
- @Deprecated
- public abstract void updateUserDetails(User user, UserDetails details)
- throws KustvaktException;
-
- @Deprecated
- public abstract void updateUserSettings(User user, UserSettings settings)
- throws KustvaktException;
public abstract Object[] validateResetPasswordRequest(String username,
String email) throws KustvaktException;
diff --git a/src/main/java/de/ids_mannheim/korap/interfaces/EncryptionIface.java b/src/main/java/de/ids_mannheim/korap/interfaces/EncryptionIface.java
index 3b035b4..ec31ed7 100644
--- a/src/main/java/de/ids_mannheim/korap/interfaces/EncryptionIface.java
+++ b/src/main/java/de/ids_mannheim/korap/interfaces/EncryptionIface.java
@@ -64,7 +64,7 @@
public String encodeBase();
- public Map validateMap(Map map) throws KustvaktException;
+ public Map<String, Object> validateMap(Map<String, Object> map) throws KustvaktException;
public String validateEntry(String input, String type)
throws KustvaktException;
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 ec70921..c83f60d 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
@@ -3,8 +3,6 @@
import de.ids_mannheim.korap.exceptions.EmptyResultException;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.user.User;
-import de.ids_mannheim.korap.user.UserDetails;
-import de.ids_mannheim.korap.user.UserSettings;
/**
* User: hanl
@@ -12,23 +10,6 @@
* Time: 11:04 AM
*/
public interface EntityHandlerIface {
- @Deprecated
- UserSettings getUserSettings(Integer userid) throws KustvaktException;
-
- @Deprecated
- int updateSettings(UserSettings settings) throws KustvaktException;
-
- @Deprecated
- UserDetails getUserDetails(Integer userid) throws KustvaktException;
-
- @Deprecated
- int updateUserDetails(UserDetails details) throws KustvaktException;
-
- // List<UserQuery> getUserQueries(User user) throws KorAPException;
-
- // UserQuery getUserQuery(String id) throws KorAPException;
-
- // void updateUserQueries(User user, List<UserQuery> newOnes) throws KorAPException;
User getAccount(String username)
throws EmptyResultException, KustvaktException;
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 2a1cde8..dbd3649 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,7 @@
// todo: where applied?
@Override
- public Map validateMap(Map 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);
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 eebc92c..e4a8e4b 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
@@ -16,8 +16,9 @@
public JsonNode preProcess(KoralNode node, KustvaktConfiguration config,
User user) {
LayerMapper mapper;
+ // inject user settings from cache!
if (user != null)
- mapper = new LayerMapper(config, user.getSettings());
+ mapper = new LayerMapper(config, null);
else
mapper = new LayerMapper(config);
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 4db050a..596941f 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
@@ -122,6 +122,7 @@
}
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();
diff --git a/src/main/java/de/ids_mannheim/korap/security/auth/APIAuthentication.java b/src/main/java/de/ids_mannheim/korap/security/auth/APIAuthentication.java
index d59e503..297a36e 100644
--- a/src/main/java/de/ids_mannheim/korap/security/auth/APIAuthentication.java
+++ b/src/main/java/de/ids_mannheim/korap/security/auth/APIAuthentication.java
@@ -58,7 +58,7 @@
}
@Override
- public TokenContext createUserSession(User user, Map<String, String> attr)
+ public TokenContext createUserSession(User user, Map<String, Object> attr)
throws KustvaktException {
TokenContext c = new TokenContext();
c.setUsername(user.getUsername());
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 4470a30..e97ea53 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
@@ -74,7 +74,7 @@
// not supported!
@Override
- public TokenContext createUserSession(User user, Map<String, String> attr)
+ public TokenContext createUserSession(User user, Map<String, Object> attr)
throws KustvaktException {
return 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 73eecd1..2eca9e0 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
@@ -12,7 +12,6 @@
import de.ids_mannheim.korap.user.*;
import de.ids_mannheim.korap.utils.StringUtils;
import de.ids_mannheim.korap.utils.TimeUtils;
-import de.ids_mannheim.korap.web.utils.KustvaktMap;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
@@ -109,7 +108,7 @@
AuthenticationIface provider = getProvider(context.getTokenType(),
null);
if (provider == null) {
-
+ //todo:
}
try {
@@ -128,8 +127,9 @@
* @return User
* @throws KustvaktException
*/
+ @Override
public User authenticate(int type, String username, String password,
- Map<String, String> attributes) throws KustvaktException {
+ Map<String, Object> attributes) throws KustvaktException {
User user;
switch (type) {
case 1:
@@ -147,8 +147,9 @@
}
// todo: dont use annotations for caching
+ @Override
@CachePut(value = "users", key = "#user.getUsername()")
- public TokenContext createTokenContext(User user, Map<String, String> attr,
+ public TokenContext createTokenContext(User user, Map<String, Object> attr,
String provider_key) throws KustvaktException {
AuthenticationIface provider = getProvider(provider_key,
Attributes.API_AUTHENTICATION);
@@ -159,7 +160,7 @@
TokenContext context = provider.createUserSession(user, attr);
if (context == null)
throw new KustvaktException(StatusCodes.NOT_SUPPORTED);
- context.setUserAgent(attr.get(Attributes.USER_AGENT));
+ context.setUserAgent((String) attr.get(Attributes.USER_AGENT));
context.setHostAddress(Attributes.HOST);
return context;
}
@@ -175,7 +176,7 @@
return false;
}
- private User authenticateShib(Map<String, String> attributes)
+ private User authenticateShib(Map<String, Object> attributes)
throws KustvaktException {
// todo use persistent id, since eppn is not unique
String eppn = (String) attributes.get(Attributes.EPPN);
@@ -196,8 +197,8 @@
//todo: what if attributes null?
private User authenticate(String username, String password,
- Map<String, String> attr) throws KustvaktException {
- Map<String, String> attributes = crypto.validateMap(attr);
+ Map<String, Object> attr) throws KustvaktException {
+ Map<String, Object> attributes = crypto.validateMap(attr);
String safeUS;
User unknown;
// just to make sure that the plain password does not appear anywhere in the logs!
@@ -214,8 +215,6 @@
else {
try {
unknown = entHandler.getAccount(safeUS);
- unknown.setSettings(
- entHandler.getUserSettings(unknown.getId()));
}catch (EmptyResultException e) {
// mask exception to disable user guessing in possible attacks
throw new WrappedException(new KustvaktException(username,
@@ -459,11 +458,9 @@
* @throws KustvaktException
*/
//fixme: remove clientinfo object (not needed), use json representation to get stuff
- public User createUserAccount(Map attributes, boolean confirmation_required)
- throws KustvaktException {
- KustvaktMap kmap = new KustvaktMap(attributes);
-
- Map<String, String> safeMap = crypto.validateMap(attributes);
+ public User createUserAccount(Map<String, Object> attributes,
+ boolean confirmation_required) throws KustvaktException {
+ Map<String, Object> safeMap = crypto.validateMap(attributes);
if (safeMap.get(Attributes.USERNAME) == null || ((String) safeMap
.get(Attributes.USERNAME)).isEmpty())
throw new KustvaktException(StatusCodes.ILLEGAL_ARGUMENT,
@@ -474,10 +471,12 @@
StatusCodes.ILLEGAL_ARGUMENT, "password must be set",
"password");
- String username = crypto.validateEntry(safeMap.get(Attributes.USERNAME),
- Attributes.USERNAME);
- String safePass = crypto.validateEntry(safeMap.get(Attributes.PASSWORD),
- Attributes.PASSWORD);
+ String username = crypto
+ .validateEntry((String) safeMap.get(Attributes.USERNAME),
+ Attributes.USERNAME);
+ String safePass = crypto
+ .validateEntry((String) safeMap.get(Attributes.PASSWORD),
+ Attributes.PASSWORD);
String hash;
try {
hash = crypto.produceSecureHash(safePass);
@@ -487,9 +486,6 @@
}
KorAPUser user = User.UserFactory.getUser(username);
- UserDetails det = UserDetails.newDetailsIterator(safeMap);
- user.setDetails(det);
- user.setSettings(new UserSettings());
if (confirmation_required) {
user.setAccountLocked(true);
URIParam param = new URIParam(crypto.createToken(),
@@ -499,6 +495,16 @@
user.setPassword(hash);
try {
entHandler.createAccount(user);
+ Userdetails2 details = new Userdetails2(user.getId());
+ details.readDefaults(safeMap);
+ details.checkRequired();
+
+ UserSettings2 settings = new UserSettings2(user.getId());
+ settings.readDefaults(safeMap);
+ settings.checkRequired();
+
+ UserdataFactory.getDaoInstance(Userdetails2.class).store(details);
+ UserdataFactory.getDaoInstance(UserSettings2.class).store(settings);
}catch (KustvaktException e) {
throw new WrappedException(e, StatusCodes.CREATE_ACCOUNT_FAILED,
user.toString());
@@ -510,11 +516,11 @@
}
//todo:
- private ShibUser createShibbUserAccount(Map<String, String> attributes)
+ private ShibUser createShibbUserAccount(Map<String, Object> attributes)
throws KustvaktException {
jlog.debug("creating shibboleth user account for user attr: {}",
attributes);
- Map<String, String> safeMap = crypto.validateMap(attributes);
+ Map<String, Object> safeMap = crypto.validateMap(attributes);
//todo eppn non-unique.join with idp or use persistent_id as username identifier
ShibUser user = User.UserFactory
@@ -635,9 +641,10 @@
username), StatusCodes.PASSWORD_RESET_FAILED, username);
}
- this.getUserData(ident, Userdetails2.class);
+ Userdata data = this.getUserData(ident, Userdetails2.class);
KorAPUser user = (KorAPUser) ident;
- if (!mail.equals(user.getDetails().getEmail()))
+
+ if (!mail.equals(data.get(Attributes.EMAIL)))
// throw new NotAuthorizedException(StatusCodes.ILLEGAL_ARGUMENT,
// "invalid parameter: email", "email");
throw new WrappedException(new KustvaktException(user.getId(),
@@ -658,80 +665,52 @@
new DateTime(param.getUriExpiration()) };
}
- @Deprecated
- public void updateUserSettings(User user, UserSettings settings)
- throws KustvaktException {
- if (user instanceof DemoUser)
- return;
- else {
- Map map = crypto.validateMap(settings.toObjectMap());
- settings = UserSettings.fromObjectMap(map);
- try {
- entHandler.updateSettings(settings);
- }catch (KustvaktException e) {
- jlog.error("Error ", e);
- throw new WrappedException(e,
- StatusCodes.UPDATE_ACCOUNT_FAILED);
- }
- }
- }
-
- @Deprecated
- public void updateUserDetails(User user, UserDetails details)
- throws KustvaktException {
- if (user instanceof DemoUser)
- return;
- else {
- Map map = crypto.validateMap(details.toMap());
-
- try {
- entHandler
- .updateUserDetails(UserDetails.newDetailsIterator(map));
- }catch (KustvaktException e) {
- jlog.error("Error ", e);
- throw new WrappedException(e,
- StatusCodes.UPDATE_ACCOUNT_FAILED);
- }
- }
- }
-
@Override
- public <T extends Userdata> T getUserData(User user, Class<T> clazz) {
- UserDataDbIface<T> dao = UserdataFactory.getDaoInstance(clazz);
- return dao.get(user);
+ public <T extends Userdata> T getUserData(User user, Class<T> clazz)
+ throws WrappedException {
+
+ try {
+ UserDataDbIface<T> dao = UserdataFactory.getDaoInstance(clazz);
+ return dao.get(user);
+ }catch (KustvaktException e) {
+ jlog.error("Error ", e);
+ throw new WrappedException(e, StatusCodes.GET_ACCOUNT_FAILED);
+ }
}
//todo: cache userdata outside of the user object!
@Override
- public void updateUserData(Userdata data) {
- UserDataDbIface dao = UserdataFactory.getDaoInstance(data.getClass());
- dao.update(data);
- }
-
- public UserDetails getUserDetails(User user) throws KustvaktException {
+ public void updateUserData(Userdata data) throws WrappedException {
try {
- for (Userdata data : user.getUserdata()) {
- if (data instanceof Userdetails2) {
-
- }
- }
- if (user.getDetails() == null)
- user.setDetails(entHandler.getUserDetails(user.getId()));
+ data.validate(this.crypto);
+ UserDataDbIface dao = UserdataFactory
+ .getDaoInstance(data.getClass());
+ dao.update(data);
}catch (KustvaktException e) {
- throw new WrappedException(e, StatusCodes.GET_ACCOUNT_FAILED);
+ jlog.error("Error ", e);
+ throw new WrappedException(e, StatusCodes.UPDATE_ACCOUNT_FAILED);
}
- return user.getDetails();
}
- public UserSettings getUserSettings(User user) throws KustvaktException {
- try {
- if (user.getSettings() == null)
- user.setSettings(entHandler.getUserSettings(user.getId()));
- }catch (KustvaktException e) {
- throw new WrappedException(e, StatusCodes.GET_ACCOUNT_FAILED);
- }
- return user.getSettings();
- }
+ // public UserDetails getUserDetails(User user) throws KustvaktException {
+ // try {
+ // if (user.getDetails() == null)
+ // user.setDetails(entHandler.getUserDetails(user.getId()));
+ // }catch (KustvaktException e) {
+ // throw new WrappedException(e, StatusCodes.GET_ACCOUNT_FAILED);
+ // }
+ // return user.getDetails();
+ // }
+ //
+ // public UserSettings getUserSettings(User user) throws KustvaktException {
+ // try {
+ // if (user.getSettings() == null)
+ // user.setSettings(entHandler.getUserSettings(user.getId()));
+ // }catch (KustvaktException e) {
+ // throw new WrappedException(e, StatusCodes.GET_ACCOUNT_FAILED);
+ // }
+ // return user.getSettings();
+ // }
private String cache_key(String input) throws KustvaktException {
try {
diff --git a/src/main/java/de/ids_mannheim/korap/security/auth/OpenIDconnectAuthentication.java b/src/main/java/de/ids_mannheim/korap/security/auth/OpenIDconnectAuthentication.java
index a1871c9..3f0ebe4 100644
--- a/src/main/java/de/ids_mannheim/korap/security/auth/OpenIDconnectAuthentication.java
+++ b/src/main/java/de/ids_mannheim/korap/security/auth/OpenIDconnectAuthentication.java
@@ -44,9 +44,9 @@
}
@Override
- public TokenContext createUserSession(User user, Map<String, String> attr)
+ public TokenContext createUserSession(User user, Map<String, Object> attr)
throws KustvaktException {
- String cl_secret = attr.get(Attributes.CLIENT_SECRET);
+ String cl_secret = (String) attr.get(Attributes.CLIENT_SECRET);
if (cl_secret == null)
throw new KustvaktException(StatusCodes.REQUEST_INVALID);
attr.remove(cl_secret);
diff --git a/src/main/java/de/ids_mannheim/korap/security/auth/SessionAuthentication.java b/src/main/java/de/ids_mannheim/korap/security/auth/SessionAuthentication.java
index 3a74954..68b04c8 100644
--- a/src/main/java/de/ids_mannheim/korap/security/auth/SessionAuthentication.java
+++ b/src/main/java/de/ids_mannheim/korap/security/auth/SessionAuthentication.java
@@ -56,7 +56,7 @@
}
@Override
- public TokenContext createUserSession(User user, Map attr)
+ public TokenContext createUserSession(User user, Map<String, Object> attr)
throws KustvaktException {
DateTime now = TimeUtils.getNow();
DateTime ex = TimeUtils
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 c88f5e1..70eb878 100644
--- a/src/main/java/de/ids_mannheim/korap/user/DemoUser.java
+++ b/src/main/java/de/ids_mannheim/korap/user/DemoUser.java
@@ -19,7 +19,7 @@
this.setDetails(new UserDetails());
this.setSettings(new UserSettings());
this.setAccountCreation(ACCOUNT_CREATED);
- this.setQueries(UserQuery.demoUserQueries());
+// 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 9eeff3a..a31beab 100644
--- a/src/main/java/de/ids_mannheim/korap/user/TokenContext.java
+++ b/src/main/java/de/ids_mannheim/korap/user/TokenContext.java
@@ -33,7 +33,7 @@
@Getter(AccessLevel.PRIVATE)
@Setter(AccessLevel.PRIVATE)
- private Map<String, String> parameters;
+ private Map<String, Object> parameters;
private String hostAddress;
private String userAgent;
@@ -54,7 +54,7 @@
return m;
}
- public Map<String, String> params() {
+ public Map<String, Object> params() {
return new HashMap<>(parameters);
}
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 5cc1403..22c8188 100644
--- a/src/main/java/de/ids_mannheim/korap/user/User.java
+++ b/src/main/java/de/ids_mannheim/korap/user/User.java
@@ -5,10 +5,14 @@
import de.ids_mannheim.korap.utils.JsonUtils;
import de.ids_mannheim.korap.utils.TimeUtils;
import de.ids_mannheim.korap.web.utils.KustvaktMap;
+import lombok.AccessLevel;
import lombok.Data;
+import lombok.Getter;
+import lombok.Setter;
import org.joda.time.DateTime;
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -26,9 +30,15 @@
private boolean isAccountLocked;
private int type;
private ParamFields fields;
+ @Getter(AccessLevel.PRIVATE)
+ @Setter(AccessLevel.PRIVATE)
private UserSettings settings;
//todo: remove!
+ @Getter(AccessLevel.PRIVATE)
+ @Setter(AccessLevel.PRIVATE)
private UserDetails details;
+ @Getter(AccessLevel.PRIVATE)
+ @Setter(AccessLevel.PRIVATE)
private List<UserQuery> queries;
private List<Userdata> userdata;
@@ -39,6 +49,7 @@
this.isAccountLocked = false;
this.username = "";
this.id = -1;
+ this.userdata = new ArrayList<>();
}
protected User(int type) {
diff --git a/src/main/java/de/ids_mannheim/korap/user/UserDataDbIface.java b/src/main/java/de/ids_mannheim/korap/user/UserDataDbIface.java
index 2d2f231..7ee663c 100644
--- a/src/main/java/de/ids_mannheim/korap/user/UserDataDbIface.java
+++ b/src/main/java/de/ids_mannheim/korap/user/UserDataDbIface.java
@@ -1,21 +1,23 @@
package de.ids_mannheim.korap.user;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+
/**
* @author hanl
* @date 27/01/2016
*/
public interface UserDataDbIface<T extends Userdata> {
- public int store(T data);
+ public int store(T data) throws KustvaktException;
- public int update(T data);
+ public int update(T data) throws KustvaktException;
- public T get(Integer id);
+ public T get(Integer id) throws KustvaktException;
- public T get(User user);
+ public T get(User user) throws KustvaktException;
- public int delete(T data);
+ public int delete(T data) throws KustvaktException;
- public int deleteAll();
+ public int deleteAll() throws KustvaktException;
}
diff --git a/src/main/java/de/ids_mannheim/korap/user/UserDetails.java b/src/main/java/de/ids_mannheim/korap/user/UserDetails.java
index e9d74d0..135fbd2 100644
--- a/src/main/java/de/ids_mannheim/korap/user/UserDetails.java
+++ b/src/main/java/de/ids_mannheim/korap/user/UserDetails.java
@@ -13,6 +13,7 @@
*/
// todo: set certain fields required!
+@Deprecated
@Data
public class UserDetails {
diff --git a/src/main/java/de/ids_mannheim/korap/user/UserSettings2.java b/src/main/java/de/ids_mannheim/korap/user/UserSettings2.java
index 6e87a53..d6b86a9 100644
--- a/src/main/java/de/ids_mannheim/korap/user/UserSettings2.java
+++ b/src/main/java/de/ids_mannheim/korap/user/UserSettings2.java
@@ -15,4 +15,9 @@
public String[] requiredFields() {
return new String[0];
}
+
+ @Override
+ public String[] defaultFields() {
+ return new String[0];
+ }
}
diff --git a/src/main/java/de/ids_mannheim/korap/user/UserSettingsDao.java b/src/main/java/de/ids_mannheim/korap/user/UserSettingsDao.java
index 5af93e7..c82ac64 100644
--- a/src/main/java/de/ids_mannheim/korap/user/UserSettingsDao.java
+++ b/src/main/java/de/ids_mannheim/korap/user/UserSettingsDao.java
@@ -24,7 +24,7 @@
}
@Override
public int store(UserSettings2 data) {
- String sql = "INSERT INTO user_details2 (user_id, data) VALUES (:userid, :data);";
+ String sql = "INSERT INTO user_settings2 (user_id, data) VALUES (:userid, :data);";
MapSqlParameterSource source = new MapSqlParameterSource();
source.addValue("userid", data.getUserID());
source.addValue("data", data.data());
@@ -43,7 +43,7 @@
@Override
public int update(UserSettings2 data) {
- String sql = "UPDATE user_details2 SET data = :data WHERE user_id=:userid;";
+ String sql = "UPDATE user_settings2 SET data = :data WHERE user_id=:userid;";
MapSqlParameterSource source = new MapSqlParameterSource();
source.addValue("userid", data.getUserID());
source.addValue("data", data.data());
@@ -57,7 +57,7 @@
@Override
public UserSettings2 get(Integer id) {
- String sql = "SELECT * FROM user_details2 WHERE id=:id;";
+ String sql = "SELECT * FROM user_settings2 WHERE id=:id;";
MapSqlParameterSource source = new MapSqlParameterSource();
source.addValue("id", id);
@@ -83,7 +83,7 @@
@Override
public UserSettings2 get(User user) {
- String sql = "SELECT * FROM user_details2 WHERE user_id=:userid;";
+ String sql = "SELECT * FROM user_settings2 WHERE user_id=:userid;";
MapSqlParameterSource source = new MapSqlParameterSource();
source.addValue("userid", user.getId());
@@ -110,7 +110,7 @@
@Override
public int delete(UserSettings2 data) {
- String sql = "DELETE FROM user_details2 WHERE id=:id";
+ String sql = "DELETE FROM user_settings2 WHERE id=:id";
MapSqlParameterSource source = new MapSqlParameterSource();
source.addValue("id", data.getId());
try {
@@ -122,7 +122,7 @@
@Override
public int deleteAll() {
- String sql = "DELETE FROM user_details2;";
+ String sql = "DELETE FROM user_settings2;";
try {
return this.jdbcTemplate.update(sql, new HashMap<String, Object>());
}catch (DataAccessException e) {
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 42d8247..bf53486 100644
--- a/src/main/java/de/ids_mannheim/korap/user/Userdata.java
+++ b/src/main/java/de/ids_mannheim/korap/user/Userdata.java
@@ -2,6 +2,7 @@
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.utils.JsonUtils;
import lombok.AccessLevel;
import lombok.Data;
@@ -58,18 +59,31 @@
public boolean isValid() {
// return this.missing(this.fields).isEmpty() && this.userID != -1;
- return validationReturn().length == 0;
+ return missing().length == 0;
}
- public String[] validationReturn() {
+ public String[] missing() {
StringBuilder b = new StringBuilder();
Set<String> m = missing(this.fields);
+
+ if (m.isEmpty())
+ return new String[0];
+
for (String k : m) {
b.append(k).append(";");
}
return b.toString().split(";");
}
+ public void checkRequired() throws KustvaktException {
+ if (!isValid()) {
+ String[] fields = missing();
+ throw new KustvaktException(StatusCodes.MISSING_ARGUMENTS,
+ "User data object not valid. Missing fields: " + Arrays
+ .asList(fields));
+ }
+ }
+
public Set<String> keys() {
return this.fields.keySet();
}
@@ -78,6 +92,10 @@
return this.fields.values();
}
+ public Map<String, Object> fields() {
+ return new HashMap<>(this.fields);
+ }
+
public void setData(String data) {
Map m = JsonUtils.readSimple(data, Map.class);
if (m != null)
@@ -85,14 +103,8 @@
}
public void update(Userdata other) {
- if (other != null && this.getClass().equals(other.getClass())) {
- if (!other.isValid()) {
- throw new RuntimeException(
- "User data object not valid. Missing fields: "
- + missing(this.fields));
- }
+ if (other != null && this.getClass().equals(other.getClass()))
this.fields.putAll(other.fields);
- }
}
public String data() {
@@ -103,6 +115,20 @@
this.fields.put(key, value);
}
+ public void validate(EncryptionIface crypto) throws KustvaktException {
+ this.fields = crypto.validateMap(this.fields);
+ }
+
+ public void readDefaults(Map<String, Object> map) {
+ for (String k : defaultFields()) {
+ Object o = map.get(k);
+ if (o != null)
+ this.fields.put(k, o);
+ }
+ }
+
public abstract String[] requiredFields();
+ public abstract String[] defaultFields();
+
}
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 6b02d28..35cc02b 100644
--- a/src/main/java/de/ids_mannheim/korap/user/UserdataFactory.java
+++ b/src/main/java/de/ids_mannheim/korap/user/UserdataFactory.java
@@ -2,6 +2,8 @@
import de.ids_mannheim.korap.config.BeanConfiguration;
import de.ids_mannheim.korap.config.KustvaktClassLoader;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.interfaces.db.PersistenceClient;
import java.lang.reflect.Constructor;
@@ -40,7 +42,7 @@
}
public static UserDataDbIface getDaoInstance(
- Class<? extends Userdata> data) {
+ Class<? extends Userdata> data) throws KustvaktException {
if (instances.get(data) == null) {
Class<? extends UserDataDbIface> cl = getClass(data);
if (BeanConfiguration.hasContext() && cl != null) {
@@ -55,7 +57,7 @@
return null;
}
}
- throw new RuntimeException(
+ throw new KustvaktException(StatusCodes.NOT_SUPPORTED,
"No database class found for type " + data.getSimpleName());
}else
return instances.get(data);
diff --git a/src/main/java/de/ids_mannheim/korap/user/Userdetails2.java b/src/main/java/de/ids_mannheim/korap/user/Userdetails2.java
index 141b9b1..0f40f57 100644
--- a/src/main/java/de/ids_mannheim/korap/user/Userdetails2.java
+++ b/src/main/java/de/ids_mannheim/korap/user/Userdetails2.java
@@ -17,4 +17,11 @@
Attributes.LASTNAME, Attributes.FIRSTNAME };
}
+ @Override
+ public String[] defaultFields() {
+ return new String[] { Attributes.EMAIL, Attributes.ADDRESS,
+ Attributes.LASTNAME, Attributes.FIRSTNAME, Attributes.PHONE,
+ Attributes.COUNTRY, Attributes.INSTITUTION, Attributes.GENDER };
+ }
+
}
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 05f3c53..86424c5 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
@@ -107,7 +107,7 @@
// is actual an invalid request
throw KustvaktResponseHandler.throwit(StatusCodes.REQUEST_INVALID);
- Map<String, String> attr = new HashMap<>();
+ Map<String, Object> attr = new HashMap<>();
if (scopes != null && !scopes.isEmpty())
attr.put(Attributes.SCOPES, scopes);
attr.put(Attributes.HOST, host);
@@ -117,7 +117,8 @@
User user = controller.authenticate(0, values[0], values[1], attr);
Userdata data = this.controller
.getUserData(user, Userdetails2.class);
- user.addUserData(data);
+ // todo: is this necessary?
+// attr.putAll(data.fields());
context = controller.createTokenContext(user, attr,
Attributes.API_AUTHENTICATION);
}catch (KustvaktException e) {
@@ -174,7 +175,7 @@
.equalsIgnoreCase("null"))
throw KustvaktResponseHandler.throwit(StatusCodes.REQUEST_INVALID);
- Map<String, String> attr = new HashMap<>();
+ Map<String, Object> attr = new HashMap<>();
attr.put(Attributes.HOST, host);
attr.put(Attributes.USER_AGENT, agent);
TokenContext context;
@@ -203,7 +204,7 @@
// the shibfilter decrypted the values
// define default provider for returned access token strategy?!
- Map<String, String> attr = new HashMap<>();
+ Map<String, Object> attr = new HashMap<>();
attr.put(Attributes.HOST, host);
attr.put(Attributes.USER_AGENT, agent);
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 9e85bbf..c516364 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
@@ -122,12 +122,12 @@
public Response getStatus(@Context SecurityContext context,
@QueryParam("scope") String scopes) {
TokenContext ctx = (TokenContext) context.getUserPrincipal();
- User user;
+ Map<String, Object> details;
try {
- user = this.controller.getUser(ctx.getUsername());
+ User user = this.controller.getUser(ctx.getUsername());
Userdata data = this.controller
.getUserData(user, Userdetails2.class);
- user.addUserData(data);
+ details = data.fields();
Set<String> base_scope = StringUtils.toSet(scopes, " ");
base_scope.retainAll(StringUtils.toSet(scopes));
scopes = StringUtils.toString(base_scope);
@@ -137,7 +137,7 @@
// json format with scope callback parameter
// todo: add other scopes as well!
return Response.ok(JsonUtils
- .toJSON(Scopes.mapScopes(scopes, user.getDetails()))).build();
+ .toJSON(Scopes.mapScopes(scopes, details))).build();
}
@GET
@@ -172,7 +172,7 @@
@Context SecurityContext context,
@HeaderParam(ContainerRequest.USER_AGENT) String agent,
@HeaderParam(ContainerRequest.HOST) String host,
- MultivaluedMap<String, String> form)
+ MultivaluedMap<String, Object> form)
throws OAuthSystemException, URISyntaxException {
// user needs to be authenticated to this service!
TokenContext c = (TokenContext) context.getUserPrincipal();
@@ -184,7 +184,7 @@
new MD5Generator());
User user;
- Map<String, String> attr = new HashMap<>();
+ Map<String, Object> attr = new HashMap<>();
attr.put(Attributes.HOST, host);
attr.put(Attributes.USER_AGENT, agent);
attr.put(Attributes.USERNAME, c.getUsername());
@@ -438,7 +438,7 @@
.entity(res.getBody()).build();
}
- Map<String, String> attr = new HashMap<>();
+ Map<String, Object> attr = new HashMap<>();
attr.put(Attributes.HOST, host);
attr.put(Attributes.USER_AGENT, agent);
attr.put(Attributes.SCOPES,
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 7bb87e7..7a6b249 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
@@ -669,7 +669,7 @@
//todo ?!
CollectionQueryBuilder3 query = new CollectionQueryBuilder3();
if (resource instanceof VirtualCollection) {
- query.setBaseQuery((String) resource.getData());
+ query.setBaseQuery(resource.getData());
}else if (resource instanceof Corpus) {
query.addQuery("corpusID=" + resource.getName());
}
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 3d8e0e4..03b19bc 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
@@ -59,27 +59,20 @@
public Response signUp(
@HeaderParam(ContainerRequest.USER_AGENT) String agent,
@HeaderParam(ContainerRequest.HOST) String host,
- @Context Locale locale,
- MultivaluedMap<String, String> form_values) {
- Map<String, String> wrapper = FormRequestWrapper
+ @Context Locale locale, MultivaluedMap form_values) {
+ Map<String, Object> wrapper = FormRequestWrapper
.toMap(form_values, true);
wrapper.put(Attributes.HOST, host);
wrapper.put(Attributes.USER_AGENT, agent);
UriBuilder uriBuilder;
User user;
- if (wrapper.get(Attributes.EMAIL) == null)
- throw KustvaktResponseHandler
- .throwit(StatusCodes.ILLEGAL_ARGUMENT, "parameter missing",
- "email");
-
try {
uriBuilder = info.getBaseUriBuilder();
uriBuilder.path(KustvaktServer.API_VERSION).path("user")
.path("confirm");
user = controller.createUserAccount(wrapper, true);
-
}catch (KustvaktException e) {
throw KustvaktResponseHandler.throwit(e);
}
@@ -217,20 +210,19 @@
public Response getStatus(@Context SecurityContext context,
@QueryParam("scopes") String scopes) {
TokenContext ctx = (TokenContext) context.getUserPrincipal();
- User user;
+ Scopes m;
try {
- user = controller.getUser(ctx.getUsername());
+ User user = controller.getUser(ctx.getUsername());
Userdata data = controller.getUserData(user, Userdetails2.class);
- user.addUserData(data);
Set<String> base_scope = StringUtils.toSet(scopes, " ");
if (scopes != null)
base_scope.retainAll(StringUtils.toSet(scopes));
scopes = StringUtils.toString(base_scope);
+ m = Scopes.mapScopes(scopes, data.fields());
}catch (KustvaktException e) {
throw KustvaktResponseHandler.throwit(e);
}
- Scopes m = Scopes.mapScopes(scopes, user.getDetails());
return Response.ok(m.toEntity()).build();
}
@@ -261,9 +253,9 @@
@ResourceFilters({ AuthFilter.class, DefaultFilter.class,
PiwikFilter.class })
public Response updateSettings(@Context SecurityContext context,
- @Context Locale locale, MultivaluedMap<String, String> form) {
+ @Context Locale locale, MultivaluedMap form) {
TokenContext ctx = (TokenContext) context.getUserPrincipal();
- Map<String, String> settings = FormRequestWrapper.toMap(form, false);
+ Map<String, Object> settings = FormRequestWrapper.toMap(form, false);
try {
User user = controller.getUser(ctx.getUsername());
@@ -297,20 +289,17 @@
public Response getDetails(@Context SecurityContext context,
@Context Locale locale) {
TokenContext ctx = (TokenContext) context.getUserPrincipal();
- User user;
+ String result;
try {
- user = controller.getUser(ctx.getUsername());
+ User user = controller.getUser(ctx.getUsername());
Userdata data = controller.getUserData(user, Userdetails2.class);
- user.addUserData(data);
-
+ data.addField(Attributes.USERNAME, ctx.getUsername());
+ result = data.data();
}catch (KustvaktException e) {
jlog.error("Exception encountered!", e);
throw KustvaktResponseHandler.throwit(e);
}
-
- Map m = user.getDetails().toMap();
- m.put(Attributes.USERNAME, ctx.getUsername());
- return Response.ok(JsonUtils.toJSON(m)).build();
+ return Response.ok(result).build();
}
@POST
@@ -322,7 +311,7 @@
@Context Locale locale, MultivaluedMap form) {
TokenContext ctx = (TokenContext) context.getUserPrincipal();
- Map<String, String> wrapper = FormRequestWrapper.toMap(form, true);
+ Map<String, Object> wrapper = FormRequestWrapper.toMap(form, true);
try {
User user = controller.getUser(ctx.getUsername());
diff --git a/src/main/java/de/ids_mannheim/korap/web/utils/FormRequestWrapper.java b/src/main/java/de/ids_mannheim/korap/web/utils/FormRequestWrapper.java
index b688ab0..f486b1b 100644
--- a/src/main/java/de/ids_mannheim/korap/web/utils/FormRequestWrapper.java
+++ b/src/main/java/de/ids_mannheim/korap/web/utils/FormRequestWrapper.java
@@ -16,7 +16,7 @@
*/
public class FormRequestWrapper extends HttpServletRequestWrapper {
- private MultivaluedMap<String, String> form;
+ private MultivaluedMap<String, Object> form;
/**
* Constructs a request object wrapping the given request.
@@ -25,7 +25,7 @@
* @throws IllegalArgumentException if the request is null
*/
public FormRequestWrapper(HttpServletRequest request,
- MultivaluedMap<String, String> form) {
+ MultivaluedMap<String, Object> form) {
super(request);
this.form = form;
}
@@ -48,7 +48,7 @@
return values;
}
- public Map<String, String> singleValueMap() {
+ public Map<String, Object> singleValueMap() {
return toMap(this.form, false);
}
@@ -57,9 +57,9 @@
* in value list and returns the result
* @return key/value map
*/
- public static Map<String, String> toMap(MultivaluedMap<String, String> form,
+ public static Map<String, Object> toMap(MultivaluedMap<String, Object> form,
boolean strict) {
- HashMap<String, String> map = new HashMap<>();
+ HashMap<String, Object> map = new HashMap<>();
for (String key : form.keySet()) {
if (strict && form.get(key).size() > 1)
continue;
@@ -74,7 +74,7 @@
}
public void put(String key, String... values) {
- this.form.put(key, Arrays.<String>asList(values));
+ this.form.put(key, Arrays.<Object>asList(values));
}
}
diff --git a/src/test/java/UserdataTest.java b/src/test/java/UserdataTest.java
index ea47a99..b635ddc 100644
--- a/src/test/java/UserdataTest.java
+++ b/src/test/java/UserdataTest.java
@@ -1,4 +1,5 @@
import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.user.*;
import org.junit.AfterClass;
import org.junit.Before;
@@ -64,26 +65,43 @@
data.addField(Attributes.COUNTRY, "Germany");
String[] req = data.requiredFields();
- String[] r = data.validationReturn();
+ String[] r = data.missing();
assert r.length > 0;
assert r.length == req.length;
assert !data.isValid();
}
@Test
- public void testUserdatafactory() {
+ public void testSettingsValidation() {
+ Userdata data = new UserSettings2(1);
+ data.addField(Attributes.FILE_FORMAT_FOR_EXPORT, "export");
+
+ String[] req = data.requiredFields();
+ String[] r = data.missing();
+ assert r.length == 0;
+ assert r.length == req.length;
+ assert data.isValid();
+ }
+
+ @Test
+ public void testUserdatafactory() throws KustvaktException {
UserDataDbIface dao = UserdataFactory
.getDaoInstance(Userdetails2.class);
assert UserDetailsDao.class.equals(dao.getClass());
}
- @Test(expected = RuntimeException.class)
- public void testUserdatafactoryError() {
+ @Test(expected = KustvaktException.class)
+ public void testUserdatafactoryError() throws KustvaktException {
UserdataFactory.getDaoInstance(new Userdata(1) {
@Override
public String[] requiredFields() {
return new String[0];
}
+
+ @Override
+ public String[] defaultFields() {
+ return new String[0];
+ }
}.getClass());
}
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 739b16d..c96906d 100644
--- a/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
+++ b/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
@@ -33,6 +33,10 @@
Map m = new HashMap<>();
m.put(Attributes.USERNAME, credentials[0]);
m.put(Attributes.PASSWORD, credentials[1]);
+ m.put(Attributes.FIRSTNAME, "test");
+ m.put(Attributes.LASTNAME, "user");
+ m.put(Attributes.EMAIL, "test@ids-mannheim.de");
+ m.put(Attributes.ADDRESS, "Mannheim");
Assert.assertNotNull("userdatabase handler must not be null", dao);
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 9673bd5..62beae8 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
@@ -55,7 +55,7 @@
assert ClientResponse.Status.OK.getStatusCode() == response.getStatus();
JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
- System.out.println("COLLECTIONS " + node);
+
assert node.size() > 0;
}
@@ -69,20 +69,22 @@
JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
assert node != null;
- System.out.println("JSON NODE RESULT " + node);
+
+ System.out.println("-------------------------------");
+ System.out.println("NODE COLLECTIONS" + node);
String id = node.path(0).path("id").asText();
response = resource().path(getAPIVersion()).path("collection").path(id)
.path("stats").header(Attributes.AUTHORIZATION,
BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
.get(ClientResponse.class);
- System.out.println("----------------------------- testStats 2");
- System.out.println(response.getEntity(String.class));
+
assert ClientResponse.Status.OK.getStatusCode() == response.getStatus();
node = JsonUtils.readTree(response.getEntity(String.class));
assert node != null;
int docs = node.path("documents").asInt();
- System.out.println("THE FINAL NODE : " + node);
+ System.out.println("-------------------------------");
+ System.out.println("NODE " + node);
assert docs > 0 && docs < 15;
}