Search in sources :

Example 6 with Jwt

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();
}
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 7 with Jwt

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");
}
Also used : JwtClaimsSet(org.forgerock.json.jose.jwt.JwtClaimsSet) Callback(javax.security.auth.callback.Callback) Jwt(org.forgerock.json.jose.jwt.Jwt) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) Test(org.testng.annotations.Test)

Example 8 with Jwt

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();
}
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 9 with Jwt

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);
}
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

Jwt (org.forgerock.json.jose.jwt.Jwt)9 Test (org.testng.annotations.Test)8 Callback (javax.security.auth.callback.Callback)7 JwtClaimsSet (org.forgerock.json.jose.jwt.JwtClaimsSet)7 Subject (javax.security.auth.Subject)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 MessageInfo (javax.security.auth.message.MessageInfo)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)3 JwtPrincipal (com.sun.identity.entitlement.JwtPrincipal)1 Principal (java.security.Principal)1 SignedJwt (org.forgerock.json.jose.jws.SignedJwt)1 RealmContext (org.forgerock.openam.rest.RealmContext)1 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)1 ClientContext (org.forgerock.services.context.ClientContext)1 Context (org.forgerock.services.context.Context)1