Search in sources :

Example 41 with InternalSession

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

the class LoginViewBean method getPrevSuccessURLAndSetCookie.

/** Retrieves the original AuthContext and the session,
     *  sets the cookie and retrieves the original
     *  success login url.
     *  @return redirect_url, a String
     */
String getPrevSuccessURLAndSetCookie() {
    loginDebug.message("Restoring original Session !");
    InternalSession oldSession = AuthUtils.getOldSession(ac);
    clearCookieAndDestroySession(ac);
    if (oldSession != null) {
        ac.getLoginState().setSession(oldSession);
    }
    String redirect_url = oldSession.getProperty(ISAuthConstants.SUCCESS_URL);
    return redirect_url;
}
Also used : InternalSession(com.iplanet.dpro.session.service.InternalSession)

Example 42 with InternalSession

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

the class LogoutViewBean method forwardTo.

/**
     * Forwards the request to this view bean, displaying the page. This
     * method is the equivalent of <code>RequestDispatcher.forward()</code>,
     * meaning that the same semantics apply to the use of this method.
     * This method makes implicit use of the display URL returned
     * by the <code>getDisplayURL()</code> method.
     * @param requestContext servlet context for auth request
     */
public void forwardTo(RequestContext requestContext) {
    SessionID sessionID = null;
    SSOToken token = null;
    InternalSession intSess = null;
    java.util.Locale locale = null;
    logoutDebug.message("In forwardTo()");
    if (requestContext != null) {
        request = requestContext.getRequest();
        response = requestContext.getResponse();
    }
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Expires", "0");
    gotoUrl = request.getParameter("goto");
    if (logoutDebug.messageEnabled()) {
        logoutDebug.message("Goto query param : " + gotoUrl);
    }
    try {
        sessionID = new SessionID(request);
        intSess = AuthD.getSession(sessionID);
        if (intSess != null) {
            populateL10NFileAttrs(intSess);
            String localeStr = intSess.getProperty(ISAuthConstants.LOCALE);
            // I18N get resource bundle
            locale = com.sun.identity.shared.locale.Locale.getLocale(localeStr);
            fallbackLocale = locale;
        } else {
            ISLocaleContext localeContext = new ISLocaleContext();
            localeContext.setLocale(request);
            locale = localeContext.getLocale();
            if (locale == null) {
                String localeStr = AuthD.getAuth().getPlatformLocale();
                locale = com.sun.identity.shared.locale.Locale.getLocale(localeStr);
            }
        }
        rb = (ResourceBundle) rbCache.getResBundle("amAuthUI", locale);
        clientType = AuthUtils.getClientType(request);
        if (logoutDebug.messageEnabled()) {
            logoutDebug.message("clienttype is : " + clientType);
        }
        token = SSOTokenManager.getInstance().createSSOToken(sessionID.toString());
    } catch (Exception e) {
        ResultVal = getL10NMessage(e, locale);
    }
    // Get the Login URL and query map
    if (token != null) {
        try {
            loginURL = token.getProperty(ISAuthConstants.FULL_LOGIN_URL);
        } catch (com.iplanet.sso.SSOException ssoExp) {
            if (logoutDebug.messageEnabled()) {
                logoutDebug.message("LogoutViewBean.forwardTo: " + " Cannot get Login URL");
            }
        }
    }
    // If there is a gotoUrl value and the orgDN is null do some additional processing
    if (orgDN == null && isGotoSet()) {
        if (logoutDebug.messageEnabled()) {
            logoutDebug.message("OrgDN was null, getting from request for goto validation");
        }
        // First check if there is a org parameter in request, for example realm=/sub-realm
        String orgParm = AuthUtils.getOrgParam(AuthUtils.parseRequestParameters(request));
        if (orgParm == null) {
            if (logoutDebug.messageEnabled()) {
                logoutDebug.message("Attempting to get orgDN from AuthUtils for serverName " + request.getServerName());
            }
            orgDN = AuthUtils.getOrganizationDN(request.getServerName(), true, request);
        } else {
            if (logoutDebug.messageEnabled()) {
                logoutDebug.message("Attempting to get orgDN from AuthUtils for orgParm " + orgParm);
            }
            orgDN = AuthUtils.getOrganizationDN(orgParm, true, request);
        }
        if (orgDN == null) {
            // Last resort, get it from the root domain
            orgDN = DNMapper.orgNameToDN("/");
        }
    }
    if (isGotoSet()) {
        gotoUrl = AuthUtils.getValidGotoURL(request, orgDN);
        if (logoutDebug.messageEnabled()) {
            logoutDebug.message("Goto after validation for orgDN: " + orgDN + " gotoUrl: " + gotoUrl);
        }
    }
    // set the cookie Value or set the logoutcookie string in
    // the case of URL rewriting otherwise set in the responsed
    // header
    Cookie[] cookieArr = request.getCookies();
    if ((cookieArr != null) && (cookieArr.length != 0)) {
        cookieSupported = true;
    } else {
        cookieSupported = false;
    }
    if (cookieSupported) {
        logoutDebug.message("Cookie is supported");
        AuthUtils.clearAllCookies(request, response);
    } else {
        logoutDebug.message("Cookie is not supported");
        if ((sessionID != null) && (sessionID.toString().length() != 0)) {
            logoutCookie = AuthUtils.getLogoutCookieString(sessionID);
            if (logoutDebug.messageEnabled()) {
                logoutDebug.message("Logout Cookie is " + logoutCookie);
            }
        }
    }
    // get the Logout JSP page path
    jsp_page = appendLogoutCookie(getFileName(LOGOUT_JSP));
    if ((intSess != null) && intSess.isTimedOut()) {
        try {
            if (logoutDebug.messageEnabled()) {
                logoutDebug.message("Goto Login URL : " + loginURL);
            }
            if (doSendRedirect(loginURL)) {
                response.sendRedirect(appendLogoutCookie(loginURL));
                return;
            } else {
                int queryIndex = loginURL.indexOf("?");
                String qString = null;
                if (queryIndex != -1) {
                    qString = loginURL.substring(queryIndex);
                }
                if (qString != null) {
                    jsp_page = appendLogoutCookie(getFileName(LOGIN_JSP) + qString);
                } else {
                    jsp_page = appendLogoutCookie(getFileName(LOGIN_JSP));
                }
            }
        } catch (Exception e) {
            if (logoutDebug.messageEnabled()) {
                logoutDebug.message("Redirect failed : " + loginURL, e);
            }
            ResultVal = getL10NMessage(e, locale);
        }
        super.forwardTo(requestContext);
        return;
    }
    boolean wasTokenValid = false;
    try {
        wasTokenValid = AuthUtils.logout(intSess, token, request, response);
        ResultVal = rb.getString("logout.successful");
        String postProcessURL = AuthUtils.getPostProcessURL(request, AMPostAuthProcessInterface.POST_PROCESS_LOGOUT_URL);
        if (postProcessURL != null) {
            gotoUrl = postProcessURL;
        }
    } catch (SSOException ssoe) {
        try {
            if (logoutDebug.messageEnabled()) {
                logoutDebug.message("Exception during logout", ssoe);
                logoutDebug.message("Goto Login URL : " + LOGINURL);
            }
            if (doSendRedirect(LOGINURL)) {
                response.sendRedirect(appendLogoutCookie(LOGINURL));
                return;
            } else {
                jsp_page = appendLogoutCookie(getFileName(LOGIN_JSP));
            }
        } catch (Exception ex) {
            if (logoutDebug.messageEnabled()) {
                logoutDebug.message("Redirect failed:" + LOGINURL, ex);
            }
            ResultVal = ex.getMessage();
        }
        super.forwardTo(requestContext);
        return;
    }
    if (!wasTokenValid) {
        if (!isGotoSet()) {
            String originalRedirectURL = AuthUtils.getOrigRedirectURL(request, sessionID);
            if (originalRedirectURL != null) {
                try {
                    if (logoutDebug.messageEnabled()) {
                        logoutDebug.message("Original Redirect URL: " + originalRedirectURL);
                    }
                    int index = originalRedirectURL.indexOf("/Login");
                    if (index != -1) {
                        originalRedirectURL = originalRedirectURL.substring(0, index) + "/Logout";
                    }
                    if (logoutDebug.messageEnabled()) {
                        logoutDebug.message("Redirect to Original Redirect URL :" + originalRedirectURL);
                    }
                    if (doSendRedirect(originalRedirectURL)) {
                        response.sendRedirect(appendLogoutCookie(originalRedirectURL));
                        return;
                    }
                } catch (Exception e) {
                    ResultVal = getL10NMessage(e, locale);
                }
            } else {
                try {
                    if (logoutDebug.messageEnabled()) {
                        logoutDebug.message("Goto LOGINURL : " + LOGINURL);
                    }
                    if (doSendRedirect(LOGINURL)) {
                        response.sendRedirect(appendLogoutCookie(LOGINURL));
                        return;
                    } else {
                        jsp_page = appendLogoutCookie(getFileName(LOGIN_JSP));
                    }
                } catch (Exception e) {
                    ResultVal = getL10NMessage(e, locale);
                }
            }
        }
    }
    if (!redirectToGoto(locale)) {
        super.forwardTo(requestContext);
    }
}
Also used : Cookie(javax.servlet.http.Cookie) SSOToken(com.iplanet.sso.SSOToken) SSOException(com.iplanet.sso.SSOException) ServletException(javax.servlet.ServletException) ModelControlException(com.iplanet.jato.model.ModelControlException) IOException(java.io.IOException) SSOException(com.iplanet.sso.SSOException) InternalSession(com.iplanet.dpro.session.service.InternalSession) SSOException(com.iplanet.sso.SSOException) ISLocaleContext(com.sun.identity.common.ISLocaleContext) SessionID(com.iplanet.dpro.session.SessionID)

Aggregations

InternalSession (com.iplanet.dpro.session.service.InternalSession)42 SessionID (com.iplanet.dpro.session.SessionID)17 Test (org.testng.annotations.Test)16 SSOException (com.iplanet.sso.SSOException)10 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)10 SSOToken (com.iplanet.sso.SSOToken)9 Token (org.forgerock.openam.cts.api.tokens.Token)8 SessionException (com.iplanet.dpro.session.SessionException)6 SSOTokenManager (com.iplanet.sso.SSOTokenManager)5 IOException (java.io.IOException)5 ModelControlException (com.iplanet.jato.model.ModelControlException)4 Map (java.util.Map)4 Session (com.iplanet.dpro.session.Session)3 AuthContextLocal (com.sun.identity.authentication.server.AuthContextLocal)3 AuthD (com.sun.identity.authentication.service.AuthD)3 SessionInfo (com.iplanet.dpro.session.share.SessionInfo)2 AuthException (com.sun.identity.authentication.service.AuthException)2 InvalidPasswordException (com.sun.identity.authentication.spi.InvalidPasswordException)2 ISLocaleContext (com.sun.identity.common.ISLocaleContext)2 SMSException (com.sun.identity.sm.SMSException)2