]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - SimpleArgeoUser.java
c021f8e4453a8e1ae61975c7839c644c9f9d7288
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org
.argeo
.security
;
19 import java
.io
.Serializable
;
20 import java
.util
.ArrayList
;
21 import java
.util
.HashMap
;
22 import java
.util
.List
;
25 import org
.argeo
.ArgeoException
;
28 * Read-write implementation of an Argeo user. Typically initialized with a
29 * generic instance (read-only9 in order to modify a user.
31 public class SimpleArgeoUser
implements ArgeoUser
, Serializable
,
32 Comparable
<ArgeoUser
> {
33 private static final long serialVersionUID
= 1L;
35 private String username
;
36 private String password
;
37 private Map
<String
, UserNature
> userNatures
= new HashMap
<String
, UserNature
>();
38 private List
<String
> roles
= new ArrayList
<String
>();
40 public SimpleArgeoUser() {
44 public SimpleArgeoUser(ArgeoUser argeoUser
) {
45 username
= argeoUser
.getUsername();
46 password
= argeoUser
.getPassword();
47 userNatures
= new HashMap
<String
, UserNature
>(
48 argeoUser
.getUserNatures());
49 roles
= new ArrayList
<String
>(argeoUser
.getRoles());
52 public Map
<String
, UserNature
> getUserNatures() {
56 public void updateUserNatures(Map
<String
, UserNature
> userNaturesData
) {
57 updateUserNaturesWithCheck(userNatures
, userNaturesData
);
60 public static void updateUserNaturesWithCheck(
61 Map
<String
, UserNature
> userNatures
,
62 Map
<String
, UserNature
> userNaturesData
) {
64 if (userNatures
.size() != userNaturesData
.size())
65 throw new ArgeoException(
66 "It is forbidden to add or remove user natures via this method");
68 for (String type
: userNatures
.keySet()) {
69 if (!userNaturesData
.containsKey(type
))
70 throw new ArgeoException(
71 "Could not find a user nature of type " + type
);
74 for (String key
: userNatures
.keySet()) {
75 userNatures
.put(key
, userNaturesData
.get(key
));
80 public boolean equals(Object obj
) {
81 if (!(obj
instanceof ArgeoUser
))
83 return ((ArgeoUser
) obj
).getUsername().equals(username
);
86 public int compareTo(ArgeoUser o
) {
87 return username
.compareTo(o
.getUsername());
91 public int hashCode() {
92 return username
.hashCode();
96 public String
toString() {
100 public List
<String
> getRoles() {
104 public String
getUsername() {
108 public void setUsername(String username
) {
109 this.username
= username
;
112 public void setUserNatures(Map
<String
, UserNature
> userNatures
) {
113 this.userNatures
= userNatures
;
116 public void setRoles(List
<String
> roles
) {
120 public String
getPassword() {
124 public void setPassword(String password
) {
125 this.password
= password
;