Search in sources :

Example 71 with SessionID

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

the class LoginAuthenticatorTest method shouldGetLoginProcessForInitialRequestWithAuthIndexTypeLevelWithSessionUpgrade.

@Test
public void shouldGetLoginProcessForInitialRequestWithAuthIndexTypeLevelWithSessionUpgrade() throws AuthException, AuthLoginException, SSOException, RestAuthException {
    //Given
    LoginConfiguration loginConfiguration = new LoginConfiguration();
    HttpServletRequest request = mock(HttpServletRequest.class);
    String sessionId = null;
    AuthIndexType authIndexType = AuthIndexType.LEVEL;
    String authIndexValue = "15";
    String ssoTokenId = "SSO_TOKEN_ID";
    AuthContextLocalWrapper authContextLocalWrapper = mock(AuthContextLocalWrapper.class);
    SSOToken ssoToken = mock(SSOToken.class);
    loginConfiguration.httpRequest(request).sessionId(sessionId).indexType(authIndexType).indexValue(authIndexValue).sessionUpgrade(ssoTokenId);
    given(ssoToken.getProperty("AuthLevel")).willReturn("10");
    given(coreServicesWrapper.getDomainNameByRequest(request)).willReturn("ORG_DN");
    given(coreServicesWrapper.getAuthContext(eq(request), eq((HttpServletResponse) null), (SessionID) anyObject(), eq(true), eq(false))).willReturn(authContextLocalWrapper);
    given(coreServicesWrapper.getExistingValidSSOToken(eq(new SessionID("SSO_TOKEN_ID")))).willReturn(ssoToken);
    given(coreServicesWrapper.isNewRequest(authContextLocalWrapper)).willReturn(true);
    given(coreServicesWrapper.doesValueContainKey(anyString(), anyString())).willReturn(false);
    given(coreServicesWrapper.doesValueContainKey("INDEX_VALUE", "INDEX_VALUE")).willReturn(true);
    given(authContextLocalWrapper.isSessionUpgrade()).willReturn(true);
    //When
    LoginProcess loginProcess = loginAuthenticator.getLoginProcess(loginConfiguration);
    //Then
    verify(authContextLocalWrapper).login(AuthContext.IndexType.LEVEL, "15");
    assertNotNull(loginProcess);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SSOToken(com.iplanet.sso.SSOToken) HttpServletResponse(javax.servlet.http.HttpServletResponse) AuthContextLocalWrapper(org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper) SessionID(com.iplanet.dpro.session.SessionID) Test(org.testng.annotations.Test)

Example 72 with SessionID

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

the class LoginAuthenticatorTest method shouldGetLoginProcessForInitialRequestWithAuthIndexTypeCompositeWithSessionUpgrade.

@Test
public void shouldGetLoginProcessForInitialRequestWithAuthIndexTypeCompositeWithSessionUpgrade() throws AuthException, AuthLoginException, SSOException, RestAuthException {
    //Given
    LoginConfiguration loginConfiguration = new LoginConfiguration();
    HttpServletRequest request = mock(HttpServletRequest.class);
    String sessionId = null;
    AuthIndexType authIndexType = AuthIndexType.COMPOSITE;
    String authIndexValue = "INDEX_VALUE";
    String ssoTokenId = "SSO_TOKEN_ID";
    AuthContextLocalWrapper authContextLocalWrapper = mock(AuthContextLocalWrapper.class);
    SSOToken ssoToken = mock(SSOToken.class);
    loginConfiguration.httpRequest(request).sessionId(sessionId).indexType(authIndexType).indexValue(authIndexValue).sessionUpgrade(ssoTokenId);
    given(coreServicesWrapper.getDomainNameByRequest(Matchers.<HttpServletRequest>anyObject())).willReturn("ORG_DN");
    given(coreServicesWrapper.getAuthContext((HttpServletRequest) anyObject(), eq((HttpServletResponse) null), (SessionID) anyObject(), eq(true), eq(false))).willReturn(authContextLocalWrapper);
    given(authContextLocalWrapper.isSessionUpgrade()).willReturn(true);
    given(coreServicesWrapper.getExistingValidSSOToken(eq(new SessionID("SSO_TOKEN_ID")))).willReturn(ssoToken);
    given(coreServicesWrapper.isNewRequest(authContextLocalWrapper)).willReturn(true);
    //When
    LoginProcess loginProcess = loginAuthenticator.getLoginProcess(loginConfiguration);
    //Then
    verify(authContextLocalWrapper).login(AuthContext.IndexType.COMPOSITE_ADVICE, "INDEX_VALUE");
    assertNotNull(loginProcess);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SSOToken(com.iplanet.sso.SSOToken) HttpServletResponse(javax.servlet.http.HttpServletResponse) AuthContextLocalWrapper(org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper) SessionID(com.iplanet.dpro.session.SessionID) Test(org.testng.annotations.Test)

Example 73 with SessionID

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

the class NamingService method usePreferredNamingURL.

private URL usePreferredNamingURL(NamingRequest request, float reqVersion) throws ServerEntryNotFoundException, MalformedURLException {
    String preferredNamingURL = null;
    URL preferredURL = null;
    if (request == null) {
        return null;
    }
    preferredNamingURL = request.getPreferredNamingURL();
    if (preferredNamingURL == null) {
        return null;
    }
    String sessionid = request.getSessionId();
    if (sessionid == null) {
        return null;
    }
    URL url = new URL(request.getPreferredNamingURL());
    String uri = (reqVersion < 3.0) ? SystemProperties.get(Constants.AM_SERVICES_DEPLOYMENT_DESCRIPTOR) : WebtopNaming.getURI(url);
    String serverID = WebtopNaming.getServerID(url.getProtocol(), url.getHost(), Integer.toString(url.getPort()), uri);
    SessionID sessionID = new SessionID(sessionid);
    String primary_id = sessionID.getExtension().getPrimaryID();
    if (primary_id != null) {
        String secondarysites = WebtopNaming.getSecondarySites(primary_id);
        if ((secondarysites != null) && (serverID != null)) {
            if (secondarysites.indexOf(serverID) != -1) {
                preferredURL = url;
            }
        }
    }
    return preferredURL;
}
Also used : SessionID(com.iplanet.dpro.session.SessionID) URL(java.net.URL)

Example 74 with SessionID

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

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

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