Search in sources :

Example 26 with SessionException

use of com.iplanet.dpro.session.SessionException in project OpenAM by OpenRock.

the class SessionCookies method getLBCookie.

/**
     * Returns load balancer cookie value for the Session.
     * @param  sid Session ID for load balancer cookie.
     * @return load balancer cookie value.
     * @throws SessionException if session is invalid.
     */
public String getLBCookie(SessionID sid) throws SessionException {
    String cookieValue = null;
    lbCookieName = SystemProperties.get(Constants.AM_LB_COOKIE_NAME, "amlbcookie");
    if (sessionDebug.messageEnabled()) {
        sessionDebug.message("Session.getLBCookie()" + "lbCookieName is:" + lbCookieName);
    }
    if (sid == null || StringUtils.isBlank(sid.toString())) {
        throw new SessionException(SessionBundle.rbName, "invalidSessionID", null);
    }
    if (SystemProperties.isServerMode()) {
        SessionService sessionService = InjectorHolder.getInstance(SessionService.class);
        if (!sessionService.isSiteEnabled()) {
            cookieValue = WebtopNaming.getLBCookieValue(sid.getSessionServerID());
            return lbCookieName + "=" + cookieValue;
        }
    }
    if (RESET_LB_COOKIE_NAME) {
        if (SystemProperties.isServerMode()) {
            SessionService sessionService = InjectorHolder.getInstance(SessionService.class);
            if (sessionService.isSessionFailoverEnabled() && sessionService.isLocalSite(sid)) {
                cookieValue = WebtopNaming.getLBCookieValue(sessionService.getCurrentHostServer(sid));
            }
        } else {
            Session sess = sessionCache.readSession(sid);
            if (sess != null) {
                cookieValue = sess.getProperty(lbCookieName);
            }
        }
    }
    if (StringUtils.isBlank(cookieValue)) {
        cookieValue = WebtopNaming.getLBCookieValue(sid.getExtension().getPrimaryID());
    }
    return lbCookieName + "=" + cookieValue;
}
Also used : SessionService(com.iplanet.dpro.session.service.SessionService) SessionException(com.iplanet.dpro.session.SessionException) Session(com.iplanet.dpro.session.Session)

Example 27 with SessionException

use of com.iplanet.dpro.session.SessionException in project OpenAM by OpenRock.

the class SessionPLLSender method sendPLLRequest.

/**
     * Returns a Session Response object based on the XML document received from
     * remote Session Server. This is in response to a request that we send to
     * the session server.
     *
     * @param svcurl The URL of the Session Service.
     * @param sreq The Session Request XML document.
     * @return a Vector of responses from the remote server
     * @exception com.iplanet.dpro.session.SessionException if there was an error in sending the XML
     *            document or if the response has multiple components.
     */
public SessionResponse sendPLLRequest(URL svcurl, SessionRequest sreq) throws SessionException {
    try {
        String cookies = sessionCookies.getCookieName() + "=" + sreq.getSessionID();
        if (!SystemProperties.isServerMode()) {
            SessionID sessionID = new SessionID(sreq.getSessionID());
            cookies = cookies + ";" + sessionCookies.getLBCookie(sessionID);
        }
        final Request req = new Request(sreq.toXMLString());
        final RequestSet set = new RequestSet(SESSION_SERVICE);
        set.addRequest(req);
        final Vector responses = PLLClient.send(svcurl, cookies, set);
        if (responses.size() != 1) {
            throw new SessionException(SessionBundle.rbName, "unexpectedResponse", null);
        }
        final Response res = (Response) responses.elementAt(0);
        return SessionResponse.parseXML(res.getContent());
    } catch (Exception e) {
        throw new SessionException(e);
    }
}
Also used : Response(com.iplanet.services.comm.share.Response) SessionResponse(com.iplanet.dpro.session.share.SessionResponse) RequestSet(com.iplanet.services.comm.share.RequestSet) SessionRequest(com.iplanet.dpro.session.share.SessionRequest) Request(com.iplanet.services.comm.share.Request) SessionException(com.iplanet.dpro.session.SessionException) SessionID(com.iplanet.dpro.session.SessionID) Vector(java.util.Vector) SessionException(com.iplanet.dpro.session.SessionException)

Example 28 with SessionException

use of com.iplanet.dpro.session.SessionException in project OpenAM by OpenRock.

the class SessionPollerSender method run.

public void run() {
    try {
        SessionRequest sreq = new SessionRequest(SessionRequest.GetSession, sid.toString(), false);
        SessionResponse sres = pllSender.sendPLLRequest(session.getSessionServiceURL(), sreq);
        if (sres.getException() != null) {
            sessionCache.removeSID(sid);
            return;
        }
        List<SessionInfo> infos = sres.getSessionInfo();
        if (infos.size() == 1) {
            info = infos.get(0);
        }
    } catch (Exception ex) {
        sessionCache.removeSID(sid);
        if (debug.messageEnabled())
            debug.message("Could not connect to the session server" + ex.getMessage());
    }
    if (info != null) {
        if (debug.messageEnabled()) {
            debug.message("Updating" + info.toXMLString());
        }
        try {
            if (info.getState().equals("invalid") || info.getState().equals("destroyed")) {
                sessionCache.removeSID(sid);
            } else {
                long oldMaxCachingTime = session.getMaxCachingTime();
                long oldMaxIdleTime = session.getMaxIdleTime();
                long oldMaxSessionTime = session.getMaxSessionTime();
                session.update(info);
                if ((!session.isScheduled()) || (oldMaxCachingTime > session.getMaxCachingTime()) || (oldMaxIdleTime > session.getMaxIdleTime()) || (oldMaxSessionTime > session.getMaxSessionTime())) {
                    session.scheduleToTimerPool();
                }
            }
        } catch (SessionException se) {
            sessionCache.removeSID(sid);
            debug.error("Exception encountered while update in polling", se);
        }
    } else {
        sessionCache.removeSID(sid);
    }
    session.setIsPolling(false);
}
Also used : SessionInfo(com.iplanet.dpro.session.share.SessionInfo) SessionException(com.iplanet.dpro.session.SessionException) SessionResponse(com.iplanet.dpro.session.share.SessionResponse) SessionRequest(com.iplanet.dpro.session.share.SessionRequest) SessionException(com.iplanet.dpro.session.SessionException)

Example 29 with SessionException

use of com.iplanet.dpro.session.SessionException in project OpenAM by OpenRock.

the class CDCServlet method redirectWithAuthNResponse.

/**
     * Constructs the Liberty AuthNResponse with Restricted SSOToken
     * and redirects the user to the requested resouce
     */
private void redirectWithAuthNResponse(HttpServletRequest request, HttpServletResponse response, SSOToken token) throws ServletException, IOException {
    String gotoURL = getRedirectURL(request, response);
    if (debug.messageEnabled()) {
        debug.message("CDCServlet.redirectWithAuthNResponse: gotoURL = " + gotoURL);
    }
    if (debug.messageEnabled()) {
        debug.message("CDCServlet.redirectWithAuthNResponse: After encoding: gotoURL = " + gotoURL);
    }
    if (gotoURL != null) {
        try {
            String inResponseTo = request.getParameter(REQUEST_ID);
            String spDescriptor = request.getParameter(PROVIDER_ID);
            String resTokenID = null;
            /**
                 * validateAndGetRestriction throws an exception if an agent
                 * profile with provider id and goto url is not present
                 */
            TokenRestriction tokenRes = spValidator.validateAndGetRestriction(FSAuthnRequest.parseURLEncodedRequest(request), gotoURL);
            if (uniqueCookieEnabled) {
                resTokenID = sessionService.getRestrictedTokenId(token.getTokenID().toString(), tokenRes);
            } else {
                resTokenID = token.getTokenID().toString();
            }
            FSAssertion assertion = createAssertion(spDescriptor, SELF_PROVIDER_ID, resTokenID, token.getAuthType(), token.getProperty("authInstant"), token.getPrincipal().getName(), inResponseTo);
            String relayState = request.getParameter(RELAY_STATE);
            Status status = new Status(new StatusCode(IFSConstants.STATUS_CODE_SUCCESS));
            FSAuthnResponse authnResponse = createAuthnResponse(SELF_PROVIDER_ID, responseID, inResponseTo, status, assertion, relayState);
            sendAuthnResponse(request, response, authnResponse, gotoURL);
        } catch (SAMLException se) {
            debug.error("CDCServlet.doGetPost", se);
            showError(response);
        } catch (FSMsgException fe) {
            debug.error("CDCServlet.doGetPost", fe);
            showError(response);
        } catch (FSException fse) {
            debug.error("CDCServlet.doGetPost", fse);
            showError(response);
        } catch (SessionException e) {
            debug.error("CDCServlet.doGetPost", e);
        } catch (SSOException ssoe) {
            debug.error("CDCServlet.doGetPost", ssoe);
        } catch (Exception e) {
            debug.error("CDCServlet.doGetPost", e);
            spValidator = new LdapSPValidator();
            showError(response, FORBIDDEN_STR_MATCH);
        }
    }
}
Also used : Status(com.sun.identity.saml.protocol.Status) FSMsgException(com.sun.identity.federation.message.common.FSMsgException) TokenRestriction(com.iplanet.dpro.session.TokenRestriction) SessionException(com.iplanet.dpro.session.SessionException) SSOException(com.iplanet.sso.SSOException) StatusCode(com.sun.identity.saml.protocol.StatusCode) SAMLException(com.sun.identity.saml.common.SAMLException) ServletException(javax.servlet.ServletException) ParseException(java.text.ParseException) SSOException(com.iplanet.sso.SSOException) FSMsgException(com.sun.identity.federation.message.common.FSMsgException) SAMLException(com.sun.identity.saml.common.SAMLException) FSException(com.sun.identity.federation.common.FSException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) SessionException(com.iplanet.dpro.session.SessionException) FSAuthnResponse(com.sun.identity.federation.message.FSAuthnResponse) FSAssertion(com.sun.identity.federation.message.FSAssertion) FSException(com.sun.identity.federation.common.FSException)

Example 30 with SessionException

use of com.iplanet.dpro.session.SessionException in project OpenAM by OpenRock.

the class SessionUtils method getTrustedSourceList.

/* build the trust source set*/
private static Set getTrustedSourceList() throws SessionException {
    Set result = new HashSet();
    try {
        String rawList = SystemProperties.get(Constants.TRUSTED_SOURCE_LIST);
        if (rawList != null) {
            StringTokenizer stk = new StringTokenizer(rawList, ",");
            while (stk.hasMoreTokens()) {
                result.add(InetAddress.getByName(stk.nextToken()));
            }
        } else {
            // use platform server list as a default fallback
            Set<String> psl = WebtopNaming.getPlatformServerList();
            if (psl == null) {
                throw new SessionException(SessionBundle.rbName, "emptyTrustedSourceList", null);
            }
            for (String e : psl) {
                try {
                    URL url = new URL(e);
                    result.add(InetAddress.getByName(url.getHost()));
                } catch (Exception ex) {
                    debug.error("SessionUtils.getTrustedSourceList : " + "Validating Host exception", ex);
                }
            }
        }
    } catch (Exception e) {
        throw new SessionException(e);
    }
    return result;
}
Also used : StringTokenizer(java.util.StringTokenizer) HashSet(java.util.HashSet) Set(java.util.Set) SessionException(com.iplanet.dpro.session.SessionException) URL(java.net.URL) SSOException(com.iplanet.sso.SSOException) SessionException(com.iplanet.dpro.session.SessionException) HashSet(java.util.HashSet)

Aggregations

SessionException (com.iplanet.dpro.session.SessionException)60 SessionID (com.iplanet.dpro.session.SessionID)22 Session (com.iplanet.dpro.session.Session)18 SSOException (com.iplanet.sso.SSOException)15 SessionResponse (com.iplanet.dpro.session.share.SessionResponse)9 SessionInfo (com.iplanet.dpro.session.share.SessionInfo)8 URL (java.net.URL)8 Map (java.util.Map)7 Test (org.testng.annotations.Test)7 InternalSession (com.iplanet.dpro.session.service.InternalSession)6 SessionRequest (com.iplanet.dpro.session.share.SessionRequest)6 IdRepoException (com.sun.identity.idm.IdRepoException)6 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)6 DelegationException (com.sun.identity.delegation.DelegationException)5 InterruptedIOException (java.io.InterruptedIOException)5 ConnectException (java.net.ConnectException)5 HashSet (java.util.HashSet)5 Set (java.util.Set)5 TokenRestriction (com.iplanet.dpro.session.TokenRestriction)4 SSOToken (com.iplanet.sso.SSOToken)4