1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.shiro.util;
20
21 import org.apache.shiro.authz.Permission;
22 import org.apache.shiro.authz.permission.PermissionResolver;
23
24 import java.util.Arrays;
25 import java.util.Collection;
26 import java.util.LinkedHashSet;
27 import java.util.Set;
28
29
30
31
32
33
34
35 public class PermissionUtils {
36
37 public static Set<Permission> resolveDelimitedPermissions(String s, PermissionResolver permissionResolver) {
38 Set<String> permStrings = toPermissionStrings(s);
39 return resolvePermissions(permStrings, permissionResolver);
40 }
41
42 public static Set<String> toPermissionStrings(String permissionsString) {
43 String[] tokens = StringUtils.split(permissionsString);
44 if (tokens != null && tokens.length > 0) {
45 return new LinkedHashSet<String>(Arrays.asList(tokens));
46 }
47 return null;
48 }
49
50 public static Set<Permission> resolvePermissions(Collection<String> permissionStrings, PermissionResolver permissionResolver) {
51 Set<Permission> permissions = new LinkedHashSet<Permission>(permissionStrings.size());
52 for (String permissionString : permissionStrings) {
53 permissions.add(permissionResolver.resolvePermission(permissionString));
54 }
55 return permissions;
56 }
57 }