use of org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper in project OpenAM by OpenRock.
the class RestAuthenticationHandlerTest method shouldCleanupAfterAuthenticationComplete.
@Test
public void shouldCleanupAfterAuthenticationComplete() throws Exception {
// Given
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
String module = "LDAP";
String existingSesssionId = "session1";
AuthContextLocalWrapper authContextLocalWrapper = mock(AuthContextLocalWrapper.class);
LoginProcess loginProcess = mock(LoginProcess.class);
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
restAuthenticationHandler.initiateAuthentication(request, response, "module", module, existingSesssionId);
// Then
verify(loginProcess).cleanup();
}
use of org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper in project OpenAM by OpenRock.
the class RestAuthenticationHandlerTest method shouldInitiateAuthenticationViaGET4.
@Test
public void shouldInitiateAuthenticationViaGET4() 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[] callbacks = new Callback[0];
AuthContextLocalWrapper authContextLocalWrapper = mock(AuthContextLocalWrapper.class);
LoginProcess loginProcess = mock(LoginProcess.class);
given(loginProcess.getLoginStage()).willReturn(LoginStage.REQUIREMENTS_WAITING);
given(loginProcess.getCallbacks()).willReturn(callbacks);
given(loginProcess.getAuthContext()).willReturn(authContextLocalWrapper);
PagePropertiesCallback pagePropertiesCallback = mock(PagePropertiesCallback.class);
given(pagePropertiesCallback.getTemplateName()).willReturn("TEMPLATE_NAME");
given(pagePropertiesCallback.getModuleName()).willReturn("MODULE_NAME");
given(pagePropertiesCallback.getPageState()).willReturn("PAGE_STATE");
JsonValue jsonCallbacks = new JsonValue(new HashMap<String, Object>());
jsonCallbacks.add("KEY", "VALUE");
Map<String, String> responseHeaders = new HashMap<String, String>();
responseHeaders.put("HEADER_KEY", "HEADER_VALUE");
JsonValue jsonResponse = new JsonValue(new HashMap<String, Object>());
jsonResponse.add("KEY", "VALUE");
RestAuthResponseException restAuthResponseException = new RestAuthResponseException(999, responseHeaders, jsonResponse);
given(loginAuthenticator.getLoginProcess(Matchers.<LoginConfiguration>anyObject())).willReturn(loginProcess);
given(restAuthCallbackHandlerManager.handleCallbacks(request, httpResponse, callbacks)).willThrow(restAuthResponseException);
given(authIdHelper.createAuthId(Matchers.<LoginConfiguration>anyObject(), eq(authContextLocalWrapper))).willReturn("AUTH_ID");
//When
try {
restAuthenticationHandler.initiateAuthentication(request, httpResponse, authIndexType, indexValue, sessionUpgradeSSOTokenId);
} catch (RestAuthResponseException e) {
JsonValue response = e.getJsonResponse();
assertEquals(response.size(), 2);
assertEquals(response.get("authId").asString(), "AUTH_ID");
assertEquals(response.get("KEY").asString(), "VALUE");
Map<String, String> headers = e.getResponseHeaders();
assertEquals(headers.get("HEADER_KEY"), "HEADER_VALUE");
assertEquals(e.getStatusCode(), 999);
return;
}
//Then
fail();
}
use of org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper in project OpenAM by OpenRock.
the class RestAuthenticationHandlerTest method shouldInitiateAuthenticationViaGET2.
@Test
public void shouldInitiateAuthenticationViaGET2() 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 };
PagePropertiesCallback pagePropertiesCallback = mock(PagePropertiesCallback.class);
given(pagePropertiesCallback.getTemplateName()).willReturn("TEMPLATE_NAME");
given(pagePropertiesCallback.getModuleName()).willReturn("MODULE_NAME");
given(pagePropertiesCallback.getPageState()).willReturn("PAGE_STATE");
given(pagePropertiesCallback.getHeader()).willReturn("HEADER");
AuthContextLocalWrapper authContextLocalWrapper = mock(AuthContextLocalWrapper.class);
LoginProcess loginProcess = mock(LoginProcess.class);
given(loginProcess.getLoginStage()).willReturn(LoginStage.REQUIREMENTS_WAITING);
given(loginProcess.getCallbacks()).willReturn(callbacks);
given(loginProcess.getPagePropertiesCallback()).willReturn(pagePropertiesCallback);
given(loginProcess.getAuthContext()).willReturn(authContextLocalWrapper);
JsonValue jsonCallbacks = new JsonValue(new HashMap<String, Object>());
jsonCallbacks.add("KEY", "VALUE");
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(), 5);
assertEquals(response.get("authId").asString(), "AUTH_ID");
assertEquals(response.get("template").asString(), "TEMPLATE_NAME");
assertEquals(response.get("stage").asString(), "MODULE_NAMEPAGE_STATE");
assertEquals(response.get("header").asString(), "HEADER");
assertEquals(response.get("callbacks").get("KEY").asString(), "VALUE");
}
use of org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper in project OpenAM by OpenRock.
the class LoginAuthenticatorTest method shouldGetLoginProcessForInitialRequestWithAuthIndexTypeRoleWithSessionUpgradeButNotRequired.
@Test
public void shouldGetLoginProcessForInitialRequestWithAuthIndexTypeRoleWithSessionUpgradeButNotRequired() throws AuthException, AuthLoginException, SSOException, RestAuthException {
//Given
LoginConfiguration loginConfiguration = new LoginConfiguration();
HttpServletRequest request = mock(HttpServletRequest.class);
String sessionId = null;
AuthIndexType authIndexType = AuthIndexType.ROLE;
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(ssoToken.getProperty("Role")).willReturn("INDEX_VALUE");
given(coreServicesWrapper.getDomainNameByRequest(request)).willReturn("ORG_DN");
given(coreServicesWrapper.getAuthContext(eq(request), eq((HttpServletResponse) null), (SessionID) anyObject(), eq(false), 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);
//When
LoginProcess loginProcess = loginAuthenticator.getLoginProcess(loginConfiguration);
//Then
assertThat(loginProcess.isSuccessful()).isTrue();
verify(authContextLocalWrapper, never()).login();
assertNotNull(loginProcess);
}
use of org.forgerock.openam.core.rest.authn.core.wrappers.AuthContextLocalWrapper in project OpenAM by OpenRock.
the class LoginAuthenticatorTest method shouldGetLoginProcessForInitialRequestWithAuthIndexTypeServiceWithSessionUpgradeButNotRequired.
@Test
public void shouldGetLoginProcessForInitialRequestWithAuthIndexTypeServiceWithSessionUpgradeButNotRequired() throws AuthException, AuthLoginException, SSOException, RestAuthException {
//Given
LoginConfiguration loginConfiguration = new LoginConfiguration();
HttpServletRequest request = mock(HttpServletRequest.class);
String sessionId = null;
AuthIndexType authIndexType = AuthIndexType.SERVICE;
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(ssoToken.getProperty("Service")).willReturn("INDEX_VALUE");
given(coreServicesWrapper.getDomainNameByRequest(request)).willReturn("ORG_DN");
given(coreServicesWrapper.getAuthContext(eq(request), eq((HttpServletResponse) null), (SessionID) anyObject(), eq(false), 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);
//When
LoginProcess loginProcess = loginAuthenticator.getLoginProcess(loginConfiguration);
//Then
assertThat(loginProcess.isSuccessful()).isTrue();
verify(authContextLocalWrapper, never()).login();
assertNotNull(loginProcess);
}
Aggregations