org.apache.james.userrepository
Class AbstractUsersRepository

java.lang.Object
  |
  +--org.apache.avalon.framework.logger.AbstractLogEnabled
        |
        +--org.apache.james.userrepository.AbstractUsersRepository
All Implemented Interfaces:
Component, LogEnabled, UsersRepository
Direct Known Subclasses:
AbstractJdbcUsersRepository

public abstract class AbstractUsersRepository
extends AbstractLogEnabled
implements UsersRepository, Component

A partial implementation of a Repository to store users.

This implements common functionality found in different UsersRespository implementations, and makes it easier to create new User repositories.

Author:
Darrell DeBoer , Charles Benett

Field Summary
 
Fields inherited from interface org.apache.james.services.UsersRepository
ROLE, USER
 
Constructor Summary
AbstractUsersRepository()
           
 
Method Summary
 void addUser(String name, Object attributes)
          Adds a user to the repository with the specified attributes.
 boolean addUser(User user)
          Adds a user to the repository with the specified User object.
 boolean contains(String name)
          Returns whether or not this user is in the repository
 boolean containsCaseInsensitive(String name)
          Returns whether or not this user is in the repository.
 int countUsers()
          Returns a count of the users in the repository.
protected abstract  void doAddUser(User user)
          Adds a user to the underlying Repository.
protected abstract  void doRemoveUser(User user)
          Removes a user from the underlying repository.
protected abstract  void doUpdateUser(User user)
          Updates a user record to match the supplied User.
 Object getAttributes(String name)
          Deprecated. As of James 1.2.2 . Use the getUserByName method.
 String getRealName(String name)
          Returns the user name of the user matching name on an equalsIgnoreCase basis.
 User getUserByName(String name)
          Get the user object with the specified user name.
protected  User getUserByName(String name, boolean ignoreCase)
          Gets a user by name, ignoring case if specified.
 User getUserByNameCaseInsensitive(String name)
          Get the user object with the specified user name.
 Iterator list()
          List users in repository.
protected abstract  Iterator listAllUsers()
          Returns a list populated with all of the Users in the repository.
protected  List listUserNames()
          Produces the complete list of User names, with correct case.
 void removeUser(String name)
          Removes a user from the repository
 boolean test(String name, Object attributes)
          Deprecated. As of James 1.2.2, use test(String name, String password)
 boolean test(String name, String password)
          Test if user with name 'name' has password 'password'.
 boolean updateUser(User user)
          Update the repository with the specified user object.
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractUsersRepository

public AbstractUsersRepository()
Method Detail

listAllUsers

protected abstract Iterator listAllUsers()
Returns a list populated with all of the Users in the repository.

Returns:
an Iterator of Users.

doAddUser

protected abstract void doAddUser(User user)
Adds a user to the underlying Repository. The user name must not clash with an existing user.


doRemoveUser

protected abstract void doRemoveUser(User user)
Removes a user from the underlying repository. If the user doesn't exist, returns ok.


doUpdateUser

protected abstract void doUpdateUser(User user)
Updates a user record to match the supplied User.


listUserNames

protected List listUserNames()
Produces the complete list of User names, with correct case.

Returns:
a List of Strings representing user names.

getUserByName

protected User getUserByName(String name,
                             boolean ignoreCase)
Gets a user by name, ignoring case if specified. This implementation gets the entire set of users, and scrolls through searching for one matching name.

Parameters:
name - the name of the user being retrieved
ignoreCase - whether the name is regarded as case-insensitive
Returns:
the user being retrieved, null if the user doesn't exist

addUser

public boolean addUser(User user)
Adds a user to the repository with the specified User object. Users names must be unique-case-insensitive in the repository.

Specified by:
addUser in interface UsersRepository
Parameters:
user - the user to be added
Returns:
true if succesful, false otherwise
Since:
James 1.2.2

addUser

public void addUser(String name,
                    Object attributes)
Adds a user to the repository with the specified attributes. In current implementations, the Object attributes is generally a String password.

Specified by:
addUser in interface UsersRepository
Parameters:
name - the name of the user to be added
attributes - the password value as a String

updateUser

public boolean updateUser(User user)
Update the repository with the specified user object. A user object with this username must already exist.

Specified by:
updateUser in interface UsersRepository
Parameters:
user - the user to be updated
Returns:
true if successful.

removeUser

public void removeUser(String name)
Removes a user from the repository

Specified by:
removeUser in interface UsersRepository
Parameters:
name - the user to remove from the repository

getAttributes

public Object getAttributes(String name)
Deprecated. As of James 1.2.2 . Use the getUserByName method.

Gets the attribute for a user. Not clear on behavior.

Specified by:
getAttributes in interface UsersRepository

getUserByName

public User getUserByName(String name)
Get the user object with the specified user name. Return null if no such user.

Specified by:
getUserByName in interface UsersRepository
Parameters:
name - the name of the user to retrieve
Returns:
the user if found, null otherwise
Since:
James 1.2.2

getUserByNameCaseInsensitive

public User getUserByNameCaseInsensitive(String name)
Get the user object with the specified user name. Match user naems on a case insensitive basis. Return null if no such user.

Specified by:
getUserByNameCaseInsensitive in interface UsersRepository
Parameters:
name - the name of the user to retrieve
Returns:
the user if found, null otherwise
Since:
James 1.2.2

getRealName

public String getRealName(String name)
Returns the user name of the user matching name on an equalsIgnoreCase basis. Returns null if no match.

Specified by:
getRealName in interface UsersRepository
Parameters:
name - the name of the user to retrieve
Returns:
the correct case sensitive name of the user

contains

public boolean contains(String name)
Returns whether or not this user is in the repository

Specified by:
contains in interface UsersRepository
Parameters:
name - the name to check in the repository
Returns:
whether the user is in the repository

containsCaseInsensitive

public boolean containsCaseInsensitive(String name)
Returns whether or not this user is in the repository. Names are matched on a case insensitive basis.

Specified by:
containsCaseInsensitive in interface UsersRepository
Parameters:
name - the name to check in the repository
Returns:
whether the user is in the repository

test

public boolean test(String name,
                    Object attributes)
Deprecated. As of James 1.2.2, use test(String name, String password)

Tests a user with the appropriate attributes. In current implementations, this typically means "check the password" where a String password is passed as the Object attributes.

Specified by:
test in interface UsersRepository
Parameters:
name - the name of the user to be tested
attributes - the password to be tested
Throws:
UnsupportedOperationException - always, as this method should not be used

test

public boolean test(String name,
                    String password)
Test if user with name 'name' has password 'password'.

Specified by:
test in interface UsersRepository
Parameters:
name - the name of the user to be tested
password - the password to be tested
Returns:
true if the test is successful, false if the password is incorrect or the user doesn't exist
Since:
James 1.2.2

countUsers

public int countUsers()
Returns a count of the users in the repository.

Specified by:
countUsers in interface UsersRepository
Returns:
the number of users in the repository

list

public Iterator list()
List users in repository.

Specified by:
list in interface UsersRepository
Returns:
Iterator over a collection of Strings, each being one user in the repository.


"Copyright © 1999-2002 Apache Jakarta Project. All Rights Reserved."