]> git.argeo.org Git - lgpl/argeo-commons.git/blob - SimpleArgeoUser.java
29166472146f8bd3e6e39aa30597da0c2b6f835d
[lgpl/argeo-commons.git] / SimpleArgeoUser.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;
18
19 import java.io.Serializable;
20 import java.util.ArrayList;
21 import java.util.HashMap;
22 import java.util.List;
23 import java.util.Map;
24
25 import org.argeo.ArgeoException;
26
27 /**
28 * Read-write implementation of an Argeo user. Typically initialized with a
29 * generic instance (read-only9 in order to modify a user.
30 */
31 @Deprecated
32 public class SimpleArgeoUser implements ArgeoUser, Serializable,
33 Comparable<ArgeoUser> {
34 private static final long serialVersionUID = 1L;
35
36 private String username;
37 private String password;
38 private Map<String, UserNature> userNatures = new HashMap<String, UserNature>();
39 private List<String> roles = new ArrayList<String>();
40
41 public SimpleArgeoUser() {
42
43 }
44
45 public SimpleArgeoUser(ArgeoUser argeoUser) {
46 username = argeoUser.getUsername();
47 password = argeoUser.getPassword();
48 userNatures = new HashMap<String, UserNature>(
49 argeoUser.getUserNatures());
50 roles = new ArrayList<String>(argeoUser.getRoles());
51 }
52
53 public Map<String, UserNature> getUserNatures() {
54 return userNatures;
55 }
56
57 @Deprecated
58 public void updateUserNatures(Map<String, UserNature> userNaturesData) {
59 updateUserNaturesWithCheck(userNatures, userNaturesData);
60 }
61
62 @Deprecated
63 public static void updateUserNaturesWithCheck(
64 Map<String, UserNature> userNatures,
65 Map<String, UserNature> userNaturesData) {
66 // checks consistency
67 if (userNatures.size() != userNaturesData.size())
68 throw new ArgeoException(
69 "It is forbidden to add or remove user natures via this method");
70
71 for (String type : userNatures.keySet()) {
72 if (!userNaturesData.containsKey(type))
73 throw new ArgeoException(
74 "Could not find a user nature of type " + type);
75 }
76
77 for (String key : userNatures.keySet()) {
78 userNatures.put(key, userNaturesData.get(key));
79 }
80 }
81
82 @Override
83 public boolean equals(Object obj) {
84 if (!(obj instanceof ArgeoUser))
85 return false;
86 return ((ArgeoUser) obj).getUsername().equals(username);
87 }
88
89 public int compareTo(ArgeoUser o) {
90 return username.compareTo(o.getUsername());
91 }
92
93 @Override
94 public int hashCode() {
95 return username.hashCode();
96 }
97
98 @Override
99 public String toString() {
100 return username;
101 }
102
103 public List<String> getRoles() {
104 return roles;
105 }
106
107 public String getUsername() {
108 return username;
109 }
110
111 public void setUsername(String username) {
112 this.username = username;
113 }
114
115 @Deprecated
116 public void setUserNatures(Map<String, UserNature> userNatures) {
117 this.userNatures = userNatures;
118 }
119
120 public void setRoles(List<String> roles) {
121 this.roles = roles;
122 }
123
124 public String getPassword() {
125 return password;
126 }
127
128 public void setPassword(String password) {
129 this.password = password;
130 }
131 }