use of org.forgerock.jaspi.modules.session.jwt.ServletJwtSessionModule in project OpenAM by OpenRock.
the class PersistentCookieAuthModuleTest method shouldCallOnLoginSuccessWhenJwtNotValidated.
@Test
public void shouldCallOnLoginSuccessWhenJwtNotValidated() 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");
//When
persistentCookieAuthModule.onLoginSuccess(messageInfo, requestParamsMap, request, response, ssoToken);
//Then
assertEquals(map.size(), 1);
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 org.forgerock.jaspi.modules.session.jwt.ServletJwtSessionModule 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);
}
Aggregations