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
.core
;
19 import java
.util
.HashSet
;
20 import java
.util
.Iterator
;
21 import java
.util
.List
;
24 import org
.argeo
.security
.ArgeoUser
;
25 import org
.argeo
.security
.UserAdminDao
;
26 import org
.argeo
.security
.UserAdminService
;
27 import org
.argeo
.security
.nature
.SimpleUserNature
;
29 public class DefaultUserAdminService
implements UserAdminService
{
30 private String superUsername
= "root";
31 private UserAdminDao userAdminDao
;
33 public void newRole(String role
) {
34 userAdminDao
.createRole(role
, getSuperUsername());
37 public void updateUserPassword(String username
, String password
) {
38 userAdminDao
.updateUserPassword(username
, password
);
41 public void newUser(ArgeoUser user
) {
43 SimpleUserNature simpleUserNature
;
45 simpleUserNature
= SimpleUserNature
46 .findSimpleUserNature(user
, null);
47 } catch (Exception e
) {
48 simpleUserNature
= new SimpleUserNature();
49 user
.getUserNatures().put("simpleUserNature", simpleUserNature
);
52 if (simpleUserNature
.getLastName() == null
53 || simpleUserNature
.getLastName().equals("")) {
54 // to prevent issue with sn in LDAP
55 simpleUserNature
.setLastName("empty");
58 userAdminDao
.createUser(user
);
63 public void synchronize() {
64 // TODO Auto-generated method stub
68 public ArgeoUser
getUser(String username
) {
69 return userAdminDao
.getUser(username
);
72 public Boolean
userExists(String username
) {
73 return userAdminDao
.userExists(username
);
76 public void updateUser(ArgeoUser user
) {
77 userAdminDao
.updateUser(user
);
80 public void deleteUser(String username
) {
81 userAdminDao
.deleteUser(username
);
85 public void deleteRole(String role
) {
86 userAdminDao
.deleteRole(role
);
89 public Set
<ArgeoUser
> listUsersInRole(String role
) {
90 Set
<ArgeoUser
> lst
= new HashSet
<ArgeoUser
>(
91 userAdminDao
.listUsersInRole(role
));
92 Iterator
<ArgeoUser
> it
= lst
.iterator();
93 while (it
.hasNext()) {
94 if (it
.next().getUsername().equals(getSuperUsername())) {
102 public Set
<ArgeoUser
> listUsers() {
103 return userAdminDao
.listUsers();
106 public List
<String
> listUserRoles(String username
) {
107 return getUser(username
).getRoles();
110 public Set
<String
> listEditableRoles() {
111 return userAdminDao
.listEditableRoles();
114 // TODO: expose it via the interface as well?
115 public String
getSuperUsername() {
116 return superUsername
;
119 public void setUserAdminDao(UserAdminDao userAdminDao
) {
120 this.userAdminDao
= userAdminDao
;