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.core.Content;
37 import info.magnolia.cms.util.DeprecationUtil;
38
39 import java.io.Serializable;
40 import java.util.Calendar;
41 import java.util.Collection;
42 import java.util.Collections;
43 import java.util.Map;
44
45 import org.apache.jackrabbit.util.ISO8601;
46
47
48
49
50
51
52
53 public class MgnlUser extends AbstractUser implements User, Serializable {
54 private final Map<String, String> properties;
55 private final Collection<String> directGroups;
56 private final Collection<String> directRoles;
57 private final Collection<String> allGroups;
58 private final Collection<String> allRoles;
59
60 private final String name;
61 private final String language;
62 private final String encodedPassword;
63 private boolean enabled = true;
64 private String path;
65 private String uuid;
66 private final String realm;
67
68
69
70
71
72
73
74
75
76 public MgnlUser(String name, String realm, Collection<String> directGroups, Collection<String> directRoles, Map<String, String> properties, String path, String uuid, Collection<String> allGroups, Collection<String> allRoles) {
77 this.name = name;
78 this.directRoles = directRoles;
79 this.directGroups = directGroups;
80 this.allRoles = allRoles;
81 this.allGroups = allGroups;
82 this.properties = properties;
83 this.realm = realm;
84
85
86 this.language = properties.get(MgnlUserManager.PROPERTY_LANGUAGE);
87
88 final String enabledByDefault = properties.get(MgnlUserManager.PROPERTY_ENABLED);
89
90 this.enabled = enabledByDefault == null ? true : Boolean.parseBoolean(properties.get(MgnlUserManager.PROPERTY_ENABLED));
91
92 this.encodedPassword = properties.get(MgnlUserManager.PROPERTY_PASSWORD);
93 this.path = path;
94 this.uuid = uuid;
95 }
96
97
98
99
100 @Deprecated
101 public MgnlUser(String name, String realm, Collection<String> directGroups, Collection<String> directRoles, Map<String, String> properties, String path, String uuid) {
102 this(name, realm, directGroups, directRoles, properties, path, uuid, Collections.emptySet(), Collections.emptySet());
103 final String reason = "This constructor is deprecated since Magnolia 5.5.5.\n" +
104 "Be warned that instantiating directly MgnlUser with this constructor will result in an inconsistent object missing all roles and groups.\n" +
105 "Please use new public constructor instead.";
106 DeprecationUtil.isDeprecated(reason);
107 }
108
109
110
111
112 @Deprecated
113 public MgnlUser(String name, String realm, Collection<String> directGroups, Collection<String> directRoles, Map<String, String> properties) {
114 this(name, realm, directGroups, directRoles, properties, null, null);
115 }
116
117 @Override
118 public boolean inGroup(String groupName) {
119 return allGroups.contains(groupName);
120 }
121
122 @Override
123 public boolean isEnabled() {
124 return enabled;
125 }
126
127 @Override
128 public boolean hasRole(String roleName) {
129 return allRoles.contains(roleName);
130 }
131
132 public int getFailedLoginAttempts() {
133 try {
134 return Integer.valueOf(this.properties.get("failedLoginAttempts"));
135 } catch (Exception e) {
136 return 0;
137 }
138 }
139
140 public Calendar getReleaseTime() {
141 try {
142 return ISO8601.parse(this.properties.get("releaseTime"));
143 } catch (Exception e) {
144 return null;
145 }
146 }
147
148 @Override
149 public String getName() {
150 return name;
151 }
152
153 @Override
154 public String getPassword() {
155 return encodedPassword;
156 }
157
158 @Deprecated
159
160
161
162 protected String decodePassword(String encodedPassword) {
163 throw new UnsupportedOperationException();
164 }
165
166 @Override
167 public String getLanguage() {
168 return this.language;
169 }
170
171 @Override
172 public String getProperty(String propertyName) {
173 return properties.get(propertyName);
174 }
175
176 @Override
177 public Collection<String> getGroups() {
178 return Collections.unmodifiableCollection(directGroups);
179 }
180
181 @Override
182 public Collection<String> getAllGroups() {
183 return Collections.unmodifiableCollection(allGroups);
184 }
185
186 @Override
187 public Collection<String> getRoles() {
188 return Collections.unmodifiableCollection(directRoles);
189 }
190
191 @Override
192 public Collection<String> getAllRoles() {
193 return Collections.unmodifiableCollection(allRoles);
194 }
195
196 public String getPath() {
197 return this.path;
198 }
199
200 @Deprecated
201 public void setPath(String path) {
202 this.path = path;
203 }
204
205
206 public String getRealm() {
207 return realm;
208 }
209
210
211
212
213
214
215 @Deprecated
216 public void setLastAccess() {
217 throw new UnsupportedOperationException("Use manager to update user details.");
218 }
219
220
221
222
223
224
225 @Deprecated
226 public Content getUserNode() {
227 throw new UnsupportedOperationException("Underlying storage node is no longer exposed nor required for custom user stores.");
228 }
229
230
231
232
233 @Override
234 @Deprecated
235 public void setProperty(String propertyName, String value) {
236 throw new UnsupportedOperationException("Use manager to modify properties of the user.");
237 }
238
239 @Override
240 public String getIdentifier() {
241 return uuid;
242 }
243
244
245
246
247 @Deprecated
248 public String getUuid() {
249 return uuid;
250 }
251
252 @Override
253 public String toString() {
254 return "MgnlUser - " + name + " [" + uuid + "]";
255 }
256 }