1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.rest.setup; |
35 |
|
|
36 |
|
import info.magnolia.jcr.predicate.AbstractPredicate; |
37 |
|
import info.magnolia.jcr.util.NodeUtil; |
38 |
|
import info.magnolia.jcr.util.PropertyUtil; |
39 |
|
import info.magnolia.module.InstallContext; |
40 |
|
import info.magnolia.module.delta.AbstractRepositoryTask; |
41 |
|
import info.magnolia.module.delta.TaskExecutionException; |
42 |
|
import info.magnolia.repository.RepositoryConstants; |
43 |
|
|
44 |
|
import java.util.Iterator; |
45 |
|
|
46 |
|
import javax.jcr.Node; |
47 |
|
import javax.jcr.RepositoryException; |
48 |
|
import javax.jcr.Session; |
49 |
|
|
50 |
|
import org.slf4j.Logger; |
51 |
|
import org.slf4j.LoggerFactory; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
|
|
| 96.3% |
Uncovered Elements: 1 (27) |
Complexity: 6 |
Complexity Density: 0.32 |
|
56 |
|
class UpdateRestEditorRoleTask extends AbstractRepositoryTask { |
57 |
|
private static final Logger log = LoggerFactory.getLogger(UpdateRestEditorRoleTask.class); |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
59 |
4 |
UpdateRestEditorRoleTask(String name, String description) {... |
60 |
4 |
super(name, description); |
61 |
|
} |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
63 |
3 |
@Override... |
64 |
|
protected void doExecute(InstallContext installContext) throws RepositoryException, TaskExecutionException { |
65 |
3 |
Session session = installContext.getJCRSession(RepositoryConstants.USER_ROLES); |
66 |
3 |
Node rest = session.getNode("/rest"); |
67 |
|
|
68 |
|
|
69 |
3 |
NodeUtil.renameNode(rest, "rest-editor"); |
70 |
|
|
71 |
3 |
updateAcl(rest, "userroles", "path", "/rest", "/rest-editor"); |
72 |
|
|
73 |
|
|
74 |
3 |
updateAcl(rest, "uri", "path", "/.rest*", "/.rest/*"); |
75 |
|
|
76 |
|
|
77 |
3 |
PropertyUtil.setProperty(rest, "description", "This role grants GET/POST permissions to REST services APIs (nodes, properties), for a limited set of workspaces."); |
78 |
3 |
PropertyUtil.setProperty(rest, "title", "REST Editor"); |
79 |
|
} |
80 |
|
|
|
|
| 92.3% |
Uncovered Elements: 1 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
81 |
6 |
private void updateAcl(Node roleNode, String workspace, String propertyName, String oldValue, String newValue) throws RepositoryException {... |
82 |
6 |
if (!roleNode.hasNode("acl_" + workspace)) { |
83 |
2 |
log.warn(String.format("Cannot update acl_%s for role %s, ACL node was not found.", workspace, roleNode.getName())); |
84 |
2 |
return; |
85 |
|
} |
86 |
|
|
87 |
4 |
Node aclNode = roleNode.getNode("acl_" + workspace); |
88 |
4 |
Iterable<Node> matchingChildNodes = NodeUtil.getNodes(aclNode, new AbstractPredicate<Node>() { |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
89 |
4 |
@Override... |
90 |
|
public boolean evaluateTyped(Node node) { |
91 |
4 |
String property = PropertyUtil.getString(node, propertyName); |
92 |
4 |
return property != null && property.equals(oldValue); |
93 |
|
} |
94 |
|
}); |
95 |
|
|
96 |
4 |
Iterator<Node> iterator = matchingChildNodes.iterator(); |
97 |
4 |
if (iterator.hasNext()) { |
98 |
4 |
Node node = iterator.next(); |
99 |
4 |
node.setProperty(propertyName, newValue); |
100 |
|
} |
101 |
|
} |
102 |
|
} |