Search in sources :

Example 26 with SessionID

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

the class SessionCommand method displaySessions.

private List displaySessions(SSOToken ssoToken) throws CLIException {
    String origHost = getStringOptionValue(ARGUMENT_HOST_NAME);
    String host = trimTrailingSlash(origHost);
    StringTokenizer st = new StringTokenizer(host, ":");
    if (st.countTokens() != 3) {
        Object[] params = { origHost };
        throw new CLIException(MessageFormat.format(getResourceString("session-invalid-host-name"), params), ExitCodes.INVALID_OPTION_VALUE);
    }
    curSessionID = new SessionID(ssoToken.getTokenID().toString());
    String filter = getStringOptionValue(IArgument.FILTER);
    if ((filter == null) || (filter.trim().length() == 0)) {
        filter = "*";
    }
    try {
        curSession = sessionCache.getSession(curSessionID);
        return getSessionList(host, filter);
    } catch (SessionException se) {
        throw new CLIException(se, ExitCodes.SESSION_BASED_LOGIN_FAILED);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) SessionException(com.iplanet.dpro.session.SessionException) SessionID(com.iplanet.dpro.session.SessionID)

Example 27 with SessionID

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

the class SMProfileModelImpl method initSessionsList.

/**
     * Initializes sessions list.
     *
     * @param pattern user id pattern to search for.
     * @throws AMConsoleException if unable to initialized the session list.
     */
private void initSessionsList(String pattern) throws AMConsoleException {
    pattern = pattern.toLowerCase();
    String[] params = { serverName, pattern };
    logEvent("ATTEMPT_GET_CURRENT_SESSIONS", params);
    try {
        Session session = sessionCache.getSession(new SessionID(getUserSSOToken().getTokenID().toString()));
        SearchResults result = session.getValidSessions(serverName, pattern);
        Map<String, Session> sessions = (Map<String, Session>) result.getResultAttributes();
        String errorMessage = AMAdminUtils.getSearchResultWarningMessage(result, this);
        smSessionCache = new SMSessionCache(sessions.values(), errorMessage, this);
        logEvent("SUCCEED_GET_CURRENT_SESSIONS", params);
    } catch (SessionException se) {
        String strError = getErrorString(se);
        String[] paramsEx = { serverName, pattern, strError };
        logEvent("SESSION_EXCEPTION_GET_CURRENT_SESSIONS", paramsEx);
        throw new AMConsoleException(strError);
    }
}
Also used : SessionException(com.iplanet.dpro.session.SessionException) SearchResults(com.sun.identity.common.SearchResults) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) SessionID(com.iplanet.dpro.session.SessionID) HashMap(java.util.HashMap) Map(java.util.Map) Session(com.iplanet.dpro.session.Session)

Example 28 with SessionID

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

the class AuthContext method login.

private void login(IndexType indexType, String indexName, String[] params, Map envMap, String locale, HttpServletRequest request, HttpServletResponse response) throws AuthLoginException {
    if (ssoToken != null) {
        try {
            organizationName = ssoToken.getProperty(ISAuthConstants.ORGANIZATION);
            ssoTokenID = ssoToken.getTokenID().toString();
            authURL = sessionCache.getSession(new SessionID(ssoTokenID)).getSessionServiceURL();
        } catch (Exception e) {
            throw new AuthLoginException(e);
        }
    }
    if (authURL != null) {
        authServiceURL = getAuthServiceURL(authURL.getProtocol(), authURL.getHost(), Integer.toString(authURL.getPort()), authURL.getPath());
    }
    AuthLoginException authException = null;
    try {
        if (authServiceURL == null) {
            authServiceURL = getAuthServiceURL(server_proto, server_host, server_port, server_uri);
        }
        if (authServiceURL != null) {
            if (authDebug.messageEnabled()) {
                authDebug.message("AuthContext.login : runLogin against " + authServiceURL);
            }
            runLogin(indexType, indexName, params, envMap, locale, request, response);
            return;
        }
    } catch (AuthLoginException e) {
        authException = e;
        authDebug.error("Failed to login to " + authServiceURL);
    } catch (Exception e) {
        authDebug.error("Failed to login to " + authServiceURL + ": " + e.getMessage(), e);
    }
    if (authURL == null) {
        // failover when authURL is not specified
        Vector serviceURLs = null;
        try {
            serviceURLs = WebtopNaming.getServiceAllURLs(AuthXMLTags.AUTH_SERVICE);
        } catch (Exception e) {
            throw new AuthLoginException(amAuthContext, "loginError", new Object[] { e.getMessage() });
        }
        if (authDebug.messageEnabled()) {
            authDebug.message("Org Name : " + organizationName);
            authDebug.message("ssoTokenID: " + ssoTokenID);
            authDebug.message("serviceURLs: " + serviceURLs);
        }
        if (serviceURLs != null) {
            serviceURLs.remove(authServiceURL);
            for (Enumeration e = serviceURLs.elements(); e.hasMoreElements(); ) {
                authServiceURL = (URL) e.nextElement();
                try {
                    runLogin(indexType, indexName, params, envMap, locale, request, response);
                    return;
                } catch (AuthLoginException ex) {
                    authException = ex;
                    authDebug.error("Failed to login in failover with " + authServiceURL + ": " + ex.getMessage());
                }
            }
        }
    }
    authDebug.error("Authentication failed.");
    if (authException != null) {
        throw authException;
    } else {
        throw new AuthLoginException(amAuthContext, "loginError", null);
    }
}
Also used : Enumeration(java.util.Enumeration) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) SessionID(com.iplanet.dpro.session.SessionID) Vector(java.util.Vector) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) SSOException(com.iplanet.sso.SSOException) AMSecurityPropertiesException(com.sun.identity.security.AMSecurityPropertiesException) IOException(java.io.IOException) AuthException(com.sun.identity.authentication.service.AuthException)

Example 29 with SessionID

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

the class AuthClientUtils method getCookieURLForSessionUpgrade.

public static String getCookieURLForSessionUpgrade(HttpServletRequest request) {
    String cookieURL = null;
    try {
        SSOTokenManager tokenManager = SSOTokenManager.getInstance();
        SSOToken token = tokenManager.createSSOToken(request);
        Hashtable reqDataHash = parseRequestParameters(request);
        if (tokenManager.isValidToken(token)) {
            cookieURL = getCookieURL(new SessionID(token.getTokenID().toString()));
            if (cookieURL != null && !isLocalServer(cookieURL, true) && (forceAuthFlagExists(reqDataHash) || checkSessionUpgrade(token, reqDataHash))) {
                return cookieURL;
            }
        }
    } catch (SSOException ssoe) {
        if (utilDebug.messageEnabled()) {
            utilDebug.message("SSOException occurred while checking session upgrade case", ssoe);
        }
    }
    return null;
}
Also used : SSOTokenManager(com.iplanet.sso.SSOTokenManager) SSOToken(com.iplanet.sso.SSOToken) Hashtable(java.util.Hashtable) SSOException(com.iplanet.sso.SSOException) SessionID(com.iplanet.dpro.session.SessionID)

Example 30 with SessionID

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

the class AuthClientUtils method getSessionIDFromRequest.

/**
     * Returns the Session ID for this request.  If Authetnication Cookie and
     * Valid AM Cookie are there and request method is GET then use Valid
     * AM Cookie else use Auth Cookie. The cookie in the request for invalid
     * sessions is in auth cookie, <code>com.iplanet.am.auth.cookie</code>,
     * and for active/inactive sessions in <code>com.iplanet.am.cookie</code>.
     *
     * @param request HTTP Servlet Request.
     * @return Session ID for this request.
     */
public static SessionID getSessionIDFromRequest(HttpServletRequest request) {
    boolean isGetRequest = (request != null && request.getMethod().equalsIgnoreCase("GET"));
    SessionID amCookieSid = new SessionID(request);
    SessionID authCookieSid = getSidFromCookie(request);
    SessionID sessionID;
    if (authCookieSid == null) {
        sessionID = amCookieSid;
    } else {
        if (isGetRequest) {
            sessionID = amCookieSid;
        } else {
            sessionID = authCookieSid;
        }
    }
    if (utilDebug.messageEnabled()) {
        utilDebug.message("AuthUtils:returning sessionID:" + sessionID);
    }
    return sessionID;
}
Also used : SessionID(com.iplanet.dpro.session.SessionID)

Aggregations

SessionID (com.iplanet.dpro.session.SessionID)105 Test (org.testng.annotations.Test)44 SessionException (com.iplanet.dpro.session.SessionException)31 SSOToken (com.iplanet.sso.SSOToken)23 InternalSession (com.iplanet.dpro.session.service.InternalSession)18 SSOException (com.iplanet.sso.SSOException)18 AuthContextLocalWrapper (org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper)17 HttpServletResponse (javax.servlet.http.HttpServletResponse)16 HttpServletRequest (javax.servlet.http.HttpServletRequest)15 Session (com.iplanet.dpro.session.Session)14 URL (java.net.URL)9 Map (java.util.Map)9 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)8 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 SMSException (com.sun.identity.sm.SMSException)4 Token (org.forgerock.openam.cts.api.tokens.Token)4 SessionIDExtensions (com.iplanet.dpro.session.SessionIDExtensions)3 TokenRestriction (com.iplanet.dpro.session.TokenRestriction)3 SessionInfo (com.iplanet.dpro.session.share.SessionInfo)3