1 /*
2 * Copyright 2003 - 2013 The eFaps Team
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * Revision: $Rev$
17 * Last Changed: $Date$
18 * Last Changed By: $Author$
19 */
20
21 package org.efaps.jaas.xml;
22
23 import java.util.HashSet;
24 import java.util.Set;
25
26 import org.apache.commons.lang3.builder.ToStringBuilder;
27
28 /**
29 * The class implements the {@link java.security.Principal} interface for a
30 * person. The class is used from the {@link XMLUserLoginModule} class to implement
31 * a JAAS login module and set the person principals.<br/>
32 * A person principal instance stores also all found {@link #groups} and
33 * {@link #roles}.
34 *
35 * @author The eFaps Team
36 * @version $Id$
37 */
38 public class XMLPersonPrincipal
39 extends AbstractXMLPrincipal
40 {
41 /***
42 * The password of this person is stored in this instance variable.
43 *
44 * @see #getPassword()
45 * @see #setPassword(String)
46 */
47 private String password = null;
48
49 /***
50 * The first name of this person is stored in this instance variable.
51 *
52 * @see #getFirstName
53 * @see #setFirstName
54 */
55 private String firstName = null;
56
57 /***
58 * The last name of this person is stored in this instance variable.
59 *
60 * @see #getLastName
61 * @see #setLastName
62 */
63 private String lastName = null;
64
65 /***
66 * The email adresse of this person is stored in this instance variable.
67 *
68 * @see #getEmail
69 * @see #setEmail
70 */
71 private String email = null;
72
73 /***
74 * The organization name of this person is stored in this instance variable.
75 *
76 * @see #getOrganisation
77 * @see #setOrganisation
78 */
79 private String organisation = null;
80
81 /***
82 * The URL of this person is stored in this instance variable.
83 *
84 * @see #getUrl
85 * @see #setUrl
86 */
87 private String url = null;
88
89 /***
90 * The phone number of this person is stored in this instance variable.
91 *
92 * @see #getPhone
93 * @see #setPhone
94 */
95 private String phone = null;
96
97 /***
98 * The mobile number of this person is stored in this instance variable.
99 *
100 * @see #getMobile
101 * @see #setMobile
102 */
103 private String mobile = null;
104
105 /***
106 * The fax number of this person is stored in this instance variable.
107 *
108 * @see #getFax
109 * @see #setFax
110 */
111 private String fax = null;
112
113 /**
114 * All groups assign to this person are stored in this instance variable.
115 *
116 * @see #getRoles
117 */
118 private final Set<XMLRolePrincipal> roles = new HashSet<XMLRolePrincipal>();
119
120 /**
121 * All groups assign to this person are stored in this instance variable.
122 *
123 * @see #getGroups
124 */
125 private final Set<XMLGroupPrincipal> groups = new HashSet<XMLGroupPrincipal>();
126
127 /**
128 * A new role with givevn name is added. The role is added as role
129 * principal (instance of {@link XMLRolePrincipal}).
130 *
131 * @param _role name of role to add
132 * @see #roles
133 */
134 public void addRole(final String _role)
135 {
136 this.roles.add(new XMLRolePrincipal(_role));
137 }
138
139 /**
140 * A new group with givevn name is added. The group is added as role
141 * principal (instance of {@link XMLGroupPrincipal}).
142 *
143 * @param _group name of group to add
144 * @see #groups
145 */
146 public void addGroup(final String _group)
147 {
148 this.groups.add(new XMLGroupPrincipal(_group));
149 }
150
151 /**
152 * Returns the password of this principal stored in instance variable
153 * {@link #password}.
154 *
155 * @return name of this person principal
156 * @see #password
157 * @see #setPassword
158 */
159 public String getPassword()
160 {
161 return this.password;
162 }
163
164 /**
165 * Sets the password of this person principal stored in instance variable
166 * {@link #password}. The method must be public, because it is set from the
167 * XML to bean converter in {@link XMLUserLoginModule}.
168 *
169 * @param _password new name to set for this person principal
170 * @see #password
171 * @see #getPassword
172 */
173 public void setPassword(final String _password)
174 {
175 this.password = _password;
176 }
177
178 /**
179 * Returns the first name of this person principal stored in instance
180 * variable {@link #firstName}.
181 *
182 * @return name of this person principal
183 * @see #firstName
184 * @see #setFirstName
185 */
186 public String getFirstName()
187 {
188 return this.firstName;
189 }
190
191 /**
192 * Sets the first name of this person principal stored in instance variable
193 * {@link #firstName}. The method must be public, because it is set from
194 * the XML to bean converter in {@link XMLUserLoginModule}.
195 *
196 * @param _firstName new first name to set for this person principal
197 * @see #firstName
198 * @see #getFirstName
199 */
200 public void setFirstName(final String _firstName)
201 {
202 this.firstName = _firstName;
203 }
204
205 /**
206 * Returns the last name of this person principal stored in instance
207 * variable {@link #lastName}.
208 *
209 * @return name of this person principal
210 * @see #lastName
211 * @see #setLastName
212 */
213 public String getLastName()
214 {
215 return this.lastName;
216 }
217
218 /**
219 * Sets the last name of this person principal stored in instance variable
220 * {@link #lastNaem}. The method must be public, because it is set from the
221 * XML to bean converter in {@link XMLUserLoginModule}.
222 *
223 * @param _lastName new last name to set for this person principal
224 * @see #lastName
225 * @see #getLastName
226 */
227 public void setLastName(final String _lastName)
228 {
229 this.lastName = _lastName;
230 }
231
232 /**
233 * Returns the email of this person principal stored in instance variable
234 * {@link #email}.
235 *
236 * @return email address of this person principal
237 * @see #email
238 * @see #setEmail
239 */
240 public String getEmail()
241 {
242 return this.email;
243 }
244
245 /**
246 * Sets the email address of this person principal stored in instance
247 * variable {@link #email}. The method must be public, because it is set
248 * from the XML to bean converter in {@link XMLUserLoginModule}.
249 *
250 * @param _email new email address to set for this person principal
251 * @see #email
252 * @see #getEmail
253 */
254 public void setEmail(final String _email)
255 {
256 this.email = _email;
257 }
258
259 /**
260 * Returns the organization name of this person principal stored in instance
261 * variable {@link #organisation}.
262 *
263 * @return organization name of this person principal
264 * @see #organisation
265 * @see #setOrganisation
266 */
267 public String getOrganisation()
268 {
269 return this.organisation;
270 }
271
272 /**
273 * Sets the organisation name of this person principal stored in instance
274 * variable {@link #organisation}. The method must be public, because it is
275 * set from the XML to bean converter in {@link XMLUserLoginModule}.
276 *
277 * @param _organisation new organisation name to set for this person
278 * principal
279 * @see #organisation
280 * @see #getOrganisation
281 */
282 public void setOrganisation(final String _organisation)
283 {
284 this.organisation = _organisation;
285 }
286
287 /**
288 * Returns the URL of this person principal stored in instance variable
289 * {@link #url}.
290 *
291 * @return URL address of this person principal
292 * @see #url
293 * @see #setUrl
294 */
295 public String getUrl()
296 {
297 return this.url;
298 }
299
300 /**
301 * Sets the URL address of this person principal stored in instance
302 * variable {@link #url}. The method must be public, because it is set from
303 * the XML to bean converter in {@link XMLUserLoginModule}.
304 *
305 * @param _url new url address to set for this person principal
306 * @see #url
307 * @see #getUrl
308 */
309 public void setUrl(final String _url)
310 {
311 this.url = _url;
312 }
313
314 /**
315 * Returns the phone number of this person principal stored in instance
316 * variable {@link #phone}.
317 *
318 * @return phone number of this person principal
319 * @see #phone
320 * @see #setPhone
321 */
322 public String getPhone()
323 {
324 return this.phone;
325 }
326
327 /**
328 * Sets the phone number of this person principal stored in instance
329 * variable {@link #phone}. The method must be public, because it is set
330 * from the XML to bean converter in {@link XMLUserLoginModule}.
331 *
332 * @param _phone new phone number to set for this person principal
333 * @see #phone
334 * @see #getPhone
335 */
336 public void setPhone(final String _phone)
337 {
338 this.phone = _phone;
339 }
340
341 /**
342 * Returns the mobile number of this person principal stored in instance
343 * variable {@link #mobile}.
344 *
345 * @return mobile number of this person principal
346 * @see #mobile
347 * @see #setMobile
348 */
349 public String getMobile()
350 {
351 return this.mobile;
352 }
353
354 /**
355 * Sets the mobile number of this person principal stored in instance variable
356 * {@link #mobile}. The method must be public, because it is set from the
357 * XML to bean converter in {@link XMLUserLoginModule}.
358 *
359 * @param _mobile new phone number to set for this person principal
360 * @see #mobile
361 * @see #getMobile
362 */
363 public void setMobile(final String _mobile)
364 {
365 this.mobile = _mobile;
366 }
367
368 /**
369 * Returns the fax number of this person principal stored in instance
370 * variable {@link #fax}.
371 *
372 * @return fax number of this person principal
373 * @see #fax
374 * @see #setFax
375 */
376 public String getFax()
377 {
378 return this.fax;
379 }
380
381 /**
382 * Sets the fax number of this person principal stored in instance variable
383 * {@link #fax}. The method must be public, because it is set from the
384 * XML to bean converter in {@link XMLUserLoginModule}.
385 *
386 * @param _fax new fax number to set for this person principal
387 * @see #fax
388 * @see #getPhone
389 */
390 public void setFax(final String _fax)
391 {
392 this.fax = _fax;
393 }
394
395 /**
396 * Returns the name of this principal stored in instance variable
397 * {@link #roles}.
398 *
399 * @return all assigned roles of this person principal
400 * @see #roles
401 */
402 public Set<XMLRolePrincipal> getRoles()
403 {
404 return this.roles;
405 }
406
407 /**
408 * Returns the groups of this principal stored in instance variable
409 * {@link #groups}.
410 *
411 * @return all assigned groups of this person principal
412 * @see #groups
413 */
414 public Set<XMLGroupPrincipal> getGroups()
415 {
416 return this.groups;
417 }
418
419 /**
420 * Returns a string representation of this person principal.
421 *
422 * @return string representation of this person principal
423 */
424 @Override
425 public String toString()
426 {
427 return new ToStringBuilder(this)
428 .appendSuper(super.toString())
429 .append("firstName", getFirstName())
430 .append("lastName", getLastName())
431 .append("email", getEmail())
432 .append("organisation", getOrganisation())
433 .append("url", getEmail())
434 .append("phone", getPhone())
435 .append("fax", getFax())
436 .append("password", getPassword())
437 .append("roles", getRoles())
438 .append("groups", getGroups())
439 .toString();
440 }
441 }