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