Search in sources :

Example 81 with Authenticator

use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project carbon-identity-framework by wso2.

the class DefaultStepHandler method handleResponse.

protected void handleResponse(HttpServletRequest request, HttpServletResponse response, AuthenticationContext context) throws FrameworkException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Receive a response from the external party");
    }
    SequenceConfig sequenceConfig = context.getSequenceConfig();
    int currentStep = context.getCurrentStep();
    boolean isNoneCanHandle = true;
    StepConfig stepConfig = sequenceConfig.getStepMap().get(currentStep);
    for (AuthenticatorConfig authenticatorConfig : stepConfig.getAuthenticatorList()) {
        ApplicationAuthenticator authenticator = authenticatorConfig.getApplicationAuthenticator();
        // Call authenticate if canHandle
        if (authenticator != null && authenticator.canHandle(request) && (context.getCurrentAuthenticator() == null || authenticator.getName().equals(context.getCurrentAuthenticator()))) {
            isNoneCanHandle = false;
            if (LOG.isDebugEnabled()) {
                LOG.debug(authenticator.getName() + " can handle the request.");
            }
            doAuthentication(request, response, context, authenticatorConfig);
            break;
        }
    }
    if (isNoneCanHandle) {
        throw new FrameworkException("No authenticator can handle the request in step :  " + currentStep);
    }
}
Also used : AuthenticatorConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig) FederatedApplicationAuthenticator(org.wso2.carbon.identity.application.authentication.framework.FederatedApplicationAuthenticator) LocalApplicationAuthenticator(org.wso2.carbon.identity.application.authentication.framework.LocalApplicationAuthenticator) ApplicationAuthenticator(org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticator) FrameworkException(org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException) StepConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig) SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)

Example 82 with Authenticator

use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project carbon-identity-framework by wso2.

the class JITProvisioningPostAuthenticationHandlerTest method testHandleWithAuthenticatedUserWithFederatedIdp.

@Test(description = "This test case tests the Post JIT provisioning handling flow with an authenticated user")
public void testHandleWithAuthenticatedUserWithFederatedIdp() throws FrameworkException, FederatedAssociationManagerException, AccountLockServiceException, UserStoreException {
    AuthenticationContext context = processAndGetAuthenticationContext(sp, true, true);
    FederatedAssociationManager federatedAssociationManager = mock(FederatedAssociationManagerImpl.class);
    when(FrameworkUtils.getFederatedAssociationManager()).thenReturn(federatedAssociationManager);
    doReturn("test").when(federatedAssociationManager).getUserForFederatedAssociation(Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
    when(FrameworkUtils.getStepBasedSequenceHandler()).thenReturn(Mockito.mock(StepBasedSequenceHandler.class));
    mockStatic(FrameworkServiceDataHolder.class);
    PowerMockito.when(FrameworkServiceDataHolder.getInstance()).thenReturn(frameworkServiceDataHolder);
    mockStatic(AccountLockService.class);
    when(frameworkServiceDataHolder.getAccountLockService()).thenReturn(accountLockService);
    when(accountLockService.isAccountLocked(anyString(), anyString())).thenReturn(false);
    RealmService mockRealmService = mock(RealmService.class);
    PowerMockito.when(FrameworkServiceDataHolder.getInstance().getRealmService()).thenReturn(mockRealmService);
    UserRealm mockUserRealm = mock(UserRealm.class);
    UserStoreManager mockUserStoreManager = mock(UserStoreManager.class);
    Map<String, String> mockClaimValues = mock(HashMap.class);
    mockStatic(IdentityTenantUtil.class);
    when(IdentityTenantUtil.getTenantId(anyString())).thenReturn(1);
    when(mockRealmService.getTenantUserRealm(anyInt())).thenReturn(mockUserRealm);
    when(mockUserRealm.getUserStoreManager()).thenReturn(mockUserStoreManager);
    when(mockUserStoreManager.getUserClaimValues(anyString(), eq(new String[] { AccountConstants.ACCOUNT_DISABLED_CLAIM }), eq(UserCoreConstants.DEFAULT_PROFILE))).thenReturn(mockClaimValues);
    when(mockClaimValues.get(AccountConstants.ACCOUNT_DISABLED_CLAIM)).thenReturn("false");
    PostAuthnHandlerFlowStatus postAuthnHandlerFlowStatus = postJITProvisioningHandler.handle(request, response, context);
    Assert.assertEquals(postAuthnHandlerFlowStatus, PostAuthnHandlerFlowStatus.SUCCESS_COMPLETED, "Post JIT provisioning handler executed while having a authenticated user without federated " + "authenticator");
}
Also used : FederatedAssociationManager(org.wso2.carbon.identity.user.profile.mgt.association.federation.FederatedAssociationManager) AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) UserRealm(org.wso2.carbon.user.core.UserRealm) RealmService(org.wso2.carbon.user.core.service.RealmService) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) Mockito.anyString(org.mockito.Mockito.anyString) StepBasedSequenceHandler(org.wso2.carbon.identity.application.authentication.framework.handler.sequence.StepBasedSequenceHandler) PostAuthnHandlerFlowStatus(org.wso2.carbon.identity.application.authentication.framework.handler.request.PostAuthnHandlerFlowStatus) Test(org.testng.annotations.Test) AbstractFrameworkTest(org.wso2.carbon.identity.application.authentication.framework.AbstractFrameworkTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 83 with Authenticator

use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project carbon-identity-framework by wso2.

the class JITProvisioningPostAuthenticationHandlerTest method testHandleWithAuthenticatedUserWithoutFederatedIdp.

@Test(description = "This test case tests the Post JIT provisioning handling flow with an authenticated user")
public void testHandleWithAuthenticatedUserWithoutFederatedIdp() throws FrameworkException {
    AuthenticationContext context = processAndGetAuthenticationContext(sp, true, false);
    PostAuthnHandlerFlowStatus postAuthnHandlerFlowStatus = postJITProvisioningHandler.handle(request, response, context);
    Assert.assertEquals(postAuthnHandlerFlowStatus, PostAuthnHandlerFlowStatus.SUCCESS_COMPLETED, "Post JIT provisioning handler executed while having a authenticated user without federated " + "authenticator");
}
Also used : AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) PostAuthnHandlerFlowStatus(org.wso2.carbon.identity.application.authentication.framework.handler.request.PostAuthnHandlerFlowStatus) Test(org.testng.annotations.Test) AbstractFrameworkTest(org.wso2.carbon.identity.application.authentication.framework.AbstractFrameworkTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 84 with Authenticator

use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project carbon-identity-framework by wso2.

the class DefaultRequestPathBasedSequenceHandlerTest method testHandleInvalidCredentialException.

/*
        Request path authenticator throws an InvalidCredentialsException
     */
@Test
public void testHandleInvalidCredentialException() throws Exception {
    // mock the behaviour of the request path authenticator
    when(requestPathAuthenticator.canHandle(any(HttpServletRequest.class))).thenReturn(true);
    doThrow(new InvalidCredentialsException("Invalid Credentials.")).when(requestPathAuthenticator).process(request, response, context);
    requestPathBasedSequenceHandler.handle(request, response, context);
    assertEquals(context.isRequestAuthenticated(), false);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) InvalidCredentialsException(org.wso2.carbon.identity.application.authentication.framework.exception.InvalidCredentialsException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 85 with Authenticator

use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project carbon-identity-framework by wso2.

the class DefaultRequestPathBasedSequenceHandlerTest method testHandleLogoutFailedException.

/*
        Request path authenticator throws a LogoutFailedException
    */
@Test(expectedExceptions = FrameworkException.class)
public void testHandleLogoutFailedException() throws Exception {
    // mock the behaviour of the request path authenticator
    when(requestPathAuthenticator.canHandle(any(HttpServletRequest.class))).thenReturn(true);
    doThrow(new LogoutFailedException("Logout Failed.")).when(requestPathAuthenticator).process(request, response, context);
    requestPathBasedSequenceHandler.handle(request, response, context);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) LogoutFailedException(org.wso2.carbon.identity.application.authentication.framework.exception.LogoutFailedException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)27 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)25 Test (org.testng.annotations.Test)23 IdentityProviderManagementException (org.wso2.carbon.idp.mgt.IdentityProviderManagementException)23 ArrayList (java.util.ArrayList)22 HashMap (java.util.HashMap)22 AuthenticatorConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig)22 ApplicationAuthenticator (org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticator)19 StepConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig)19 SequenceConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)16 FrameworkException (org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException)15 LocalAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig)15 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)15 IOException (java.io.IOException)12 Map (java.util.Map)12 FederatedApplicationAuthenticator (org.wso2.carbon.identity.application.authentication.framework.FederatedApplicationAuthenticator)12 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)11 RequestPathAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig)11 Property (org.wso2.carbon.identity.application.common.model.Property)10 HttpResponse (org.apache.http.HttpResponse)8