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.security.app.dialog.action;
35
36 import info.magnolia.jcr.util.NodeUtil;
37 import info.magnolia.security.app.dialog.field.AccessControlList;
38 import info.magnolia.security.app.dialog.field.WorkspaceAccessFieldFactory;
39 import info.magnolia.ui.admincentral.dialog.action.SaveDialogAction;
40 import info.magnolia.ui.admincentral.dialog.action.SaveDialogActionDefinition;
41 import info.magnolia.ui.api.action.ActionExecutionException;
42 import info.magnolia.ui.form.EditorCallback;
43 import info.magnolia.ui.form.EditorValidator;
44 import info.magnolia.ui.vaadin.integration.jcr.JcrNodeAdapter;
45
46 import javax.jcr.Node;
47 import javax.jcr.RepositoryException;
48 import javax.jcr.Value;
49
50 import org.apache.commons.lang.StringUtils;
51
52 import com.vaadin.data.Item;
53
54
55
56
57 public class SaveRoleDialogAction extends SaveDialogAction {
58
59 public SaveRoleDialogAction(SaveDialogActionDefinition definition, Item item, EditorValidator validator, EditorCallback callback) {
60 super(definition, item, validator, callback);
61 }
62
63 @Override
64 public void execute() throws ActionExecutionException {
65
66 validator.showValidation(true);
67 if (validator.isValid()) {
68 final JcrNodeAdapter itemChanged = (JcrNodeAdapter) item;
69
70 try {
71
72 final Node node = itemChanged.applyChanges();
73
74 for (Node aclNode : NodeUtil.getNodes(node)) {
75
76
77
78 if (aclNode.hasProperty(WorkspaceAccessFieldFactory.INTERMEDIARY_FORMAT_PROPERTY_NAME)) {
79
80 AccessControlList acl = new AccessControlList();
81
82 for (Node entryNode : NodeUtil.getNodes(aclNode)) {
83
84 if (entryNode.hasProperty(WorkspaceAccessFieldFactory.INTERMEDIARY_FORMAT_PROPERTY_NAME)) {
85 String path = entryNode.getProperty(AccessControlList.PATH_PROPERTY_NAME).getString();
86 long accessType = (int) entryNode.getProperty(WorkspaceAccessFieldFactory.ACCESS_TYPE_PROPERTY_NAME).getLong();
87 long permissions = entryNode.getProperty(AccessControlList.PERMISSIONS_PROPERTY_NAME).getLong();
88
89 if (path.equals("/")) {
90 } else if (path.equals("/*")) {
91 path = "/";
92 } else {
93 path = StringUtils.removeEnd(path, "/*");
94 path = StringUtils.removeEnd(path, "/");
95 }
96
97 if (StringUtils.isNotBlank(path)) {
98 acl.addEntry(new AccessControlList.Entry(permissions, accessType, path));
99 }
100 }
101
102 entryNode.remove();
103 }
104
105 aclNode.setProperty(WorkspaceAccessFieldFactory.INTERMEDIARY_FORMAT_PROPERTY_NAME, (Value)null);
106 acl.saveEntries(aclNode);
107 }
108 }
109
110 node.getSession().save();
111 } catch (final RepositoryException e) {
112 throw new ActionExecutionException(e);
113 }
114 callback.onSuccess(getDefinition().getName());
115
116 } else {
117
118 }
119 }
120
121 }