Java Code Examples for org.apache.shiro.util.StringUtils#clean()

The following examples show how to use org.apache.shiro.util.StringUtils#clean() . 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: EnhancedWildcardPermission.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
protected void initWildcardString(String wildcardString, boolean caseSensitive) {
	wildcardString = StringUtils.clean(wildcardString);
	if (isBlank(wildcardString)) {
		throw new IllegalArgumentException(
				"Wildcard string cannot be null or empty. Make sure permission strings are properly formatted.");
	}
	checkWildcard(wildcardString);
	if (!caseSensitive) {
		wildcardString = wildcardString.toLowerCase();
	}

	List<String> permits = CollectionUtils.asList(wildcardString.split(PERMIT_DIVIDER_TOKEN));
	permitParts = new ArrayList<Set<String>>();
	for (String permit : permits) {
		Set<String> permitPart = CollectionUtils.asSet(permit.split(PERMIT_PART_DIVIDER_TOKEN));
		if (permitPart.isEmpty()) {
			throw new IllegalArgumentException(
					"Wildcard string cannot contain parts with only dividers. Make sure permission strings are properly formatted.");
		}
		permitParts.add(permitPart);
	}

	if (permitParts.isEmpty()) {
		throw new IllegalArgumentException(
				"Wildcard string cannot contain only dividers. Make sure permission strings are properly formatted.");
	}
}
 
Example 2
Source File: WebSecurityModule.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * This method is copied from the same method in Shiro in class DefaultFilterChainManager.
 */
private String[] toNameConfigPair(String token) throws ConfigurationException {
    String[] pair = token.split("\\[", 2);
    String name = StringUtils.clean(pair[0]);

    if (name == null) {
        throw new IllegalArgumentException("Filter name not found for filter chain definition token: " + token);
    }
    String config = null;

    if (pair.length == 2) {
        config = StringUtils.clean(pair[1]);
        //if there was an open bracket, it assumed there is a closing bracket, so strip it too:
        config = config.substring(0, config.length() - 1);
        config = StringUtils.clean(config);

        //backwards compatibility prior to implementing SHIRO-205:
        //prior to SHIRO-205 being implemented, it was common for end-users to quote the config inside brackets
        //if that config required commas.  We need to strip those quotes to get to the interior quoted definition
        //to ensure any existing quoted definitions still function for end users:
        if (config != null && config.startsWith("\"") && config.endsWith("\"")) {
            String stripped = config.substring(1, config.length() - 1);
            stripped = StringUtils.clean(stripped);

            //if the stripped value does not have any internal quotes, we can assume that the entire config was
            //quoted and we can use the stripped value.
            if (stripped != null && stripped.indexOf('"') == -1) {
                config = stripped;
            }
            //else:
            //the remaining config does have internal quotes, so we need to assume that each comma delimited
            //pair might be quoted, in which case we need the leading and trailing quotes that we stripped
            //So we ignore the stripped value.
        }
    }

    return new String[]{name, config};

}