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);
}
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();
}
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(), "");
}
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");
}
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);
}
Aggregations