Search in sources :

Example 11 with ServiceProvider

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.

the class DefaultInboundUserProvisioningListener method doPostUpdateRoleListOfUser.

@Override
public boolean doPostUpdateRoleListOfUser(String userName, String[] deletedRoles, String[] newRoles, UserStoreManager userStoreManager) throws UserStoreException {
    if (!isEnable()) {
        return true;
    }
    String[] roleList = userStoreManager.getRoleListOfUser(userName);
    Map<String, String> inboundAttributes = new HashMap<>();
    Map<ClaimMapping, List<String>> outboundAttributes = new HashMap<>();
    if (userName != null) {
        outboundAttributes.put(ClaimMapping.build(IdentityProvisioningConstants.USERNAME_CLAIM_URI, null, null, false), Arrays.asList(new String[] { userName }));
    }
    if (roleList != null && roleList.length > 0) {
        outboundAttributes.put(ClaimMapping.build(IdentityProvisioningConstants.GROUP_CLAIM_URI, null, null, false), Arrays.asList(roleList));
    }
    if (newRoles != null && roleList.length > 0) {
        outboundAttributes.put(ClaimMapping.build(IdentityProvisioningConstants.NEW_GROUP_CLAIM_URI, null, null, false), Arrays.asList(newRoles));
    }
    if (deletedRoles != null && deletedRoles.length > 0) {
        outboundAttributes.put(ClaimMapping.build(IdentityProvisioningConstants.DELETED_GROUP_CLAIM_URI, null, null, false), Arrays.asList(deletedRoles));
    }
    String domainName = UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration());
    if (log.isDebugEnabled()) {
        log.debug("Adding domain name : " + domainName + " to user : " + userName);
    }
    String domainAwareName = UserCoreUtil.addDomainToName(userName, domainName);
    ProvisioningEntity provisioningEntity = new ProvisioningEntity(ProvisioningEntityType.USER, domainAwareName, ProvisioningOperation.PUT, outboundAttributes);
    Claim[] claimArray = null;
    try {
        claimArray = userStoreManager.getUserClaimValues(userName, null);
    } catch (UserStoreException e) {
        if (e.getMessage().contains("UserNotFound")) {
            if (log.isDebugEnabled()) {
                log.debug("User " + userName + " not found in user store");
            }
        } else {
            throw e;
        }
    }
    if (claimArray != null) {
        for (Claim claim : claimArray) {
            inboundAttributes.put(claim.getClaimUri(), claim.getValue());
        }
    }
    provisioningEntity.setInboundAttributes(inboundAttributes);
    String tenantDomainName = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    ThreadLocalProvisioningServiceProvider threadLocalServiceProvider;
    threadLocalServiceProvider = IdentityApplicationManagementUtil.getThreadLocalProvisioningServiceProvider();
    if (threadLocalServiceProvider != null) {
        String serviceProvider = threadLocalServiceProvider.getServiceProviderName();
        tenantDomainName = threadLocalServiceProvider.getTenantDomain();
        if (threadLocalServiceProvider.getServiceProviderType() == ProvisioningServiceProviderType.OAUTH) {
            try {
                serviceProvider = ApplicationManagementService.getInstance().getServiceProviderNameByClientId(threadLocalServiceProvider.getServiceProviderName(), IdentityApplicationConstants.OAuth2.NAME, tenantDomainName);
            } catch (IdentityApplicationManagementException e) {
                log.error("Error while provisioning", e);
                return true;
            }
        }
        // call framework method to provision the user.
        OutboundProvisioningManager.getInstance().provision(provisioningEntity, serviceProvider, threadLocalServiceProvider.getClaimDialect(), tenantDomainName, threadLocalServiceProvider.isJustInTimeProvisioning());
    } else {
        // call framework method to provision the user.
        OutboundProvisioningManager.getInstance().provision(provisioningEntity, ApplicationConstants.LOCAL_SP, IdentityProvisioningConstants.WSO2_CARBON_DIALECT, tenantDomainName, false);
    }
    return true;
}
Also used : HashMap(java.util.HashMap) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) ProvisioningEntity(org.wso2.carbon.identity.provisioning.ProvisioningEntity) ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) UserStoreException(org.wso2.carbon.user.core.UserStoreException) List(java.util.List) ThreadLocalProvisioningServiceProvider(org.wso2.carbon.identity.application.common.model.ThreadLocalProvisioningServiceProvider) Claim(org.wso2.carbon.user.core.claim.Claim)

Example 12 with ServiceProvider

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.

the class DefaultInboundUserProvisioningListener method doPreAddUser.

@Override
public boolean doPreAddUser(String userName, Object credential, String[] roleList, Map<String, String> inboundAttributes, String profile, UserStoreManager userStoreManager) throws UserStoreException {
    if (!isEnable()) {
        return true;
    }
    Map<ClaimMapping, List<String>> outboundAttributes = new HashMap<>();
    if (credential != null) {
        outboundAttributes.put(ClaimMapping.build(IdentityProvisioningConstants.PASSWORD_CLAIM_URI, null, null, false), Arrays.asList(new String[] { ((StringBuffer) credential).toString() }));
    }
    if (userName != null) {
        outboundAttributes.put(ClaimMapping.build(IdentityProvisioningConstants.USERNAME_CLAIM_URI, null, null, false), Arrays.asList(new String[] { userName }));
    }
    if (roleList != null) {
        outboundAttributes.put(ClaimMapping.build(IdentityProvisioningConstants.GROUP_CLAIM_URI, null, null, false), Arrays.asList(roleList));
    }
    String domainName = UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration());
    if (log.isDebugEnabled()) {
        log.debug("Adding domain name : " + domainName + " to user : " + userName);
    }
    String domainAwareName = UserCoreUtil.addDomainToName(userName, domainName);
    ProvisioningEntity provisioningEntity = new ProvisioningEntity(ProvisioningEntityType.USER, domainAwareName, ProvisioningOperation.POST, outboundAttributes);
    // set the in-bound attribute list.in this particular case this is in the wso2.org claim
    // dialect.
    provisioningEntity.setInboundAttributes(inboundAttributes);
    String tenantDomainName = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    ThreadLocalProvisioningServiceProvider threadLocalServiceProvider;
    threadLocalServiceProvider = IdentityApplicationManagementUtil.getThreadLocalProvisioningServiceProvider();
    if (threadLocalServiceProvider != null) {
        String serviceProvider = threadLocalServiceProvider.getServiceProviderName();
        tenantDomainName = threadLocalServiceProvider.getTenantDomain();
        if (threadLocalServiceProvider.getServiceProviderType() == ProvisioningServiceProviderType.OAUTH) {
            try {
                serviceProvider = ApplicationManagementService.getInstance().getServiceProviderNameByClientId(threadLocalServiceProvider.getServiceProviderName(), IdentityApplicationConstants.OAuth2.NAME, tenantDomainName);
            } catch (IdentityApplicationManagementException e) {
                log.error("Error while provisioning", e);
                return true;
            }
        }
        // call framework method to provision the user.
        OutboundProvisioningManager.getInstance().provision(provisioningEntity, serviceProvider, threadLocalServiceProvider.getClaimDialect(), tenantDomainName, threadLocalServiceProvider.isJustInTimeProvisioning());
    } else {
        // call framework method to provision the user.
        OutboundProvisioningManager.getInstance().provision(provisioningEntity, ApplicationConstants.LOCAL_SP, IdentityProvisioningConstants.WSO2_CARBON_DIALECT, tenantDomainName, false);
    }
    return true;
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) HashMap(java.util.HashMap) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) List(java.util.List) ThreadLocalProvisioningServiceProvider(org.wso2.carbon.identity.application.common.model.ThreadLocalProvisioningServiceProvider) ProvisioningEntity(org.wso2.carbon.identity.provisioning.ProvisioningEntity)

Example 13 with ServiceProvider

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.

the class DefaultInboundUserProvisioningListener method doPostUpdateCredential.

@Override
public boolean doPostUpdateCredential(String userName, Object credential, UserStoreManager userStoreManager) throws UserStoreException {
    if (!isEnable()) {
        return true;
    }
    Map<ClaimMapping, List<String>> outboundAttributes = new HashMap<ClaimMapping, List<String>>();
    if (credential != null) {
        outboundAttributes.put(ClaimMapping.build(IdentityProvisioningConstants.PASSWORD_CLAIM_URI, null, null, false), Arrays.asList(credential.toString()));
    }
    if (userName != null) {
        outboundAttributes.put(ClaimMapping.build(IdentityProvisioningConstants.USERNAME_CLAIM_URI, null, null, false), Arrays.asList(userName));
    }
    String domainName = UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration());
    if (log.isDebugEnabled()) {
        log.debug("Adding domain name : " + domainName + " to user : " + userName);
    }
    String domainAwareName = UserCoreUtil.addDomainToName(userName, domainName);
    ProvisioningEntity provisioningEntity = new ProvisioningEntity(ProvisioningEntityType.USER, domainAwareName, ProvisioningOperation.PATCH, outboundAttributes);
    String tenantDomainName = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    ThreadLocalProvisioningServiceProvider threadLocalServiceProvider;
    threadLocalServiceProvider = IdentityApplicationManagementUtil.getThreadLocalProvisioningServiceProvider();
    if (threadLocalServiceProvider != null) {
        String serviceProvider = threadLocalServiceProvider.getServiceProviderName();
        tenantDomainName = threadLocalServiceProvider.getTenantDomain();
        if (threadLocalServiceProvider.getServiceProviderType() == ProvisioningServiceProviderType.OAUTH) {
            try {
                serviceProvider = ApplicationManagementService.getInstance().getServiceProviderNameByClientId(threadLocalServiceProvider.getServiceProviderName(), "oauth2", tenantDomainName);
            } catch (IdentityApplicationManagementException e) {
                log.error("Error while provisioning", e);
                return true;
            }
        }
        // call framework method to provision the user.
        OutboundProvisioningManager.getInstance().provision(provisioningEntity, serviceProvider, threadLocalServiceProvider.getClaimDialect(), tenantDomainName, threadLocalServiceProvider.isJustInTimeProvisioning());
    } else {
        // call framework method to provision the user.
        OutboundProvisioningManager.getInstance().provision(provisioningEntity, ApplicationConstants.LOCAL_SP, WSO2_CARBON_DIALECT, tenantDomainName, false);
    }
    return true;
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) HashMap(java.util.HashMap) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) List(java.util.List) ThreadLocalProvisioningServiceProvider(org.wso2.carbon.identity.application.common.model.ThreadLocalProvisioningServiceProvider) ProvisioningEntity(org.wso2.carbon.identity.provisioning.ProvisioningEntity)

Example 14 with ServiceProvider

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.

the class DefaultInboundUserProvisioningListener method doPreDeleteUser.

@Override
public boolean doPreDeleteUser(String userName, UserStoreManager userStoreManager) throws UserStoreException {
    if (!isEnable()) {
        return true;
    }
    Map<ClaimMapping, List<String>> outboundAttributes = new HashMap<>();
    outboundAttributes.put(ClaimMapping.build(IdentityProvisioningConstants.USERNAME_CLAIM_URI, null, null, false), Arrays.asList(new String[] { userName }));
    String domainName = UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration());
    if (log.isDebugEnabled()) {
        log.debug("Adding domain name : " + domainName + " to user : " + userName);
    }
    String domainAwareName = UserCoreUtil.addDomainToName(userName, domainName);
    ProvisioningEntity provisioningEntity = new ProvisioningEntity(ProvisioningEntityType.USER, domainAwareName, ProvisioningOperation.DELETE, outboundAttributes);
    String tenantDomainName = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    ThreadLocalProvisioningServiceProvider threadLocalServiceProvider;
    threadLocalServiceProvider = IdentityApplicationManagementUtil.getThreadLocalProvisioningServiceProvider();
    if (threadLocalServiceProvider != null) {
        String serviceProvider = threadLocalServiceProvider.getServiceProviderName();
        tenantDomainName = threadLocalServiceProvider.getTenantDomain();
        if (threadLocalServiceProvider.getServiceProviderType() == ProvisioningServiceProviderType.OAUTH) {
            try {
                serviceProvider = ApplicationManagementService.getInstance().getServiceProviderNameByClientId(threadLocalServiceProvider.getServiceProviderName(), IdentityApplicationConstants.OAuth2.NAME, tenantDomainName);
            } catch (IdentityApplicationManagementException e) {
                log.error("Error while provisioning", e);
                return true;
            }
        }
        // call framework method to provision the user.
        OutboundProvisioningManager.getInstance().provision(provisioningEntity, serviceProvider, threadLocalServiceProvider.getClaimDialect(), tenantDomainName, threadLocalServiceProvider.isJustInTimeProvisioning());
    } else {
        OutboundProvisioningManager.getInstance().provision(provisioningEntity, ApplicationConstants.LOCAL_SP, IdentityProvisioningConstants.WSO2_CARBON_DIALECT, tenantDomainName, false);
    }
    return true;
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) HashMap(java.util.HashMap) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) List(java.util.List) ThreadLocalProvisioningServiceProvider(org.wso2.carbon.identity.application.common.model.ThreadLocalProvisioningServiceProvider) ProvisioningEntity(org.wso2.carbon.identity.provisioning.ProvisioningEntity)

Example 15 with ServiceProvider

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.

the class ProvisioningIdentityProviderMgtListener method destroyConnector.

/**
 * @param identityProviderName
 * @param tenantDomain
 * @throws IdentityProvisioningException
 */
public void destroyConnector(String identityProviderName, String tenantDomain) throws IdentityProvisioningException {
    ProvisioningConnectorCacheKey cacheKey = new ProvisioningConnectorCacheKey(identityProviderName);
    ProvisioningConnectorCacheEntry entry = ProvisioningConnectorCache.getInstance().getValueFromCache(cacheKey, tenantDomain);
    if (entry != null) {
        ProvisioningConnectorCache.getInstance().clearCacheEntry(cacheKey, tenantDomain);
        if (log.isDebugEnabled()) {
            log.debug("Provisioning cached entry removed for idp " + identityProviderName);
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Provisioning cached entry not found for idp " + identityProviderName);
        }
    }
    int tenantId;
    try {
        RealmService realmService = ProvisioningServiceDataHolder.getInstance().getRealmService();
        tenantId = realmService.getTenantManager().getTenantId(tenantDomain);
    } catch (UserStoreException e) {
        throw new IdentityProvisioningException("Error occurred while retrieving tenant id from tenant domain", e);
    }
    try {
        List<String> serviceProviders = provisioningManagementDAO.getSPNamesOfProvisioningConnectorsByIDP(identityProviderName, tenantId);
        for (String serviceProvider : serviceProviders) {
            ServiceProviderProvisioningConnectorCacheKey key = new ServiceProviderProvisioningConnectorCacheKey(serviceProvider);
            ServiceProviderProvisioningConnectorCacheEntry cacheEntry = ServiceProviderProvisioningConnectorCache.getInstance().getValueFromCache(key, tenantDomain);
            if (cacheEntry != null) {
                ServiceProviderProvisioningConnectorCache.getInstance().clearCacheEntry(key, tenantDomain);
                if (log.isDebugEnabled()) {
                    log.debug("Service Provider '" + serviceProvider + "' Provisioning cached entry removed for idp " + identityProviderName);
                }
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Service Provider '" + serviceProvider + "' Provisioning cached entry not found for idp " + identityProviderName);
                }
            }
        }
    } catch (IdentityApplicationManagementException e) {
        throw new IdentityProvisioningException("Error occurred while removing cache entry from the " + "service provider provisioning connector cache", e);
    }
}
Also used : ServiceProviderProvisioningConnectorCacheEntry(org.wso2.carbon.identity.provisioning.cache.ServiceProviderProvisioningConnectorCacheEntry) ProvisioningConnectorCacheEntry(org.wso2.carbon.identity.provisioning.cache.ProvisioningConnectorCacheEntry) IdentityProvisioningException(org.wso2.carbon.identity.provisioning.IdentityProvisioningException) ServiceProviderProvisioningConnectorCacheKey(org.wso2.carbon.identity.provisioning.cache.ServiceProviderProvisioningConnectorCacheKey) ProvisioningConnectorCacheKey(org.wso2.carbon.identity.provisioning.cache.ProvisioningConnectorCacheKey) RealmService(org.wso2.carbon.user.core.service.RealmService) ServiceProviderProvisioningConnectorCacheEntry(org.wso2.carbon.identity.provisioning.cache.ServiceProviderProvisioningConnectorCacheEntry) ServiceProviderProvisioningConnectorCacheKey(org.wso2.carbon.identity.provisioning.cache.ServiceProviderProvisioningConnectorCacheKey) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) UserStoreException(org.wso2.carbon.user.api.UserStoreException)

Aggregations

ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)222 Test (org.testng.annotations.Test)120 ServiceProvider (org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider)96 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)85 ArrayList (java.util.ArrayList)65 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)58 HashMap (java.util.HashMap)50 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationRequestConfig)49 ApplicationManagementService (org.wso2.carbon.identity.application.mgt.ApplicationManagementService)40 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)35 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)33 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)29 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig)26 SequenceConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)25 IdentityException (org.wso2.carbon.identity.base.IdentityException)23 Property (org.wso2.carbon.identity.application.common.model.xsd.Property)21 LocalAndOutboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig)20 InboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationConfig)20 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)20 Matchers.anyString (org.mockito.Matchers.anyString)19