Java Code Examples for org.apache.shiro.util.CollectionUtils#asSet()

The following examples show how to use org.apache.shiro.util.CollectionUtils#asSet() . 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: RolesAuthorizationFilter.java    From tapestry-security with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked"})
public boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws IOException {

    Subject subject = getSubject(request, response);
    String[] rolesArray = (String[]) mappedValue;

    if (rolesArray == null || rolesArray.length == 0) {
        //no roles specified, so nothing to check - allow access.
        return true;
    }

    Set<String> roles = CollectionUtils.asSet(rolesArray);
    return subject.hasAllRoles(roles);
}