use of javax.security.auth.message.MessageInfo 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