use of com.iplanet.sso.SSOTokenID in project OpenAM by OpenRock.
the class StatelessSSOTokenTest method shouldUseSessionIdAsTokenId.
@Test
public void shouldUseSessionIdAsTokenId() throws Exception {
// Given
String sessionId = "test session id";
given(mockSession.getID()).willReturn(new SessionID(sessionId));
// When
SSOTokenID result = statelessSSOToken.getTokenID();
// Then
assertThat(result.toString()).isEqualTo(sessionId);
}
use of com.iplanet.sso.SSOTokenID in project OpenAM by OpenRock.
the class PersistentCookieAuthModuleTest method shouldCallOnLoginSuccess.
@Test
public void shouldCallOnLoginSuccess() throws AuthenticationException, SSOException {
//Given
persistentCookieAuthModule = new PersistentCookieAuthModule(new ServletJwtSessionModule(), amKeyProvider, coreWrapper) {
@Override
protected String getKeyAlias(String orgName) throws SSOException, SMSException {
return "KEY_ALIAS";
}
};
MessageInfo messageInfo = mock(MessageInfo.class);
Map requestParamsMap = new HashMap();
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
SSOToken ssoToken = mock(SSOToken.class);
Map<String, Object> map = new HashMap<String, Object>();
given(messageInfo.getMap()).willReturn(map);
Principal principal = mock(Principal.class);
given(principal.getName()).willReturn("PRINCIPAL_NAME");
SSOTokenID ssoTokenId = mock(SSOTokenID.class);
given(ssoTokenId.toString()).willReturn("SSO_TOKEN_ID");
given(ssoToken.getPrincipal()).willReturn(principal);
given(ssoToken.getAuthType()).willReturn("AUTH_TYPE");
given(ssoToken.getTokenID()).willReturn(ssoTokenId);
given(ssoToken.getProperty("Organization")).willReturn("ORGANISATION");
given(ssoToken.getProperty("jwtValidated")).willReturn("true");
//When
persistentCookieAuthModule.onLoginSuccess(messageInfo, requestParamsMap, request, response, ssoToken);
//Then
assertEquals(map.size(), 2);
assertEquals(map.get("jwtValidated"), true);
Map<String, Object> contextMap = (Map<String, Object>) map.get("org.forgerock.authentication.context");
assertEquals(contextMap.get("openam.usr"), "PRINCIPAL_NAME");
assertEquals(contextMap.get("openam.aty"), "AUTH_TYPE");
assertEquals(contextMap.get("openam.sid"), "SSO_TOKEN_ID");
assertEquals(contextMap.get("openam.rlm"), "ORGANISATION");
assertEquals(contextMap.get("openam.clientip"), null);
}
use of com.iplanet.sso.SSOTokenID 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 com.iplanet.sso.SSOTokenID 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 com.iplanet.sso.SSOTokenID 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