Search in sources :

Example 1 with ServletJwtSessionModule

use of org.forgerock.jaspi.modules.session.jwt.ServletJwtSessionModule in project OpenAM by OpenRock.

the class PersistentCookieAuthModuleTest method shouldCallOnLoginSuccessWhenJwtNotValidated.

@Test
public void shouldCallOnLoginSuccessWhenJwtNotValidated() throws AuthenticationException, SSOException {
    //Given
    persistentCookieAuthModule = new PersistentCookieAuthModule(new ServletJwtSessionModule(), amKeyProvider, coreWrapper) {

        @Override
        protected String getKeyAlias(String orgName) throws SSOException, SMSException {
            return "KEY_ALIAS";
        }
    };
    MessageInfo messageInfo = mock(MessageInfo.class);
    Map requestParamsMap = new HashMap();
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    SSOToken ssoToken = mock(SSOToken.class);
    Map<String, Object> map = new HashMap<String, Object>();
    given(messageInfo.getMap()).willReturn(map);
    Principal principal = mock(Principal.class);
    given(principal.getName()).willReturn("PRINCIPAL_NAME");
    SSOTokenID ssoTokenId = mock(SSOTokenID.class);
    given(ssoTokenId.toString()).willReturn("SSO_TOKEN_ID");
    given(ssoToken.getPrincipal()).willReturn(principal);
    given(ssoToken.getAuthType()).willReturn("AUTH_TYPE");
    given(ssoToken.getTokenID()).willReturn(ssoTokenId);
    given(ssoToken.getProperty("Organization")).willReturn("ORGANISATION");
    //When
    persistentCookieAuthModule.onLoginSuccess(messageInfo, requestParamsMap, request, response, ssoToken);
    //Then
    assertEquals(map.size(), 1);
    Map<String, Object> contextMap = (Map<String, Object>) map.get("org.forgerock.authentication.context");
    assertEquals(contextMap.get("openam.usr"), "PRINCIPAL_NAME");
    assertEquals(contextMap.get("openam.aty"), "AUTH_TYPE");
    assertEquals(contextMap.get("openam.sid"), "SSO_TOKEN_ID");
    assertEquals(contextMap.get("openam.rlm"), "ORGANISATION");
    assertEquals(contextMap.get("openam.clientip"), null);
}
Also used : SSOTokenID(com.iplanet.sso.SSOTokenID) SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) HashMap(java.util.HashMap) HttpServletResponse(javax.servlet.http.HttpServletResponse) SSOException(com.iplanet.sso.SSOException) MessageInfo(javax.security.auth.message.MessageInfo) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletJwtSessionModule(org.forgerock.jaspi.modules.session.jwt.ServletJwtSessionModule) HashMap(java.util.HashMap) Map(java.util.Map) Principal(java.security.Principal) Test(org.testng.annotations.Test)

Example 2 with ServletJwtSessionModule

use of org.forgerock.jaspi.modules.session.jwt.ServletJwtSessionModule in project OpenAM by OpenRock.

the class PersistentCookieAuthModuleTest method shouldCallOnLoginSuccess.

@Test
public void shouldCallOnLoginSuccess() throws AuthenticationException, SSOException {
    //Given
    persistentCookieAuthModule = new PersistentCookieAuthModule(new ServletJwtSessionModule(), amKeyProvider, coreWrapper) {

        @Override
        protected String getKeyAlias(String orgName) throws SSOException, SMSException {
            return "KEY_ALIAS";
        }
    };
    MessageInfo messageInfo = mock(MessageInfo.class);
    Map requestParamsMap = new HashMap();
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    SSOToken ssoToken = mock(SSOToken.class);
    Map<String, Object> map = new HashMap<String, Object>();
    given(messageInfo.getMap()).willReturn(map);
    Principal principal = mock(Principal.class);
    given(principal.getName()).willReturn("PRINCIPAL_NAME");
    SSOTokenID ssoTokenId = mock(SSOTokenID.class);
    given(ssoTokenId.toString()).willReturn("SSO_TOKEN_ID");
    given(ssoToken.getPrincipal()).willReturn(principal);
    given(ssoToken.getAuthType()).willReturn("AUTH_TYPE");
    given(ssoToken.getTokenID()).willReturn(ssoTokenId);
    given(ssoToken.getProperty("Organization")).willReturn("ORGANISATION");
    given(ssoToken.getProperty("jwtValidated")).willReturn("true");
    //When
    persistentCookieAuthModule.onLoginSuccess(messageInfo, requestParamsMap, request, response, ssoToken);
    //Then
    assertEquals(map.size(), 2);
    assertEquals(map.get("jwtValidated"), true);
    Map<String, Object> contextMap = (Map<String, Object>) map.get("org.forgerock.authentication.context");
    assertEquals(contextMap.get("openam.usr"), "PRINCIPAL_NAME");
    assertEquals(contextMap.get("openam.aty"), "AUTH_TYPE");
    assertEquals(contextMap.get("openam.sid"), "SSO_TOKEN_ID");
    assertEquals(contextMap.get("openam.rlm"), "ORGANISATION");
    assertEquals(contextMap.get("openam.clientip"), null);
}
Also used : SSOTokenID(com.iplanet.sso.SSOTokenID) SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) HashMap(java.util.HashMap) HttpServletResponse(javax.servlet.http.HttpServletResponse) SSOException(com.iplanet.sso.SSOException) MessageInfo(javax.security.auth.message.MessageInfo) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletJwtSessionModule(org.forgerock.jaspi.modules.session.jwt.ServletJwtSessionModule) HashMap(java.util.HashMap) Map(java.util.Map) Principal(java.security.Principal) Test(org.testng.annotations.Test)

Aggregations

SSOException (com.iplanet.sso.SSOException)2 SSOToken (com.iplanet.sso.SSOToken)2 SSOTokenID (com.iplanet.sso.SSOTokenID)2 SMSException (com.sun.identity.sm.SMSException)2 Principal (java.security.Principal)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 MessageInfo (javax.security.auth.message.MessageInfo)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 ServletJwtSessionModule (org.forgerock.jaspi.modules.session.jwt.ServletJwtSessionModule)2 Test (org.testng.annotations.Test)2