1 /************************************************************************ 2 * Copyright (c) 2000-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.services; 19 20 import java.util.Iterator; 21 22 /*** 23 * Interface for a repository of users. A repository represents a logical 24 * grouping of users, typically by common purpose. E.g. the users served by an 25 * email server or the members of a mailing list. 26 * 27 * 28 * @version $Revision: 407988 $ 29 */ 30 public interface UsersRepository { 31 32 /*** 33 * The component role used by components implementing this service 34 */ 35 String ROLE = "org.apache.james.services.UsersRepository"; 36 37 String USER = "USER"; 38 39 /*** 40 * Adds a user to the repository with the specified User object. 41 * 42 * @param user the user to be added 43 * 44 * @return true if succesful, false otherwise 45 * @since James 1.2.2 46 */ 47 boolean addUser(User user); 48 49 /*** 50 * Adds a user to the repository with the specified attributes. In current 51 * implementations, the Object attributes is generally a String password. 52 * 53 * @param name the name of the user to be added 54 * @param attributes see decription 55 */ 56 void addUser(String name, Object attributes); 57 58 /*** 59 * Adds a user to the repository with the specified password 60 * 61 * @param username the username of the user to be added 62 * @param password the password of the user to add 63 * @return true if succesful, false otherwise 64 * 65 * @since James 2.3.0 66 */ 67 boolean addUser(String username, String password); 68 69 /*** 70 * Get the user object with the specified user name. Return null if no 71 * such user. 72 * 73 * @param name the name of the user to retrieve 74 * @return the user being retrieved, null if the user doesn't exist 75 * 76 * @since James 1.2.2 77 */ 78 User getUserByName(String name); 79 80 /*** 81 * Get the user object with the specified user name. Match user naems on 82 * a case insensitive basis. Return null if no such user. 83 * 84 * @param name the name of the user to retrieve 85 * @return the user being retrieved, null if the user doesn't exist 86 * 87 * @since James 1.2.2 88 */ 89 User getUserByNameCaseInsensitive(String name); 90 91 /*** 92 * Returns the user name of the user matching name on an equalsIgnoreCase 93 * basis. Returns null if no match. 94 * 95 * @param name the name to case-correct 96 * @return the case-correct name of the user, null if the user doesn't exist 97 */ 98 String getRealName(String name); 99 100 /*** 101 * Update the repository with the specified user object. A user object 102 * with this username must already exist. 103 * 104 * @return true if successful. 105 */ 106 boolean updateUser(User user); 107 108 /*** 109 * Removes a user from the repository 110 * 111 * @param name the user to remove from the repository 112 */ 113 void removeUser(String name); 114 115 /*** 116 * Returns whether or not this user is in the repository 117 * 118 * @param name the name to check in the repository 119 * @return whether the user is in the repository 120 */ 121 boolean contains(String name); 122 123 /*** 124 * Returns whether or not this user is in the repository. Names are 125 * matched on a case insensitive basis. 126 * 127 * @param name the name to check in the repository 128 * @return whether the user is in the repository 129 */ 130 boolean containsCaseInsensitive(String name); 131 132 /*** 133 * Test if user with name 'name' has password 'password'. 134 * 135 * @param name the name of the user to be tested 136 * @param password the password to be tested 137 * 138 * @return true if the test is successful, false if the user 139 * doesn't exist or if the password is incorrect 140 * 141 * @since James 1.2.2 142 */ 143 boolean test(String name, String password); 144 145 /*** 146 * Returns a count of the users in the repository. 147 * 148 * @return the number of users in the repository 149 */ 150 int countUsers(); 151 152 /*** 153 * List users in repository. 154 * 155 * @return Iterator over a collection of Strings, each being one user in the repository. 156 */ 157 Iterator list(); 158 159 }