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 | 0 | public class PermissionUtils { |
36 | |
|
37 | |
public static Set<Permission> resolveDelimitedPermissions(String s, PermissionResolver permissionResolver) { |
38 | 17 | Set<String> permStrings = toPermissionStrings(s); |
39 | 17 | return resolvePermissions(permStrings, permissionResolver); |
40 | |
} |
41 | |
|
42 | |
public static Set<String> toPermissionStrings(String permissionsString) { |
43 | 17 | String[] tokens = StringUtils.split(permissionsString); |
44 | 17 | if (tokens != null && tokens.length > 0) { |
45 | 17 | return new LinkedHashSet<String>(Arrays.asList(tokens)); |
46 | |
} |
47 | 0 | return null; |
48 | |
} |
49 | |
|
50 | |
public static Set<Permission> resolvePermissions(Collection<String> permissionStrings, PermissionResolver permissionResolver) { |
51 | 17 | Set<Permission> permissions = new LinkedHashSet<Permission>(permissionStrings.size()); |
52 | 17 | for (String permissionString : permissionStrings) { |
53 | 23 | permissions.add(permissionResolver.resolvePermission(permissionString)); |
54 | 23 | } |
55 | 17 | return permissions; |
56 | |
} |
57 | |
} |