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.admininterface.trees;
35
36 import info.magnolia.cms.core.Content;
37 import info.magnolia.cms.core.NodeData;
38 import info.magnolia.cms.exchange.ExchangeException;
39 import info.magnolia.cms.security.AccessDeniedException;
40 import info.magnolia.cms.security.Security;
41 import info.magnolia.cms.security.SecuritySupport;
42 import info.magnolia.cms.security.User;
43 import info.magnolia.cms.security.UserManager;
44 import info.magnolia.cms.util.ExclusiveWrite;
45 import info.magnolia.module.admininterface.AdminTreeMVCHandler;
46
47 import javax.jcr.PathNotFoundException;
48 import javax.jcr.RepositoryException;
49 import javax.servlet.http.HttpServletRequest;
50 import javax.servlet.http.HttpServletResponse;
51
52 import org.apache.commons.lang.StringUtils;
53
54
55
56
57
58 public class UsersTreeHandler extends AdminTreeMVCHandler {
59
60 private final SecuritySupport securitySupport;
61
62 public UsersTreeHandler(String name, HttpServletRequest request, HttpServletResponse response) {
63 super(name, request, response);
64 securitySupport = Security.getSecuritySupport();
65 }
66
67 @Override
68 public String createNode() {
69 getTree().setPath(path);
70 synchronized (ExclusiveWrite.getInstance()) {
71 final UserManager userMan = securitySupport.getUserManager(StringUtils.substringAfterLast(path, "/"));
72 final User user = userMan.createUser(this.getNewNodeName(), "");
73 setNewNodeName(user.getName());
74 }
75 return VIEW_TREE;
76 }
77
78 @Override
79 public String renameNode(String newName) throws AccessDeniedException, ExchangeException, PathNotFoundException, RepositoryException {
80 newName = super.renameNode(newName);
81
82 String path = this.getPath();
83 String newPath = StringUtils.substringBeforeLast(path, "/") + "/" + newName;
84 Content acls = getHierarchyManager().getContent(newPath + "/acl_users");
85 for (Content acl : acls.getChildren()) {
86 NodeData pathND = acl.getNodeData("path");
87 String aclPath = pathND.getString();
88 if (aclPath.startsWith(path + "/")) {
89 pathND.setValue(newPath + "/" + StringUtils.substringAfter(aclPath, path + "/"));
90 }
91 if (path.equals(aclPath)) {
92 pathND.setValue(newPath);
93 }
94 }
95 acls.save();
96 return newName;
97 }
98
99
100 }