Java Code Examples for org.wso2.carbon.identity.core.util.IdentityUtil#isUserStoreCaseSensitive()

The following examples show how to use org.wso2.carbon.identity.core.util.IdentityUtil#isUserStoreCaseSensitive() . 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: User.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }
    if (!(o instanceof User)) {
        return false;
    }

    User user = (User) o;

    if (!tenantDomain.equals(user.tenantDomain)) {
        return false;
    }

    boolean isUsernameCaseSensitive = IdentityUtil.isUserStoreCaseSensitive(userStoreDomain,
            IdentityTenantUtil.getTenantId(tenantDomain));

    if (isUsernameCaseSensitive) {
        if (!userName.equals(user.userName)) {
            return false;
        }
    } else {
        if (!userName.equalsIgnoreCase(user.userName)) {
            return false;
        }
    }

    if (!userStoreDomain.equals(user.userStoreDomain)) {
        return false;
    }

    return true;
}
 
Example 2
Source File: User.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * This method will retrieve the 'CaseInsensitiveUsername' property from the respective userstore and set that
 * value.
 */
protected void updateCaseSensitivity() {

    if (StringUtils.isNotEmpty(tenantDomain) && StringUtils.isNotEmpty(userStoreDomain)
            && IdentityTenantUtil.getRealmService() != null) {
        this.isUsernameCaseSensitive = IdentityUtil
                .isUserStoreCaseSensitive(userStoreDomain, IdentityTenantUtil.getTenantId(tenantDomain));
    }
}
 
Example 3
Source File: InMemoryIdentityDataStore.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
public void remove(String userName, UserStoreManager userStoreManager) throws IdentityException {

    try {
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);

        Cache<String, UserIdentityClaimsDO> cache = getCache();
        if (userName == null) {
            return;
        }
        if (userStoreManager instanceof org.wso2.carbon.user.core.UserStoreManager) {
            if (!IdentityUtil.isUserStoreCaseSensitive((org.wso2.carbon.user.core.UserStoreManager) userStoreManager)) {
                if (log.isDebugEnabled()) {
                    log.debug("Case insensitive user store found. Changing username from : " + userName + " to : " +
                            userName.toLowerCase());
                }
                userName = userName.toLowerCase();
            }
        }
        org.wso2.carbon.user.core.UserStoreManager store = (org.wso2.carbon.user.core.UserStoreManager)
                userStoreManager;
        String domainName = store.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig
                .PROPERTY_DOMAIN_NAME);

        cache.remove(domainName + userStoreManager.getTenantId() + userName);
    } catch (UserStoreException e) {
        log.error("Error while obtaining tenant ID from user store manager");
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
Example 4
Source File: InMemoryIdentityDataStore.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
@Override
public void remove(String userName, UserStoreManager userStoreManager) throws IdentityException {

    try {
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);

        Cache<String, UserIdentityClaimsDO> cache = getCache();
        if (userName == null) {
            return;
        }
        if (userStoreManager instanceof org.wso2.carbon.user.core.UserStoreManager) {
            if (!IdentityUtil.isUserStoreCaseSensitive((org.wso2.carbon.user.core.UserStoreManager) userStoreManager)) {
                if (log.isDebugEnabled()) {
                    log.debug("Case insensitive user store found. Changing username from : " + userName + " to : " +
                            userName.toLowerCase());
                }
                userName = userName.toLowerCase();
            }
        }
        org.wso2.carbon.user.core.UserStoreManager store = (org.wso2.carbon.user.core.UserStoreManager)
                userStoreManager;
        String domainName = store.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig
                .PROPERTY_DOMAIN_NAME);

        cache.remove(domainName + userStoreManager.getTenantId() + userName);
    } catch (UserStoreException e) {
        log.error("Error while obtaining tenant ID from user store manager");
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
Example 5
Source File: InMemoryIdentityDataStore.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
@Override
public UserIdentityClaimsDO load(String userName, UserStoreManager userStoreManager) {

    try {
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
        Cache<String, UserIdentityClaimsDO> cache = getCache();
        if (userName != null && cache != null) {
            if (userStoreManager instanceof org.wso2.carbon.user.core.UserStoreManager) {
                if (!IdentityUtil.isUserStoreCaseSensitive((org.wso2.carbon.user.core.UserStoreManager)
                        userStoreManager)) {
                    if (log.isDebugEnabled()) {
                        log.debug("Case insensitive user store found. Changing username from : " + userName +
                                " to : " + userName.toLowerCase());
                    }
                    userName = userName.toLowerCase();
                }
            }

            org.wso2.carbon.user.core.UserStoreManager store = (org.wso2.carbon.user.core.UserStoreManager) userStoreManager;

            String domainName = store.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);

            UserIdentityClaimsDO userIdentityDTO = (UserIdentityClaimsDO) cache.get(domainName + userStoreManager
                    .getTenantId() + userName);

            if (userIdentityDTO != null && log.isDebugEnabled()) {
                StringBuilder data = new StringBuilder("{");
                if (userIdentityDTO.getUserIdentityDataMap() != null) {
                    for (Map.Entry<String, String> entry : userIdentityDTO.getUserIdentityDataMap().entrySet()) {
                        data.append("[" + entry.getKey() + " = " + entry.getValue() + "], ");
                    }
                }
                if (data.indexOf(",") >= 0) {
                    data.deleteCharAt(data.lastIndexOf(","));
                }
                data.append("}");
                log.debug("Loaded UserIdentityClaimsDO from cache for user :" + userName + " with claims: " + data);

            }
            return userIdentityDTO;
        }
    } catch (UserStoreException e) {
        log.error("Error while obtaining tenant ID from user store manager");
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
    return null;
}
 
Example 6
Source File: InMemoryIdentityDataStore.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
@Override
public UserIdentityClaimsDO load(String userName, UserStoreManager userStoreManager) {

    try {
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
        Cache<String, UserIdentityClaimsDO> cache = getCache();
        if (userName != null && cache != null) {
            if (userStoreManager instanceof org.wso2.carbon.user.core.UserStoreManager) {
                if (!IdentityUtil.isUserStoreCaseSensitive((org.wso2.carbon.user.core.UserStoreManager)
                        userStoreManager)) {
                    if (log.isDebugEnabled()) {
                        log.debug("Case insensitive user store found. Changing username from : " + userName +
                                " to : " + userName.toLowerCase());
                    }
                    userName = userName.toLowerCase();
                }
            }

            org.wso2.carbon.user.core.UserStoreManager store = (org.wso2.carbon.user.core.UserStoreManager) userStoreManager;

            String domainName = store.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);

            UserIdentityClaimsDO userIdentityDTO = (UserIdentityClaimsDO) cache.get(domainName + userStoreManager
                    .getTenantId() + userName);

            if (userIdentityDTO != null && log.isDebugEnabled()) {
                StringBuilder data = new StringBuilder("{");
                if (userIdentityDTO.getUserIdentityDataMap() != null) {
                    for (Map.Entry<String, String> entry : userIdentityDTO.getUserIdentityDataMap().entrySet()) {
                        data.append("[" + entry.getKey() + " = " + entry.getValue() + "], ");
                    }
                }
                if (data.indexOf(",") >= 0) {
                    data.deleteCharAt(data.lastIndexOf(","));
                }
                data.append("}");
                log.debug("Loaded UserIdentityClaimsDO from cache for user :" + userName + " with claims: " + data);

            }
            return userIdentityDTO;
        }
    } catch (UserStoreException e) {
        log.error("Error while obtaining tenant ID from user store manager");
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
    return null;
}