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