Example usage for org.apache.shiro.authz.permission PermissionResolver resolvePermission

List of usage examples for org.apache.shiro.authz.permission PermissionResolver resolvePermission

Introduction

In this page you can find the example usage for org.apache.shiro.authz.permission PermissionResolver resolvePermission.

Prototype

Permission resolvePermission(String permissionString);

Source Link

Document

Resolves a Permission based on the given String representation.

Usage

From source file:com.stormpath.shiro.realm.CustomDataPermissionResolver.java

License:Apache License

/**
 * Returns a set of Shiro {@link Permission} instances stored in the specified {@link CustomData} resource.  This
 * implementation will://  ww  w. ja va  2  s  . c o m
 * <ol>
 * <li>{@link #getPermissionStrings(com.stormpath.sdk.directory.CustomData) Get all permission strings} stored
 * in the CustomData instance</li>
 * <li>Loop over these strings, and for each one, create a {@link Permission} instance using the
 * {@link #getPermissionResolver() permissionResolver} property.</li>
 * <li>Return the total constructed Set of Permission instances to the caller.</li>
 * </ol>
 *
 * @param customData the CustomData instance that may contain permission strings to obtain
 * @return a set of Shiro {@link Permission} instances stored in the specified {@link CustomData} resource.
 */
protected Set<Permission> getPermissions(CustomData customData) {

    Set<String> permStrings = getPermissionStrings(customData);

    if (CollectionUtils.isEmpty(permStrings)) {
        return Collections.emptySet();
    }

    PermissionResolver permissionResolver = getPermissionResolver();

    Set<Permission> perms = new HashSet<Permission>(permStrings.size());

    for (String s : permStrings) {
        Permission perm = permissionResolver.resolvePermission(s);
        perms.add(perm);
    }

    return perms;
}