Search in sources :

Example 21 with Session

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

the class SMProfileModelImpl method getValidSessions.

private Map<String, Session> getValidSessions(Session session, String pattern) throws AMConsoleException {
    Map<String, Session> sessions = Collections.emptyMap();
    try {
        SearchResults result = session.getValidSessions(serverName, pattern);
        Map<String, Session> validSessions = result.getResultAttributes();
        if ((validSessions != null) && !validSessions.isEmpty()) {
            sessions = new HashMap<String, Session>(validSessions.size());
            for (Session s : validSessions.values()) {
                if (s != null) {
                    sessions.put(s.getID().toString(), s);
                }
            }
        }
    } catch (SessionException se) {
        throw new AMConsoleException(getErrorString(se));
    }
    return sessions;
}
Also used : SessionException(com.iplanet.dpro.session.SessionException) SearchResults(com.sun.identity.common.SearchResults) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) Session(com.iplanet.dpro.session.Session)

Example 22 with Session

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

the class SMProfileModelImpl method invalidateSessions.

public List<String> invalidateSessions(List<String> list, String pattern) throws AMConsoleException {
    List<String> failList = Collections.emptyList();
    if ((list != null) && !list.isEmpty()) {
        Session session = getCurrentSession();
        Map<String, Session> validSessions = getValidSessions(session, pattern);
        list.retainAll(validSessions.keySet());
        if (!list.isEmpty()) {
            String currentSessionHandler = null;
            try {
                currentSessionHandler = session.getProperty(SESSION_HANDLE_PROP);
            } catch (SessionException se) {
                throw new AMConsoleException(getErrorString(se));
            }
            String[] params = new String[2];
            params[0] = serverName;
            String curSessionId = null;
            failList = new ArrayList<String>(list.size());
            for (String sessionId : list) {
                Session s = validSessions.get(sessionId);
                params[1] = sessionId;
                boolean isCurrentSession = false;
                try {
                    isCurrentSession = currentSessionHandler.equals(s.getProperty(SESSION_HANDLE_PROP));
                } catch (SessionException se) {
                    logEvent("SESSION_EXCEPTION_INVALIDATE_SESSIONS", params);
                    throw new AMConsoleException(getErrorString(se));
                }
                if (isCurrentSession) {
                    curSessionId = sessionId;
                    validSession = false;
                } else {
                    try {
                        logEvent("ATTEMPT_INVALIDATE_SESSIONS", params);
                        session.destroySession(s);
                        logEvent("SUCCEED_INVALIDATE_SESSIONS", params);
                    } catch (SessionException se) {
                        String[] paramsEx = { serverName, sessionId, getErrorString(se) };
                        logEvent("SESSION_EXCEPTION_INVALIDATE_SESSIONS", paramsEx);
                        try {
                            failList.add(s.getProperty(USER_ID));
                        } catch (SessionException e) {
                            debug.error("SMProfileModelImpl.invalidateSessions", e);
                        }
                        debug.error("SMProfileModelImpl.invalidateSessions", se);
                    }
                }
            }
            if (!validSession) {
                params[1] = curSessionId;
                logEvent("ATTEMPT_INVALIDATE_SESSIONS", params);
                try {
                    session.destroySession(session);
                    logEvent("SUCCEED_INVALIDATE_SESSIONS", params);
                } catch (SessionException se) {
                    String[] paramsEx = { serverName, curSessionId, getErrorString(se) };
                    logEvent("SESSION_EXCEPTION_INVALIDATE_SESSIONS", paramsEx);
                }
            }
        }
    }
    return failList;
}
Also used : SessionException(com.iplanet.dpro.session.SessionException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) Session(com.iplanet.dpro.session.Session)

Example 23 with Session

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

the class SSOProviderImpl method createSSOToken.

/**
     * Creates a single sign on token.
     *
     * @param tokenId       single sign on token ID.
     * @param invokedByAuth boolean flag indicating that this method has been invoked by the AuthContext.getSSOToken()
     * API.
     * @param possiblyResetIdleTime If true, the idle time of the token/session may be reset to zero.  If false, the
     * idle time will never be reset.
     * @return single sign on token.
     * @throws SSOException if the single sign on token cannot be created for any reason.
     * @throws java.lang.UnsupportedOperationException only here to satisfy the interface, this is never thrown.
     */
public SSOToken createSSOToken(String tokenId, boolean invokedByAuth, boolean possiblyResetIdleTime) throws SSOException, UnsupportedOperationException {
    try {
        SessionID sessionId = new SessionID(tokenId);
        sessionId.setComingFromAuth(invokedByAuth);
        Session session = sessionCache.getSession(sessionId, false, possiblyResetIdleTime);
        SSOToken ssoToken = new SSOTokenImpl(session);
        return ssoToken;
    } catch (Exception e) {
        if (debug.messageEnabled()) {
            debug.message("SSOProviderImpl.createSSOToken(tokenId, " + invokedByAuth + ", " + possiblyResetIdleTime + ") could not create SSOToken for token ID \"" + tokenId + "\" (" + e.getMessage() + ")");
        }
        throw new SSOException(e);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) 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 24 with Session

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

the class SSOProviderImpl method logout.

@Override
public void logout(final SSOToken token) throws SSOException {
    try {
        Session session = sessionCache.getSession(new SessionID(token.getTokenID().toString()));
        session.logout();
    } catch (SessionException e) {
        if (debug.messageEnabled()) {
            debug.message("Logout: ", e);
        }
        throw new SSOException(e);
    }
}
Also used : SessionException(com.iplanet.dpro.session.SessionException) SSOException(com.iplanet.sso.SSOException) SessionID(com.iplanet.dpro.session.SessionID) Session(com.iplanet.dpro.session.Session)

Example 25 with Session

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

the class SSOProviderImpl method createSSOToken.

/**
     * Creates a single sign on token.
     *
     * @param tokenId  single sign on token ID.
     * @param clientIP client IP address
     * @return single sign on token.
     * @throws SSOException                  if the single sign on token cannot be created.
     * @throws UnsupportedOperationException Thrown to indicate that the
     *                                       requested operation is not supported.
     * @deprecated Use #createSSOToken(String, String)
     */
public SSOToken createSSOToken(String tokenId, String clientIP) throws SSOException, UnsupportedOperationException {
    try {
        SessionID sessionId = new SessionID(tokenId);
        Session session = sessionCache.getSession(sessionId);
        if (checkIP && !isIPValid(session, clientIP)) {
            throw new Exception(SSOProviderBundle.getString("invalidIP"));
        }
        SSOToken ssoToken = new SSOTokenImpl(session);
        return ssoToken;
    } catch (Exception e) {
        if (debug.messageEnabled()) {
            debug.message("could not create SSOToken for token ID \"" + tokenId + "\" (" + e.getMessage() + ")");
        }
        throw new SSOException(e);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) 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)

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