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;
}
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);
}
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());
}
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);
}
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.");
}
Aggregations