|
2 | 2 |
|
3 | 3 | import com.marklogic.client.io.DocumentMetadataHandle.Capability; |
4 | 4 | import com.marklogic.client.io.DocumentMetadataHandle.DocumentPermissions; |
5 | | -import com.marklogic.client.ext.util.DocumentPermissionsParser; |
6 | 5 |
|
7 | 6 | public class DefaultDocumentPermissionsParser implements DocumentPermissionsParser { |
8 | 7 |
|
9 | | - @Override |
10 | | - public void parsePermissions(String str, DocumentPermissions permissions) { |
11 | | - if (str != null && str.trim().length() > 0) { |
12 | | - String[] tokens = str.split(","); |
13 | | - for (int i = 0; i < tokens.length; i += 2) { |
14 | | - String role = tokens[i]; |
15 | | - if (i + 1 >= tokens.length) { |
16 | | - throw new IllegalArgumentException("Unable to parse permissions string, which must be a comma-separated " + |
17 | | - "list of role names and capabilities - i.e. role1,read,role2,update,role3,execute; string: " + str); |
18 | | - } |
19 | | - String capability = tokens[i + 1]; |
20 | | - Capability c = null; |
21 | | - if (capability.equals("execute")) { |
22 | | - c = Capability.EXECUTE; |
23 | | - } else if (capability.equals("insert")) { |
24 | | - c = Capability.INSERT; |
25 | | - } else if (capability.equals("update")) { |
26 | | - c = Capability.UPDATE; |
27 | | - } else if (capability.equals("read")) { |
28 | | - c = Capability.READ; |
29 | | - } |
30 | | - if (permissions.containsKey(role)) { |
31 | | - permissions.get(role).add(c); |
32 | | - } else { |
33 | | - permissions.add(role, c); |
34 | | - } |
35 | | - } |
36 | | - } |
37 | | - } |
| 8 | + @Override |
| 9 | + public void parsePermissions(String str, DocumentPermissions permissions) { |
| 10 | + if (str != null && str.trim().length() > 0) { |
| 11 | + String[] tokens = str.split(","); |
| 12 | + for (int i = 0; i < tokens.length; i += 2) { |
| 13 | + String role = tokens[i]; |
| 14 | + if (i + 1 >= tokens.length) { |
| 15 | + throw new IllegalArgumentException("Unable to parse permissions string, which must be a comma-separated " + |
| 16 | + "list of role names and capabilities - i.e. role1,read,role2,update,role3,execute; string: " + str); |
| 17 | + } |
| 18 | + Capability c; |
| 19 | + try { |
| 20 | + c = Capability.getValueOf(tokens[i + 1]); |
| 21 | + } catch (Exception e) { |
| 22 | + throw new IllegalArgumentException("Unable to parse permissions string: " + str + "; cause: " + e.getMessage()); |
| 23 | + } |
| 24 | + if (permissions.containsKey(role)) { |
| 25 | + permissions.get(role).add(c); |
| 26 | + } else { |
| 27 | + permissions.add(role, c); |
| 28 | + } |
| 29 | + } |
| 30 | + } |
| 31 | + } |
38 | 32 |
|
39 | 33 | } |
0 commit comments