Java Code Examples for org.wso2.carbon.user.core.UserCoreConstants#PRIMARY_DEFAULT_DOMAIN_NAME

The following examples show how to use org.wso2.carbon.user.core.UserCoreConstants#PRIMARY_DEFAULT_DOMAIN_NAME . 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: OutboundProvisioningManager.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private String getDomainFromName(String name) {
    int index;
    if ((index = name.indexOf("/")) > 0) {
        String domain = name.substring(0, index);
        return domain;
    }
    return UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME;
}
 
Example 3
Source File: AbstractOutboundProvisioningConnector.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private String getDomainFromUserName(String username) {
    int index;
    String domain = UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME;
    if (StringUtils.isNotBlank(username)) {
        if ((index = username.indexOf("/")) > 0) {
             domain = username.substring(0, index);
        }
        return domain;
    }
    return domain;
}
 
Example 4
Source File: IdentityUtil.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
public static String getPrimaryDomainName() {
    RealmConfiguration realmConfiguration = IdentityTenantUtil.getRealmService().getBootstrapRealmConfiguration();
    if (realmConfiguration.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME) != null) {
        return realmConfiguration.getUserStoreProperty(
                UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME).toUpperCase();
    } else {
        return UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME;
    }
}
 
Example 5
Source File: Utils.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
public static String getUserStoreDomainName(String userName) {
    int index;
    String userDomain;
    if ((index = userName.indexOf(CarbonConstants.DOMAIN_SEPARATOR)) >= 0) {
        // remove domain name if exist
        userDomain = userName.substring(0, index);
    } else {
        userDomain = UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME;
    }
    return userDomain;
}
 
Example 6
Source File: FileBasedUserStoreDAOImpl.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Get a List of existing domain names.
 *
 * @return : list of domain names
 * @throws IdentityUserStoreMgtException
 */
private List<String> getDomainNames() throws IdentityUserStoreMgtException {

    List<String> domains = new ArrayList<String>();

    RealmConfiguration realmConfiguration = null;
    try {
        realmConfiguration = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration();
    } catch (UserStoreException e) {
        throw new IdentityUserStoreMgtException(" Error occurred while retrieving the realm configuration ", e);
    }

    // To add PRIMARY domain to the domains list
    String domain = realmConfiguration.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
    if (domain == null) {
        domain = UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME;
    }
    domains.add(domain);

    RealmConfiguration secondaryRealmConfiguration = realmConfiguration.getSecondaryRealmConfig();
    while (secondaryRealmConfiguration != null) {
        domains.add(secondaryRealmConfiguration.getUserStoreProperty(UserCoreConstants.
                RealmConfig.PROPERTY_DOMAIN_NAME));
        secondaryRealmConfiguration = secondaryRealmConfiguration.getSecondaryRealmConfig();
    }
    return domains;
}
 
Example 7
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 8
Source File: OutboundProvisioningManager.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
private String getDomainFromName(String name) {
    int index;
    if ((index = name.indexOf("/")) > 0) {
        String domain = name.substring(0, index);
        return domain;
    }
    return UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME;
}
 
Example 9
Source File: FIDOUtil.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public static String getDomainName(String username) {
    int index = username.indexOf(CarbonConstants.DOMAIN_SEPARATOR);
    if (index < 0) {
        return UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME;
    }
    return username.substring(0, index);
}
 
Example 10
Source File: IdentityUtil.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public static String getPrimaryDomainName() {
    RealmConfiguration realmConfiguration = IdentityTenantUtil.getRealmService().getBootstrapRealmConfiguration();
    if(realmConfiguration.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME) != null){
        return realmConfiguration.getUserStoreProperty(
                UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME).toUpperCase();
    } else {
        return UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME;
    }
}
 
Example 11
Source File: Utils.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public static String getUserStoreDomainName(String userName) {
    int index;
    String userDomain;
    if ((index = userName.indexOf(CarbonConstants.DOMAIN_SEPARATOR)) >= 0) {
        // remove domain name if exist
        userDomain = userName.substring(0, index);
    } else {
        userDomain = UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME;
    }
    return userDomain;
}
 
Example 12
Source File: SCIMCommonUtils.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public static String getGroupNameWithDomain(String groupName) {

        if (groupName == null) {
            return groupName;
        }

        if (groupName.indexOf(CarbonConstants.DOMAIN_SEPARATOR) > 0) {
            return groupName;
        } else {
            return UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME
                    + CarbonConstants.DOMAIN_SEPARATOR + groupName;
        }
    }
 
Example 13
Source File: ClaimMetadataUtilsTest.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
private void setUpLocalClaims() {

        String localClaimURI1 = "testLocalClaimURI1";
        String localClaimURI2 = "testLocalClaimURI2";

        {
            localClaim1 = new LocalClaim(localClaimURI1);

            AttributeMapping attributeMapping1 = new AttributeMapping(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME,
                    "uid");
            AttributeMapping attributeMapping2 = new AttributeMapping("AD", "sAMAccountName");

            List<AttributeMapping> attributeMappingList = new ArrayList<>();
            attributeMappingList.add(attributeMapping1);
            attributeMappingList.add(attributeMapping2);

            Map<String, String> claimPropertiesMap = new HashMap<>();
            claimPropertiesMap.put(ClaimConstants.DISPLAY_NAME_PROPERTY, "username");
            claimPropertiesMap.put(ClaimConstants.READ_ONLY_PROPERTY, "true");

            localClaim2 = new LocalClaim(localClaimURI2, attributeMappingList, claimPropertiesMap);

            localClaims = new LocalClaim[]{localClaim1, localClaim2};
        }

        {
            localClaimDTO1 = new LocalClaimDTO();
            localClaimDTO1.setLocalClaimURI(localClaimURI1);

            AttributeMappingDTO attributeMappingDTO1 = new AttributeMappingDTO();
            attributeMappingDTO1.setUserStoreDomain(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME);
            attributeMappingDTO1.setAttributeName("uid");

            AttributeMappingDTO attributeMappingDTO2 = new AttributeMappingDTO();
            attributeMappingDTO2.setUserStoreDomain("AD");
            attributeMappingDTO2.setAttributeName("sAMAccountName");

            AttributeMappingDTO[] attributeMappingDTOs = new AttributeMappingDTO[]{attributeMappingDTO1,
                    attributeMappingDTO2};

            ClaimPropertyDTO claimPropertyDTO1 = new ClaimPropertyDTO();
            claimPropertyDTO1.setPropertyName(ClaimConstants.DISPLAY_NAME_PROPERTY);
            claimPropertyDTO1.setPropertyValue("username");

            ClaimPropertyDTO claimPropertyDTO2 = new ClaimPropertyDTO();
            claimPropertyDTO2.setPropertyName(ClaimConstants.READ_ONLY_PROPERTY);
            claimPropertyDTO2.setPropertyValue("true");

            ClaimPropertyDTO[] claimPropertyDTOs = new ClaimPropertyDTO[]{claimPropertyDTO1, claimPropertyDTO2};

            localClaimDTO2 = new LocalClaimDTO();
            localClaimDTO2.setLocalClaimURI(localClaimURI2);
            localClaimDTO2.setAttributeMappings(attributeMappingDTOs);
            localClaimDTO2.setClaimProperties(claimPropertyDTOs);

            localClaimDTOs = new LocalClaimDTO[]{localClaimDTO1, localClaimDTO2};
        }
    }
 
Example 14
Source File: ClaimMetadataUtilsTest.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
@DataProvider(name = "Authentication")
public Object[][] credentials() {

    String localClaimURI3 = "testLocalClaimURI3";
    AttributeMapping attributeMapping1 = new AttributeMapping(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME,
            "uid");
    AttributeMapping attributeMapping2 = new AttributeMapping("AD", "sAMAccountName");

    List<AttributeMapping> attributeMappingList = new ArrayList<>();
    attributeMappingList.add(attributeMapping1);
    attributeMappingList.add(attributeMapping2);

    Map<String, String> claimPropertiesMap = new HashMap<>();
    claimPropertiesMap.put(ClaimConstants.DISPLAY_NAME_PROPERTY, "username");
    claimPropertiesMap.put(ClaimConstants.DESCRIPTION_PROPERTY, "Username of the system");
    claimPropertiesMap.put(ClaimConstants.REGULAR_EXPRESSION_PROPERTY, "^[\\S]{5,30}$");
    claimPropertiesMap.put(ClaimConstants.DISPLAY_ORDER_PROPERTY, "1");
    claimPropertiesMap.put(ClaimConstants.SUPPORTED_BY_DEFAULT_PROPERTY, "true");
    claimPropertiesMap.put(ClaimConstants.REQUIRED_PROPERTY, "true");
    claimPropertiesMap.put(ClaimConstants.READ_ONLY_PROPERTY, "true");
    claimPropertiesMap.put(ClaimConstants.DEFAULT_ATTRIBUTE, "uid");

    LocalClaim localClaim3 = new LocalClaim(localClaimURI3, attributeMappingList, claimPropertiesMap);

    String localClaimURI4 = "testLocalClaimURI4";

    Map<String, String> claimPropertiesMap2 = new HashMap<>();
    claimPropertiesMap2.put(ClaimConstants.DISPLAY_NAME_PROPERTY, "username");
    claimPropertiesMap2.put(ClaimConstants.DESCRIPTION_PROPERTY, "Username of the system");
    claimPropertiesMap2.put(ClaimConstants.REGULAR_EXPRESSION_PROPERTY, "^[\\S]{5,30}$");
    claimPropertiesMap2.put(ClaimConstants.DISPLAY_ORDER_PROPERTY, "1");
    claimPropertiesMap2.put(ClaimConstants.SUPPORTED_BY_DEFAULT_PROPERTY, "false");
    claimPropertiesMap2.put(ClaimConstants.REQUIRED_PROPERTY, "false");
    claimPropertiesMap2.put(ClaimConstants.READ_ONLY_PROPERTY, "false");
    claimPropertiesMap2.put(ClaimConstants.DEFAULT_ATTRIBUTE, "uid");

    LocalClaim localClaim4 = new LocalClaim(localClaimURI4, attributeMappingList, claimPropertiesMap2);

    return new Object[][] {{localClaim1}, {localClaim2}, {localClaim3}, {localClaim4}};

}