Search in sources :

Example 1 with SessionResponse

use of com.iplanet.dpro.session.share.SessionResponse 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 2 with SessionResponse

use of com.iplanet.dpro.session.share.SessionResponse 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 3 with SessionResponse

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

the class Requests method getSessionResponseWithRetry.

/**
     * Sends remote session request without retries.
     *
     * @param svcurl Session Service URL.
     * @param sreq Session Request object.
     * @exception SessionException
     */
public SessionResponse getSessionResponseWithRetry(URL svcurl, SessionRequest sreq, Session session) throws SessionException {
    SessionResponse sres;
    Object context = RestrictedTokenContext.getCurrent();
    SSOToken appSSOToken = null;
    if (!SystemProperties.isServerMode() && !(session.getID().getComingFromAuth())) {
        appSSOToken = AccessController.doPrivileged(AdminTokenAction.getInstance());
        session.createContext(appSSOToken);
    }
    try {
        if (context != null) {
            sreq.setRequester(RestrictedTokenContext.marshal(context));
        }
        sres = pllSender.sendPLLRequest(svcurl, sreq);
        while (sres.getException() != null) {
            session.processSessionResponseException(sres, appSSOToken);
            context = session.getContext();
            if (context != null) {
                sreq.setRequester(RestrictedTokenContext.marshal(context));
            }
            // send request again
            sres = pllSender.sendPLLRequest(svcurl, sreq);
        }
    } catch (Exception e) {
        throw new SessionException(e);
    }
    return sres;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SessionResponse(com.iplanet.dpro.session.share.SessionResponse)

Example 4 with SessionResponse

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

the class RemoteOperations method refresh.

/**
     *
     * @param session The Session to update.
     * @param reset If true, then update the last modified timestamp of the Session.
     * @return
     * @throws SessionException
     */
public SessionInfo refresh(Session session, boolean reset) throws SessionException {
    SessionID sessionID = session.getID();
    if (debug.messageEnabled()) {
        debug.message(MessageFormat.format("Remote fetch SessionInfo for {0}\n" + "Reset: {1}", sessionID, reset));
    }
    SessionRequest sreq = new SessionRequest(SessionRequest.GetSession, sessionID.toString(), reset);
    SessionResponse sres = requests.sendRequestWithRetry(session.getSessionServiceURL(), sreq, session);
    if (sres.getException() != null) {
        throw new SessionException(SessionBundle.rbName, INVALID_SESSION_STATE, null);
    }
    List<SessionInfo> infos = sres.getSessionInfo();
    if (infos.size() != 1) {
        throw new SessionException(SessionBundle.rbName, UNEXPECTED_SESSION, null);
    }
    return infos.get(0);
}
Also used : SessionException(com.iplanet.dpro.session.SessionException) SessionInfo(com.iplanet.dpro.session.share.SessionInfo) SessionResponse(com.iplanet.dpro.session.share.SessionResponse) SessionID(com.iplanet.dpro.session.SessionID) SessionRequest(com.iplanet.dpro.session.share.SessionRequest)

Example 5 with SessionResponse

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

the class SessionRequestHandler method processRequest.

private Response processRequest(final PLLAuditor auditor, final Request req, final HttpServletRequest servletRequest, final HttpServletResponse servletResponse) {
    final SessionRequest sreq = SessionRequest.parseXML(req.getContent());
    auditor.setMethod(sreq.getMethodName());
    SessionResponse sres = new SessionResponse(sreq.getRequestID(), sreq.getMethodID());
    Object context;
    try {
        // use remote client IP as default RestrictedToken context
        context = SessionUtils.getClientAddress(servletRequest);
        this.clientToken = null;
    } catch (Exception ex) {
        sessionDebug.error("SessionRequestHandler encounterd exception", ex);
        sres.setException(ex.getMessage());
        return auditedExceptionResponse(auditor, sres);
    }
    String requester = sreq.getRequester();
    if (requester != null) {
        try {
            context = RestrictedTokenContext.unmarshal(requester);
            if (context instanceof SSOToken) {
                SSOTokenManager ssoTokenManager = SSOTokenManager.getInstance();
                SSOToken adminToken = (SSOToken) context;
                if (!ssoTokenManager.isValidToken(adminToken)) {
                    sres.setException(SessionBundle.getString("appTokenInvalid") + requester);
                    return auditedExceptionResponse(auditor, sres);
                }
                this.clientToken = (SSOToken) context;
            }
        } catch (Exception ex) {
            if (sessionDebug.warningEnabled()) {
                sessionDebug.warning("SessionRequestHandler.processRequest:" + "app token invalid, sending Session response" + " with Exception");
            }
            sres.setException(SessionBundle.getString("appTokenInvalid") + requester);
            return auditedExceptionResponse(auditor, sres);
        }
    }
    try {
        sres = (SessionResponse) RestrictedTokenContext.doUsing(context, new RestrictedTokenAction() {

            public Object run() throws Exception {
                return processSessionRequest(auditor, sreq, servletRequest, servletResponse);
            }
        });
    } catch (Exception ex) {
        sessionDebug.error("SessionRequestHandler encounterd exception", ex);
        sres.setException(ex.getMessage());
    }
    if (sres.getException() == null) {
        auditor.auditAccessSuccess();
    } else {
        auditor.auditAccessFailure(sres.getException());
    }
    return new Response(sres.toXMLString());
}
Also used : SSOTokenManager(com.iplanet.sso.SSOTokenManager) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(com.iplanet.services.comm.share.Response) SessionResponse(com.iplanet.dpro.session.share.SessionResponse) SSOToken(com.iplanet.sso.SSOToken) SessionResponse(com.iplanet.dpro.session.share.SessionResponse) SessionRequest(com.iplanet.dpro.session.share.SessionRequest) SessionException(com.iplanet.dpro.session.SessionException) RestrictedTokenAction(com.sun.identity.session.util.RestrictedTokenAction)

Aggregations

SessionResponse (com.iplanet.dpro.session.share.SessionResponse)12 SessionException (com.iplanet.dpro.session.SessionException)10 SessionRequest (com.iplanet.dpro.session.share.SessionRequest)7 SessionInfo (com.iplanet.dpro.session.share.SessionInfo)5 SessionID (com.iplanet.dpro.session.SessionID)3 SSOToken (com.iplanet.sso.SSOToken)3 URL (java.net.URL)3 Response (com.iplanet.services.comm.share.Response)2 HashMap (java.util.HashMap)2 ThreadPoolException (com.iplanet.am.util.ThreadPoolException)1 Session (com.iplanet.dpro.session.Session)1 Request (com.iplanet.services.comm.share.Request)1 RequestSet (com.iplanet.services.comm.share.RequestSet)1 SSOException (com.iplanet.sso.SSOException)1 SSOTokenManager (com.iplanet.sso.SSOTokenManager)1 SearchResults (com.sun.identity.common.SearchResults)1 RestrictedTokenAction (com.sun.identity.session.util.RestrictedTokenAction)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1