]> git.argeo.org Git - lgpl/argeo-commons.git/blob - security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/nature/SimpleUserNature.java
Improve Security
[lgpl/argeo-commons.git] / security / runtime / org.argeo.security.core / src / main / java / org / argeo / security / nature / SimpleUserNature.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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
17 package org.argeo.security.nature;
18
19 import org.argeo.ArgeoException;
20 import org.argeo.security.AbstractUserNature;
21 import org.argeo.security.ArgeoUser;
22 import org.argeo.security.UserNature;
23
24 public class SimpleUserNature extends AbstractUserNature {
25 /**
26 * No PAI, for internal use within the Argeo Security framework. Will
27 * probably be removed.
28 */
29 public final static String TYPE = "simpleUser";
30
31 private static final long serialVersionUID = 1L;
32 private String email;
33 private String firstName;
34 private String lastName;
35 private String description;
36
37 public String getEmail() {
38 return email;
39 }
40
41 public void setEmail(String email) {
42 this.email = email;
43 }
44
45 public String getFirstName() {
46 return firstName;
47 }
48
49 public void setFirstName(String firstName) {
50 this.firstName = firstName;
51 }
52
53 public String getLastName() {
54 return lastName;
55 }
56
57 public void setLastName(String lastName) {
58 this.lastName = lastName;
59 }
60
61 public String getDescription() {
62 return description;
63 }
64
65 public void setDescription(String description) {
66 this.description = description;
67 }
68
69 /*
70 * SECURITY UTILITIES
71 */
72 /**
73 * Finds a user nature extending {@link SimpleUserNature} in the provided
74 * user.
75 *
76 * @param user
77 * the user to scan
78 * @param simpleNatureType
79 * the type under which a {@link SimpleUserNature} is registered,
80 * useful if there are many. can be null.
81 * @return the {@link SimpleUserNature}
82 * @throws ArgeoException
83 * if no simple user nature was found
84 */
85 public final static SimpleUserNature findSimpleUserNature(ArgeoUser user,
86 String simpleNatureType) {
87 SimpleUserNature simpleNature = null;
88 if (simpleNatureType != null)
89 simpleNature = (SimpleUserNature) user.getUserNatures().get(
90 simpleNatureType);
91 else
92 for (UserNature userNature : user.getUserNatures().values())
93 if (userNature instanceof SimpleUserNature)
94 simpleNature = (SimpleUserNature) userNature;
95
96 if (simpleNature == null)
97 throw new ArgeoException("No simple user nature in user " + user);
98 return simpleNature;
99 }
100
101 }