use of org.forgerock.json.jose.jwt.Jwt in project OpenAM by OpenRock.
the class PersistentCookieAuthModuleTest method shouldEnforceClientIPOnLoginWhenClientIPIsNotOnRequest.
@Test(expectedExceptions = AuthLoginException.class)
public void shouldEnforceClientIPOnLoginWhenClientIPIsNotOnRequest() throws LoginException {
//Given
MessageInfo messageInfo = mock(MessageInfo.class);
Subject clientSubject = new Subject();
Callback[] callbacks = new Callback[0];
Jwt jwt = mock(Jwt.class);
JwtClaimsSet claimsSet = mock(JwtClaimsSet.class);
Map<String, Object> claimsSetContext = new HashMap<String, Object>();
HttpServletRequest request = mock(HttpServletRequest.class);
Map options = new HashMap();
options.put("openam-auth-persistent-cookie-enforce-ip", Collections.singleton("true"));
persistentCookieAuthModule.initialize(null, null, options);
given(jwtSessionModule.validateJwtSessionCookie(messageInfo)).willReturn(jwt);
given(jwt.getClaimsSet()).willReturn(claimsSet);
given(claimsSet.getClaim(AuthenticationFramework.ATTRIBUTE_AUTH_CONTEXT, Map.class)).willReturn(claimsSetContext);
claimsSetContext.put("openam.rlm", "REALM");
given(amLoginModuleBinder.getRequestOrg()).willReturn("REALM");
claimsSetContext.put("openam-auth-persistent-cookie-enforce-ip", "CLIENT_IP");
given(amLoginModuleBinder.getHttpServletRequest()).willReturn(request);
//When
persistentCookieAuthModule.process(messageInfo, clientSubject, callbacks);
//Then
fail();
}
use of org.forgerock.json.jose.jwt.Jwt in project OpenAM by OpenRock.
the class PersistentCookieAuthModuleTest method shouldProcessCallbacksWhenJASPIContextNotFound.
@Test
public void shouldProcessCallbacksWhenJASPIContextNotFound() throws LoginException {
//Given
Callback[] callbacks = new Callback[0];
int state = ISAuthConstants.LOGIN_START;
Jwt jwt = mock(Jwt.class);
JwtClaimsSet claimsSet = mock(JwtClaimsSet.class);
given(jwtSessionModule.validateJwtSessionCookie(Matchers.<MessageInfo>anyObject())).willReturn(jwt);
given(jwt.getClaimsSet()).willReturn(claimsSet);
given(claimsSet.getClaim("org.forgerock.authentication.context", Map.class)).willReturn(null);
shouldInitialiseAuthModule();
//When
boolean exceptionCaught = false;
AuthLoginException exception = null;
try {
persistentCookieAuthModule.process(callbacks, state);
} catch (AuthLoginException e) {
exceptionCaught = true;
exception = e;
}
//Then
verify(amLoginModuleBinder).setUserSessionProperty(JwtSessionModule.TOKEN_IDLE_TIME_IN_MINUTES_CLAIM_KEY, "60");
verify(amLoginModuleBinder).setUserSessionProperty(JwtSessionModule.MAX_TOKEN_LIFE_IN_MINUTES_KEY, "300");
verify(jwtSessionModule).validateJwtSessionCookie(Matchers.<MessageInfo>anyObject());
assertTrue(exceptionCaught);
assertEquals(exception.getErrorCode(), "jaspiContextNotFound");
}
use of org.forgerock.json.jose.jwt.Jwt in project OpenAM by OpenRock.
the class PersistentCookieAuthModuleTest method shouldEnforceClientIPOnLoginWhenClientIPIsNotStoredInPCookie.
@Test(expectedExceptions = AuthLoginException.class)
public void shouldEnforceClientIPOnLoginWhenClientIPIsNotStoredInPCookie() throws LoginException {
//Given
MessageInfo messageInfo = mock(MessageInfo.class);
Subject clientSubject = new Subject();
Callback[] callbacks = new Callback[0];
Jwt jwt = mock(Jwt.class);
JwtClaimsSet claimsSet = mock(JwtClaimsSet.class);
Map<String, Object> claimsSetContext = new HashMap<String, Object>();
HttpServletRequest request = mock(HttpServletRequest.class);
Map options = new HashMap();
options.put("openam-auth-persistent-cookie-enforce-ip", Collections.singleton("true"));
persistentCookieAuthModule.initialize(null, null, options);
given(jwtSessionModule.validateJwtSessionCookie(messageInfo)).willReturn(jwt);
given(jwt.getClaimsSet()).willReturn(claimsSet);
given(claimsSet.getClaim(AuthenticationFramework.ATTRIBUTE_AUTH_CONTEXT, Map.class)).willReturn(claimsSetContext);
claimsSetContext.put("openam.rlm", "REALM");
given(amLoginModuleBinder.getRequestOrg()).willReturn("REALM");
given(amLoginModuleBinder.getHttpServletRequest()).willReturn(request);
given(request.getRemoteAddr()).willReturn("CLIENT_IP");
//When
persistentCookieAuthModule.process(messageInfo, clientSubject, callbacks);
//Then
fail();
}
use of org.forgerock.json.jose.jwt.Jwt in project OpenAM by OpenRock.
the class PersistentCookieAuthModuleTest method shouldEnforceClientIPOnLoginWhenClientIPIsSame.
@Test
public void shouldEnforceClientIPOnLoginWhenClientIPIsSame() throws LoginException {
//Given
MessageInfo messageInfo = mock(MessageInfo.class);
Subject clientSubject = new Subject();
Callback[] callbacks = new Callback[0];
Jwt jwt = mock(Jwt.class);
JwtClaimsSet claimsSet = mock(JwtClaimsSet.class);
Map<String, Object> claimsSetContext = new HashMap<String, Object>();
HttpServletRequest request = mock(HttpServletRequest.class);
Map options = new HashMap();
options.put("openam-auth-persistent-cookie-enforce-ip", Collections.singleton("true"));
persistentCookieAuthModule.initialize(null, null, options);
given(jwtSessionModule.validateJwtSessionCookie(messageInfo)).willReturn(jwt);
given(jwt.getClaimsSet()).willReturn(claimsSet);
given(claimsSet.getClaim(AuthenticationFramework.ATTRIBUTE_AUTH_CONTEXT, Map.class)).willReturn(claimsSetContext);
claimsSetContext.put("openam.rlm", "REALM");
given(amLoginModuleBinder.getRequestOrg()).willReturn("REALM");
claimsSetContext.put("openam.clientip", "CLIENT_IP");
given(amLoginModuleBinder.getHttpServletRequest()).willReturn(request);
given(request.getRemoteAddr()).willReturn("CLIENT_IP");
//When
boolean result = persistentCookieAuthModule.process(messageInfo, clientSubject, callbacks);
//Then
assertTrue(result);
}
Aggregations