Search in sources :

Example 91 with SessionID

use of com.iplanet.dpro.session.SessionID 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)

Example 92 with SessionID

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

the class RemoteHandler method getLogHostURL.

private URL getLogHostURL(String loggedBySID) {
    SessionID sid = new SessionID(loggedBySID);
    String sessionProtocol = sid.getSessionServerProtocol();
    String sessionHost = sid.getSessionServer();
    String sessionPort = sid.getSessionServerPort();
    String sessionURI = sid.getSessionServerURI();
    //
    if ((!manager.isLocal) && ((sessionProtocol == null) || (sessionProtocol.length() <= 0) || (sessionHost == null) || (sessionHost.length() <= 0))) {
        if (Debug.messageEnabled()) {
            Debug.message("RemoteHandler.getLogHostURL(): remote serv = " + logServURL);
        }
        return (logServURL);
    }
    if (Debug.messageEnabled()) {
        Debug.message("RemoteHandler.getLogHostURL(): " + " sessionProtocol: " + sessionProtocol + " sessionHost: " + sessionHost + " sessionPort: " + sessionPort + " sessionURI: " + sessionURI);
    }
    URL loggingURL = null;
    try {
        loggingURL = WebtopNaming.getServiceURL(LogConstants.LOGGING_SERVICE, sessionProtocol, sessionHost, sessionPort, sessionURI);
        if (Debug.messageEnabled()) {
            Debug.message("RemoteHandler.getLogHostURL(): WebtopNaming logging" + "service URL: " + loggingURL);
        }
    } catch (URLNotFoundException unfe) {
        Debug.error("RemoteHandler.getLogHostURL(): URLNotFoundException: ", unfe);
        return null;
    }
    return loggingURL;
}
Also used : URLNotFoundException(com.iplanet.services.naming.URLNotFoundException) SessionID(com.iplanet.dpro.session.SessionID) URL(java.net.URL)

Example 93 with SessionID

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

the class CTSOperationsTest method shouldInvokeRemoteActionDuringSetProperty.

@Test
public void shouldInvokeRemoteActionDuringSetProperty() throws SessionException, CoreTokenException {
    // Given
    String name = "name";
    String value = "value";
    SessionID mockSessionID = mock(SessionID.class);
    given(mockSession.getID()).willReturn(mockSessionID);
    Token mockToken = mock(Token.class);
    given(mockCTS.read(anyString())).willReturn(mockToken);
    InternalSession mockInternalSession = mock(InternalSession.class);
    given(mockAdapter.fromToken(eq(mockToken))).willReturn(mockInternalSession);
    // When
    ctsOperations.setProperty(mockSession, name, value);
    // Then
    verify(mockRemote).setProperty(mockSession, name, value);
}
Also used : InternalSession(com.iplanet.dpro.session.service.InternalSession) Token(org.forgerock.openam.cts.api.tokens.Token) Mockito.anyString(org.mockito.Mockito.anyString) SessionID(com.iplanet.dpro.session.SessionID) Test(org.testng.annotations.Test)

Example 94 with SessionID

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

the class MultiServerClusterMonitorTest method canDeterministicallyEstablishFailoverHostServerIdForSessionIfHomeServerIsDown.

@Test
public void canDeterministicallyEstablishFailoverHostServerIdForSessionIfHomeServerIsDown() throws Exception {
    // Given
    // A site with 2x AM servers, if server "01" is presented a session that is homed
    // on server "02" which is down, then a deterministic routing algorithm should be
    // used to generate a sequence of alternative servers to try to re-home the session
    // to. The first of these alternate servers that is found to be up will become the
    // new home server for that session.
    given(mockServiceConfig.isSessionFailoverEnabled()).willReturn(true);
    given(mockServiceConfig.isUseInternalRequestRoutingEnabled()).willReturn(true);
    given(mockServerConfig.getServerIDsInLocalSite()).willReturn(CollectionUtils.asSet("01", "02"));
    given(mockServerConfig.getServerFromID("01")).willReturn("http://openam1.example.com:18080/openam");
    given(mockServerConfig.getServerFromID("02")).willReturn("http://openam2.example.com:28080/openam");
    // the 'site'
    given(mockServerConfig.getServerFromID("03")).willReturn("http://openam.example.com:8080/openam");
    given(mockServerConfig.getLocalServerID()).willReturn("02");
    given(mockServerConfig.getLocalServerSessionServiceURL()).willReturn(new URL("http://openam2.example.com:28080/openam/sessionservice"));
    given(mockServerConfig.getAllServerIDs()).willReturn(CollectionUtils.asList("02", "01"));
    given(mockServerConfig.isSite("02")).willReturn(false);
    given(mockServerConfig.isSite("01")).willReturn(false);
    given(mockServerConfig.isLocalServer("03")).willReturn(false);
    given(mockServerConfig.isPrimaryServer("03")).willReturn(true);
    ClusterStateService mockClusterService = mock(ClusterStateService.class);
    given(mockFactory.createClusterStateService(eq(mockSessionService), eq(mockServerConfig), eq(mockServiceConfig), any(Map.class), any(Map.class))).willReturn(mockClusterService);
    given(mockClusterService.isUp("01")).willReturn(true);
    given(mockClusterService.isUp("02")).willReturn(false);
    given(mockClusterService.getServerSelectionListSize()).willReturn(2);
    given(mockClusterService.getServerSelection(0)).willReturn("01");
    SessionID mockSessionID = mock(SessionID.class);
    SessionIDExtensions mockExtensions = mock(SessionIDExtensions.class);
    given(mockSessionID.getExtension()).willReturn(mockExtensions);
    given(mockExtensions.getPrimaryID()).willReturn("02");
    given(mockSessionID.getSessionServerID()).willReturn("03");
    given(mockExtensions.getStorageKey()).willReturn("4059025133086137527");
    // When
    MultiServerClusterMonitor clusterMonitor = new MultiServerClusterMonitor(mockSessionService, mockDebug, mockServiceConfig, mockServerConfig, mockFactory);
    String currentHostServer = clusterMonitor.getCurrentHostServer(mockSessionID);
    // Then
    assertThat(currentHostServer).isEqualTo("01");
}
Also used : SessionIDExtensions(com.iplanet.dpro.session.SessionIDExtensions) Map(java.util.Map) SessionID(com.iplanet.dpro.session.SessionID) URL(java.net.URL) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 95 with SessionID

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

the class MultiServerClusterMonitorTest method canEstablishHostServerIdForSession.

@Test
public void canEstablishHostServerIdForSession() throws Exception {
    // Given
    given(mockServiceConfig.isSessionFailoverEnabled()).willReturn(true);
    given(mockServiceConfig.isUseInternalRequestRoutingEnabled()).willReturn(true);
    given(mockServerConfig.getServerIDsInLocalSite()).willReturn(CollectionUtils.asSet("01", "02"));
    given(mockServerConfig.getServerFromID("01")).willReturn("http://openam1.example.com:18080/openam");
    given(mockServerConfig.getServerFromID("02")).willReturn("http://openam2.example.com:28080/openam");
    // the 'site'
    given(mockServerConfig.getServerFromID("03")).willReturn("http://openam.example.com:8080/openam");
    given(mockServerConfig.getLocalServerID()).willReturn("01");
    given(mockServerConfig.getLocalServerSessionServiceURL()).willReturn(new URL("http://openam1.example.com:18080/openam/sessionservice"));
    given(mockServerConfig.getAllServerIDs()).willReturn(CollectionUtils.asList("02", "01"));
    given(mockServerConfig.isSite("02")).willReturn(false);
    given(mockServerConfig.isSite("01")).willReturn(false);
    given(mockServerConfig.isLocalServer("03")).willReturn(false);
    given(mockServerConfig.isPrimaryServer("03")).willReturn(true);
    ClusterStateService mockClusterService = mock(ClusterStateService.class);
    given(mockFactory.createClusterStateService(eq(mockSessionService), eq(mockServerConfig), eq(mockServiceConfig), any(Map.class), any(Map.class))).willReturn(mockClusterService);
    given(mockClusterService.isUp("01")).willReturn(true);
    SessionID mockSessionID = mock(SessionID.class);
    SessionIDExtensions mockExtensions = mock(SessionIDExtensions.class);
    given(mockSessionID.getExtension()).willReturn(mockExtensions);
    given(mockExtensions.getPrimaryID()).willReturn("01");
    given(mockSessionID.getSessionServerID()).willReturn("03");
    // When
    MultiServerClusterMonitor clusterMonitor = new MultiServerClusterMonitor(mockSessionService, mockDebug, mockServiceConfig, mockServerConfig, mockFactory);
    String currentHostServer = clusterMonitor.getCurrentHostServer(mockSessionID);
    // Then
    assertThat(currentHostServer).isEqualTo("01");
}
Also used : SessionIDExtensions(com.iplanet.dpro.session.SessionIDExtensions) Map(java.util.Map) SessionID(com.iplanet.dpro.session.SessionID) URL(java.net.URL) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

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