]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/SimpleArgeoUser.java
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
;
27 public class SimpleArgeoUser
implements ArgeoUser
, Serializable
{
28 private static final long serialVersionUID
= 1L;
30 private String username
;
31 private String password
;
32 private Map
<String
, UserNature
> userNatures
= new HashMap
<String
, UserNature
>();
33 private List
<String
> roles
= new ArrayList
<String
>();
35 public SimpleArgeoUser() {
39 public SimpleArgeoUser(ArgeoUser argeoUser
) {
40 username
= argeoUser
.getUsername();
41 password
= argeoUser
.getPassword();
42 userNatures
= new HashMap
<String
, UserNature
>(
43 argeoUser
.getUserNatures());
44 roles
= new ArrayList
<String
>(argeoUser
.getRoles());
47 public Map
<String
, UserNature
> getUserNatures() {
51 public void updateUserNatures(Map
<String
, UserNature
> userNaturesData
) {
52 updateUserNaturesWithCheck(userNatures
, userNaturesData
);
55 public static void updateUserNaturesWithCheck(
56 Map
<String
, UserNature
> userNatures
,
57 Map
<String
, UserNature
> userNaturesData
) {
59 if (userNatures
.size() != userNaturesData
.size())
60 throw new ArgeoException(
61 "It is forbidden to add or remove user natures via this method");
63 for (String type
: userNatures
.keySet()) {
64 if (!userNaturesData
.containsKey(type
))
65 throw new ArgeoException(
66 "Could not find a user nature of type " + type
);
69 // for (int i = 0; i < userNatures.size(); i++) {
70 // String type = userNatures.get(i).getType();
71 // boolean found = false;
72 // for (int j = 0; j < userNatures.size(); j++) {
73 // String newType = userNaturesData.get(j).getType();
74 // if (type.equals(newType))
78 // throw new ArgeoException(
79 // "Could not find a user nature of type " + type);
82 for (String key
: userNatures
.keySet()) {
83 userNatures
.put(key
, userNaturesData
.get(key
));
88 public String
toString() {
92 public List
<String
> getRoles() {
96 public String
getUsername() {
100 public void setUsername(String username
) {
101 this.username
= username
;
104 public void setUserNatures(Map
<String
, UserNature
> userNatures
) {
105 this.userNatures
= userNatures
;
108 public void setRoles(List
<String
> roles
) {
112 public String
getPassword() {
116 public void setPassword(String password
) {
117 this.password
= password
;