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.module.delta;
35
36 import info.magnolia.cms.security.Group;
37 import info.magnolia.cms.security.GroupManager;
38 import info.magnolia.cms.security.SecuritySupport;
39 import info.magnolia.module.InstallContext;
40
41 import javax.jcr.RepositoryException;
42
43
44
45
46
47
48 public class AddGroupToGroupTask extends AbstractRepositoryTask {
49 private final String parentGroupName;
50 private final String nestedGroupName;
51
52 public AddGroupToGroupTask(String taskName, String nestedGroupName, String parentGroupName) {
53 super(taskName, "Adding group \"" + nestedGroupName + "\" to group \"" + parentGroupName + "\"");
54 this.parentGroupName = parentGroupName;
55 this.nestedGroupName = nestedGroupName;
56 }
57
58 @Override
59 protected void doExecute(InstallContext ctx) throws RepositoryException, TaskExecutionException {
60 final GroupManager groupManager = SecuritySupport.Factory.getInstance().getGroupManager();
61 final Group group = groupManager.getGroup(parentGroupName);
62 if (group == null) {
63 ctx.warn("Group \"" + parentGroupName + "\" not found, can't add \"" + nestedGroupName + "\" to its sub-groups.");
64 } else {
65
66 try{
67 group.addGroup(nestedGroupName);
68 }
69 catch (UnsupportedOperationException e) {
70 ctx.warn("Can't add the group \"" + nestedGroupName + "\" to the \"" + parentGroupName+ "\" group due to an unsupported operation exception. This is most likely the case if the groups are managed externally.");
71 }
72 }
73 }
74 }