Search in sources :

Example 6 with ApplicationConfig

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

the class DefaultClaimHandler method retrieveAllNunNullUserClaimValues.

private Map<String, String> retrieveAllNunNullUserClaimValues(AuthenticatedUser authenticatedUser, ClaimManager claimManager, ApplicationConfig appConfig, AbstractUserStoreManager userStore) throws FrameworkException {
    String tenantDomain = authenticatedUser.getTenantDomain();
    Map<String, String> allLocalClaims = new HashMap<>();
    try {
        org.wso2.carbon.user.api.ClaimMapping[] claimMappings = claimManager.getAllClaimMappings(ApplicationConstants.LOCAL_IDP_DEFAULT_CLAIM_DIALECT);
        List<String> localClaimURIs = new ArrayList<>();
        for (org.wso2.carbon.user.api.ClaimMapping mapping : claimMappings) {
            String claimURI = mapping.getClaim().getClaimUri();
            localClaimURIs.add(claimURI);
        }
        allLocalClaims = userStore.getUserClaimValuesWithID(authenticatedUser.getUserId(), localClaimURIs.toArray(new String[0]), null);
        if (allLocalClaims == null) {
            return new HashMap<>();
        }
    } catch (UserStoreException e) {
        if (e.getMessage().contains("UserNotFound")) {
            if (log.isDebugEnabled()) {
                log.debug("User " + authenticatedUser.getLoggableUserId() + " not found in user store");
            }
        } else {
            throw new FrameworkException("Error occurred while getting all user claims for " + authenticatedUser.getLoggableUserId() + " in " + tenantDomain, e);
        }
    } catch (UserIdNotFoundException e) {
        throw new FrameworkException("User id is not available for user: " + authenticatedUser.getLoggableUserId(), e);
    }
    return allLocalClaims;
}
Also used : FrameworkException(org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UserIdNotFoundException(org.wso2.carbon.identity.application.authentication.framework.exception.UserIdNotFoundException) ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) UserStoreException(org.wso2.carbon.user.api.UserStoreException)

Example 7 with ApplicationConfig

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

the class DefaultClaimFilter method getSpClaimMappings.

private List<ClaimMapping> getSpClaimMappings(ApplicationConfig appConfig) {
    Map<String, String> spClaimMapping = appConfig.getClaimMappings();
    Map<String, String> mandatoryClaims = appConfig.getMandatoryClaimMappings();
    Map<String, String> requestedClaims = appConfig.getRequestedClaimMappings();
    List<ClaimMapping> spClaimMappingsList = new ArrayList<>();
    spClaimMapping.forEach((key, value) -> {
        ClaimMapping claimMapping = ClaimMapping.build(value, key, null, false);
        mandatoryClaims.entrySet().stream().filter(entry1 -> key.equals(entry1.getKey())).map(entry1 -> true).forEach(claimMapping::setMandatory);
        requestedClaims.entrySet().stream().filter(entry2 -> key.equals(entry2.getKey())).map(entry2 -> true).forEach(claimMapping::setRequested);
        spClaimMappingsList.add(claimMapping);
    });
    return spClaimMappingsList;
}
Also used : ApplicationConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.ApplicationConfig) List(java.util.List) ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) FrameworkConstants(org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants) Map(java.util.Map) ClaimFilter(org.wso2.carbon.identity.application.authentication.framework.handler.claims.ClaimFilter) CollectionUtils.isEmpty(org.apache.commons.collections.CollectionUtils.isEmpty) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) ArrayList(java.util.ArrayList) ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) ArrayList(java.util.ArrayList)

Example 8 with ApplicationConfig

use of org.wso2.carbon.identity.application.authentication.framework.config.model.ApplicationConfig 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 9 with ApplicationConfig

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

the class DefaultStepBasedSequenceHandlerTest method testGetSpRoleClaimUri.

/*
        Find SP mapped role claim URI among mapped claims
     */
@Test(dataProvider = "spRoleClaimUriProvider")
public void testGetSpRoleClaimUri(String spRoleClaimUri, String expectedRoleClaimUri) throws Exception {
    Util.mockIdentityUtil();
    ApplicationConfig appConfig = mock(ApplicationConfig.class);
    when(appConfig.getRoleClaim()).thenReturn(spRoleClaimUri);
    assertEquals(stepBasedSequenceHandler.getSpRoleClaimUri(appConfig), expectedRoleClaimUri);
}
Also used : ApplicationConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.ApplicationConfig) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 10 with ApplicationConfig

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

the class DefaultStepBasedSequenceHandlerTest method testGetSpRoleClaimUriSpMappedClaim.

/*
        Get role claim URI from SP mapped claims
     */
@Test(dataProvider = "spClaimMappingProvider")
public void testGetSpRoleClaimUriSpMappedClaim(Map<String, String> claimMappings, String expectedRoleClaim) throws Exception {
    Util.mockIdentityUtil();
    ApplicationConfig appConfig = mock(ApplicationConfig.class);
    when(appConfig.getClaimMappings()).thenReturn(claimMappings);
    String roleClaim = stepBasedSequenceHandler.getSpRoleClaimUri(appConfig);
    assertEquals(roleClaim, expectedRoleClaim);
}
Also used : ApplicationConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.ApplicationConfig) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ApplicationConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.ApplicationConfig)25 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)11 SequenceConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 Test (org.testng.annotations.Test)7 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)6 ArrayList (java.util.ArrayList)5 FrameworkException (org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException)5 HashMap (java.util.HashMap)4 StringUtils.defaultString (org.apache.commons.lang.StringUtils.defaultString)4 AuthenticatorConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig)4 StepConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig)4 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)4 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)4 PostAuthenticationFailedException (org.wso2.carbon.identity.application.authentication.framework.exception.PostAuthenticationFailedException)3 LocalAndOutboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig)3 List (java.util.List)2 Map (java.util.Map)2 ApplicationAuthenticator (org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticator)2 ExternalIdPConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.ExternalIdPConfig)2