Search in sources :

Example 16 with MessageInfo

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);
}
Also used : HashMap(java.util.HashMap) Jwt(org.forgerock.json.jose.jwt.Jwt) Subject(javax.security.auth.Subject) MessageInfo(javax.security.auth.message.MessageInfo) HttpServletRequest(javax.servlet.http.HttpServletRequest) JwtClaimsSet(org.forgerock.json.jose.jwt.JwtClaimsSet) Callback(javax.security.auth.callback.Callback) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Aggregations

MessageInfo (javax.security.auth.message.MessageInfo)16 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 Subject (javax.security.auth.Subject)10 HashMap (java.util.HashMap)8 Map (java.util.Map)7 Test (org.testng.annotations.Test)7 Principal (java.security.Principal)6 AuthException (javax.security.auth.message.AuthException)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 Callback (javax.security.auth.callback.Callback)5 SSOToken (com.iplanet.sso.SSOToken)4 ServerAuthContext (javax.security.auth.message.config.ServerAuthContext)4 Jwt (org.forgerock.json.jose.jwt.Jwt)4 JwtClaimsSet (org.forgerock.json.jose.jwt.JwtClaimsSet)4 SSOTokenID (com.iplanet.sso.SSOTokenID)3 SSOException (com.iplanet.sso.SSOException)2 SecurityContext (com.sun.enterprise.security.SecurityContext)2 AuthenticationException (com.sun.identity.authentication.spi.AuthenticationException)2 SMSException (com.sun.identity.sm.SMSException)2 AuthStatus (javax.security.auth.message.AuthStatus)2