Search in sources :

Example 11 with MessageInfo

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

Example 12 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)12 HashMap (java.util.HashMap)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 Map (java.util.Map)7 Subject (javax.security.auth.Subject)7 Test (org.testng.annotations.Test)7 Principal (java.security.Principal)5 Callback (javax.security.auth.callback.Callback)5 SSOToken (com.iplanet.sso.SSOToken)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)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 AuthenticationException (com.sun.identity.authentication.spi.AuthenticationException)2 SMSException (com.sun.identity.sm.SMSException)2 AuthException (javax.security.auth.message.AuthException)2 ServletJwtSessionModule (org.forgerock.jaspi.modules.session.jwt.ServletJwtSessionModule)2 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)1 LoginException (javax.security.auth.login.LoginException)1