Search in sources :

Example 6 with LoginProcess

use of org.forgerock.openam.core.rest.authn.core.LoginProcess 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 7 with LoginProcess

use of org.forgerock.openam.core.rest.authn.core.LoginProcess 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 8 with LoginProcess

use of org.forgerock.openam.core.rest.authn.core.LoginProcess 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

LoginProcess (org.forgerock.openam.core.rest.authn.core.LoginProcess)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 AuthContextLocalWrapper (org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper)7 Test (org.testng.annotations.Test)7 JsonValue (org.forgerock.json.JsonValue)5 LoginConfiguration (org.forgerock.openam.core.rest.authn.core.LoginConfiguration)4 SSOToken (com.iplanet.sso.SSOToken)3 SSOTokenID (com.iplanet.sso.SSOTokenID)3 PagePropertiesCallback (com.sun.identity.authentication.spi.PagePropertiesCallback)3 Callback (javax.security.auth.callback.Callback)3 SignedJwt (org.forgerock.json.jose.jws.SignedJwt)2 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)1 L10NMessageImpl (com.sun.identity.shared.locale.L10NMessageImpl)1 SignatureException (java.security.SignatureException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JsonException (org.forgerock.json.JsonException)1 JwsSigningException (org.forgerock.json.jose.exceptions.JwsSigningException)1 JwtClaimsSet (org.forgerock.json.jose.jwt.JwtClaimsSet)1