Added various log4j2 configurations.
Change-Id: I638d2dd0e1edd80006d0c8d476505f2bc43931e2
diff --git a/full/src/main/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManager.java b/full/src/main/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManager.java
index a399c5f..64ed9ac 100644
--- a/full/src/main/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManager.java
+++ b/full/src/main/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManager.java
@@ -16,6 +16,7 @@
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
+import com.mchange.rmi.NotAuthorizedException;
// import com.novell.ldap.*; search() funktioniert nicht korrekt, ausgewechselt gegen unboundID's Bibliothek 20.04.17/FB
//Using JAR from unboundID:
import com.unboundid.ldap.sdk.LDAPException;
@@ -30,7 +31,6 @@
import de.ids_mannheim.korap.dao.AdminDao;
import de.ids_mannheim.korap.exceptions.EmptyResultException;
import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.exceptions.NotAuthorizedException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.exceptions.WrappedException;
import de.ids_mannheim.korap.interfaces.AuthenticationIface;
diff --git a/full/src/main/java/de/ids_mannheim/korap/authentication/OpenIDconnectAuthentication.java b/full/src/main/java/de/ids_mannheim/korap/authentication/OpenIDconnectAuthentication.java
deleted file mode 100644
index 549b4c7..0000000
--- a/full/src/main/java/de/ids_mannheim/korap/authentication/OpenIDconnectAuthentication.java
+++ /dev/null
@@ -1,99 +0,0 @@
-package de.ids_mannheim.korap.authentication;
-
-import java.text.ParseException;
-import java.util.Map;
-
-import com.nimbusds.jose.JOSEException;
-import com.nimbusds.jwt.SignedJWT;
-
-import de.ids_mannheim.korap.config.Attributes;
-import de.ids_mannheim.korap.config.FullConfiguration;
-import de.ids_mannheim.korap.config.JWTSigner;
-import de.ids_mannheim.korap.constant.TokenType;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.exceptions.StatusCodes;
-import de.ids_mannheim.korap.handlers.OAuthDb;
-import de.ids_mannheim.korap.interfaces.AuthenticationIface;
-import de.ids_mannheim.korap.interfaces.db.PersistenceClient;
-import de.ids_mannheim.korap.security.context.TokenContext;
-import de.ids_mannheim.korap.user.User;
-import net.sf.ehcache.CacheManager;
-import net.sf.ehcache.Element;
-
-/**
- * @author hanl
- * @date 12/11/2014
- */
-public class OpenIDconnectAuthentication implements AuthenticationIface {
-
- private OAuthDb database;
- private FullConfiguration config;
-
-
- public OpenIDconnectAuthentication (FullConfiguration config,
- PersistenceClient client) {
- this.database = new OAuthDb(client);
- this.config = config;
- }
-
-
- @Override
- public TokenContext getTokenContext (String authToken)
- throws KustvaktException {
- return this.database.getContext(authToken);
- }
-
-
- @Override
- public TokenContext createTokenContext (User user, Map<String, Object> attr)
- throws KustvaktException {
- String cl_secret = (String) attr.get(Attributes.CLIENT_SECRET);
- if (cl_secret == null)
- throw new KustvaktException(StatusCodes.REQUEST_INVALID);
- attr.remove(cl_secret);
- JWTSigner signer;
- try {
- signer = new JWTSigner(cl_secret.getBytes(), config.getIssuer(),
- config.getTokenTTL());
- }
- catch (JOSEException e1) {
- // e1.printStackTrace();
- throw new KustvaktException(StatusCodes.ILLEGAL_ARGUMENT,
- "Failed creating JWT.", e1);
- }
- TokenContext c = new TokenContext();
- c.setUsername(user.getUsername());
- SignedJWT jwt = signer.createJWT(user, attr);
- try {
- c.setExpirationTime(
- jwt.getJWTClaimsSet().getExpirationTime().getTime());
- }
- catch (ParseException e) {
- throw new KustvaktException(StatusCodes.ILLEGAL_ARGUMENT);
- }
- c.setTokenType(getTokenType());
- c.setToken(jwt.serialize());
- CacheManager.getInstance().getCache("id_tokens")
- .put(new Element(c.getToken(), c));
- return c;
- }
-
-
- @Override
- public void removeUserSession (String token) throws KustvaktException {
- // emit token from cache only
- }
-
-
- @Override
- public TokenContext refresh (TokenContext context)
- throws KustvaktException {
- throw new UnsupportedOperationException("method not supported");
- }
-
-
- @Override
- public TokenType getTokenType () {
- return TokenType.ID_TOKEN;
- }
-}
diff --git a/full/src/main/java/de/ids_mannheim/korap/handlers/JDBCClient.java b/full/src/main/java/de/ids_mannheim/korap/handlers/JDBCClient.java
index 1479564..e1c9acd 100644
--- a/full/src/main/java/de/ids_mannheim/korap/handlers/JDBCClient.java
+++ b/full/src/main/java/de/ids_mannheim/korap/handlers/JDBCClient.java
@@ -22,6 +22,7 @@
* @author hanl
* @date 13/01/2014
*/
+@Deprecated
@Data
public class JDBCClient extends PersistenceClient<NamedParameterJdbcTemplate> {
diff --git a/full/src/main/java/de/ids_mannheim/korap/handlers/OAuthDb.java b/full/src/main/java/de/ids_mannheim/korap/handlers/OAuthDb.java
deleted file mode 100644
index 838b1c0..0000000
--- a/full/src/main/java/de/ids_mannheim/korap/handlers/OAuthDb.java
+++ /dev/null
@@ -1,283 +0,0 @@
-package de.ids_mannheim.korap.handlers;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Timestamp;
-import java.util.List;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-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;
-
-import de.ids_mannheim.korap.config.Attributes;
-import de.ids_mannheim.korap.config.ClientInfo;
-import de.ids_mannheim.korap.constant.TokenType;
-import de.ids_mannheim.korap.exceptions.DatabaseException;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.exceptions.StatusCodes;
-import de.ids_mannheim.korap.interfaces.db.PersistenceClient;
-import de.ids_mannheim.korap.security.context.TokenContext;
-import de.ids_mannheim.korap.user.User;
-import de.ids_mannheim.korap.utils.BooleanUtils;
-import de.ids_mannheim.korap.utils.TimeUtils;
-import edu.emory.mathcs.backport.java.util.Collections;
-
-/**
- * Created by hanl on 7/14/14.
- */
-public class OAuthDb {
-
- private static final Logger jlog = LogManager.getLogger(OAuthDb.class);
- private NamedParameterJdbcTemplate jdbcTemplate;
-
-
- public OAuthDb (PersistenceClient client) {
- this.jdbcTemplate = (NamedParameterJdbcTemplate) client.getSource();
- }
-
-
- public ClientInfo getClient (String clientid) {
- MapSqlParameterSource s = new MapSqlParameterSource();
- s.addValue("cl", clientid);
- String sql = "select * from oauth2_client where client_id=:cl;";
-
- try {
- return this.jdbcTemplate.queryForObject(sql, s,
- new RowMapper<ClientInfo>() {
- @Override
- public ClientInfo mapRow (ResultSet rs, int rowNum)
- throws SQLException {
- ClientInfo info = new ClientInfo(rs
- .getString("client_id"), rs
- .getString("client_secret"));
- info.setId(rs.getInt("id"));
- info.setClient_type(rs.getString("client_type"));
- info.setRedirect_uri(rs.getString("redirect_uri"));
- info.setUrl(rs.getString("url"));
- info.setConfidential(rs
- .getBoolean("is_confidential"));
- return info;
- }
- });
- }
- catch (EmptyResultDataAccessException ex) {
- jlog.error(clientid+" client found "+ ex.fillInStackTrace());
- return null;
- }
- }
-
-
- // fixme: what to delete? difference client/application table?
- public boolean revokeToken (String token) throws KustvaktException {
- String sql = "delete from oauth2_access_token WHERE access_token=:token;";
- MapSqlParameterSource s = new MapSqlParameterSource();
- s.addValue("token", token);
- try {
- return this.jdbcTemplate.update(sql, s) == 1;
- }
- catch (DataAccessException e) {
- jlog.error("token could not be revoked", e.fillInStackTrace());
- return false;
- }
- }
-
-
- public boolean revokeAuthorization (ClientInfo info, User user) {
- MapSqlParameterSource source = new MapSqlParameterSource();
- source.addValue("us", user.getId());
- source.addValue("cls", info.getClient_secret());
- source.addValue("clid", info.getClient_id());
-
- String tokens = "delete from oauth2_access_token where user_id=:us and client_id in "
- + "(select client_id from oauth2_client where client_id=:clid and client_secret=:cls);";
-
- try {
- this.jdbcTemplate.update(tokens, source);
- }
- catch (DataAccessException e) {
- jlog.error("authorization could not be revoked for user "+
- user.getUsername());
- return false;
- }
- //fixme: if int row not updated, false!!
- return true;
- }
-
-
- public boolean addToken (String token, String refresh, Integer userid,
- String client_id, String scopes, int expiration)
- throws KustvaktException {
- MapSqlParameterSource s = new MapSqlParameterSource();
- s.addValue("token", token);
- s.addValue("rt", refresh);
- s.addValue("ex", new Timestamp(TimeUtils.plusSeconds(expiration)
- .getMillis()));
- s.addValue("us", userid);
- s.addValue("sc", scopes);
- s.addValue("st", BooleanUtils.getBoolean(true));
- s.addValue("cli", client_id);
- String sql = "insert into oauth2_access_token (access_token, refresh_token, scopes, client_id, user_id, expiration, status) "
- + "values (:token, :rt, :sc, :cli, :us, :ex, :st);";
- try {
- return this.jdbcTemplate.update(sql, s) == 1;
- }
- catch (DataAccessException e) {
- e.printStackTrace();
- jlog.error("token "+token+" could not be added for user "+
- userid);
- return false;
- }
- }
-
-
- // returns the first token to find
- public String getToken (String client_id, Integer userid) {
- String sql = "select access_token from oauth2_access_token where user_id=:uid"
- + " and status=1 and client_id=:cli limit 1;";
- MapSqlParameterSource s = new MapSqlParameterSource();
- s.addValue("uid", userid);
- s.addValue("cli", client_id);
- try {
- return this.jdbcTemplate.queryForObject(sql, s, String.class);
- }
- catch (EmptyResultDataAccessException ex) {
- jlog.error("no token found for user "+ userid);
- return null;
- }
- catch (DataAccessException ex) {
- jlog.error("token retrieval failed for user "+ userid);
- return null;
- }
- }
-
-
- public List<ClientInfo> getAuthorizedClients (Integer userid) {
- String sql = "select cl.* from oauth2_client as cl where cl.client_id in (select cd.client_id from oauth2_access_token as cd "
- + "where cd.user_id=:user) or cl.is_confidential=:conf;";
-
- //todo: test query
- // "select cl.* from oauth2_client as cl inner join oauth2_access_token as cd "
- // + "on cd.client_id=cl.client_id where cd.user_id=:user or cl.is_confidential=:conf;"
-
- MapSqlParameterSource s = new MapSqlParameterSource();
- s.addValue("user", userid);
- s.addValue("conf", BooleanUtils.getBoolean(true));
- try {
- // secret is not returned for this function
- return this.jdbcTemplate.query(sql, s, new RowMapper<ClientInfo>() {
-
- @Override
- public ClientInfo mapRow (ResultSet rs, int rowNum)
- throws SQLException {
- ClientInfo info = new ClientInfo(rs.getString("client_id"), "*****");
- info.setConfidential(rs.getBoolean("is_confidential"));
- info.setUrl(rs.getString("url"));
- info.setId(rs.getInt("id"));
- info.setRedirect_uri(rs.getString("redirect_uri"));
- return info;
- }
- });
- }
- catch (DataAccessException e) {
- jlog.error("Data access error", e);
- return Collections.emptyList();
- }
-
- }
-
-
- // todo: expired token must trigger an invalid token exception to trigger a refresh token
- public TokenContext getContext (final String token)
- throws KustvaktException {
- String sql = "select ko.username, oa.expiration, oa.scopes from oauth2_access_token as oa inner join korap_users as ko "
- + "on ko.id=oa.user_id where oa.access_token=:token and oa.expiration > :now;";
- MapSqlParameterSource s = new MapSqlParameterSource();
- s.addValue("token", token);
- s.addValue("now", new Timestamp(TimeUtils.getNow().getMillis()));
-
- try {
- TokenContext context = this.jdbcTemplate.queryForObject(sql, s,
- new RowMapper<TokenContext>() {
- @Override
- public TokenContext mapRow (ResultSet rs, int rowNum)
- throws SQLException {
- long exp = rs.getTimestamp("expiration").getTime();
- TokenContext c = new TokenContext();
- c.setUsername(rs.getString(Attributes.USERNAME));
- c.setExpirationTime(exp);
- c.setToken(token);
- c.setTokenType(TokenType.BEARER);
-// c.setTokenType(Attributes.OAUTH2_AUTHORIZATION);
- c.addContextParameter(Attributes.SCOPE,
- rs.getString(Attributes.SCOPE));
- return c;
- }
- });
- return context;
- }
- catch (EmptyResultDataAccessException ee) {
- jlog.error("no context found for token "+ token);
- revokeToken(token);
- throw new KustvaktException(StatusCodes.EXPIRED, "token", token);
- }
- catch (DataAccessException e) {
- jlog.error("token context retrieval failed for "+ token);
- throw new KustvaktException(StatusCodes.ILLEGAL_ARGUMENT,
- "invalid token", token);
- }
-
- }
-
-
- // subsequently delete all access and auth code tokens associated!
- public void removeClient (ClientInfo info, User user)
- throws KustvaktException {
- MapSqlParameterSource p = new MapSqlParameterSource();
- p.addValue("url", info.getUrl());
- p.addValue("cls", info.getClient_secret());
- p.addValue("clid", info.getClient_id());
- String sql = "delete from oauth2_client where client_id=:clid and client_secret=:cls and"
- + " url=:url;";
- try {
- this.jdbcTemplate.update(sql, p);
- }
- catch (DataAccessException e) {
- e.printStackTrace();
- jlog.error("removing client "+info.getClient_id()+" failed");
- throw new DatabaseException(new KustvaktException(user.getId(),
- StatusCodes.ILLEGAL_ARGUMENT, "arguments given not valid",
- info.toJSON()), StatusCodes.CLIENT_DEREGISTRATION_FAILED,
- info.toJSON());
-
- }
- }
-
-
- public void registerClient (ClientInfo info, User user)
- throws KustvaktException {
- MapSqlParameterSource p = new MapSqlParameterSource();
- p.addValue("clid", info.getClient_id());
- p.addValue("con", info.isConfidential());
- p.addValue("cls", info.getClient_secret());
- p.addValue("clt", info.getClient_type());
- p.addValue("url", info.getUrl());
- p.addValue("r_url", info.getRedirect_uri());
- String sql = "insert into oauth2_client (client_id, client_secret, client_type, url, is_confidential, redirect_uri) "
- + "VALUES (:clid, :cls, :clt, :url, :con, :r_url);";
- try {
- this.jdbcTemplate.update(sql, p);
- }
- catch (DataAccessException e) {
- e.printStackTrace();
- jlog.error("registering client "+info.getClient_id()+" failed");
- throw new DatabaseException(new KustvaktException(user.getId(),
- StatusCodes.ILLEGAL_ARGUMENT, "arguments given not valid",
- info.toJSON()), StatusCodes.CLIENT_REGISTRATION_FAILED,
- info.toJSON());
- }
- }
-}
diff --git a/full/src/main/java/de/ids_mannheim/korap/handlers/UserDetailsDao.java b/full/src/main/java/de/ids_mannheim/korap/handlers/UserDetailsDao.java
index 0d6004e..b550dae 100644
--- a/full/src/main/java/de/ids_mannheim/korap/handlers/UserDetailsDao.java
+++ b/full/src/main/java/de/ids_mannheim/korap/handlers/UserDetailsDao.java
@@ -22,6 +22,7 @@
* @author hanl
* @date 27/01/2016
*/
+@Deprecated
public class UserDetailsDao implements UserDataDbIface<UserDetails> {
private NamedParameterJdbcTemplate jdbcTemplate;
diff --git a/full/src/main/java/de/ids_mannheim/korap/handlers/UserSettingsDao.java b/full/src/main/java/de/ids_mannheim/korap/handlers/UserSettingsDao.java
index ba2f927..55d19d9 100644
--- a/full/src/main/java/de/ids_mannheim/korap/handlers/UserSettingsDao.java
+++ b/full/src/main/java/de/ids_mannheim/korap/handlers/UserSettingsDao.java
@@ -25,6 +25,7 @@
* @author hanl
* @date 28/01/2016
*/
+@Deprecated
public class UserSettingsDao implements UserDataDbIface<UserSettings> {
private static final Logger jlog = LogManager
diff --git a/full/src/main/resources/default-config.xml b/full/src/main/resources/default-config.xml
index 0c14584..d67d911 100644
--- a/full/src/main/resources/default-config.xml
+++ b/full/src/main/resources/default-config.xml
@@ -247,13 +247,13 @@
ref="kustvakt_config" />
</bean>
- <bean id="openid_auth"
+ <!-- <bean id="openid_auth"
class="de.ids_mannheim.korap.authentication.OpenIDconnectAuthentication">
<constructor-arg type="de.ids_mannheim.korap.config.KustvaktConfiguration"
ref="kustvakt_config" />
<constructor-arg
type="de.ids_mannheim.korap.interfaces.db.PersistenceClient" ref="kustvakt_db" />
- </bean>
+ </bean> -->
<bean id="session_auth"
class="de.ids_mannheim.korap.authentication.SessionAuthentication">
@@ -271,7 +271,7 @@
<ref bean="ldap_auth" />
<ref bean="session_auth" />
<!-- <ref bean="api_auth" /> -->
- <ref bean="openid_auth" />
+ <!-- <ref bean="openid_auth" /> -->
<ref bean="oauth2_auth" />
</util:list>
diff --git a/full/src/main/resources/ehcache.xml b/full/src/main/resources/ehcache.xml
index 8cddd0e..27a4b56 100644
--- a/full/src/main/resources/ehcache.xml
+++ b/full/src/main/resources/ehcache.xml
@@ -34,8 +34,7 @@
diskSpoolBufferSizeMB="30"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
- statistics="false"/>
-
+ />
<!-- EM -->
<cache name='authorization'
diff --git a/full/src/main/resources/log4j2-debug.properties b/full/src/main/resources/log4j2-debug.properties
new file mode 100644
index 0000000..817e355
--- /dev/null
+++ b/full/src/main/resources/log4j2-debug.properties
@@ -0,0 +1,31 @@
+appenders = console, debugFile
+appender.console.type = Console
+appender.console.name = STDOUT
+appender.console.layout.type = PatternLayout
+appender.console.layout.pattern = %d{yyyy-MM-dd, HH:mm:ss} %C{6} - %M%n %-5p: %m%n
+
+appender.debugFile.type = File
+appender.debugFile.name = DEBUGLOG
+appender.debugFile.fileName=./logs/debug.log
+appender.debugFile.layout.type=PatternLayout
+appender.debugFile.layout.pattern= %d{yyyy-MM-dd, HH:mm:ss} %C{6} - %M%n %-5p: %m%n
+
+rootLogger.level = warn
+rootLogger.appenderRefs = debugFile
+rootLogger.appenderRef.file.ref = DEBUGLOG
+rootLogger.additivity=false
+
+loggers=file
+logger.file.name=de.ids_mannheim.korap
+logger.file.level = debug
+logger.file.appenderRefs = debugFile
+logger.file.appenderRef.file.ref = DEBUGLOG
+logger.file.additivity=false
+
+
+#loggers=file
+#logger.file.name=com.sun.jersey.test.framework.spi.container
+#logger.file.level = info
+#logger.file.appenderRefs = file
+#logger.file.appenderRef.file.ref = ERRORLOG
+#logger.file.additivity=false
\ No newline at end of file
diff --git a/full/src/main/resources/log4j2.properties b/full/src/main/resources/log4j2.properties
index b616418..1acd50c 100644
--- a/full/src/main/resources/log4j2.properties
+++ b/full/src/main/resources/log4j2.properties
@@ -1,29 +1,16 @@
-appenders = console, file
+appenders = console, mainFile
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-MM-dd, HH:mm:ss} %C{6} - %M%n %-5p: %m%n
-appender.file.type = File
-appender.file.name = ERRORLOG
-appender.file.fileName=./logs/errors.log
-appender.file.layout.type=PatternLayout
-appender.file.layout.pattern= %d{yyyy-MM-dd, HH:mm:ss} %C{6} - %M%n %-5p: %m%n
+appender.mainFile.type = File
+appender.mainFile.name = MAINLOG
+appender.mainFile.fileName=./logs/main.log
+appender.mainFile.layout.type=PatternLayout
+appender.mainFile.layout.pattern= %d{yyyy-MM-dd, HH:mm:ss} %C{6} - %M%n %-5p: %m%n
-rootLogger.level = error
-rootLogger.appenderRefs = stdout
-rootLogger.appenderRef.stdout.ref = STDOUT
-
-loggers=file
-logger.file.name=de.ids_mannheim.korap
-logger.file.level = error
-logger.file.appenderRefs = file
-logger.file.appenderRef.file.ref = ERRORLOG
-logger.file.additivity=true
-
-#loggers=file
-#logger.file.name=com.sun.jersey.test.framework.spi.container
-#logger.file.level = info
-#logger.file.appenderRefs = file
-#logger.file.appenderRef.file.ref = ERRORLOG
-#logger.file.additivity=false
\ No newline at end of file
+rootLogger.level = warn
+rootLogger.appenderRefs = mainFile
+rootLogger.appenderRef.file.ref = MAINLOG
+rootLogger.additivity=false
\ No newline at end of file