Search in sources :

Example 21 with SequenceConfig

use of org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig in project carbon-identity-framework by wso2.

the class PostAuthAssociationHandlerTest method processAndGetAuthenticationContext.

/**
 * To get the authentication context and to call the handle method of the PostAuthAssociationHandler.
 *
 * @param sp1 Service Provider
 * @return relevant authentication context.
 * @throws FrameworkException Framework Exception.
 */
private AuthenticationContext processAndGetAuthenticationContext(ServiceProvider sp1, boolean withAuthenticatedUser, boolean isFederated, boolean withSpRoleMapping) throws FrameworkException {
    AuthenticationContext context = getAuthenticationContext(sp1);
    SequenceConfig sequenceConfig = configurationLoader.getSequenceConfig(context, Collections.emptyMap(), sp1);
    sequenceConfig.getApplicationConfig().setAlwaysSendMappedLocalSubjectId(true);
    context.setSequenceConfig(sequenceConfig);
    context.setProperty(FrameworkConstants.STEP_BASED_SEQUENCE_HANDLER_TRIGGERED, true);
    ApplicationAuthenticator applicationAuthenticator = mock(ApplicationAuthenticator.class);
    if (isFederated) {
        applicationAuthenticator = mock(FederatedApplicationAuthenticator.class);
    }
    when(applicationAuthenticator.getName()).thenReturn("Authenticator1");
    if (withAuthenticatedUser) {
        AuthenticatedUser authenticatedUser = new AuthenticatedUser();
        authenticatedUser.setUserName("federated");
        authenticatedUser.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        authenticatedUser.setAuthenticatedSubjectIdentifier("federated");
        sequenceConfig.setAuthenticatedUser(authenticatedUser);
        AuthenticatorConfig authenticatorConfig = new AuthenticatorConfig();
        authenticatorConfig.setApplicationAuthenticator(applicationAuthenticator);
        for (Map.Entry<Integer, StepConfig> entry : sequenceConfig.getStepMap().entrySet()) {
            StepConfig stepConfig = entry.getValue();
            stepConfig.setAuthenticatedAutenticator(authenticatorConfig);
            stepConfig.setAuthenticatedUser(authenticatedUser);
        }
        context.setSequenceConfig(sequenceConfig);
    }
    if (withSpRoleMapping) {
        sequenceConfig.getApplicationConfig().getClaimMappings().put(getLocalGroupsClaimURI(), getLocalGroupsClaimURI());
        sequenceConfig.getApplicationConfig().getServiceProvider().getClaimConfig().setLocalClaimDialect(true);
        sequenceConfig.getApplicationConfig().getRoleMappings().put(ORI_ROLE_1, SP_MAPPED_ROLE_1);
        sequenceConfig.getApplicationConfig().getRoleMappings().put(ORI_ROLE_2, SP_MAPPED_ROLE_2);
    }
    return context;
}
Also used : AuthenticatorConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig) AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) FederatedApplicationAuthenticator(org.wso2.carbon.identity.application.authentication.framework.FederatedApplicationAuthenticator) ApplicationAuthenticator(org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticator) StepConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig) SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) FederatedApplicationAuthenticator(org.wso2.carbon.identity.application.authentication.framework.FederatedApplicationAuthenticator) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) Map(java.util.Map) HashMap(java.util.HashMap)

Example 22 with SequenceConfig

use of org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig in project carbon-identity-framework by wso2.

the class DefaultRequestPathBasedSequenceHandlerTest method testGetServiceProviderMappedUserRoles.

@Test(dataProvider = "spRoleMappingDataProvider")
public void testGetServiceProviderMappedUserRoles(Map<String, String> spRoleMappings, List<String> localUserRoles, String multiAttributeSeparator, String expectedRoles) throws Exception {
    Util.mockMultiAttributeSeparator(multiAttributeSeparator);
    SequenceConfig sequenceConfig = Util.mockSequenceConfig(spRoleMappings);
    mockStatic(ApplicationMgtSystemConfig.class);
    mockStatic(IdentityTenantUtil.class);
    when(ApplicationMgtSystemConfig.getInstance()).thenReturn(applicationMgtSystemConfig);
    when(applicationMgtSystemConfig.getApplicationDAO()).thenReturn(applicationDAO);
    when(IdentityTenantUtil.getRealmService()).thenReturn(mockRealmService);
    when(mockRealmService.getBootstrapRealmConfiguration()).thenReturn(mockRealmConfiguration);
    String mappedRoles = requestPathBasedSequenceHandler.getServiceProviderMappedUserRoles(sequenceConfig, localUserRoles);
    assertEquals(mappedRoles, expectedRoles);
}
Also used : SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 23 with SequenceConfig

use of org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig in project carbon-identity-framework by wso2.

the class DefaultStepBasedSequenceHandlerTest method testHandleSingleStep.

/**
 * First step of the sequence is handled
 */
@Test
public void testHandleSingleStep() throws Exception {
    // mock the step handler
    StepHandler stepHandler = getMockedStepHandlerForIncompleteStep(true);
    mockStatic(FrameworkUtils.class);
    when(FrameworkUtils.getStepHandler()).thenReturn(stepHandler);
    StepConfig stepConfig = new StepConfig();
    SequenceConfig sequenceConfig = new SequenceConfig();
    sequenceConfig.getStepMap().put(1, stepConfig);
    context.setSequenceConfig(sequenceConfig);
    stepBasedSequenceHandler.handle(request, response, context);
    assertFalse(context.getSequenceConfig().isCompleted());
    assertTrue(context.isRequestAuthenticated());
}
Also used : StepConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig) StepHandler(org.wso2.carbon.identity.application.authentication.framework.handler.step.StepHandler) SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 24 with SequenceConfig

use of org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig in project carbon-identity-framework by wso2.

the class DefaultStepBasedSequenceHandlerTest method testHandlePostUserName.

@Test(dataProvider = "postAuthenticationDataProvider")
public void testHandlePostUserName(String subjectClaimUriFromAppConfig, String spSubjectClaimValue, boolean appendTenantDomainToSubject, boolean appendUserStoreDomainToSubject, String authenticatedUserNameInSequence, String expectedSubjectIdentifier) throws Exception {
    stepBasedSequenceHandler = new DefaultStepBasedSequenceHandler();
    ApplicationConfig applicationConfig = spy(new ApplicationConfig(new ServiceProvider()));
    when(applicationConfig.getSubjectClaimUri()).thenReturn(subjectClaimUriFromAppConfig);
    when(applicationConfig.isUseTenantDomainInLocalSubjectIdentifier()).thenReturn(appendTenantDomainToSubject);
    when(applicationConfig.isUseUserstoreDomainInLocalSubjectIdentifier()).thenReturn(appendUserStoreDomainToSubject);
    AuthenticatedUser authenticatedUser = new AuthenticatedUser();
    authenticatedUser.setUserName(authenticatedUserNameInSequence);
    authenticatedUser.setTenantDomain(FOO_TENANT);
    authenticatedUser.setUserStoreDomain(XY_USER_STORE_DOMAIN);
    SequenceConfig sequenceConfig = spy(new SequenceConfig());
    Map<Integer, StepConfig> stepConfigMap = new HashMap<>();
    StepConfig stepConfig = spy(new StepConfig());
    when(stepConfig.getAuthenticatedUser()).thenReturn(authenticatedUser);
    when(stepConfig.isSubjectIdentifierStep()).thenReturn(false);
    when(stepConfig.isSubjectAttributeStep()).thenReturn(false);
    AuthenticatorConfig authenticatorConfig = new AuthenticatorConfig();
    authenticatorConfig.setApplicationAuthenticator(authenticator);
    when(stepConfig.getAuthenticatedAutenticator()).thenReturn(authenticatorConfig);
    stepConfigMap.put(1, stepConfig);
    sequenceConfig.setStepMap(stepConfigMap);
    sequenceConfig.setAuthenticatedUser(authenticatedUser);
    sequenceConfig.setApplicationConfig(applicationConfig);
    // SP subject claim value
    context.setProperty(FrameworkConstants.SERVICE_PROVIDER_SUBJECT_CLAIM_VALUE, spSubjectClaimValue);
    context.setSequenceConfig(sequenceConfig);
    stepBasedSequenceHandler.handlePostAuthentication(request, response, context);
    assertEquals(context.getSequenceConfig().getAuthenticatedUser().getUserName(), authenticatedUserNameInSequence);
}
Also used : AuthenticatorConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig) ApplicationConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.ApplicationConfig) HashMap(java.util.HashMap) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) ThreadLocalProvisioningServiceProvider(org.wso2.carbon.identity.application.common.model.ThreadLocalProvisioningServiceProvider) StepConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig) SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 25 with SequenceConfig

use of org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig in project carbon-identity-framework by wso2.

the class DefaultStepBasedSequenceHandlerTest method testGetServiceProviderMappedUserRoles.

@Test(dataProvider = "spRoleMappingDataProvider")
public void testGetServiceProviderMappedUserRoles(Map<String, String> spRoleMappings, List<String> localUserRoles, String multiAttributeSeparator, String expectedRoles) throws Exception {
    Util.mockMultiAttributeSeparator(multiAttributeSeparator);
    mockStatic(ApplicationMgtSystemConfig.class);
    mockStatic(IdentityTenantUtil.class);
    when(ApplicationMgtSystemConfig.getInstance()).thenReturn(applicationMgtSystemConfig);
    when(applicationMgtSystemConfig.getApplicationDAO()).thenReturn(applicationDAO);
    when(IdentityTenantUtil.getRealmService()).thenReturn(mockRealmService);
    when(mockRealmService.getBootstrapRealmConfiguration()).thenReturn(mockRealmConfiguration);
    SequenceConfig sequenceConfig = Util.mockSequenceConfig(spRoleMappings);
    String mappedRoles = stepBasedSequenceHandler.getServiceProviderMappedUserRoles(sequenceConfig, localUserRoles);
    assertEquals(mappedRoles, expectedRoles, "Service Provider Mapped Role do not have the expect value.");
}
Also used : SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

SequenceConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)79 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)42 Test (org.testng.annotations.Test)36 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)33 HttpServletRequest (javax.servlet.http.HttpServletRequest)28 HttpServletResponse (javax.servlet.http.HttpServletResponse)28 StepConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig)24 AuthenticatorConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig)19 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)19 FrameworkException (org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException)18 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 HashMap (java.util.HashMap)13 ApplicationAuthenticator (org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticator)13 AuthHistory (org.wso2.carbon.identity.application.authentication.framework.context.AuthHistory)11 ApplicationConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.ApplicationConfig)10 FederatedApplicationAuthenticator (org.wso2.carbon.identity.application.authentication.framework.FederatedApplicationAuthenticator)9 Map (java.util.Map)8 ExternalIdPConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.ExternalIdPConfig)8 JsSequenceHandlerAbstractTest (org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence.JsSequenceHandlerAbstractTest)8 AuthGraphNode (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.AuthGraphNode)7