aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/ConfigurationProviderImpl.java6
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/SSOManager.java7
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/AttributQueryAction.java7
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/DBAuthenticationSessionStoreage.java54
-rw-r--r--id/server/idserverlib/src/main/resources/session.common.beans.xml54
-rw-r--r--id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/spring/test/SpringExpressionAwareProcessEngineTest.java2
-rw-r--r--id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/test/ProcessEngineTest.java2
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOASessionDBUtils.java229
-rw-r--r--id/server/moa-id-spring-initializer/src/main/java/at/gv/egovernment/moa/id/auth/MOAIDAuthSpringResourceProvider.java5
9 files changed, 218 insertions, 148 deletions
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/ConfigurationProviderImpl.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/ConfigurationProviderImpl.java
index 5c2f86732..a07099a93 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/ConfigurationProviderImpl.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/ConfigurationProviderImpl.java
@@ -185,6 +185,10 @@ public abstract class ConfigurationProviderImpl implements ConfigurationProvider
String propertyName = key.toString().substring(propPrefix.length());
moaSessionProp.put(propertyName, props.get(key.toString()));
}
+ if (key.toString().startsWith(propPrefix+"dbcp")) {
+ String propertyName = "hibernate."+(key.toString().substring(propPrefix.length()));
+ moaSessionProp.put(propertyName, props.get(key.toString()));
+ }
}
// read Config Hibernate properties
@@ -222,7 +226,7 @@ public abstract class ConfigurationProviderImpl implements ConfigurationProvider
config.addAnnotatedClass(InterfederationSessionStore.class);
//config.addAnnotatedClass(ProcessInstanceStore.class);
config.addProperties(moaSessionProp);
- MOASessionDBUtils.initHibernate(config, moaSessionProp);
+ //MOASessionDBUtils.initHibernate(config, moaSessionProp);
//initial advanced logging
if (Boolean.valueOf(props.getProperty("configuration.advancedlogging.active", "false"))) {
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/SSOManager.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/SSOManager.java
index bc7dd272b..0799760ce 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/SSOManager.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/SSOManager.java
@@ -63,6 +63,7 @@ public class SSOManager {
@Autowired private IAuthenticationSessionStoreage authenticatedSessionStore;
@Autowired protected AuthConfiguration authConfig;
+ @Autowired private MOASessionDBUtils moaSessionDBUtils;
/**
* Check if interfederation IDP is requested via HTTP GET parameter or if interfederation cookie exists.
@@ -159,7 +160,7 @@ public class SSOManager {
} else {
Logger.warn("MOASession is marked as interfederated SSO session but no interfederated IDP is found. Switch to local authentication ...");
- MOASessionDBUtils.delete(storedSession);
+ moaSessionDBUtils.delete(storedSession);
}
}
@@ -200,7 +201,7 @@ public class SSOManager {
public String existsOldSSOSession(String ssoId) {
Logger.trace("Check that the SSOID has already been used");
- Session session = MOASessionDBUtils.getCurrentSession();
+ Session session = moaSessionDBUtils.getCurrentSession();
List<OldSSOSessionIDStore> result;
@@ -289,7 +290,7 @@ public class SSOManager {
//no local SSO session exist -> request interfederated IDP
Logger.info("Delete interfederated IDP " + selectedIDP.getIdpurlprefix()
+ " from MOASession " + storedSession.getSessionid());
- MOASessionDBUtils.delete(selectedIDP);
+ moaSessionDBUtils.delete(selectedIDP);
} else {
Logger.warn("MOASession is marked as interfederated SSO session but no interfederated IDP is found. Switch to local authentication ...");
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/AttributQueryAction.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/AttributQueryAction.java
index 2168316ab..98c6632f1 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/AttributQueryAction.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/pvp2x/AttributQueryAction.java
@@ -80,6 +80,7 @@ public class AttributQueryAction implements IAction {
@Autowired private AuthenticationDataBuilder authDataBuilder;
@Autowired private IDPCredentialProvider pvpCredentials;
@Autowired private AuthConfiguration authConfig;
+ @Autowired private MOASessionDBUtils moaSessionDBUtils;
private final static List<String> DEFAULTSTORKATTRIBUTES = Arrays.asList(
new String[]{PVPConstants.EID_STORK_TOKEN_NAME});
@@ -198,7 +199,7 @@ public class AttributQueryAction implements IAction {
((PVPTargetConfiguration) pendingReq).getRequest().getInboundMessage() instanceof AttributeQuery) {
try {
activeOA.setAttributeQueryUsed(true);
- MOASessionDBUtils.saveOrUpdate(activeOA);
+ moaSessionDBUtils.saveOrUpdate(activeOA);
} catch (MOADatabaseException e) {
Logger.error("MOASession interfederation information can not stored to database.", e);
@@ -251,11 +252,11 @@ public class AttributQueryAction implements IAction {
//mark attribute request as used
if (nextIDPInformation.isStoreSSOInformation()) {
nextIDPInformation.setAttributesRequested(true);
- MOASessionDBUtils.saveOrUpdate(nextIDPInformation);
+ moaSessionDBUtils.saveOrUpdate(nextIDPInformation);
//delete federated IDP from Session
} else {
- MOASessionDBUtils.delete(nextIDPInformation);
+ moaSessionDBUtils.delete(nextIDPInformation);
}
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/DBAuthenticationSessionStoreage.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/DBAuthenticationSessionStoreage.java
index 094e25040..cb470a7b9 100644
--- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/DBAuthenticationSessionStoreage.java
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/DBAuthenticationSessionStoreage.java
@@ -65,7 +65,7 @@ import at.gv.egovernment.moa.util.MiscUtil;
public class DBAuthenticationSessionStoreage implements IAuthenticationSessionStoreage{
@Autowired AuthConfiguration authConfig;
-
+ @Autowired MOASessionDBUtils moaSessionDBUtils;
private static JsonMapper mapper = new JsonMapper();
@Override
@@ -104,7 +104,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt
encryptSession(session, dbsession);
//store AssertionStore element to Database
- MOASessionDBUtils.saveOrUpdate(dbsession);
+ moaSessionDBUtils.saveOrUpdate(dbsession);
Logger.info("Create MOASession with sessionID: " + id);
return session;
@@ -166,7 +166,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt
dbsession.setAdditionalInformation(
mapper.serialize(sessionExtensions));
- MOASessionDBUtils.saveOrUpdate(dbsession);
+ moaSessionDBUtils.saveOrUpdate(dbsession);
Logger.debug("MOASession with sessionID=" + sessionID + " is stored in Database");
@@ -193,7 +193,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt
dbsession.setAuthenticated(session.isAuthenticated());
dbsession.setUpdated(new Date());
- MOASessionDBUtils.saveOrUpdate(dbsession);
+ moaSessionDBUtils.saveOrUpdate(dbsession);
Logger.debug("MOASession with sessionID=" + session.getSessionID() + " is stored in Database");
} catch (MOADatabaseException e) {
@@ -205,7 +205,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt
@Override
public void destroySession(String moaSessionID) throws MOADatabaseException {
- Session session = MOASessionDBUtils.getCurrentSession();
+ Session session = moaSessionDBUtils.getCurrentSession();
List<AuthenticatedSessionStore> result;
Transaction tx = null;
@@ -257,7 +257,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt
//set Timestamp in this state, because automated timestamp generation is buggy in Hibernate 4.2.1
dbsession.setUpdated(new Date());
- MOASessionDBUtils.saveOrUpdate(dbsession);
+ moaSessionDBUtils.saveOrUpdate(dbsession);
Logger.trace("Change SessionID complete.");
@@ -281,7 +281,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt
try {
session = searchInDatabase(moaSessionID, true);
session.setAuthenticated(isAuthenticated);
- MOASessionDBUtils.saveOrUpdate(session);
+ moaSessionDBUtils.saveOrUpdate(session);
} catch (MOADatabaseException e) {
@@ -293,7 +293,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt
public String getMOASessionSSOID(String SSOSessionID) {
MiscUtil.assertNotNull(SSOSessionID, "SSOsessionID");
Logger.trace("Get authenticated session with SSOID " + SSOSessionID + " from database.");
- Session session = MOASessionDBUtils.getCurrentSession();
+ Session session = moaSessionDBUtils.getCurrentSession();
List<AuthenticatedSessionStore> result;
Transaction tx = null;
@@ -346,7 +346,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt
//TODO: is this method really needed??
MiscUtil.assertNotNull(SSOId, "SSOSessionID");
Logger.trace("Get authenticated session with SSOID " + SSOId + " from database.");
- Session session = MOASessionDBUtils.getCurrentSession();
+ Session session = moaSessionDBUtils.getCurrentSession();
List<AuthenticatedSessionStore> result;
Transaction tx = null;
@@ -387,7 +387,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt
try {
- Session session = MOASessionDBUtils.getCurrentSession();
+ Session session = moaSessionDBUtils.getCurrentSession();
List<AuthenticatedSessionStore> result;
Logger.trace("Add SSO information to session " + moaSessionID);
@@ -495,7 +495,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt
AuthenticatedSessionStore dbsession = searchInDatabase(moaSession.getSessionID(), false);
oas.addAll(dbsession.getActiveOAsessions());
- session = MOASessionDBUtils.getCurrentSession();
+ session = moaSessionDBUtils.getCurrentSession();
session.getTransaction().commit();
return oas;
@@ -525,7 +525,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt
AuthenticatedSessionStore dbsession = searchInDatabase(moaSession.getSessionID(), false);
idps.addAll(dbsession.getInderfederation());
- session = MOASessionDBUtils.getCurrentSession();
+ session = moaSessionDBUtils.getCurrentSession();
session.getTransaction().commit();
return idps;
@@ -552,7 +552,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt
MiscUtil.assertNotNull(userNameID, "userNameID");
Logger.trace("Get moaSession for userNameID " + userNameID + " and OA "
+ oaID + " from database.");
- Session session = MOASessionDBUtils.getCurrentSession();
+ Session session = moaSessionDBUtils.getCurrentSession();
Transaction tx = null;
List<AuthenticatedSessionStore> result = null;;
@@ -598,7 +598,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt
MiscUtil.assertNotNull(protocolType, "usedProtocol");
Logger.trace("Get active OnlineApplication for sessionID " + moaSession.getSessionID() + " with OAID "
+ oaID + " from database.");
- Session session = MOASessionDBUtils.getCurrentSession();
+ Session session = moaSessionDBUtils.getCurrentSession();
List<AuthenticatedSessionStore> result;
Transaction tx = null;
@@ -640,7 +640,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt
try {
MiscUtil.assertNotNull(nameID, "nameID");
Logger.trace("Get authenticated session with pedingRequestID " + nameID + " from database.");
- Session session = MOASessionDBUtils.getCurrentSession();
+ Session session = moaSessionDBUtils.getCurrentSession();
List<AuthenticatedSessionStore> result;
@@ -677,7 +677,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt
public InterfederationSessionStore searchInterfederatedIDPFORSSOWithMOASession(String sessionID) {
MiscUtil.assertNotNull(sessionID, "MOASession");
Logger.trace("Get interfederated IDP for SSO with sessionID " + sessionID + " from database.");
- Session session = MOASessionDBUtils.getCurrentSession();
+ Session session = moaSessionDBUtils.getCurrentSession();
List<AuthenticatedSessionStore> result;
Transaction tx = null;
@@ -714,7 +714,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt
MiscUtil.assertNotNull(sessionID, "MOASession");
MiscUtil.assertNotNull(idpID, "Interfederated IDP ID");
Logger.trace("Get interfederated IDP "+ idpID + " for SSO with sessionID " + sessionID + " from database.");
- Session session = MOASessionDBUtils.getCurrentSession();
+ Session session = moaSessionDBUtils.getCurrentSession();
List<AuthenticatedSessionStore> result;
Transaction tx = null;
@@ -818,7 +818,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt
//store AssertionStore element to Database
try {
- MOASessionDBUtils.saveOrUpdate(dbsession);
+ moaSessionDBUtils.saveOrUpdate(dbsession);
} catch (MOADatabaseException e) {
Logger.warn("MOASession could not be created.");
@@ -831,7 +831,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt
public InterfederationSessionStore searchInterfederatedIDPFORAttributeQueryWithSessionID(String moaSessionID) {
MiscUtil.assertNotNull(moaSessionID, "MOASessionID");
Logger.trace("Get interfederated IDP for AttributeQuery with sessionID " + moaSessionID + " from database.");
- Session session = MOASessionDBUtils.getCurrentSession();
+ Session session = moaSessionDBUtils.getCurrentSession();
List<AuthenticatedSessionStore> result;
Transaction tx = null;
@@ -872,7 +872,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt
MiscUtil.assertNotNull(pedingRequestID, "pedingRequestID");
Logger.trace("Get authenticated session with pedingRequestID " + pedingRequestID + " from database.");
- Session session = MOASessionDBUtils.getCurrentSession();
+ Session session = moaSessionDBUtils.getCurrentSession();
List<AuthenticatedSessionStore> result;
@@ -907,7 +907,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt
}
}
- MOASessionDBUtils.saveOrUpdate(authsession);
+ moaSessionDBUtils.saveOrUpdate(authsession);
return true;
} catch (Throwable e) {
@@ -922,7 +922,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt
Date expioredateupdate = new Date(now.getTime() - authDataTimeOutUpdated);
List<AuthenticatedSessionStore> results;
- Session session = MOASessionDBUtils.getCurrentSession();
+ Session session = moaSessionDBUtils.getCurrentSession();
Transaction tx = null;
try {
synchronized (session) {
@@ -972,26 +972,26 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt
}
- private static void cleanDelete(AuthenticatedSessionStore result) {
+ private void cleanDelete(AuthenticatedSessionStore result) {
try {
result.setSession("blank".getBytes());
- MOASessionDBUtils.saveOrUpdate(result);
+ moaSessionDBUtils.saveOrUpdate(result);
} catch (MOADatabaseException e) {
Logger.warn("Blank authenticated session with sessionID=" + result.getSessionid() + " FAILED.", e);
} finally {
- if (!MOASessionDBUtils.delete(result))
+ if (!moaSessionDBUtils.delete(result))
Logger.error("Authenticated session with sessionID=" + result.getSessionid() + " not removed! (Error during Database communication)");
}
}
@SuppressWarnings("rawtypes")
- private static AuthenticatedSessionStore searchInDatabase(String sessionID, boolean commit) throws MOADatabaseException {
+ private AuthenticatedSessionStore searchInDatabase(String sessionID, boolean commit) throws MOADatabaseException {
MiscUtil.assertNotNull(sessionID, "moasessionID");
Logger.trace("Get authenticated session with sessionID " + sessionID + " from database.");
- Session session = MOASessionDBUtils.getCurrentSession();
+ Session session = moaSessionDBUtils.getCurrentSession();
List result;
Transaction tx = null;
diff --git a/id/server/idserverlib/src/main/resources/session.common.beans.xml b/id/server/idserverlib/src/main/resources/session.common.beans.xml
new file mode 100644
index 000000000..abc3c3200
--- /dev/null
+++ b/id/server/idserverlib/src/main/resources/session.common.beans.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans profile="redis"
+ xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xmlns:aop="http://www.springframework.org/schema/aop"
+ xmlns:p="http://www.springframework.org/schema/p"
+ xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
+
+ <context:annotation-config/>
+
+ <bean id="sessionDataSource" class="org.apache.commons.dbcp2.BasicDataSource" lazy-init="true" destroy-method="close">
+ <aop:scoped-proxy/>
+ <property name="driverClassName" value="${moasession.hibernate.connection.driver_class}" />
+ <property name="url" value="${moasession.hibernate.connection.url}"/>
+ <property name="username" value="${moasession.hibernate.connection.username}" />
+ <property name="password" value="${moasession.hibernate.connection.password}" />
+
+ <property name="connectionProperties" value="${moasession.dbcp.connectionProperties}" />
+ <property name="initialSize" value="${moasession.dbcp.initialSize}" />
+ <property name="maxTotal" value="${moasession.dbcp.maxActive}" />
+ <property name="maxIdle" value="${moasession.dbcp.maxIdle}" />
+ <property name="minIdle" value="${moasession.dbcp.minIdle}" />
+ <!-- property name="maxWait" value="${moasession.dbcp.maxWaitMillis}" / -->
+ <property name="testOnBorrow" value="${moasession.dbcp.testOnBorrow}" />
+ <property name="testOnReturn" value="${moasession.dbcp.testOnReturn}" />
+ <property name="testWhileIdle" value="${moasession.dbcp.testWhileIdle}" />
+ <property name="validationQuery" value="${moasession.dbcp.validationQuery}" />
+ </bean>
+
+ <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
+ <property name="dataSource" ref="sessionDataSource"/>
+ <property name="packagesToScan" value="at.gv.egovernment.moa.id.commons.db" />
+ <property name="hibernateProperties">
+ <props>
+ <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
+ <prop key="hibernate.show_sql">${moasession.hibernate.show_sql}</prop>
+ <prop key="hibernate.hbm2ddl.auto">update</prop>
+ <prop key="current_session_context_class">thread</prop>
+ <prop key="hibernate.transaction.flush_before_completion">true</prop>
+ <prop key="hibernate.transaction.auto_close_session">true</prop>
+ </props>
+ </property>
+ </bean>
+
+ <bean id="moaSessionDBUtils" class="at.gv.egovernment.moa.id.commons.db.MOASessionDBUtils">
+ </bean>
+
+
+</beans> \ No newline at end of file
diff --git a/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/spring/test/SpringExpressionAwareProcessEngineTest.java b/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/spring/test/SpringExpressionAwareProcessEngineTest.java
index 2cb2a3278..b308e2fa8 100644
--- a/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/spring/test/SpringExpressionAwareProcessEngineTest.java
+++ b/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/spring/test/SpringExpressionAwareProcessEngineTest.java
@@ -78,7 +78,7 @@ public class SpringExpressionAwareProcessEngineTest {
config.addProperties(props);
//config.addAnnotatedClass(ProcessInstanceStore.class);
config.addAnnotatedClass(AssertionStore.class);
- MOASessionDBUtils.initHibernate(config, props);
+ //MOASessionDBUtils.initHibernate(config, props);
} catch (Exception e) {
e.printStackTrace();
}
diff --git a/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/test/ProcessEngineTest.java b/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/test/ProcessEngineTest.java
index a7e351e25..197627a66 100644
--- a/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/test/ProcessEngineTest.java
+++ b/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/test/ProcessEngineTest.java
@@ -73,7 +73,7 @@ public class ProcessEngineTest {
config.addProperties(props);
//config.addAnnotatedClass(ProcessInstanceStore.class);
config.addAnnotatedClass(AssertionStore.class);
- MOASessionDBUtils.initHibernate(config, props);
+ //MOASessionDBUtils.initHibernate(config, props);
} catch (Exception e) {
e.printStackTrace();
}
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOASessionDBUtils.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOASessionDBUtils.java
index ecb13ef34..88de9ceb5 100644
--- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOASessionDBUtils.java
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOASessionDBUtils.java
@@ -24,62 +24,67 @@ package at.gv.egovernment.moa.id.commons.db;
import java.util.Properties;
-import org.apache.commons.lang3.StringUtils;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
-import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
-import org.hibernate.service.ServiceRegistry;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
import at.gv.egovernment.moa.id.commons.db.ex.MOADatabaseException;
import at.gv.egovernment.moa.logging.Logger;
-public final class MOASessionDBUtils {
+@Transactional
+public class MOASessionDBUtils {
- private static SessionFactory sessionFactory;
- private static ServiceRegistry serviceRegistry;
-
- @SuppressWarnings("rawtypes")
- private static final ThreadLocal THREAD_LOCAL = new ThreadLocal();
- private static boolean automaticSessionHandling = false;
- private static final String[] AUTOMATIC_SESSION_HANDLING_VALUES = new String[] { "jta", "thread" };
- private static final String SESSION_HANDLING_KEY = "hibernate.current_session_context_class";
+ private SessionFactory sessionFactory;
+// private static ServiceRegistry serviceRegistry;
- protected MOASessionDBUtils() { }
+// @SuppressWarnings("rawtypes")
+// private static final ThreadLocal THREAD_LOCAL = new ThreadLocal();
+// private static boolean automaticSessionHandling = false;
+
+// private static final String[] AUTOMATIC_SESSION_HANDLING_VALUES = new String[] { "jta", "thread" };
+// private static final String SESSION_HANDLING_KEY = "hibernate.current_session_context_class";
+ @Autowired
+ public void setSessionFactory(SessionFactory sessionFactory) {
+ this.sessionFactory = sessionFactory;
+ }
- public static void initHibernate(Configuration config, Properties hibernateProperties) {
-
- String scm = StringUtils.trimToNull(hibernateProperties.getProperty(SESSION_HANDLING_KEY));
- if (scm != null) {
- automaticSessionHandling = scm.indexOf(AUTOMATIC_SESSION_HANDLING_VALUES[0]) != -1 || scm.indexOf(AUTOMATIC_SESSION_HANDLING_VALUES[1]) != -1;
- }
- Logger.debug("Evaluating hibernate property \"" + SESSION_HANDLING_KEY + "\".");
- if (automaticSessionHandling) {
- Logger.info("Hibernate is automatically handling session context management.");
- } else {
- Logger.info("Hibernate is NOT automatically handling session context management. Using build-in ThreadLocal session handling.");
- }
- try {
- //Create the SessionFactory
- Logger.debug("Creating initial MOASession session factory...");
-
- config.configure("hibernate_moasession.cfg.xml");
- //serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();
-
- serviceRegistry = new StandardServiceRegistryBuilder().
- applySettings(config.getProperties()).build();
-
- sessionFactory = config.buildSessionFactory(serviceRegistry);
- Logger.debug("Initial MOASession session factory successfully created.");
-
- } catch (Throwable ex) {
- Logger.error("Initial MOASession session factory creation failed: " + ex.getMessage());
- throw new ExceptionInInitializerError(ex);
- }
- }
+ public void initHibernate(Configuration config, Properties hibernateProperties) {
+//
+// String scm = StringUtils.trimToNull(hibernateProperties.getProperty(SESSION_HANDLING_KEY));
+// if (scm != null) {
+// automaticSessionHandling = scm.indexOf(AUTOMATIC_SESSION_HANDLING_VALUES[0]) != -1 || scm.indexOf(AUTOMATIC_SESSION_HANDLING_VALUES[1]) != -1;
+// }
+// Logger.debug("Evaluating hibernate property \"" + SESSION_HANDLING_KEY + "\".");
+// if (automaticSessionHandling) {
+// Logger.info("Hibernate is automatically handling session context management.");
+// } else {
+// Logger.info("Hibernate is NOT automatically handling session context management. Using build-in ThreadLocal session handling.");
+// }
+// try {
+// //Create the SessionFactory
+// Logger.debug("Creating initial MOASession session factory...");
+//
+// config.configure("hibernate_moasession.cfg.xml");
+// //serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();
+//
+// // serviceRegistry = new StandardServiceRegistryBuilder().
+// // applySettings(config.getProperties()).build();
+//
+// //dbSessionSessionFactory = config.buildSessionFactory(serviceRegistry);
+//
+// Logger.debug("Initial MOASession session factory successfully created.");
+//
+// } catch (Throwable ex) {
+// Logger.error("Initial MOASession session factory creation failed: " + ex.getMessage());
+// throw new ExceptionInInitializerError(ex);
+// }
+ }
/**
* Checks if a session factory is currently available. If necessary a new
@@ -89,37 +94,39 @@ public final class MOASessionDBUtils {
* @throws HibernateException
* thrown if a hibernate error occurs
*/
- public static Session getCurrentSession() {
- if (automaticSessionHandling) {
- return sessionFactory.getCurrentSession();
- }
- Session session = (Session) THREAD_LOCAL.get();
- // Open a new Session, if this Thread has none yet
- if (session == null || !session.isConnected()) {
- session = getNewSession();
- }
- return session;
+ public Session getCurrentSession() {
+ return sessionFactory.getCurrentSession();
+// if (automaticSessionHandling) {
+// return dbSessionSessionFactory.getCurrentSession();
+// }
+// Session session = (Session) THREAD_LOCAL.get();
+// // Open a new Session, if this Thread has none yet
+// if (session == null || !session.isConnected()) {
+// session = getNewSession();
+// }
+// return session;
}
@SuppressWarnings("unchecked")
- public static Session getNewSession() {
- if (automaticSessionHandling) {
- Logger.warn("Session is being automatically handled by hibernate. Therefore this session maybe not being newly created. Use HibernateUtil.getCurrentSession() instead.");
- return sessionFactory.getCurrentSession();
- }
- Session session = (Session) THREAD_LOCAL.get();
- if (session != null) {
- Logger.warn("Previous MOASession session has not been closed; closing session now.");
- closeSession();
- }
- Logger.debug("Opening new MOASession hibernate session...");
- try {
- session = sessionFactory.openSession();
- THREAD_LOCAL.set(session);
- } catch (HibernateException hex) {
- Logger.error(hex.getMessage());
- }
- return session;
+ public Session getNewSession() {
+ return sessionFactory.getCurrentSession();
+// if (automaticSessionHandling) {
+// Logger.warn("Session is being automatically handled by hibernate. Therefore this session maybe not being newly created. Use HibernateUtil.getCurrentSession() instead.");
+// return dbSessionSessionFactory.getCurrentSession();
+// }
+// Session session = (Session) THREAD_LOCAL.get();
+// if (session != null) {
+// Logger.warn("Previous MOASession session has not been closed; closing session now.");
+// closeSession();
+// }
+// Logger.debug("Opening new MOASession hibernate session...");
+// try {
+// session = dbSessionSessionFactory.openSession();
+// THREAD_LOCAL.set(session);
+// } catch (HibernateException hex) {
+// Logger.error(hex.getMessage());
+// }
+// return session;
}
/**
@@ -130,61 +137,63 @@ public final class MOASessionDBUtils {
* occurs.
*/
@SuppressWarnings("unchecked")
- public static void closeSession() {
- if (automaticSessionHandling) {
- Logger.warn("Session is being automatically handled by hibernate. Therefore the current session cannot be closed on demand.");
- return;
- }
- Logger.debug("Closing current MOASession hibernate session...");
- Session session = (Session) THREAD_LOCAL.get();
- THREAD_LOCAL.set(null);
- if (session != null) {
- try {
- session.close();
-
- } catch (HibernateException hex) {
- Logger.error(hex.getMessage());
- }
- }
+ public void closeSession() {
+ return;
+// if (automaticSessionHandling) {
+// Logger.warn("Session is being automatically handled by hibernate. Therefore the current session cannot be closed on demand.");
+// return;
+// }
+// Logger.debug("Closing current MOASession hibernate session...");
+// Session session = (Session) THREAD_LOCAL.get();
+// THREAD_LOCAL.set(null);
+// if (session != null) {
+// try {
+// session.close();
+//
+// } catch (HibernateException hex) {
+// Logger.error(hex.getMessage());
+// }
+// }
}
- public static boolean saveOrUpdate(Object dbo) throws MOADatabaseException {
- Transaction tx = null;
+ public boolean saveOrUpdate(Object dbo) throws MOADatabaseException {
+ // Transaction tx = null;
try {
- Session session = MOASessionDBUtils.getCurrentSession();
-
- synchronized (session) {
- tx = session.beginTransaction();
- session.saveOrUpdate(dbo);
- tx.commit();
- }
- return true;
+ Session session = sessionFactory.getCurrentSession();
+ session.saveOrUpdate(dbo);
+ return true;
+//
+// synchronized (session) {
+// tx = session.beginTransaction();
+// session.saveOrUpdate(dbo);
+// tx.commit();
+// }
+// return true;
} catch(HibernateException e) {
Logger.warn("Error during MOASession database saveOrUpdate. Rollback.", e);
- if (tx != null)
- tx.rollback();
+
throw new MOADatabaseException(e);
}
}
- public static boolean delete(Object dbo) {
- Transaction tx = null;
+ public boolean delete(Object dbo) {
+ //Transaction tx = null;
try {
- Session session = MOASessionDBUtils.getCurrentSession();
-
- synchronized (session) {
- tx = session.beginTransaction();
- session.delete(dbo);
- tx.commit();
- }
+ Session session = sessionFactory.getCurrentSession();
+ session.delete(dbo);
+// synchronized (session) {
+// tx = session.beginTransaction();
+// session.delete(dbo);
+// tx.commit();
+// }
return true;
} catch(HibernateException e) {
Logger.warn("Error during MOASession database delete. Rollback.", e);
- if (tx != null)
- tx.rollback();
+// if (tx != null)
+// tx.rollback();
return false;
}
}
diff --git a/id/server/moa-id-spring-initializer/src/main/java/at/gv/egovernment/moa/id/auth/MOAIDAuthSpringResourceProvider.java b/id/server/moa-id-spring-initializer/src/main/java/at/gv/egovernment/moa/id/auth/MOAIDAuthSpringResourceProvider.java
index 47857bcfb..bfa1baddd 100644
--- a/id/server/moa-id-spring-initializer/src/main/java/at/gv/egovernment/moa/id/auth/MOAIDAuthSpringResourceProvider.java
+++ b/id/server/moa-id-spring-initializer/src/main/java/at/gv/egovernment/moa/id/auth/MOAIDAuthSpringResourceProvider.java
@@ -40,10 +40,11 @@ public class MOAIDAuthSpringResourceProvider implements SpringResourceProvider {
public Resource[] getResourcesToLoad() {
ClassPathResource moaidauthConfig = new ClassPathResource("/moaid.configuration.beans.xml", MOAIDAuthInitializer.class);
ClassPathResource configurationDBConfig = new ClassPathResource("/configuration.beans.xml", MOAIDAuthInitializer.class);
- ClassPathResource moaIdAuthBeans = new ClassPathResource("/moaid.authentication.beans.xml", MOAIDAuthInitializer.class);
+ ClassPathResource moaIdAuthBeans = new ClassPathResource("/moaid.authentication.beans.xml", MOAIDAuthInitializer.class);
+ ClassPathResource moaSessionCommonBeans = new ClassPathResource("/session.common.beans.xml", MOAIDAuthInitializer.class);
ClassPathResource moaSessionDBBeans = new ClassPathResource("/session.db.beans.xml", MOAIDAuthInitializer.class);
ClassPathResource moaSessionRedisBeans = new ClassPathResource("/session.redis.beans.xml", MOAIDAuthInitializer.class);
- return new Resource[] {configurationDBConfig, moaidauthConfig, moaIdAuthBeans, moaSessionDBBeans, moaSessionRedisBeans};
+ return new Resource[] {configurationDBConfig, moaidauthConfig, moaIdAuthBeans, moaSessionDBBeans, moaSessionRedisBeans, moaSessionCommonBeans};
}