Search in sources :

Example 11 with AuthenticationException

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

the class JaspiAuthModuleWrapperTest method shouldCallOnLoginSuccessWhenSecureResponseReturnsElse.

@Test
public void shouldCallOnLoginSuccessWhenSecureResponseReturnsElse() 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.SUCCESS);
    //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 12 with AuthenticationException

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

the class SAML2 method linkAccount.

/**
     * Links SAML2 accounts once all local auth steps have completed and we have a local principalId,
     * sets the local principal to a new SAML2Pricipal with that ID.
     */
private void linkAccount(final String principalId, final NameID nameId) throws SAML2MetaException, AuthenticationException {
    final String spEntityId = metaManager.getEntityByMetaAlias(metaAlias);
    try {
        NameIDInfo info = new NameIDInfo(spEntityId, entityName, nameId, SAML2Constants.SP_ROLE, false);
        DEBUG.message("SAML2 :: Local User {} Linked to Federation Account - {}", principalId, nameId.getValue());
        if (shouldPersistNameID(spEntityId)) {
            AccountUtils.setAccountFederation(info, principalId);
        }
        principal = new SAML2Principal(principalId);
    } catch (SAML2Exception e) {
        // exception logged later
        throw new AuthenticationException(BUNDLE_NAME, "localLinkError", new Object[0]);
    }
}
Also used : SAML2Exception(com.sun.identity.saml2.common.SAML2Exception) NameIDInfo(com.sun.identity.saml2.common.NameIDInfo) AuthenticationException(com.sun.identity.authentication.spi.AuthenticationException)

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