Hi,

In UserCoreUtil [1] there are two methods to remove user store domain from
given name. Those two methods have Inconsistent behavior.

 public static String removeDomainFromName(String name) {
        int index;
        if ((index = name.indexOf(CarbonConstants.DOMAIN_SEPARATOR)) >= 0) {
            // remove domain name if exist
            name = name.substring(index + 1);
        }
        return name;
    }

Here name which is having 'Internal/' is not treated as a special case and
just remove 'Internal/' from name.

    public static String[] removeDomainFromNames(String[] names) {
        List<String> nameList = new ArrayList<String>();
        int index;
        if (names != null && names.length != 0) {
            for (String name : names) {
                if ((index =
name.indexOf(UserCoreConstants.DOMAIN_SEPARATOR)) > 0) {
                    String domain = name.substring(0, index);
                    if
(!UserCoreConstants.INTERNAL_DOMAIN.equalsIgnoreCase(domain)) {
                        // remove domain name if exist
                        nameList.add(name.substring(index + 1));
                    } else {
                        nameList.add(name);
                    }
                }
            }
        }
        if (nameList.size() != 0) {
            return nameList.toArray(new String[nameList.size()]);
        } else {
            return names;
        }
    }

Here even though there is a consideration for 'Internal/' names which are
not having domain separator will be removed from return list.

IMO correct implementation should be removeDomainFromNames(String[] names)
invokes removeDomainFromName(String names) and inside
removeDomainFromName(String names) take 'Internal/' into consideration.

WDYT?

[1]
https://github.com/wso2/carbon4-kernel/blob/master/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/util/UserCoreUtil.java
-- 
Gayan Gunawardana
Software Engineer; WSO2 Inc.; http://wso2.com/
Email: [email protected]
Mobile: +94 (71) 8020933
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to