Search in sources :

Example 26 with AuthContextLocalWrapper

use of org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper in project OpenAM by OpenRock.

the class AuthIdHelperTest method shouldThrowSSOExceptionWhenFailToGetOrgConfig.

@Test
public void shouldThrowSSOExceptionWhenFailToGetOrgConfig() throws SSOException, SMSException, SignatureException {
    //Given
    LoginConfiguration loginConfiguration = mock(LoginConfiguration.class);
    AuthContextLocalWrapper authContext = mock(AuthContextLocalWrapper.class);
    given(coreServicesWrapper.getServiceConfigManager("iPlanetAMAuthService", null)).willThrow(SSOException.class);
    //When
    boolean exceptionCaught = false;
    RestAuthException exception = null;
    try {
        authIdHelper.createAuthId(loginConfiguration, authContext);
        fail();
    } catch (RestAuthException e) {
        exceptionCaught = true;
        exception = e;
    }
    //Then
    assertTrue(exceptionCaught);
    assertEquals(exception.getStatusCode(), 500);
}
Also used : RestAuthException(org.forgerock.openam.core.rest.authn.exceptions.RestAuthException) LoginConfiguration(org.forgerock.openam.core.rest.authn.core.LoginConfiguration) AuthContextLocalWrapper(org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper) Test(org.testng.annotations.Test)

Example 27 with AuthContextLocalWrapper

use of org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper in project OpenAM by OpenRock.

the class RestAuthenticationHandlerTest method shouldInitiateAuthenticationViaGET1.

@Test
public void shouldInitiateAuthenticationViaGET1() throws AuthLoginException, L10NMessageImpl, JSONException, IOException, RestAuthException, RestAuthResponseException {
    //Given
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse httpResponse = mock(HttpServletResponse.class);
    String authIndexType = AuthIndexType.MODULE.toString();
    String indexValue = "INDEX_VALUE";
    String sessionUpgradeSSOTokenId = null;
    AuthContextLocalWrapper authContextLocalWrapper = mock(AuthContextLocalWrapper.class);
    given(authContextLocalWrapper.getErrorCode()).willReturn("ERROR_CODE");
    given(authContextLocalWrapper.getErrorMessage()).willReturn("ERROR_MESSAGE");
    LoginProcess loginProcess = mock(LoginProcess.class);
    given(loginProcess.getLoginStage()).willReturn(LoginStage.COMPLETE);
    given(loginProcess.isSuccessful()).willReturn(false);
    given(loginProcess.getAuthContext()).willReturn(authContextLocalWrapper);
    given(loginAuthenticator.getLoginProcess(Matchers.<LoginConfiguration>anyObject())).willReturn(loginProcess);
    //When
    try {
        restAuthenticationHandler.initiateAuthentication(request, httpResponse, authIndexType, indexValue, sessionUpgradeSSOTokenId);
    } catch (RestAuthErrorCodeException e) {
        assertEquals(e.getStatusCode(), 401);
        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(), "");
        assertEquals(loginConfiguration.getSSOTokenId(), "");
        return;
    }
    //Then
    fail();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RestAuthErrorCodeException(org.forgerock.openam.core.rest.authn.exceptions.RestAuthErrorCodeException) ArgumentCaptor(org.mockito.ArgumentCaptor) 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 28 with AuthContextLocalWrapper

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

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

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

AuthContextLocalWrapper (org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper)30 Test (org.testng.annotations.Test)29 HttpServletRequest (javax.servlet.http.HttpServletRequest)24 HttpServletResponse (javax.servlet.http.HttpServletResponse)24 SessionID (com.iplanet.dpro.session.SessionID)17 SSOToken (com.iplanet.sso.SSOToken)17 LoginConfiguration (org.forgerock.openam.core.rest.authn.core.LoginConfiguration)8 LoginProcess (org.forgerock.openam.core.rest.authn.core.LoginProcess)7 JsonValue (org.forgerock.json.JsonValue)5 HashMap (java.util.HashMap)4 SSOTokenID (com.iplanet.sso.SSOTokenID)3 PagePropertiesCallback (com.sun.identity.authentication.spi.PagePropertiesCallback)3 Map (java.util.Map)3 Callback (javax.security.auth.callback.Callback)3 RestAuthException (org.forgerock.openam.core.rest.authn.exceptions.RestAuthException)3 Set (java.util.Set)1 SignedJwt (org.forgerock.json.jose.jws.SignedJwt)1 JwtClaimsSet (org.forgerock.json.jose.jwt.JwtClaimsSet)1 RestAuthErrorCodeException (org.forgerock.openam.core.rest.authn.exceptions.RestAuthErrorCodeException)1 RestAuthResponseException (org.forgerock.openam.core.rest.authn.exceptions.RestAuthResponseException)1