1 /************************************************************************
2 * Copyright (c) 1999-2006 The Apache Software Foundation. *
3 * All rights reserved. *
4 * ------------------------------------------------------------------- *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you *
6 * may not use this file except in compliance with the License. You *
7 * may obtain a copy of the License at: *
8 * *
9 * http://www.apache.org/licenses/LICENSE-2.0 *
10 * *
11 * Unless required by applicable law or agreed to in writing, software *
12 * distributed under the License is distributed on an "AS IS" BASIS, *
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
14 * implied. See the License for the specific language governing *
15 * permissions and limitations under the License. *
16 ***********************************************************************/
17
18 package org.apache.james.core;
19
20 import org.apache.avalon.framework.activity.Initializable;
21 import org.apache.avalon.framework.service.ServiceException;
22 import org.apache.avalon.framework.service.ServiceManager;
23 import org.apache.avalon.framework.service.Serviceable;
24 import org.apache.james.services.User;
25 import org.apache.james.services.UsersRepository;
26 import org.apache.james.services.UsersStore;
27
28 import java.util.Iterator;
29
30 public class LocalUsersRepository implements UsersRepository, Serviceable, Initializable {
31
32 private UsersStore usersStore;
33 private UsersRepository users;
34
35 public void service(ServiceManager serviceManager) throws ServiceException {
36 usersStore =
37 (UsersStore) serviceManager.lookup(UsersStore.ROLE);
38 }
39
40 public void initialize() throws Exception {
41 users = usersStore.getRepository("LocalUsers");
42 if (users == null) {
43 throw new ServiceException("","The user repository could not be found.");
44 }
45 }
46
47 public boolean addUser(User user) {
48 return users.addUser(user);
49 }
50
51 public void addUser(String name, Object attributes) {
52 users.addUser(name,attributes);
53 }
54
55 public boolean addUser(String username, String password) {
56 return users.addUser(username, password);
57 }
58
59 public User getUserByName(String name) {
60 return users.getUserByName(name);
61 }
62
63 public User getUserByNameCaseInsensitive(String name) {
64 return users.getUserByNameCaseInsensitive(name);
65 }
66
67 public String getRealName(String name) {
68 return users.getRealName(name);
69 }
70
71 public boolean updateUser(User user) {
72 return users.updateUser(user);
73 }
74
75 public void removeUser(String name) {
76 users.removeUser(name);
77 }
78
79 public boolean contains(String name) {
80 return users.contains(name);
81 }
82
83 public boolean containsCaseInsensitive(String name) {
84 return users.containsCaseInsensitive(name);
85 }
86
87 public boolean test(String name, String password) {
88 return users.test(name,password);
89 }
90
91 public int countUsers() {
92 return users.countUsers();
93 }
94
95 public Iterator list() {
96 return users.list();
97 }
98
99 }