diff options
Diffstat (limited to 'id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/AuthenticationSessionStoreage.java')
-rw-r--r-- | id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/AuthenticationSessionStoreage.java | 111 |
1 files changed, 72 insertions, 39 deletions
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/AuthenticationSessionStoreage.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/AuthenticationSessionStoreage.java index 5da3dd8f6..b00df8a86 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/AuthenticationSessionStoreage.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/storage/AuthenticationSessionStoreage.java @@ -1,11 +1,29 @@ +/******************************************************************************* + * Copyright 2014 Federal Chancellery Austria + * MOA-ID has been developed in a cooperation between BRZ, the Federal + * Chancellery Austria - ICT staff unit, and Graz University of Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + *******************************************************************************/ package at.gv.egovernment.moa.id.storage; -import java.io.Serializable; import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; import java.util.List; -import java.util.Set; import org.apache.commons.lang.SerializationUtils; import org.hibernate.HibernateException; @@ -13,12 +31,10 @@ import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; -import at.gv.egovernment.moa.id.AuthenticationException; -import at.gv.egovernment.moa.id.BuildException; -import at.gv.egovernment.moa.id.MOAIDException; import at.gv.egovernment.moa.id.auth.data.AuthenticationSession; +import at.gv.egovernment.moa.id.auth.exception.AuthenticationException; +import at.gv.egovernment.moa.id.auth.exception.BuildException; import at.gv.egovernment.moa.id.commons.db.MOASessionDBUtils; -import at.gv.egovernment.moa.id.commons.db.dao.session.AssertionStore; import at.gv.egovernment.moa.id.commons.db.dao.session.AuthenticatedSessionStore; import at.gv.egovernment.moa.id.commons.db.dao.session.OASessionStore; import at.gv.egovernment.moa.id.commons.db.dao.session.OldSSOSessionIDStore; @@ -136,7 +152,7 @@ public class AuthenticationSessionStoreage { Session session = MOASessionDBUtils.getCurrentSession(); - List result; + List<AuthenticatedSessionStore> result; synchronized (session) { @@ -163,18 +179,6 @@ public class AuthenticationSessionStoreage { } -// public static void dumpSessionStore() { -// synchronized (sessionStore) { -// Set<String> keys = sessionStore.keySet(); -// Iterator<String> keyIterator = keys.iterator(); -// while(keyIterator.hasNext()) { -// String key = keyIterator.next(); -// AuthenticationSession session = sessionStore.get(key); -// Logger.info("Key: " + key + " -> " + session.toString()); -// } -// } -// } - public static String changeSessionID(AuthenticationSession session) throws AuthenticationException, BuildException { @@ -204,7 +208,7 @@ public class AuthenticationSessionStoreage { } public static void addSSOInformation(String moaSessionID, String SSOSessionID, - String OAUrl) throws AuthenticationException { + String assertionID, String OAUrl) throws AuthenticationException { AuthenticatedSessionStore dbsession; Transaction tx = null; @@ -212,7 +216,7 @@ public class AuthenticationSessionStoreage { try { Session session = MOASessionDBUtils.getCurrentSession(); - List result; + List<AuthenticatedSessionStore> result; synchronized (session) { @@ -227,6 +231,7 @@ public class AuthenticationSessionStoreage { //Assertion requires an unique artifact if (result.size() != 1) { Logger.trace("No entries found."); + tx.rollback(); throw new MOADatabaseException("No session found with this sessionID"); } @@ -237,6 +242,7 @@ public class AuthenticationSessionStoreage { activeOA.setOaurlprefix(OAUrl); activeOA.setMoasession(dbsession); activeOA.setCreated(new Date()); + activeOA.setAssertionSessionID(assertionID); List<OASessionStore> activeOAs = dbsession.getActiveOAsessions(); activeOAs.add(activeOA); @@ -257,12 +263,15 @@ public class AuthenticationSessionStoreage { dbsession.setSSOsessionid(SSOSessionID); dbsession.setAuthenticated(false); dbsession.setPendingRequestID(""); - + //Store MOASession session.saveOrUpdate(dbsession); //send transaction tx.commit(); + + Logger.debug("Add SSO-Session login information for OA: " + OAUrl + + " and AssertionID: " + assertionID); } } catch (MOADatabaseException e) { @@ -293,7 +302,7 @@ public class AuthenticationSessionStoreage { throw new MOADatabaseException("No MOA Session with id: " + sessionID); } catch (Throwable e) { - Logger.warn("MOASession deserialization-exception by using MOASessionID=" + sessionID); + Logger.warn("MOASession deserialization-exception by using MOASessionID=" + sessionID, e); throw new MOADatabaseException("MOASession deserialization-exception"); } } @@ -369,20 +378,6 @@ public class AuthenticationSessionStoreage { } else { return true; - -// AuthenticatedSessionStore dbsession = result.get(0); -// -// -// if (dbsession.getSessionid().equals(moaSessionId) && dbsession.isAuthenticated()) { -// Log.info("Found SSO Session Cookie for MOA Session =" + moaSessionId); -// return true; -// -// } else { -// Log.warn("Found SSO Session with ID="+ dbsession.getSessionid() -// + " but this Session does not match to MOA Sesson ID=" + moaSessionId); -// } -// -// return false; } } @@ -431,6 +426,44 @@ public class AuthenticationSessionStoreage { } + public static AuthenticationSession getSessionWithPendingRequestID(String pedingRequestID) { + + try { + MiscUtil.assertNotNull(pedingRequestID, "pedingRequestID"); + Logger.trace("Get authenticated session with pedingRequestID " + pedingRequestID + " from database."); + Session session = MOASessionDBUtils.getCurrentSession(); + + List<AuthenticatedSessionStore> result; + + synchronized (session) { + session.beginTransaction(); + Query query = session.getNamedQuery("getSessionWithPendingRequestID"); + query.setString("sessionid", pedingRequestID); + result = query.list(); + + //send transaction + session.getTransaction().commit(); + } + + Logger.trace("Found entries: " + result.size()); + + //Assertion requires an unique artifact + if (result.size() != 1) { + Logger.trace("No entries found."); + return null; + } + + //decrypt Session + byte[] decrypted = SessionEncrytionUtil.decrypt(result.get(0).getSession()); + + return (AuthenticationSession) SerializationUtils.deserialize(decrypted); + + } catch (Throwable e) { + Logger.warn("MOASession deserialization-exception by using MOASessionID=" + pedingRequestID); + return null; + } + } + public static void clean(long now, long authDataTimeOutCreated, long authDataTimeOutUpdated) { Date expioredatecreate = new Date(now - authDataTimeOutCreated); Date expioredateupdate = new Date(now - authDataTimeOutUpdated); |