001: /****************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one *
003: * or more contributor license agreements. See the NOTICE file *
004: * distributed with this work for additional information *
005: * regarding copyright ownership. The ASF licenses this file *
006: * to you under the Apache License, Version 2.0 (the *
007: * "License"); you may not use this file except in compliance *
008: * with the License. You may obtain a copy of the License at *
009: * *
010: * http://www.apache.org/licenses/LICENSE-2.0 *
011: * *
012: * Unless required by applicable law or agreed to in writing, *
013: * software distributed under the License is distributed on an *
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
015: * KIND, either express or implied. See the License for the *
016: * specific language governing permissions and limitations *
017: * under the License. *
018: ****************************************************************/package org.apache.james.core;
019:
020: import org.apache.avalon.framework.activity.Initializable;
021: import org.apache.avalon.framework.service.ServiceException;
022: import org.apache.avalon.framework.service.ServiceManager;
023: import org.apache.avalon.framework.service.Serviceable;
024: import org.apache.james.services.User;
025: import org.apache.james.services.UsersRepository;
026: import org.apache.james.services.UsersStore;
027:
028: import java.util.Iterator;
029:
030: public class LocalUsersRepository implements UsersRepository,
031: Serviceable, Initializable {
032:
033: private UsersStore usersStore;
034: private UsersRepository users;
035:
036: public void service(ServiceManager serviceManager)
037: throws ServiceException {
038: usersStore = (UsersStore) serviceManager
039: .lookup(UsersStore.ROLE);
040: }
041:
042: public void initialize() throws Exception {
043: users = usersStore.getRepository("LocalUsers");
044: if (users == null) {
045: throw new ServiceException("",
046: "The user repository could not be found.");
047: }
048: }
049:
050: public boolean addUser(User user) {
051: return users.addUser(user);
052: }
053:
054: public void addUser(String name, Object attributes) {
055: users.addUser(name, attributes);
056: }
057:
058: public boolean addUser(String username, String password) {
059: return users.addUser(username, password);
060: }
061:
062: public User getUserByName(String name) {
063: return users.getUserByName(name);
064: }
065:
066: public User getUserByNameCaseInsensitive(String name) {
067: return users.getUserByNameCaseInsensitive(name);
068: }
069:
070: public String getRealName(String name) {
071: return users.getRealName(name);
072: }
073:
074: public boolean updateUser(User user) {
075: return users.updateUser(user);
076: }
077:
078: public void removeUser(String name) {
079: users.removeUser(name);
080: }
081:
082: public boolean contains(String name) {
083: return users.contains(name);
084: }
085:
086: public boolean containsCaseInsensitive(String name) {
087: return users.containsCaseInsensitive(name);
088: }
089:
090: public boolean test(String name, String password) {
091: return users.test(name, password);
092: }
093:
094: public int countUsers() {
095: return users.countUsers();
096: }
097:
098: public Iterator list() {
099: return users.list();
100: }
101:
102: }
|