Search in sources :

Example 1 with ThreadLocalProvisioningServiceProvider

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

the class DefaultInboundUserProvisioningListener method doPreDeleteUserClaimValues.

@Override
public boolean doPreDeleteUserClaimValues(String userName, String[] attributesToDelete, String profileName, UserStoreManager userStoreManager) throws UserStoreException {
    if (!isEnable() || ArrayUtils.isEmpty(attributesToDelete)) {
        return true;
    }
    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 }));
    }
    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);
    Map<String, String> inboundAttributes = new HashMap<>();
    for (int i = 0; i < attributesToDelete.length; i++) {
        inboundAttributes.put(attributesToDelete[i], "");
    }
    ;
    // set the in-bound attribute list.
    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 2 with ThreadLocalProvisioningServiceProvider

use of org.wso2.carbon.identity.application.common.model.ThreadLocalProvisioningServiceProvider 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 3 with ThreadLocalProvisioningServiceProvider

use of org.wso2.carbon.identity.application.common.model.ThreadLocalProvisioningServiceProvider 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 4 with ThreadLocalProvisioningServiceProvider

use of org.wso2.carbon.identity.application.common.model.ThreadLocalProvisioningServiceProvider 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 5 with ThreadLocalProvisioningServiceProvider

use of org.wso2.carbon.identity.application.common.model.ThreadLocalProvisioningServiceProvider 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)

Aggregations

HashMap (java.util.HashMap)11 ThreadLocalProvisioningServiceProvider (org.wso2.carbon.identity.application.common.model.ThreadLocalProvisioningServiceProvider)11 List (java.util.List)10 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)10 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)10 ProvisioningEntity (org.wso2.carbon.identity.provisioning.ProvisioningEntity)10 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 FrameworkException (org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException)1 UserStoreException (org.wso2.carbon.user.core.UserStoreException)1 Claim (org.wso2.carbon.user.core.claim.Claim)1