Search in sources :

Example 16 with Session

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

the class SSOProviderImpl method refreshSession.

/**
     * Refresh the Session corresponding to the single sign on token from the
     * Session Server.
     *
     * @param token single sign on token for which session need to be refreshed.
     * @param possiblyResetIdleTime if true, the idle time may be reset, if false it will never be.
     * @throws SSOException if the session cannot be refreshed.
     */
@Override
public void refreshSession(SSOToken token, boolean possiblyResetIdleTime) throws SSOException {
    try {
        SSOTokenID tokenId = token.getTokenID();
        SessionID sid = new SessionID(tokenId.toString());
        Session session = sessionCache.getSession(sid);
        session.refresh(possiblyResetIdleTime);
    } catch (Exception e) {
        debug.error("Error in refreshing the session from sessions server");
        throw new SSOException(e);
    }
}
Also used : SSOTokenID(com.iplanet.sso.SSOTokenID) SSOException(com.iplanet.sso.SSOException) SessionID(com.iplanet.dpro.session.SessionID) SSOException(com.iplanet.sso.SSOException) SessionException(com.iplanet.dpro.session.SessionException) Session(com.iplanet.dpro.session.Session)

Example 17 with Session

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

the class SSOProviderImpl method destroyToken.

/**
     * Destroys a single sign on token.
     *
     * @param destroyer
     *            The single sign on token object used to authorize the
     *            operation
     * @param destroyed
     *            The single sign on token object to be destroyed.
     * @throws SSOException
     *             if the there was an error during communication with session
     *             service.
     *
     * @supported.api
     */
public void destroyToken(SSOToken destroyer, SSOToken destroyed) throws SSOException {
    try {
        Session requester = ((SSOTokenImpl) destroyer).getSession();
        Session target = ((SSOTokenImpl) destroyed).getSession();
        requester.destroySession(target);
    } catch (SessionException e) {
        throw new SSOException(e);
    }
}
Also used : SessionException(com.iplanet.dpro.session.SessionException) SSOException(com.iplanet.sso.SSOException) Session(com.iplanet.dpro.session.Session)

Example 18 with Session

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

the class SessionCache method removeRemoteSID.

/**
     * Wrapper method for {@link #removeSID} only to be called when receiving notification of session
     * destruction from the home server.
     *
     * This method should only be called when the identified session has another instance
     * of OpenAM as its home server.
     *
     * @param info Current state of session on home server
     */
public void removeRemoteSID(SessionInfo info) {
    SessionID sessionID = new SessionID(info.getSessionID());
    long purgeDelay = getPurgeDelayForReducedCrosstalk();
    if (purgeDelay > 0) {
        Session session = readSession(sessionID);
        if (session == null) {
            /**
                 * Reduced crosstalk protection.
                 *
                 * As the indicated session has not yet been loaded, it will be created and added to the
                 * {@link #sessionTable} so that it can remain there in a DESTROYED state until it is purged.
                 */
            session = new Session(sessionID);
            try {
                session.update(info);
                writeSession(session);
            } catch (SessionException e) {
                debug.error("Exception reading remote SessionInfo", e);
            }
        }
        session.setPurgeAt(System.currentTimeMillis() + (purgeDelay * 60 * 1000));
        session.cancel();
        if (!session.isScheduled()) {
            SystemTimerPool.getTimerPool().schedule(session, new Date(session.getPurgeAt()));
        } else {
            debug.error("Unable to schedule destroyed session for purging");
        }
    }
    removeSID(sessionID);
}
Also used : SessionException(com.iplanet.dpro.session.SessionException) SessionID(com.iplanet.dpro.session.SessionID) Date(java.util.Date) Session(com.iplanet.dpro.session.Session)

Example 19 with Session

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

the class SessionCache method getSession.

/**
     * This function will get a session based on the session id.  It will allow invalid sessions to be returned,
     * and allow the caller to specify whether the session can be updated (and therefore have the idle time
     * refreshed).
     *
     * @param sessionID The Session id.
     * @param allowInvalidSessions If true, allow invalid Sessions to be returned.
     * @param possiblyResetIdleTime If true, the idle time of the session can be reset, if false, it is never reset.
     * @return A session object.
     * @throws SessionException If the Session ID object does not contain a
     *         valid session string, or the session string was valid before
     *         but has been destroyed, or there was an error during
     *         communication with session service.
     */
public Session getSession(SessionID sessionID, boolean allowInvalidSessions, boolean possiblyResetIdleTime) throws SessionException {
    if (sessionID.toString() == null || sessionID.toString().length() == 0) {
        throw new SessionException(SessionBundle.rbName, "invalidSessionID", null);
    }
    Session session = readSession(sessionID);
    if (session != null) {
        /**
             * Reduced crosstalk protection.
             *
             * When a user logs out, or the Session is destroyed and crosstalk is reduced, it is possible
             * for a destroyed session to be recovered by accessing it on a remote server. Instead the
             * session will be left in the {@link #sessionTable} until it is purged. This check will
             * detect this condition and indicate to the caller their SessionID is invalid.
             */
        if (session.getState(false) == DESTROYED && getPurgeDelayForReducedCrosstalk() > 0) {
            throw new SessionException("Session is in a destroyed state");
        }
        TokenRestriction restriction = session.getRestriction();
        try {
            if (SystemProperties.isServerMode()) {
                if ((restriction != null) && !restriction.isSatisfied(RestrictedTokenContext.getCurrent())) {
                    throw new SessionException(SessionBundle.rbName, "restrictionViolation", null);
                }
            }
        } catch (Exception e) {
            throw new SessionException(e);
        }
        if (!sessionPollerPool.getCacheBasedPolling() && session.maxCachingTimeReached()) {
            session.refresh(false);
        }
        return session;
    }
    session = new Session(sessionID);
    if (!allowInvalidSessions) {
        session.refresh(possiblyResetIdleTime);
    }
    session.setContext(RestrictedTokenContext.getCurrent());
    writeSession(session);
    if (!sessionPollerPool.isPollingEnabled()) {
        session.addInternalSessionListener();
    }
    return session;
}
Also used : TokenRestriction(com.iplanet.dpro.session.TokenRestriction) SessionException(com.iplanet.dpro.session.SessionException) SessionException(com.iplanet.dpro.session.SessionException) Session(com.iplanet.dpro.session.Session)

Example 20 with Session

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

the class DestroyAllAction method action.

@Override
public boolean action(InternalSession is, Map sessions) {
    Set<String> sids = sessions.keySet();
    debug.message("there are " + sids.size() + " sessions");
    synchronized (sessions) {
        for (String sid : sids) {
            SessionID sessID = new SessionID(sid);
            try {
                Session s = sessionCache.getSession(sessID);
                s.destroySession(s);
                debug.message("Destroy sid " + sessID);
            } catch (SessionException se) {
                if (debug.messageEnabled()) {
                    debug.message("Failed to destroy the next " + "expiring session.", se);
                }
                // in this case
                return true;
            }
        }
    }
    return false;
}
Also used : SessionException(com.iplanet.dpro.session.SessionException) SessionID(com.iplanet.dpro.session.SessionID) Session(com.iplanet.dpro.session.Session) InternalSession(com.iplanet.dpro.session.service.InternalSession)

Aggregations

Session (com.iplanet.dpro.session.Session)31 SessionException (com.iplanet.dpro.session.SessionException)22 SessionID (com.iplanet.dpro.session.SessionID)13 SSOException (com.iplanet.sso.SSOException)7 Test (org.testng.annotations.Test)7 Map (java.util.Map)5 InternalSession (com.iplanet.dpro.session.service.InternalSession)4 BeforeTest (org.testng.annotations.BeforeTest)4 SSOToken (com.iplanet.sso.SSOToken)3 SearchResults (com.sun.identity.common.SearchResults)3 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)3 HashMap (java.util.HashMap)3 StatelessSession (org.forgerock.openam.sso.providers.stateless.StatelessSession)3 URL (java.net.URL)2 Iterator (java.util.Iterator)2 SessionEvent (com.iplanet.dpro.session.SessionEvent)1 TokenRestriction (com.iplanet.dpro.session.TokenRestriction)1 SessionService (com.iplanet.dpro.session.service.SessionService)1 SessionInfo (com.iplanet.dpro.session.share.SessionInfo)1 SessionResponse (com.iplanet.dpro.session.share.SessionResponse)1