diff options
| author | Christian Maierhofer <cmaierhofer@iaik.tugraz.at> | 2016-05-03 11:38:51 +0200 | 
|---|---|---|
| committer | Christian Maierhofer <cmaierhofer@iaik.tugraz.at> | 2016-05-03 11:38:51 +0200 | 
| commit | 42e40bb58ec9b4c6b7a474e058e79d366548a520 (patch) | |
| tree | 3fdadd523377a3f37a6b069823679c4da78d2474 /id/server/idserverlib | |
| parent | 61661f2ea4978d56691f7a672469c6d43e9dba41 (diff) | |
| download | moa-id-spss-42e40bb58ec9b4c6b7a474e058e79d366548a520.tar.gz moa-id-spss-42e40bb58ec9b4c6b7a474e058e79d366548a520.tar.bz2 moa-id-spss-42e40bb58ec9b4c6b7a474e058e79d366548a520.zip | |
Added Transactional Support to MOASessionDBUtils
Diffstat (limited to 'id/server/idserverlib')
3 files changed, 68 insertions, 85 deletions
| 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 cb470a7b9..4d7936f25 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 @@ -35,6 +35,7 @@ import org.hibernate.Transaction;  import org.hibernate.resource.transaction.spi.TransactionStatus;  import org.springframework.beans.factory.annotation.Autowired;  import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional;  import com.fasterxml.jackson.core.JsonProcessingException; @@ -74,7 +75,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt  		AuthenticatedSessionStore session;  		try { -			session = searchInDatabase(moaSessionID, true); +			session = searchInDatabase(moaSessionID);  			return session.isAuthenticated();  		} catch (MOADatabaseException e) { @@ -128,7 +129,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt  			return null;  		try { -			AuthenticatedSessionStore dbsession = searchInDatabase(sessionID, true); +			AuthenticatedSessionStore dbsession = searchInDatabase(sessionID);  			return decryptSession(dbsession);  		} catch (MOADatabaseException e) { @@ -143,7 +144,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt  	@Override  	public AuthenticationSessionExtensions getAuthenticationSessionExtensions(String sessionID) throws MOADatabaseException { -		AuthenticatedSessionStore dbsession = searchInDatabase(sessionID, true); +		AuthenticatedSessionStore dbsession = searchInDatabase(sessionID);  		if (MiscUtil.isNotEmpty(dbsession.getAdditionalInformation())) {  			try { @@ -161,7 +162,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt  	@Override  	public void setAuthenticationSessionExtensions(String sessionID, AuthenticationSessionExtensions sessionExtensions) throws MOADatabaseException {  		try { -			AuthenticatedSessionStore dbsession = searchInDatabase(sessionID, true); +			AuthenticatedSessionStore dbsession = searchInDatabase(sessionID);  			dbsession.setAdditionalInformation(  					mapper.serialize(sessionExtensions)); @@ -185,7 +186,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt  	@Override  	public void storeSession(AuthenticationSession session) throws MOADatabaseException, BuildException {  		try { -			AuthenticatedSessionStore dbsession = searchInDatabase(session.getSessionID(), true); +			AuthenticatedSessionStore dbsession = searchInDatabase(session.getSessionID());  			encryptSession(session, dbsession); @@ -216,6 +217,8 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt  				  Query query = session.getNamedQuery("getSessionWithID");  				  query.setParameter("sessionid", moaSessionID);  				  result = query.list(); +				   +				    				  Logger.trace("Found entries: " + result.size()); @@ -243,7 +246,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt  	@Override  	public String changeSessionID(AuthenticationSession session, String newSessionID) throws BuildException, MOADatabaseException  { -		AuthenticatedSessionStore dbsession = searchInDatabase(session.getSessionID(), true); +		AuthenticatedSessionStore dbsession = searchInDatabase(session.getSessionID());  		Logger.debug("Change SessionID from " + session.getSessionID()   				+ "to " + newSessionID); @@ -279,7 +282,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt  		AuthenticatedSessionStore session;  		try { -			session = searchInDatabase(moaSessionID, true); +			session = searchInDatabase(moaSessionID);  			session.setAuthenticated(isAuthenticated);  			moaSessionDBUtils.saveOrUpdate(session); @@ -331,7 +334,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt  	@Override  	public boolean isSSOSession(String sessionID) throws MOADatabaseException {  		try { -			AuthenticatedSessionStore dbsession = searchInDatabase(sessionID, true); +			AuthenticatedSessionStore dbsession = searchInDatabase(sessionID);  			return dbsession.isSSOSession();  		} catch (MOADatabaseException e) { @@ -487,63 +490,63 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt  	@Override  	public List<OASessionStore> getAllActiveOAFromMOASession(AuthenticationSession moaSession) {  		MiscUtil.assertNotNull(moaSession, "MOASession"); -		Session session = null; -		 -		try { -			List<OASessionStore> oas = new ArrayList<OASessionStore>(); -			 -			AuthenticatedSessionStore dbsession = searchInDatabase(moaSession.getSessionID(), false); -			oas.addAll(dbsession.getActiveOAsessions()); -			 -			session = moaSessionDBUtils.getCurrentSession(); -			session.getTransaction().commit(); -			 -			return oas; -			 -		} catch (MOADatabaseException e) { -			Logger.warn("NO session information found for sessionID " + moaSession.getSessionID(), e); -			 -		} catch (Exception e) { -			if (session != null && session.getTransaction() != null  -					&& !session.getTransaction().getStatus().equals(TransactionStatus.COMMITTED)) { -				session.getTransaction().rollback(); -				throw e; -				 -			} -			 -		} -				 -		return null; + +		  Logger.trace("Get OAs for moaSession " + moaSession.getSessionID() + " from database."); +		  Session session = moaSessionDBUtils.getCurrentSession(); +		   +		  List<OASessionStore> result; +		  Transaction tx = null; +		  try {	 +			  synchronized (session) { +				  tx = session.beginTransaction(); +				  Query query = session.getNamedQuery("getAllActiveOAsForSessionID"); +				  query.setParameter("sessionID", moaSession.getSessionID()); +				  result = query.list(); +				   +				  //send transaction +				  tx.commit(); +			  } +			   +			  Logger.trace("Found entries: " + result.size()); +			   +			  return result; +			   +		  } catch (Exception e) { +			  if (tx != null && !tx.getStatus().equals(TransactionStatus.COMMITTED)) +				  tx.rollback(); +			  throw e; +		  }  	}  	@Override  	public List<InterfederationSessionStore> getAllActiveIDPsFromMOASession(AuthenticationSession moaSession) {  		MiscUtil.assertNotNull(moaSession, "MOASession"); -		Session session = null; -		try { -			List<InterfederationSessionStore> idps = new ArrayList<InterfederationSessionStore>();			 -			AuthenticatedSessionStore dbsession = searchInDatabase(moaSession.getSessionID(), false); -			idps.addAll(dbsession.getInderfederation()); -			 -			session = moaSessionDBUtils.getCurrentSession(); -			session.getTransaction().commit(); -			 -			return idps; -			 -		} catch (MOADatabaseException e) { -			Logger.warn("NO session information found for sessionID " + moaSession.getSessionID(), e); -			 -		} catch (Exception e) { -			if (session != null && session.getTransaction() != null  -					&& !session.getTransaction().getStatus().equals(TransactionStatus.COMMITTED)) { -				session.getTransaction().rollback(); -				throw e; -				 -			} -			 -		} -				 -		return null; + +		  Logger.trace("Get active IDPs for moaSession " + moaSession.getSessionID() + " from database."); +		  Session session = moaSessionDBUtils.getCurrentSession(); +		   +		  List<InterfederationSessionStore> result; +		  Transaction tx = null; +		  try {	 +			  synchronized (session) { +				  tx = session.beginTransaction(); +				  Query query = session.getNamedQuery("getAllActiveIDPsForSessionID"); +				  query.setParameter("sessionID", moaSession.getSessionID()); +				  result = query.list(); +				   +				  //send transaction +				  tx.commit(); +			  } +			   +			  Logger.trace("Found entries: " + result.size()); +			   +			  return result; +			   +		  } catch (Exception e) { +			  if (tx != null && !tx.getStatus().equals(TransactionStatus.COMMITTED)) +				  tx.rollback(); +			  throw e; +		  }  	}  	@Override @@ -756,7 +759,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt  		String moaSession = getMOASessionSSOID(req.getMOASessionIdentifier());		  		if (MiscUtil.isNotEmpty(moaSession)) {  			try { -				dbsession = searchInDatabase(moaSession, true); +				dbsession = searchInDatabase(moaSession);  			}catch (MOADatabaseException e) {  				Logger.error("NO MOASession found but MOASession MUST already exist!"); @@ -988,7 +991,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt  	}  	@SuppressWarnings("rawtypes") -	private  AuthenticatedSessionStore searchInDatabase(String sessionID, boolean commit) throws MOADatabaseException { +	private  AuthenticatedSessionStore searchInDatabase(String sessionID) throws MOADatabaseException {  		  MiscUtil.assertNotNull(sessionID, "moasessionID");	    		  Logger.trace("Get authenticated session with sessionID " + sessionID + " from database.");  		  Session session = moaSessionDBUtils.getCurrentSession(); @@ -1003,8 +1006,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt  				  result = query.list();  				  //send transaction -				  if (commit) -					  tx.commit(); +				  tx.commit();  			  }  			  Logger.trace("Found entries: " + result.size()); @@ -1019,7 +1021,7 @@ public class DBAuthenticationSessionStoreage implements IAuthenticationSessionSt  			  return (AuthenticatedSessionStore) result.get(0);  		  } catch (Exception e) { -				if (tx != null && !tx.getStatus().equals(TransactionStatus.COMMITTED) && commit) +				if (tx != null && !tx.getStatus().equals(TransactionStatus.COMMITTED))  					tx.rollback();  				throw e;  		}	 diff --git a/id/server/idserverlib/src/main/resources/session.common.beans.xml b/id/server/idserverlib/src/main/resources/session.common.beans.xml index abc3c3200..300bbd463 100644 --- a/id/server/idserverlib/src/main/resources/session.common.beans.xml +++ b/id/server/idserverlib/src/main/resources/session.common.beans.xml @@ -1,5 +1,5 @@  <?xml version="1.0" encoding="UTF-8"?> -<beans profile="redis" +<beans       xmlns="http://www.springframework.org/schema/beans"  	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  	xmlns:context="http://www.springframework.org/schema/context" diff --git a/id/server/idserverlib/src/main/resources/session.db.beans.xml b/id/server/idserverlib/src/main/resources/session.db.beans.xml index 0aeb24bac..18849c3f1 100644 --- a/id/server/idserverlib/src/main/resources/session.db.beans.xml +++ b/id/server/idserverlib/src/main/resources/session.db.beans.xml @@ -20,25 +20,6 @@  	<!-- MYSQL Conector -->  	<tx:annotation-driven transaction-manager="sessionTransactionManager"/> -	<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="sessionJpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">  		<property name="showSql" value="${moasession.hibernate.show_sql}" />  		<property name="generateDdl" value="${moasession.jpaVendorAdapter.generateDdl}" /> | 
