use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.
the class RestAuthCallbackHandlerManagerTest method shouldHandleCallbacksInternally.
@Test
public void shouldHandleCallbacksInternally() throws RestAuthResponseException, RestAuthException {
//Given
HttpHeaders headers = mock(HttpHeaders.class);
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
Callback callback1 = mock(Callback.class);
Callback callback2 = mock(Callback.class);
Callback[] callbacks = new Callback[] { callback1, callback2 };
RestAuthCallbackHandler restAuthCallbackHandler1 = mock(RestAuthCallbackHandler.class);
RestAuthCallbackHandler restAuthCallbackHandler2 = mock(RestAuthCallbackHandler.class);
given(restAuthCallbackHandlerFactory.getRestAuthCallbackHandler(Matchers.<Class<? extends Callback>>anyObject())).willReturn(restAuthCallbackHandler1).willReturn(restAuthCallbackHandler2);
given(restAuthCallbackHandler1.updateCallbackFromRequest(request, response, callback1)).willReturn(true);
given(restAuthCallbackHandler2.updateCallbackFromRequest(request, response, callback2)).willReturn(true);
//When
JsonValue jsonCallbacks = restAuthCallbackHandlerManager.handleCallbacks(request, response, callbacks);
//Then
verify(restAuthCallbackHandler1).updateCallbackFromRequest(request, response, callback1);
verify(restAuthCallbackHandler2).updateCallbackFromRequest(request, response, callback2);
verify(restAuthCallbackHandler1, never()).convertToJson(callback1, 1);
verify(restAuthCallbackHandler2, never()).convertToJson(callback2, 2);
assertEquals(jsonCallbacks.size(), 0);
}
use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.
the class RestAuthCallbackHandlerManagerTest method shouldHandleJsonCallbacksMixedUp.
@Test
public void shouldHandleJsonCallbacksMixedUp() throws RestAuthException {
//Given
Callback callback1 = mock(Callback.class);
Callback callback2 = mock(Callback.class);
Callback[] callbacks = new Callback[] { callback1, callback2 };
RestAuthCallbackHandler restAuthCallbackHandler1 = mock(RestAuthCallbackHandler.class);
RestAuthCallbackHandler restAuthCallbackHandler2 = mock(RestAuthCallbackHandler.class);
JsonValue jsonCallback1 = mock(JsonValue.class);
JsonValue jsonCallback2 = mock(JsonValue.class);
JsonValue jsonCallbacks = mock(JsonValue.class);
JsonValue jsonCallback1Type = mock(JsonValue.class);
JsonValue jsonCallback2Type = mock(JsonValue.class);
given(restAuthCallbackHandlerFactory.getRestAuthCallbackHandler(Matchers.<Class<? extends Callback>>anyObject())).willReturn(restAuthCallbackHandler1).willReturn(restAuthCallbackHandler2);
given(restAuthCallbackHandler1.getCallbackClassName()).willReturn("CALLBACK1");
given(restAuthCallbackHandler2.getCallbackClassName()).willReturn("CALLBACK2");
given(jsonCallback1.get("type")).willReturn(jsonCallback1Type);
given(jsonCallback2.get("type")).willReturn(jsonCallback2Type);
given(jsonCallback1Type.asString()).willReturn("CALLBACK1");
given(jsonCallback2Type.asString()).willReturn("CALLBACK2");
given(restAuthCallbackHandler1.convertFromJson(callback1, jsonCallback1)).willReturn(callback1);
given(restAuthCallbackHandler2.convertFromJson(callback2, jsonCallback2)).willReturn(callback2);
given(jsonCallbacks.size()).willReturn(2);
given(jsonCallbacks.get(0)).willReturn(jsonCallback1);
given(jsonCallbacks.get(1)).willReturn(jsonCallback2);
//When
Callback[] originalCallbacks = restAuthCallbackHandlerManager.handleJsonCallbacks(callbacks, jsonCallbacks);
//Then
verify(restAuthCallbackHandler1).convertFromJson(callback1, jsonCallback1);
verify(restAuthCallbackHandler2).convertFromJson(callback2, jsonCallback2);
assertEquals(originalCallbacks.length, 2);
assertEquals(originalCallbacks[0], callback1);
assertEquals(originalCallbacks[1], callback2);
}
use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.
the class RestAuthCallbackHandlerManagerTest method shouldHandleJsonCallbacks.
@Test
public void shouldHandleJsonCallbacks() throws RestAuthException {
//Given
Callback callback1 = mock(Callback.class);
Callback callback2 = mock(Callback.class);
Callback[] callbacks = new Callback[] { callback1, callback2 };
RestAuthCallbackHandler restAuthCallbackHandler1 = mock(RestAuthCallbackHandler.class);
RestAuthCallbackHandler restAuthCallbackHandler2 = mock(RestAuthCallbackHandler.class);
JsonValue jsonCallback1 = mock(JsonValue.class);
JsonValue jsonCallback2 = mock(JsonValue.class);
JsonValue jsonCallbacks = mock(JsonValue.class);
JsonValue jsonCallback1Type = mock(JsonValue.class);
JsonValue jsonCallback2Type = mock(JsonValue.class);
given(jsonCallbacks.size()).willReturn(2);
given(jsonCallbacks.get(0)).willReturn(jsonCallback1);
given(jsonCallbacks.get(1)).willReturn(jsonCallback2);
given(restAuthCallbackHandlerFactory.getRestAuthCallbackHandler(Matchers.<Class<? extends Callback>>anyObject())).willReturn(restAuthCallbackHandler1).willReturn(restAuthCallbackHandler2);
given(restAuthCallbackHandler1.getCallbackClassName()).willReturn("CALLBACK1");
given(restAuthCallbackHandler2.getCallbackClassName()).willReturn("CALLBACK2");
given(jsonCallback1.get("type")).willReturn(jsonCallback1Type);
given(jsonCallback2.get("type")).willReturn(jsonCallback2Type);
given(jsonCallback1Type.asString()).willReturn("CALLBACK1");
given(jsonCallback2Type.asString()).willReturn("CALLBACK2");
given(restAuthCallbackHandler1.convertFromJson(callback1, jsonCallback1)).willReturn(callback1);
given(restAuthCallbackHandler2.convertFromJson(callback2, jsonCallback2)).willReturn(callback2);
//When
Callback[] originalCallbacks = restAuthCallbackHandlerManager.handleJsonCallbacks(callbacks, jsonCallbacks);
//Then
verify(restAuthCallbackHandler1).convertFromJson(callback1, jsonCallback1);
verify(restAuthCallbackHandler2).convertFromJson(callback2, jsonCallback2);
assertEquals(originalCallbacks.length, 2);
assertEquals(originalCallbacks[0], callback1);
assertEquals(originalCallbacks[1], callback2);
}
use of javax.security.auth.callback.Callback 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 javax.security.auth.callback.Callback 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");
}
Aggregations