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.impl.user;
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.api.user.User;
27 import org.apache.james.api.user.UsersRepository;
28 import org.apache.james.api.user.UsersStore;
29
30 import java.util.Iterator;
31
32 /**
33 * Provide access to the default "LocalUsers" UsersRepository.
34 */
35 public class LocalUsersRepository implements UsersRepository, Serviceable, Initializable {
36
37 private UsersStore usersStore;
38 protected UsersRepository users;
39
40 public void setUsersStore(UsersStore usersStore) {
41 this.usersStore = usersStore;
42 }
43
44 /**
45 * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
46 */
47 public void service(ServiceManager serviceManager) throws ServiceException {
48 UsersStore usersStore =
49 (UsersStore) serviceManager.lookup(UsersStore.ROLE);
50 setUsersStore(usersStore);
51 }
52
53 /**
54 * @see org.apache.avalon.framework.activity.Initializable#initialize()
55 */
56 public void initialize() throws Exception {
57 users = usersStore.getRepository("LocalUsers");
58 if (users == null) {
59 throw new ServiceException("","The user repository could not be found.");
60 }
61 }
62
63 /**
64 * @see org.apache.james.api.user.UsersRepository#addUser(org.apache.james.api.user.User)
65 */
66 public boolean addUser(User user) {
67 return users.addUser(user);
68 }
69
70 /**
71 * @see org.apache.james.api.user.UsersRepository#addUser(java.lang.String, java.lang.Object)
72 */
73 public void addUser(String name, Object attributes) {
74 users.addUser(name,attributes);
75 }
76
77 /**
78 * @see org.apache.james.api.user.UsersRepository#addUser(java.lang.String, java.lang.String)
79 */
80 public boolean addUser(String username, String password) {
81 return users.addUser(username, password);
82 }
83
84 /**
85 * @see org.apache.james.api.user.UsersRepository#getUserByName(java.lang.String)
86 */
87 public User getUserByName(String name) {
88 return users.getUserByName(name);
89 }
90
91 /**
92 * @see org.apache.james.api.user.UsersRepository#getUserByNameCaseInsensitive(java.lang.String)
93 */
94 public User getUserByNameCaseInsensitive(String name) {
95 return users.getUserByNameCaseInsensitive(name);
96 }
97
98 /**
99 * @see org.apache.james.api.user.UsersRepository#getRealName(java.lang.String)
100 */
101 public String getRealName(String name) {
102 return users.getRealName(name);
103 }
104
105 /**
106 * @see org.apache.james.api.user.UsersRepository#updateUser(org.apache.james.api.user.User)
107 */
108 public boolean updateUser(User user) {
109 return users.updateUser(user);
110 }
111
112 /**
113 * @see org.apache.james.api.user.UsersRepository#removeUser(java.lang.String)
114 */
115 public void removeUser(String name) {
116 users.removeUser(name);
117 }
118
119 /**
120 * @see org.apache.james.api.user.UsersRepository#contains(java.lang.String)
121 */
122 public boolean contains(String name) {
123 return users.contains(name);
124 }
125
126 /**
127 * @see org.apache.james.api.user.UsersRepository#containsCaseInsensitive(java.lang.String)
128 */
129 public boolean containsCaseInsensitive(String name) {
130 return users.containsCaseInsensitive(name);
131 }
132
133 /**
134 * @see org.apache.james.api.user.UsersRepository#test(java.lang.String, java.lang.String)
135 */
136 public boolean test(String name, String password) {
137 return users.test(name,password);
138 }
139
140 /**
141 * @see org.apache.james.api.user.UsersRepository#countUsers()
142 */
143 public int countUsers() {
144 return users.countUsers();
145 }
146
147 /**
148 * @see org.apache.james.api.user.UsersRepository#list()
149 */
150 public Iterator list() {
151 return users.list();
152 }
153
154 }