From 8b4b3a97cdbdfc4158781982f6e9fc2900871198 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Fri, 17 Jan 2014 11:56:10 +0100 Subject: Exthex Version 0.2 --- .../gv/egovernment/moa/id/moduls/SSOManager.java | 140 +++++++++++---------- 1 file changed, 75 insertions(+), 65 deletions(-) (limited to 'id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/moduls/SSOManager.java') 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 7008239ab..0693aef8c 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 @@ -23,41 +23,41 @@ public class SSOManager { private static final String SSOCOOKIE = "MOA_ID_SSO"; - private static final int DEFAULTSSOTIMEOUT = 15*60; //sec + private static final int DEFAULTSSOTIMEOUT = 15 * 60; // sec private static SSOManager instance = null; private static int sso_timeout; - public static SSOManager getInstance() { if (instance == null) { instance = new SSOManager(); try { sso_timeout = (int) AuthConfigurationProvider.getInstance().getTimeOuts().getMOASessionUpdated().longValue(); - - } catch (ConfigurationException e) { + + } + catch (ConfigurationException e) { Logger.info("SSO Timeout can not be loaded from MOA-ID configuration. Use default Timeout with " + DEFAULTSSOTIMEOUT); sso_timeout = DEFAULTSSOTIMEOUT; } - + } return instance; } public boolean isValidSSOSession(String ssoSessionID, HttpServletRequest httpReq) { - - //search SSO Session + + // search SSO Session if (ssoSessionID == null) { Logger.info("No SSO Session cookie found."); - return false; + return false; } -// String moaSessionId =HTTPSessionUtils.getHTTPSessionString(httpReq.getSession(), -// AuthenticationManager.MOA_SESSION, null); + // String moaSessionId =HTTPSessionUtils.getHTTPSessionString(httpReq.getSession(), + // AuthenticationManager.MOA_SESSION, null); - return AuthenticationSessionStoreage.isValidSessionWithSSOID(ssoSessionID, null); + return AuthenticationSessionStoreage.isValidSessionWithSSOID(ssoSessionID, null); } @@ -67,51 +67,65 @@ public class SSOManager { public String existsOldSSOSession(String ssoId) { - Logger.trace("Check that the SSOID has already been used"); - Session session = MOASessionDBUtils.getCurrentSession(); - - List result; - - synchronized (session) { - session.beginTransaction(); - Query query = session.getNamedQuery("getSSOSessionWithOldSessionID"); - query.setString("sessionid", ssoId); - result = query.list(); - - //send transaction - - } - - Logger.trace("Found entries: " + result.size()); - - //Assertion requires an unique artifact - if (result.size() == 0) { - session.getTransaction().commit(); - return null; - } - - OldSSOSessionIDStore oldSSOSession = result.get(0); - - AuthenticatedSessionStore correspondingMoaSession = oldSSOSession.getMoasession(); - - if (correspondingMoaSession == null) { - Logger.info("Get request with old SSO SessionID but no corresponding SSO Session is found."); - return null; - } - - - String moasessionid = correspondingMoaSession.getSessionid(); - - session.getTransaction().commit(); + Logger.trace("Check that the SSOID has already been used"); + Session session = MOASessionDBUtils.getCurrentSession(); + + List result; + + synchronized (session) { - return moasessionid; - +// try { +// session.getTransaction().rollback(); +// } +// catch (Exception e) { +// e.printStackTrace(); +// } +// try { +// session.getSessionFactory().openSession(); +// } +// catch (Exception e) { +// e.printStackTrace(); +// } + // session.getTransaction().begin(); + + session.beginTransaction(); + Query query = session.getNamedQuery("getSSOSessionWithOldSessionID"); + query.setString("sessionid", ssoId); + result = query.list(); + + // send transaction + + } + + Logger.trace("Found entries: " + result.size()); + + // Assertion requires an unique artifact + if (result.size() == 0) { + session.getTransaction().commit(); + return null; + } + + OldSSOSessionIDStore oldSSOSession = result.get(0); + + AuthenticatedSessionStore correspondingMoaSession = oldSSOSession.getMoasession(); + + if (correspondingMoaSession == null) { + Logger.info("Get request with old SSO SessionID but no corresponding SSO Session is found."); + return null; + } + + String moasessionid = correspondingMoaSession.getSessionid(); + + session.getTransaction().commit(); + + return moasessionid; + } public String createSSOSessionInformations(String moaSessionID, String OAUrl) { String newSSOId = Random.nextRandom(); - + System.out.println("generate new SSO Tokken (" + newSSOId + ")"); if (MiscUtil.isEmpty(moaSessionID) || MiscUtil.isEmpty(OAUrl)) { @@ -123,32 +137,30 @@ public class SSOManager { } - public void setSSOSessionID(HttpServletRequest httpReq, HttpServletResponse httpResp, String ssoId) { Cookie[] cookies = httpReq.getCookies(); if (cookies != null) { - deleteSSOSessionID(httpReq, httpResp); + deleteSSOSessionID(httpReq, httpResp); } Cookie cookie = new Cookie(SSOCOOKIE, ssoId); cookie.setMaxAge(sso_timeout); cookie.setSecure(true); - cookie.setPath(httpReq.getContextPath()); - httpResp.addCookie(cookie); + cookie.setPath(httpReq.getContextPath()); + httpResp.addCookie(cookie); } - - public String getSSOSessionID(HttpServletRequest httpReq) { - Cookie[] cookies = httpReq.getCookies(); + Cookie[] cookies = httpReq.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { - //funktioniert nicht, da Cookie seltsamerweise immer unsecure übertragen wird (firefox) - //if (cookie.getName().equals(SSOCOOKIE) && cookie.getSecure()) { - + // funktioniert nicht, da Cookie seltsamerweise immer unsecure übertragen wird + // (firefox) + // if (cookie.getName().equals(SSOCOOKIE) && cookie.getSecure()) { + if (cookie.getName().equals(SSOCOOKIE)) { return cookie.getValue(); } @@ -158,14 +170,12 @@ public class SSOManager { } public void deleteSSOSessionID(HttpServletRequest httpReq, HttpServletResponse httpResp) { - Cookie[] cookies = httpReq.getCookies(); - + Cookie[] cookies = httpReq.getCookies(); + if (cookies != null) { for (Cookie cookie : cookies) { - if (!cookie.getName().equals(SSOCOOKIE)) - httpResp.addCookie(cookie); + if (!cookie.getName().equals(SSOCOOKIE)) httpResp.addCookie(cookie); } } } } - -- cgit v1.2.3