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