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.cms.security;
35
36 import info.magnolia.cms.security.auth.ACL;
37 import info.magnolia.cms.security.auth.GroupList;
38 import info.magnolia.cms.security.auth.RoleList;
39 import info.magnolia.context.MgnlContext;
40
41 import java.util.ArrayList;
42 import java.util.Collection;
43 import java.util.Map;
44
45 import javax.jcr.Value;
46 import javax.security.auth.Subject;
47
48
49
50
51 public class ExternalUserManager implements UserManager {
52
53 @Override
54 public User getUser(String name) throws UnsupportedOperationException {
55
56
57 if (name.equalsIgnoreCase(MgnlContext.getUser().getName())) {
58 return MgnlContext.getUser();
59 }
60 throw new UnsupportedOperationException("not implemented yet");
61 }
62
63 @Override
64 public User getUserById(final String id) throws UnsupportedOperationException {
65 throw new UnsupportedOperationException("not implemented yet");
66 }
67
68
69
70
71 @Override
72 public User getUser(Subject subject) throws UnsupportedOperationException {
73 return new ExternalUser(subject);
74 }
75
76 public User getUser(Map<String, String> properties, GroupList groupList, RoleList roleList){
77 return new ExternalUser(properties, groupList, roleList);
78 }
79
80 @Override
81 public Collection<User> getAllUsers() throws UnsupportedOperationException {
82 throw new UnsupportedOperationException("not implemented yet");
83 }
84
85 @Override
86 public User createUser(String name, String pw) throws UnsupportedOperationException {
87 throw new UnsupportedOperationException("not implemented yet");
88 }
89
90 @Override
91 public User createUser(String path, String name, String pw) throws UnsupportedOperationException {
92 throw new UnsupportedOperationException("not implemented yet");
93 }
94
95 @Override
96 public User changePassword(User user, String newPassword) throws UnsupportedOperationException {
97 throw new UnsupportedOperationException("not implemented yet");
98 }
99
100
101
102
103 @Override
104 public User getSystemUser() throws UnsupportedOperationException {
105 throw new UnsupportedOperationException();
106 }
107
108
109
110
111 @Override
112 public User getAnonymousUser() throws UnsupportedOperationException {
113 throw new UnsupportedOperationException();
114 }
115
116 @Override
117 public void updateLastAccessTimestamp(User user) throws UnsupportedOperationException {
118 throw new UnsupportedOperationException();
119 }
120
121 @Override
122 public boolean hasAny(String name, String roleName, String nodeRoles) throws UnsupportedOperationException {
123 throw new UnsupportedOperationException("not implemented yet");
124 }
125
126 @Override
127 public Map<String,ACL> getACLs(User user) {
128 throw new UnsupportedOperationException("not implemented yet");
129 }
130
131 @Override
132 public User addRole(User user, String roleName) {
133 throw new UnsupportedOperationException("not implemented yet");
134 }
135
136 @Override
137 public User addGroup(User user, String groupName) {
138 throw new UnsupportedOperationException("not implemented yet");
139 }
140
141 @Override
142 public int getLockTimePeriod() {
143 throw new UnsupportedOperationException("Not supported by this user manager.");
144 }
145
146 @Override
147 public int getMaxFailedLoginAttempts() {
148 throw new UnsupportedOperationException("Not supported by this user manager.");
149 }
150
151 @Override
152 public void setLockTimePeriod(int lockTimePeriod){
153 throw new UnsupportedOperationException("Not supported by this user manager.");
154 }
155
156 @Override
157 public void setMaxFailedLoginAttempts(int maxFailedLoginAttempts){
158 throw new UnsupportedOperationException("Not supported by this user manager.");
159 }
160
161 @Override
162 public User setProperty(User user, String propertyName, Value propertyValue) {
163 throw new UnsupportedOperationException("Not supported by this user manager.");
164 }
165
166 @Override
167 public User setProperty(User user, String propertyName, String propertyValue) {
168 throw new UnsupportedOperationException("Not supported by this user manager.");
169 }
170
171 @Override
172 public User removeGroup(User user, String groupName) {
173 throw new UnsupportedOperationException("not implemented yet");
174 }
175
176 @Override
177 public User removeRole(User user, String roleName) {
178 throw new UnsupportedOperationException("not implemented yet");
179 }
180
181
182
183
184 @Override
185 public Collection<String> getUsersWithGroup(final String groupName) {
186 Collection<User> users = getAllUsers();
187 Collection<String> usersWithProvidedGroup = new ArrayList<String>();
188 for (User current: users) {
189 if (current.inGroup(groupName)) {
190 usersWithProvidedGroup.add(current.getName());
191 }
192 }
193
194 return usersWithProvidedGroup;
195 }
196
197
198
199
200 @Override
201 public Collection<String> getUsersWithRole(final String roleName) {
202 Collection<User> users = getAllUsers();
203 Collection<String> usersWithProvidedGroup = new ArrayList<String>();
204 for (User current: users) {
205 if (current.hasRole(roleName)) {
206 usersWithProvidedGroup.add(current.getName());
207 }
208 }
209
210 return usersWithProvidedGroup;
211 }
212 }