Search in sources :

Example 11 with SSOTokenID

use of com.iplanet.sso.SSOTokenID in project OpenAM by OpenRock.

the class StatelessSSOTokenTest method shouldUseSessionIdAsTokenId.

@Test
public void shouldUseSessionIdAsTokenId() throws Exception {
    // Given
    String sessionId = "test session id";
    given(mockSession.getID()).willReturn(new SessionID(sessionId));
    // When
    SSOTokenID result = statelessSSOToken.getTokenID();
    // Then
    assertThat(result.toString()).isEqualTo(sessionId);
}
Also used : SSOTokenID(com.iplanet.sso.SSOTokenID) SessionID(com.iplanet.dpro.session.SessionID) Test(org.testng.annotations.Test)

Example 12 with SSOTokenID

use of com.iplanet.sso.SSOTokenID in project OpenAM by OpenRock.

the class PersistentCookieAuthModuleTest method shouldCallOnLoginSuccess.

@Test
public void shouldCallOnLoginSuccess() throws AuthenticationException, SSOException {
    //Given
    persistentCookieAuthModule = new PersistentCookieAuthModule(new ServletJwtSessionModule(), amKeyProvider, coreWrapper) {

        @Override
        protected String getKeyAlias(String orgName) throws SSOException, SMSException {
            return "KEY_ALIAS";
        }
    };
    MessageInfo messageInfo = mock(MessageInfo.class);
    Map requestParamsMap = new HashMap();
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    SSOToken ssoToken = mock(SSOToken.class);
    Map<String, Object> map = new HashMap<String, Object>();
    given(messageInfo.getMap()).willReturn(map);
    Principal principal = mock(Principal.class);
    given(principal.getName()).willReturn("PRINCIPAL_NAME");
    SSOTokenID ssoTokenId = mock(SSOTokenID.class);
    given(ssoTokenId.toString()).willReturn("SSO_TOKEN_ID");
    given(ssoToken.getPrincipal()).willReturn(principal);
    given(ssoToken.getAuthType()).willReturn("AUTH_TYPE");
    given(ssoToken.getTokenID()).willReturn(ssoTokenId);
    given(ssoToken.getProperty("Organization")).willReturn("ORGANISATION");
    given(ssoToken.getProperty("jwtValidated")).willReturn("true");
    //When
    persistentCookieAuthModule.onLoginSuccess(messageInfo, requestParamsMap, request, response, ssoToken);
    //Then
    assertEquals(map.size(), 2);
    assertEquals(map.get("jwtValidated"), true);
    Map<String, Object> contextMap = (Map<String, Object>) map.get("org.forgerock.authentication.context");
    assertEquals(contextMap.get("openam.usr"), "PRINCIPAL_NAME");
    assertEquals(contextMap.get("openam.aty"), "AUTH_TYPE");
    assertEquals(contextMap.get("openam.sid"), "SSO_TOKEN_ID");
    assertEquals(contextMap.get("openam.rlm"), "ORGANISATION");
    assertEquals(contextMap.get("openam.clientip"), null);
}
Also used : SSOTokenID(com.iplanet.sso.SSOTokenID) SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) HashMap(java.util.HashMap) HttpServletResponse(javax.servlet.http.HttpServletResponse) SSOException(com.iplanet.sso.SSOException) MessageInfo(javax.security.auth.message.MessageInfo) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletJwtSessionModule(org.forgerock.jaspi.modules.session.jwt.ServletJwtSessionModule) HashMap(java.util.HashMap) Map(java.util.Map) Principal(java.security.Principal) Test(org.testng.annotations.Test)

Example 13 with SSOTokenID

use of com.iplanet.sso.SSOTokenID in project OpenAM by OpenRock.

the class RestAuthenticationHandlerTest method shouldInitiateAuthenticationViaGET.

@Test
public void shouldInitiateAuthenticationViaGET() throws AuthLoginException, L10NMessageImpl, JSONException, IOException, RestAuthException, RestAuthResponseException {
    //Given
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse httpResponse = mock(HttpServletResponse.class);
    String authIndexType = null;
    String indexValue = null;
    String sessionUpgradeSSOTokenId = null;
    SSOTokenID ssoTokenID = mock(SSOTokenID.class);
    given(ssoTokenID.toString()).willReturn("SSO_TOKEN_ID");
    SSOToken ssoToken = mock(SSOToken.class);
    given(ssoToken.getTokenID()).willReturn(ssoTokenID);
    AuthContextLocalWrapper authContextLocalWrapper = mock(AuthContextLocalWrapper.class);
    LoginProcess loginProcess = mock(LoginProcess.class);
    given(loginProcess.getSSOToken()).willReturn(ssoToken);
    given(loginProcess.getLoginStage()).willReturn(LoginStage.COMPLETE);
    given(loginProcess.isSuccessful()).willReturn(true);
    given(loginProcess.getAuthContext()).willReturn(authContextLocalWrapper);
    given(loginAuthenticator.getLoginProcess(Matchers.<LoginConfiguration>anyObject())).willReturn(loginProcess);
    //When
    JsonValue response = restAuthenticationHandler.initiateAuthentication(request, httpResponse, authIndexType, indexValue, sessionUpgradeSSOTokenId);
    //Then
    assertEquals(response.size(), 2);
    assertEquals(response.get("tokenId").asString(), "SSO_TOKEN_ID");
    assertTrue(response.isDefined("successUrl"));
    ArgumentCaptor<LoginConfiguration> argumentCaptor = ArgumentCaptor.forClass(LoginConfiguration.class);
    verify(loginAuthenticator).getLoginProcess(argumentCaptor.capture());
    LoginConfiguration loginConfiguration = argumentCaptor.getValue();
    assertEquals(loginConfiguration.getHttpRequest(), request);
    assertEquals(loginConfiguration.getIndexType(), AuthIndexType.NONE);
    assertEquals(loginConfiguration.getIndexValue(), null);
    assertEquals(loginConfiguration.getSessionId(), "");
    assertEquals(loginConfiguration.getSSOTokenId(), "");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SSOTokenID(com.iplanet.sso.SSOTokenID) SSOToken(com.iplanet.sso.SSOToken) JsonValue(org.forgerock.json.JsonValue) HttpServletResponse(javax.servlet.http.HttpServletResponse) LoginConfiguration(org.forgerock.openam.core.rest.authn.core.LoginConfiguration) AuthContextLocalWrapper(org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper) LoginProcess(org.forgerock.openam.core.rest.authn.core.LoginProcess) Test(org.testng.annotations.Test)

Example 14 with SSOTokenID

use of com.iplanet.sso.SSOTokenID in project OpenAM by OpenRock.

the class RestAuthenticationHandlerTest method shouldInitiateAuthenticationViaPOST.

@Test
public void shouldInitiateAuthenticationViaPOST() throws AuthLoginException, L10NMessageImpl, JSONException, IOException, SignatureException, RestAuthException, RestAuthResponseException {
    //Given
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse httpResponse = mock(HttpServletResponse.class);
    JsonValue postBody = JsonValueBuilder.toJsonValue("{ \"authId\": \"AUTH_ID\" }");
    String sessionUpgradeSSOTokenId = "SSO_TOKEN_ID";
    SSOTokenID ssoTokenID = mock(SSOTokenID.class);
    given(ssoTokenID.toString()).willReturn("SSO_TOKEN_ID");
    SSOToken ssoToken = mock(SSOToken.class);
    given(ssoToken.getTokenID()).willReturn(ssoTokenID);
    AuthContextLocalWrapper authContextLocalWrapper = mock(AuthContextLocalWrapper.class);
    given(authContextLocalWrapper.getSSOToken()).willReturn(ssoToken);
    LoginProcess loginProcess = mock(LoginProcess.class);
    given(loginProcess.getSSOToken()).willReturn(ssoToken);
    given(loginProcess.getLoginStage()).willReturn(LoginStage.COMPLETE);
    given(loginProcess.isSuccessful()).willReturn(true);
    given(loginProcess.getAuthContext()).willReturn(authContextLocalWrapper);
    given(loginAuthenticator.getLoginProcess(Matchers.<LoginConfiguration>anyObject())).willReturn(loginProcess);
    SignedJwt signedJwt = mock(SignedJwt.class);
    JwtClaimsSet claimsSet = mock(JwtClaimsSet.class);
    given(signedJwt.getClaimsSet()).willReturn(claimsSet);
    given(claimsSet.getClaim("sessionId", String.class)).willReturn("SESSION_ID");
    given(claimsSet.getClaim("authIndexType", String.class)).willReturn(AuthIndexType.MODULE.getIndexType().toString());
    given(claimsSet.getClaim("authIndexValue", String.class)).willReturn("INDEX_VALUE");
    given(claimsSet.getClaim("realm", String.class)).willReturn("REALM_DN");
    given(authIdHelper.reconstructAuthId("AUTH_ID")).willReturn(signedJwt);
    //When
    JsonValue response = restAuthenticationHandler.continueAuthentication(request, httpResponse, postBody, sessionUpgradeSSOTokenId);
    //Then
    assertEquals(response.size(), 2);
    assertEquals(response.get("tokenId").asString(), "SSO_TOKEN_ID");
    assertTrue(response.isDefined("successUrl"));
    verify(authIdHelper).verifyAuthId("REALM_DN", "AUTH_ID");
    ArgumentCaptor<LoginConfiguration> argumentCaptor = ArgumentCaptor.forClass(LoginConfiguration.class);
    verify(loginAuthenticator).getLoginProcess(argumentCaptor.capture());
    LoginConfiguration loginConfiguration = argumentCaptor.getValue();
    assertEquals(loginConfiguration.getHttpRequest(), request);
    assertEquals(loginConfiguration.getIndexType(), AuthIndexType.MODULE);
    assertEquals(loginConfiguration.getIndexValue(), "INDEX_VALUE");
    assertEquals(loginConfiguration.getSessionId(), "SESSION_ID");
    assertEquals(loginConfiguration.getSSOTokenId(), "SSO_TOKEN_ID");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SSOTokenID(com.iplanet.sso.SSOTokenID) JwtClaimsSet(org.forgerock.json.jose.jwt.JwtClaimsSet) SSOToken(com.iplanet.sso.SSOToken) JsonValue(org.forgerock.json.JsonValue) HttpServletResponse(javax.servlet.http.HttpServletResponse) LoginConfiguration(org.forgerock.openam.core.rest.authn.core.LoginConfiguration) AuthContextLocalWrapper(org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper) SignedJwt(org.forgerock.json.jose.jws.SignedJwt) LoginProcess(org.forgerock.openam.core.rest.authn.core.LoginProcess) Test(org.testng.annotations.Test)

Example 15 with SSOTokenID

use of com.iplanet.sso.SSOTokenID in project OpenAM by OpenRock.

the class RestAuthenticationHandlerTest method shouldInitiateAuthenticationViaGET3.

@Test
public void shouldInitiateAuthenticationViaGET3() throws AuthLoginException, L10NMessageImpl, JSONException, IOException, RestAuthResponseException, SignatureException, RestAuthException {
    //Given
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse httpResponse = mock(HttpServletResponse.class);
    String authIndexType = null;
    String indexValue = null;
    String sessionUpgradeSSOTokenId = null;
    Callback callbackOne = mock(Callback.class);
    Callback callbackTwo = mock(Callback.class);
    Callback[] callbacks = new Callback[] { callbackOne, callbackTwo };
    SSOTokenID ssoTokenID = mock(SSOTokenID.class);
    given(ssoTokenID.toString()).willReturn("SSO_TOKEN_ID");
    SSOToken ssoToken = mock(SSOToken.class);
    given(ssoToken.getTokenID()).willReturn(ssoTokenID);
    AuthContextLocalWrapper authContextLocalWrapper = mock(AuthContextLocalWrapper.class);
    given(authContextLocalWrapper.getSSOToken()).willReturn(ssoToken);
    LoginProcess loginProcess = mock(LoginProcess.class);
    given(loginProcess.getSSOToken()).willReturn(ssoToken);
    given(loginProcess.getLoginStage()).willReturn(LoginStage.REQUIREMENTS_WAITING).willReturn(LoginStage.COMPLETE);
    given(loginProcess.getCallbacks()).willReturn(callbacks);
    given(loginProcess.getAuthContext()).willReturn(authContextLocalWrapper);
    given(loginProcess.next(callbacks)).willReturn(loginProcess);
    given(loginProcess.isSuccessful()).willReturn(true);
    given(loginProcess.getAuthContext()).willReturn(authContextLocalWrapper);
    JsonValue jsonCallbacks = new JsonValue(new HashMap<String, Object>());
    given(loginAuthenticator.getLoginProcess(Matchers.<LoginConfiguration>anyObject())).willReturn(loginProcess);
    given(restAuthCallbackHandlerManager.handleCallbacks(request, httpResponse, callbacks)).willReturn(jsonCallbacks);
    given(authIdHelper.createAuthId(Matchers.<LoginConfiguration>anyObject(), eq(authContextLocalWrapper))).willReturn("AUTH_ID");
    //When
    JsonValue response = restAuthenticationHandler.initiateAuthentication(request, httpResponse, authIndexType, indexValue, sessionUpgradeSSOTokenId);
    //Then
    assertEquals(response.size(), 2);
    assertEquals(response.get("tokenId").asString(), "SSO_TOKEN_ID");
    assertTrue(response.isDefined("successUrl"));
    verify(loginProcess).next(callbacks);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SSOTokenID(com.iplanet.sso.SSOTokenID) PagePropertiesCallback(com.sun.identity.authentication.spi.PagePropertiesCallback) Callback(javax.security.auth.callback.Callback) SSOToken(com.iplanet.sso.SSOToken) JsonValue(org.forgerock.json.JsonValue) HttpServletResponse(javax.servlet.http.HttpServletResponse) AuthContextLocalWrapper(org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper) LoginProcess(org.forgerock.openam.core.rest.authn.core.LoginProcess) Test(org.testng.annotations.Test)

Aggregations

SSOTokenID (com.iplanet.sso.SSOTokenID)16 Test (org.testng.annotations.Test)11 SSOToken (com.iplanet.sso.SSOToken)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 Map (java.util.Map)5 SSOException (com.iplanet.sso.SSOException)4 HashMap (java.util.HashMap)4 Principal (java.security.Principal)3 MessageInfo (javax.security.auth.message.MessageInfo)3 JsonValue (org.forgerock.json.JsonValue)3 LoginProcess (org.forgerock.openam.core.rest.authn.core.LoginProcess)3 AuthContextLocalWrapper (org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper)3 AttributesContext (org.forgerock.services.context.AttributesContext)3 Context (org.forgerock.services.context.Context)3 RootContext (org.forgerock.services.context.RootContext)3 SecurityContext (org.forgerock.services.context.SecurityContext)3 SessionID (com.iplanet.dpro.session.SessionID)2 SMSException (com.sun.identity.sm.SMSException)2 Iterator (java.util.Iterator)2