@Test public void shouldInitiateAuthenticationViaPOST() throws AuthLoginException, L10NMessageImpl, JSONException, IOException, SignatureException { HttpHeaders headers = mock(HttpHeaders.class); 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.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); Response response = restAuthenticationHandler.continueAuthentication(headers, request, httpResponse, postBody, sessionUpgradeSSOTokenId); assertEquals(response.getStatus(), 200); ObjectMapper objectMapper = new ObjectMapper(); JsonValue jsonValue = new JsonValue(objectMapper.readValue((String) response.getEntity(), Map.class)); assertEquals(jsonValue.size(), 2); assertEquals(jsonValue.get("tokenId").asString(), "SSO_TOKEN_ID"); assertTrue(jsonValue.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"); }
public Response continueAuthentication(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response, JsonValue postBody, String sessionUpgradeSSOTokenId) { return authenticate(headers, request, response, postBody, null, null, sessionUpgradeSSOTokenId); }
RestAuthenticationHandler { public Response continueAuthentication(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response, JsonValue postBody, String sessionUpgradeSSOTokenId) { return authenticate(headers, request, response, postBody, null, null, sessionUpgradeSSOTokenId); } }
RestAuthenticationHandler { public Response continueAuthentication(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response, JsonValue postBody, String sessionUpgradeSSOTokenId) { return authenticate(headers, request, response, postBody, null, null, sessionUpgradeSSOTokenId); } @Inject  RestAuthenticationHandler(LoginAuthenticator loginAuthenticator,
            RestAuthCallbackHandlerManager restAuthCallbackHandlerManager,
            AMAuthErrorCodeResponseStatusMapping amAuthErrorCodeResponseStatusMapping, AuthIdHelper authIdHelper); }
RestAuthenticationHandler { public Response continueAuthentication(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response, JsonValue postBody, String sessionUpgradeSSOTokenId) { return authenticate(headers, request, response, postBody, null, null, sessionUpgradeSSOTokenId); } @Inject  RestAuthenticationHandler(LoginAuthenticator loginAuthenticator,
            RestAuthCallbackHandlerManager restAuthCallbackHandlerManager,
            AMAuthErrorCodeResponseStatusMapping amAuthErrorCodeResponseStatusMapping, AuthIdHelper authIdHelper); Response initiateAuthentication(HttpHeaders headers, HttpServletRequest request,
            HttpServletResponse response, String authIndexType, String indexValue, String sessionUpgradeSSOTokenId); Response continueAuthentication(HttpHeaders headers, HttpServletRequest request,
            HttpServletResponse response, JsonValue postBody, String sessionUpgradeSSOTokenId); }
RestAuthenticationHandler { public Response continueAuthentication(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response, JsonValue postBody, String sessionUpgradeSSOTokenId) { return authenticate(headers, request, response, postBody, null, null, sessionUpgradeSSOTokenId); } @Inject  RestAuthenticationHandler(LoginAuthenticator loginAuthenticator,
            RestAuthCallbackHandlerManager restAuthCallbackHandlerManager,
            AMAuthErrorCodeResponseStatusMapping amAuthErrorCodeResponseStatusMapping, AuthIdHelper authIdHelper); Response initiateAuthentication(HttpHeaders headers, HttpServletRequest request,
            HttpServletResponse response, String authIndexType, String indexValue, String sessionUpgradeSSOTokenId); Response continueAuthentication(HttpHeaders headers, HttpServletRequest request,
            HttpServletResponse response, JsonValue postBody, String sessionUpgradeSSOTokenId);  }