]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - SimpleArgeoUser.java
29166472146f8bd3e6e39aa30597da0c2b6f835d
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.
32 public class SimpleArgeoUser
implements ArgeoUser
, Serializable
,
33 Comparable
<ArgeoUser
> {
34 private static final long serialVersionUID
= 1L;
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
>();
41 public SimpleArgeoUser() {
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());
53 public Map
<String
, UserNature
> getUserNatures() {
58 public void updateUserNatures(Map
<String
, UserNature
> userNaturesData
) {
59 updateUserNaturesWithCheck(userNatures
, userNaturesData
);
63 public static void updateUserNaturesWithCheck(
64 Map
<String
, UserNature
> userNatures
,
65 Map
<String
, UserNature
> userNaturesData
) {
67 if (userNatures
.size() != userNaturesData
.size())
68 throw new ArgeoException(
69 "It is forbidden to add or remove user natures via this method");
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
);
77 for (String key
: userNatures
.keySet()) {
78 userNatures
.put(key
, userNaturesData
.get(key
));
83 public boolean equals(Object obj
) {
84 if (!(obj
instanceof ArgeoUser
))
86 return ((ArgeoUser
) obj
).getUsername().equals(username
);
89 public int compareTo(ArgeoUser o
) {
90 return username
.compareTo(o
.getUsername());
94 public int hashCode() {
95 return username
.hashCode();
99 public String
toString() {
103 public List
<String
> getRoles() {
107 public String
getUsername() {
111 public void setUsername(String username
) {
112 this.username
= username
;
116 public void setUserNatures(Map
<String
, UserNature
> userNatures
) {
117 this.userNatures
= userNatures
;
120 public void setRoles(List
<String
> roles
) {
124 public String
getPassword() {
128 public void setPassword(String password
) {
129 this.password
= password
;