Java Code Examples for org.wso2.carbon.user.core.util.UserCoreUtil#getDomainName()

The following examples show how to use org.wso2.carbon.user.core.util.UserCoreUtil#getDomainName() . 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: ProfileMgtEventListener.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Delete federated user account associations a user has upon deleting the local user account.
 *
 * @param userName
 * @param userStoreManager
 * @return
 * @throws UserStoreException
 */
@Override
public boolean doPreDeleteUser(String userName,
        UserStoreManager userStoreManager) throws UserStoreException {

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

    String userStoreDomain = UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration());
    if (StringUtils.isBlank(userStoreDomain)) {
        userStoreDomain = UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME;
    }
    int tenantId = userStoreManager.getTenantId();

    if (log.isDebugEnabled()) {
        log.debug("doPreDeleteUser method executed in ProfileMgtEventListener for user:" +
                getFullQualifiedUsername(userName, userStoreDomain, IdentityTenantUtil.getTenantDomain(tenantId)));
    }

    deleteFederatedIdpAccountAssociations(userName, userStoreDomain, tenantId);
    return true;
}
 
Example 2
Source File: UserOperationEventListenerImpl.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
@Override
public boolean doPreDeleteUser(String userName, UserStoreManager userStoreManager) throws UserStoreException {
    if (!isEnable()) {
        return true;
    }

    String domainName = UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration());
    if (StringUtils.isBlank(domainName)) {
        domainName = UserAccountAssociationConstants.PRIMARY_USER_DOMAIN;
    }

    try {
        if (log.isDebugEnabled()) {
            log.debug("User account associations for user " + userName + " with tenant id " +
                      userStoreManager.getTenantId() + " is getting deleted.");
        }

        UserAccountAssociationDAO.getInstance().deleteUserAssociation(domainName, userStoreManager.getTenantId()
                , userName);
        return true;

    } catch (UserAccountAssociationException e) {
        throw new UserStoreException(String.format(UserAccountAssociationConstants.ErrorMessages
                                             .ERROR_WHILE_DELETING_USER_ASSOC.getDescription(), userName), e);
    }
}
 
Example 3
Source File: ListenerUtils.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * This method will append the user store domain with user/role name.
 *
 * @param entity           Entity that need to modified.
 * @param userStoreManager UserStore Manager particular user/role handled by.
 * @return UserStoreDomain/UserName or UserStoreDomain/RoleName
 */
public static String getEntityWithUserStoreDomain(String entity, UserStoreManager userStoreManager) {

    String entityWithUserStoreDomain = entity;
    if (StringUtils.isNotEmpty(entity) && userStoreManager != null) {
        String userStoreDomain = UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration());
        entityWithUserStoreDomain = UserCoreUtil.addDomainToName(entity, userStoreDomain);
    }
    return entityWithUserStoreDomain;
}
 
Example 4
Source File: ProfileMgtEventListener.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
public boolean doPreSetUserClaimValues(String userName, Map<String, String> claims, String profileName,
        UserStoreManager userStoreManager) throws UserStoreException {
    if (!isEnable()) {
        return true;
    }

    if (log.isDebugEnabled()) {
        String userStoreDomain = UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration());
        if (StringUtils.isBlank(userStoreDomain)) {
            userStoreDomain = UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME;
        }
        String tenantDomain = IdentityTenantUtil.getTenantDomain(userStoreManager.getTenantId());
        log.debug("doPreSetUserClaimValues method executed in ProfileMgtEventListener for user: " +
                getFullQualifiedUsername(userName, userStoreDomain, tenantDomain));
    }

    //The following black listed patterns contain possible invalid inputs for profile which could be used for a
    // stored XSS attack.
    String[] whiteListPatternKeys = {ALPHANUMERICS_ONLY, DIGITS_ONLY};
    String[] blackListPatternKeys = {WHITESPACE_EXISTS, URI_RESERVED_EXISTS, HTML_META_EXISTS, XML_META_EXISTS,
                                     REGEX_META_EXISTS, URL};

    if (!IdentityValidationUtil.isValid(profileName, whiteListPatternKeys, blackListPatternKeys)) {
        throw new UserStoreException("profile name contains invalid characters!");
    }
    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 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 6
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 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 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 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: CassandraUserStoreManager.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
@Override
protected String getMyDomainName() {
    return UserCoreUtil.getDomainName(realmConfig);
}
 
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;
}