Search in sources :

Example 6 with AuthenticationException

use of com.sun.identity.authentication.spi.AuthenticationException in project OpenAM by OpenRock.

the class JaspiAuthModuleWrapperTest method setUp.

@BeforeMethod
public void setUp() {
    amLoginModuleBinder = mock(AMLoginModuleBinder.class);
    serverAuthModule = mock(ServerAuthModule.class);
    jaspiAuthModuleWrapper = new JaspiAuthModuleWrapper<ServerAuthModule>(serverAuthModule, "amAuthPersistentCookie") {

        @Override
        protected Map<String, Object> initialize(Subject subject, Map sharedState, Map options) {
            return config;
        }

        @Override
        protected boolean process(MessageInfo messageInfo, Subject clientSubject, Callback[] callbacks) throws LoginException {
            processMethodCalled = true;
            return true;
        }

        @Override
        protected Map<String, Object> initialize(Map requestParamsMap, HttpServletRequest request, HttpServletResponse response, SSOToken ssoToken) throws AuthenticationException {
            return config;
        }

        @Override
        protected void onLoginSuccess(MessageInfo messageInfo, Map requestParamsMap, HttpServletRequest request, HttpServletResponse response, SSOToken ssoToken) throws AuthenticationException {
            onLoginSuccessMethodCalled = true;
        }

        @Override
        public Principal getPrincipal() {
            return null;
        }
    };
    jaspiAuthModuleWrapper.setAMLoginModule(amLoginModuleBinder);
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    given(amLoginModuleBinder.getHttpServletRequest()).willReturn(request);
    given(amLoginModuleBinder.getHttpServletResponse()).willReturn(response);
}
Also used : SSOToken(com.iplanet.sso.SSOToken) AuthenticationException(com.sun.identity.authentication.spi.AuthenticationException) ServerAuthModule(javax.security.auth.message.module.ServerAuthModule) HttpServletResponse(javax.servlet.http.HttpServletResponse) Subject(javax.security.auth.Subject) MessageInfo(javax.security.auth.message.MessageInfo) HttpServletRequest(javax.servlet.http.HttpServletRequest) Callback(javax.security.auth.callback.Callback) LoginException(javax.security.auth.login.LoginException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) HashMap(java.util.HashMap) Map(java.util.Map) Principal(java.security.Principal) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with AuthenticationException

use of com.sun.identity.authentication.spi.AuthenticationException in project OpenAM by OpenRock.

the class Adaptive method onLoginSuccess.

public void onLoginSuccess(Map requestParamsMap, HttpServletRequest request, HttpServletResponse response, SSOToken token) throws AuthenticationException {
    Map<String, String> m = new HashMap<String, String>();
    Map<String, Set> attrMap = new HashMap<String, Set>();
    if (debug.messageEnabled()) {
        debug.message("{} executing PostProcessClass", ADAPTIVE);
    }
    try {
        String s = token.getProperty("ADAPTIVE");
        if (s != null && !s.isEmpty()) {
            stringToMap(s, m);
            token.setProperty("ADAPTIVE", "");
        }
        if (m.containsKey("IPSAVE")) {
            String value = m.get("IPSAVE");
            String name = m.get("IPAttr");
            Set<String> vals = new HashSet<String>();
            vals.add(value);
            attrMap.put(name, vals);
        }
        // Now we save the attribs,  since we can do it in one shot
        if (!attrMap.isEmpty()) {
            try {
                AMIdentity id = IdUtils.getIdentity(AccessController.doPrivileged(AdminTokenAction.getInstance()), token.getProperty(Constants.UNIVERSAL_IDENTIFIER));
                id.setAttributes(attrMap);
                id.store();
            } catch (Exception e) {
                debug.error("{}.getIdentity : Unable to save Attribute : {}", ADAPTIVE, attrMap, e);
            }
        }
        // 1 year, configurable?
        int autoLoginExpire = (60 * 60 * 24) * 365;
        final Set<String> cookieDomains = AuthUtils.getCookieDomainsForRequest(request);
        if (m.containsKey("LOGINNAME")) {
            String value = m.get("LOGINVALUE");
            String name = m.get("LOGINNAME");
            addCookieToResponse(response, cookieDomains, name, value, autoLoginExpire);
        }
        if (m.containsKey("COOKIENAME")) {
            String name = m.get("COOKIENAME");
            String value = m.get("COOKIEVALUE");
            addCookieToResponse(response, cookieDomains, name, value, autoLoginExpire);
        }
        if (m.containsKey("DEVICENAME")) {
            String name = m.get("DEVICENAME");
            String value = m.get("DEVICEVALUE");
            addCookieToResponse(response, cookieDomains, name, value, autoLoginExpire);
        }
    } catch (Exception e) {
        if (debug.messageEnabled()) {
            debug.message("{}.getIdentity : Unable to Retrieve PostAuthN Params", ADAPTIVE, e);
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) AMIdentity(com.sun.identity.idm.AMIdentity) ParseException(java.text.ParseException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) SSOException(com.iplanet.sso.SSOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IdRepoException(com.sun.identity.idm.IdRepoException) GeoIp2Exception(com.maxmind.geoip2.exception.GeoIp2Exception) IOException(java.io.IOException) AuthenticationException(com.sun.identity.authentication.spi.AuthenticationException) HashSet(java.util.HashSet)

Example 8 with AuthenticationException

use of com.sun.identity.authentication.spi.AuthenticationException in project OpenAM by OpenRock.

the class JaspiAuthModuleWrapperTest method shouldCallOnLoginSuccessWhenSecureResponseReturnsSendFailure.

@Test
public void shouldCallOnLoginSuccessWhenSecureResponseReturnsSendFailure() throws AuthenticationException, AuthException {
    //Given
    Map requestParamsMap = new HashMap();
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    SSOToken ssoToken = mock(SSOToken.class);
    given(serverAuthModule.secureResponse(Matchers.<MessageInfo>anyObject(), (Subject) isNull())).willReturn(AuthStatus.SEND_FAILURE);
    //When
    boolean exceptionCaught = false;
    AuthenticationException exception = null;
    try {
        jaspiAuthModuleWrapper.onLoginSuccess(requestParamsMap, request, response, ssoToken);
    } catch (AuthenticationException e) {
        exceptionCaught = true;
        exception = e;
    }
    //Then
    verify(serverAuthModule).initialize(Matchers.<MessagePolicy>anyObject(), (MessagePolicy) isNull(), Matchers.<CallbackHandler>anyObject(), eq(config));
    assertTrue(onLoginSuccessMethodCalled);
    verify(serverAuthModule).secureResponse(Matchers.<MessageInfo>anyObject(), (Subject) isNull());
    assertTrue(exceptionCaught);
    assertEquals(exception.getErrorCode(), "authFailed");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SSOToken(com.iplanet.sso.SSOToken) HashMap(java.util.HashMap) AuthenticationException(com.sun.identity.authentication.spi.AuthenticationException) HttpServletResponse(javax.servlet.http.HttpServletResponse) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 9 with AuthenticationException

use of com.sun.identity.authentication.spi.AuthenticationException in project OpenAM by OpenRock.

the class JaspiAuthModuleWrapperTest method shouldCallOnLoginSuccessWhenSecureResponseReturnsSendContinue.

@Test
public void shouldCallOnLoginSuccessWhenSecureResponseReturnsSendContinue() throws AuthenticationException, AuthException {
    //Given
    Map requestParamsMap = new HashMap();
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    SSOToken ssoToken = mock(SSOToken.class);
    given(serverAuthModule.secureResponse(Matchers.<MessageInfo>anyObject(), (Subject) isNull())).willReturn(AuthStatus.SEND_CONTINUE);
    //When
    boolean exceptionCaught = false;
    AuthenticationException exception = null;
    try {
        jaspiAuthModuleWrapper.onLoginSuccess(requestParamsMap, request, response, ssoToken);
    } catch (AuthenticationException e) {
        exceptionCaught = true;
        exception = e;
    }
    //Then
    verify(serverAuthModule).initialize(Matchers.<MessagePolicy>anyObject(), (MessagePolicy) isNull(), Matchers.<CallbackHandler>anyObject(), eq(config));
    assertTrue(onLoginSuccessMethodCalled);
    verify(serverAuthModule).secureResponse(Matchers.<MessageInfo>anyObject(), (Subject) isNull());
    assertTrue(exceptionCaught);
    assertEquals(exception.getErrorCode(), "authFailed");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SSOToken(com.iplanet.sso.SSOToken) HashMap(java.util.HashMap) AuthenticationException(com.sun.identity.authentication.spi.AuthenticationException) HttpServletResponse(javax.servlet.http.HttpServletResponse) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 10 with AuthenticationException

use of com.sun.identity.authentication.spi.AuthenticationException in project OpenAM by OpenRock.

the class JaspiAuthModuleWrapperTest method shouldCallOnLoginSuccessAndThrowAuthenticationExceptionWhenAuthExceptionCaught.

@Test
public void shouldCallOnLoginSuccessAndThrowAuthenticationExceptionWhenAuthExceptionCaught() throws AuthenticationException, AuthException {
    //Given
    Map requestParamsMap = new HashMap();
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    SSOToken ssoToken = mock(SSOToken.class);
    doThrow(AuthException.class).when(serverAuthModule).initialize(Matchers.<MessagePolicy>anyObject(), (MessagePolicy) isNull(), Matchers.<CallbackHandler>anyObject(), eq(config));
    //When
    boolean exceptionCaught = false;
    AuthenticationException exception = null;
    try {
        jaspiAuthModuleWrapper.onLoginSuccess(requestParamsMap, request, response, ssoToken);
    } catch (AuthenticationException e) {
        exceptionCaught = true;
        exception = e;
    }
    //Then
    verify(serverAuthModule).initialize(Matchers.<MessagePolicy>anyObject(), (MessagePolicy) isNull(), Matchers.<CallbackHandler>anyObject(), eq(config));
    verify(serverAuthModule, never()).secureResponse(Matchers.<MessageInfo>anyObject(), (Subject) isNull());
    assertTrue(exceptionCaught);
    assertEquals(exception.getErrorCode(), "authFailed");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SSOToken(com.iplanet.sso.SSOToken) HashMap(java.util.HashMap) AuthenticationException(com.sun.identity.authentication.spi.AuthenticationException) HttpServletResponse(javax.servlet.http.HttpServletResponse) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Aggregations

AuthenticationException (com.sun.identity.authentication.spi.AuthenticationException)12 HashMap (java.util.HashMap)7 SSOToken (com.iplanet.sso.SSOToken)5 Map (java.util.Map)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 SSOException (com.iplanet.sso.SSOException)4 Test (org.testng.annotations.Test)4 Set (java.util.Set)3 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)2 AMIdentity (com.sun.identity.idm.AMIdentity)2 HashSet (java.util.HashSet)2 MessageInfo (javax.security.auth.message.MessageInfo)2 GeoIp2Exception (com.maxmind.geoip2.exception.GeoIp2Exception)1 IdRepoException (com.sun.identity.idm.IdRepoException)1 NameIDInfo (com.sun.identity.saml2.common.NameIDInfo)1 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)1 Debug (com.sun.identity.shared.debug.Debug)1 SMSException (com.sun.identity.sm.SMSException)1 IOException (java.io.IOException)1