Java Code Examples for org.wso2.carbon.identity.application.common.util.IdentityApplicationManagementUtil#getThreadLocalProvisioningServiceProvider()

The following examples show how to use org.wso2.carbon.identity.application.common.util.IdentityApplicationManagementUtil#getThreadLocalProvisioningServiceProvider() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SCIMUserManager.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private ServiceProvider getServiceProvider(boolean isBulkUserAdd) throws CharonException {

        ThreadLocalProvisioningServiceProvider threadLocalSP = IdentityApplicationManagementUtil
                .getThreadLocalProvisioningServiceProvider();
        //isBulkUserAdd is true indicates bulk user add
        if (isBulkUserAdd) {
            threadLocalSP.setBulkUserAdd(true);
        }
        try {
            if (threadLocalSP.getServiceProviderType() == ProvisioningServiceProviderType.OAUTH) {
                return ApplicationManagementService.getInstance().getServiceProviderByClientId(
                                                           threadLocalSP.getServiceProviderName(),
                                                           "oauth2", threadLocalSP.getTenantDomain());
            } else {
                return ApplicationManagementService.getInstance().getServiceProvider(
                        threadLocalSP.getServiceProviderName(), threadLocalSP.getTenantDomain());
            }
        } catch (IdentityApplicationManagementException e) {
            throw new CharonException("Error retrieving Service Provider. ", e);
        }
    }
 
Example 2
Source File: SCIMUserManager.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private String getUserStoreDomainFromSP() throws IdentityApplicationManagementException {

        ThreadLocalProvisioningServiceProvider threadLocalSP = IdentityApplicationManagementUtil
                .getThreadLocalProvisioningServiceProvider();
        ServiceProvider serviceProvider = null;
        if (threadLocalSP.getServiceProviderType() == ProvisioningServiceProviderType.OAUTH) {
            serviceProvider = ApplicationManagementService.getInstance()
                                                          .getServiceProviderByClientId(
                                                                  threadLocalSP.getServiceProviderName(),
                                                                  "oauth2", threadLocalSP.getTenantDomain());
        } else {
            serviceProvider = ApplicationManagementService.getInstance().getServiceProvider(
                    threadLocalSP.getServiceProviderName(), threadLocalSP.getTenantDomain());
        }

        if (serviceProvider != null && serviceProvider.getInboundProvisioningConfig() != null &&
            !StringUtils.isBlank(serviceProvider.getInboundProvisioningConfig().getProvisioningUserStore())) {
            return serviceProvider.getInboundProvisioningConfig().getProvisioningUserStore();
        }
        return null;
    }
 
Example 3
Source File: DefaultInboundUserProvisioningListener.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
@Override
public boolean doPreSetUserClaimValues(String userName, Map<String, String> inboundAttributes,
                                       String profileName, UserStoreManager userStoreManager) throws UserStoreException {

    if (!isEnable()) {
        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.PUT,
            outboundAttributes);

    // 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;
}
 
Example 4
Source File: DefaultInboundUserProvisioningListener.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
@Override
public boolean doPostUpdateCredential(String userName, Object credential, UserStoreManager userStoreManager)
        throws UserStoreException {

    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;
}
 
Example 5
Source File: DefaultInboundUserProvisioningListener.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
@Override
public boolean doPreDeleteRole(String roleName, UserStoreManager userStoreManager)
        throws UserStoreException {

    if (!isEnable()) {
        return true;
    }

    Map<ClaimMapping, List<String>> outboundAttributes = new HashMap<>();

    if (roleName != null) {
        outboundAttributes.put(ClaimMapping.build(
                IdentityProvisioningConstants.GROUP_CLAIM_URI, null, null, false), Arrays
                .asList(new String[]{roleName}));
    }

    String domainName = UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration());
    if (log.isDebugEnabled()) {
        log.debug("Adding domain name : " + domainName + " to user : " + roleName);
    }
    String domainAwareName = UserCoreUtil.addDomainToName(roleName, domainName);

    ProvisioningEntity provisioningEntity = new ProvisioningEntity(
            ProvisioningEntityType.GROUP, 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 {
        // call framework method to provision the group.
        OutboundProvisioningManager.getInstance()
                .provision(provisioningEntity, ApplicationConstants.LOCAL_SP,
                        IdentityProvisioningConstants.WSO2_CARBON_DIALECT, tenantDomainName, false);
    }

    return true;
}
 
Example 6
Source File: DefaultInboundUserProvisioningListener.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
@Override
public boolean doPreAddRole(String roleName, String[] userList, Permission[] permissions,
                            UserStoreManager userStoreManager) throws UserStoreException {

    if (!isEnable()) {
        return true;
    }
    Map<ClaimMapping, List<String>> outboundAttributes = new HashMap<>();

    if (roleName != null) {
        outboundAttributes.put(ClaimMapping.build(
                IdentityProvisioningConstants.GROUP_CLAIM_URI, null, null, false), Arrays
                .asList(new String[]{roleName}));
    }

    if (userList != null && userList.length > 0) {
        outboundAttributes.put(ClaimMapping.build(
                IdentityProvisioningConstants.USERNAME_CLAIM_URI, null, null, false), Arrays
                .asList(userList));
    }

    String domainName = UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration());
    if (log.isDebugEnabled()) {
        log.debug("Adding domain name : " + domainName + " to user : " + roleName);
    }
    String domainAwareName = UserCoreUtil.addDomainToName(roleName, domainName);

    ProvisioningEntity provisioningEntity = new ProvisioningEntity(
            ProvisioningEntityType.GROUP, domainAwareName, ProvisioningOperation.POST,
            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 {
        // call framework method to provision the group.
        OutboundProvisioningManager.getInstance()
                .provision(provisioningEntity, ApplicationConstants.LOCAL_SP,
                        IdentityProvisioningConstants.WSO2_CARBON_DIALECT, tenantDomainName, false);
    }

    return true;
}
 
Example 7
Source File: DefaultInboundUserProvisioningListener.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
@Override
public boolean doPostUpdateUserListOfRole(String roleName, String[] deletedUsers,
                                          String[] newUsers, UserStoreManager userStoreManager) throws UserStoreException {

    if (!isEnable()) {
        return true;
    }

    String[] userList = userStoreManager.getUserListOfRole(roleName);

    Map<ClaimMapping, List<String>> outboundAttributes = new HashMap<>();

    outboundAttributes.put(ClaimMapping.build(
            IdentityProvisioningConstants.GROUP_CLAIM_URI, null, null, false), Arrays
            .asList(new String[]{roleName}));

    outboundAttributes.put(ClaimMapping.build(IdentityProvisioningConstants.USERNAME_CLAIM_URI,
            null, null, false), Arrays.asList(userList));

    outboundAttributes.put(ClaimMapping.build(
            IdentityProvisioningConstants.NEW_USER_CLAIM_URI, null, null, false), Arrays
            .asList(newUsers));

    outboundAttributes.put(ClaimMapping.build(
            IdentityProvisioningConstants.DELETED_USER_CLAIM_URI, null, null, false),
            Arrays.asList(deletedUsers));

    String domainName = UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration());
    if (log.isDebugEnabled()) {
        log.debug("Adding domain name : " + domainName + " to role : " + roleName);
    }
    String domainAwareName = UserCoreUtil.addDomainToName(roleName, domainName);

    ProvisioningEntity provisioningEntity = new ProvisioningEntity(
            ProvisioningEntityType.GROUP, domainAwareName, ProvisioningOperation.PUT,
            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 {
        // call framework method to provision the group.
        OutboundProvisioningManager.getInstance()
                .provision(provisioningEntity, ApplicationConstants.LOCAL_SP,
                        IdentityProvisioningConstants.WSO2_CARBON_DIALECT, tenantDomainName, false);
    }

    return true;
}
 
Example 8
Source File: DefaultInboundUserProvisioningListener.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example 9
Source File: DefaultInboundUserProvisioningListener.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
@Override
public boolean doPreDeleteUserClaimValue(String userName, String attributeToDelete, String profileName,
                                         UserStoreManager userStoreManager) throws UserStoreException {

    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<>();
    inboundAttributes.put(attributeToDelete, "");

    // 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;
}
 
Example 10
Source File: DefaultInboundUserProvisioningListener.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
@Override
public boolean doPreDeleteUserClaimValues(String userName, String[] attributesToDelete,
                                          String profileName, UserStoreManager userStoreManager) throws UserStoreException {

    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;
}
 
Example 11
Source File: DefaultInboundUserProvisioningListener.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example 12
Source File: DefaultInboundUserProvisioningListener.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example 13
Source File: DefaultInboundUserProvisioningListener.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example 14
Source File: DefaultInboundUserProvisioningListener.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
@Override
public boolean doPreDeleteRole(String roleName, UserStoreManager userStoreManager)
        throws UserStoreException {

    if (!isEnable()) {
        return true;
    }

    Map<ClaimMapping, List<String>> outboundAttributes = new HashMap<>();

    if (roleName != null) {
        outboundAttributes.put(ClaimMapping.build(
                IdentityProvisioningConstants.GROUP_CLAIM_URI, null, null, false), Arrays
                .asList(new String[]{roleName}));
    }

    String domainName = UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration());
    if (log.isDebugEnabled()) {
        log.debug("Adding domain name : " + domainName + " to user : " + roleName);
    }
    String domainAwareName = UserCoreUtil.addDomainToName(roleName, domainName);

    ProvisioningEntity provisioningEntity = new ProvisioningEntity(
            ProvisioningEntityType.GROUP, 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 {
        // call framework method to provision the group.
        OutboundProvisioningManager.getInstance()
                .provision(provisioningEntity, ApplicationConstants.LOCAL_SP,
                        IdentityProvisioningConstants.WSO2_CARBON_DIALECT, tenantDomainName, false);
    }

    return true;
}
 
Example 15
Source File: DefaultInboundUserProvisioningListener.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
@Override
public boolean doPreAddRole(String roleName, String[] userList, Permission[] permissions,
                            UserStoreManager userStoreManager) throws UserStoreException {

    if (!isEnable()) {
        return true;
    }
    Map<ClaimMapping, List<String>> outboundAttributes = new HashMap<>();

    if (roleName != null) {
        outboundAttributes.put(ClaimMapping.build(
                IdentityProvisioningConstants.GROUP_CLAIM_URI, null, null, false), Arrays
                .asList(new String[]{roleName}));
    }

    if (userList != null && userList.length > 0) {
        outboundAttributes.put(ClaimMapping.build(
                IdentityProvisioningConstants.USERNAME_CLAIM_URI, null, null, false), Arrays
                .asList(userList));
    }

    String domainName = UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration());
    if (log.isDebugEnabled()) {
        log.debug("Adding domain name : " + domainName + " to user : " + roleName);
    }
    String domainAwareName = UserCoreUtil.addDomainToName(roleName, domainName);

    ProvisioningEntity provisioningEntity = new ProvisioningEntity(
            ProvisioningEntityType.GROUP, domainAwareName, ProvisioningOperation.POST,
            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 {
        // call framework method to provision the group.
        OutboundProvisioningManager.getInstance()
                .provision(provisioningEntity, ApplicationConstants.LOCAL_SP,
                        IdentityProvisioningConstants.WSO2_CARBON_DIALECT, tenantDomainName, false);
    }

    return true;
}
 
Example 16
Source File: DefaultInboundUserProvisioningListener.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
@Override
public boolean doPostUpdateUserListOfRole(String roleName, String[] deletedUsers,
                                          String[] newUsers, UserStoreManager userStoreManager) throws UserStoreException {

    if (!isEnable()) {
        return true;
    }

    String[] userList = userStoreManager.getUserListOfRole(roleName);

    Map<ClaimMapping, List<String>> outboundAttributes = new HashMap<>();

    outboundAttributes.put(ClaimMapping.build(
            IdentityProvisioningConstants.GROUP_CLAIM_URI, null, null, false), Arrays
            .asList(new String[]{roleName}));

    outboundAttributes.put(ClaimMapping.build(IdentityProvisioningConstants.USERNAME_CLAIM_URI,
            null, null, false), Arrays.asList(userList));

    outboundAttributes.put(ClaimMapping.build(
            IdentityProvisioningConstants.NEW_USER_CLAIM_URI, null, null, false), Arrays
            .asList(newUsers));

    outboundAttributes.put(ClaimMapping.build(
                    IdentityProvisioningConstants.DELETED_USER_CLAIM_URI, null, null, false),
            Arrays.asList(deletedUsers));

    String domainName = UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration());
    if (log.isDebugEnabled()) {
        log.debug("Adding domain name : " + domainName + " to role : " + roleName);
    }
    String domainAwareName = UserCoreUtil.addDomainToName(roleName, domainName);

    ProvisioningEntity provisioningEntity = new ProvisioningEntity(
            ProvisioningEntityType.GROUP, domainAwareName, ProvisioningOperation.PUT,
            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 {
        // call framework method to provision the group.
        OutboundProvisioningManager.getInstance()
                .provision(provisioningEntity, ApplicationConstants.LOCAL_SP,
                        IdentityProvisioningConstants.WSO2_CARBON_DIALECT, tenantDomainName, false);
    }

    return true;
}
 
Example 17
Source File: DefaultInboundUserProvisioningListener.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example 18
Source File: DefaultInboundUserProvisioningListener.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
@Override
public boolean doPreDeleteUserClaimValue(String userName, String attributeToDelete, String profileName,
                                         UserStoreManager userStoreManager) throws UserStoreException {
    if (!isEnable()) {
        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<>();
    inboundAttributes.put(attributeToDelete, "");

    // 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;
}
 
Example 19
Source File: DefaultInboundUserProvisioningListener.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example 20
Source File: DefaultInboundUserProvisioningListener.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
@Override
public boolean doPreSetUserClaimValues(String userName, Map<String, String> inboundAttributes,
                                       String profileName, UserStoreManager userStoreManager) throws UserStoreException {

    if (!isEnable()) {
        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.PUT,
            outboundAttributes);

    // 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;
}