org.apache.james.jcr
Class JCRUsersRepository

java.lang.Object
  extended by org.apache.james.jcr.JCRUsersRepository
All Implemented Interfaces:
UsersRepository

public class JCRUsersRepository
extends java.lang.Object
implements UsersRepository


Field Summary
protected  javax.jcr.Credentials credentials
          Login credentials for accessing the repository.
protected  org.apache.commons.logging.Log logger
           
protected  java.lang.String path
          Path (relative to root) of the mail repository within the workspace.
protected  javax.jcr.Repository repository
          JCR content repository used as the mail repository.
protected  java.lang.String workspace
          Name of the workspace used as the mail repository.
 
Fields inherited from interface org.apache.james.api.user.UsersRepository
ROLE, USER
 
Constructor Summary
JCRUsersRepository()
          For setter injection.
JCRUsersRepository(javax.jcr.Repository repository)
          Minimal constructor for injection.
JCRUsersRepository(javax.jcr.Repository repository, javax.jcr.Credentials credentials, java.lang.String workspace, java.lang.String path, org.apache.commons.logging.Log logger)
          Maximal constructor for injection.
 
Method Summary
 void addUser(java.lang.String name, java.lang.Object attributes)
          Deprecated. James 2.4 user is always added using username/password and eventually modified by retrieving it later.
 boolean addUser(java.lang.String username, java.lang.String password)
          Adds a user to the repository with the specified password
 boolean addUser(User user)
          Deprecated. James 2.4 user should be added using username/password because specific implementations of UsersRepository will support specific implementations of users object.
 boolean contains(java.lang.String name)
          Returns whether or not this user is in the repository
 boolean containsCaseInsensitive(java.lang.String name)
          Deprecated. James 2.4 now caseSensitive is a property of the repository implementations and the contains will search according to this property.
 int countUsers()
          Returns a count of the users in the repository.
 javax.jcr.Credentials getCredentials()
          Returns the login credentials for accessing the repository.
 org.apache.commons.logging.Log getLogger()
          Gets the current logger.
 java.lang.String getPath()
          Returns the path of the mail repository within the workspace.
 java.lang.String getRealName(java.lang.String name)
          Returns the user name of the user matching name on an equalsIgnoreCase basis.
 javax.jcr.Repository getRepository()
          Retuns the JCR content repository used as the mail repository.
 User getUserByName(java.lang.String username)
          Get the user object with the specified user name.
 User getUserByNameCaseInsensitive(java.lang.String name)
          Deprecated. James 2.4 now caseSensitive is a property of the repository implementations and the getUserByName will search according to this property.
 java.lang.String getWorkspace()
          Returns the name of the workspace used as the mail repository.
 java.util.Iterator list()
          List users in repository.
protected  javax.jcr.Session login()
          Logs into a new session.
protected  javax.jcr.NodeIterator query(javax.jcr.Session session, java.lang.String xpath)
           
 void removeUser(java.lang.String username)
          Removes a user from the repository
 void setCredentials(javax.jcr.Credentials credentials)
          Sets the login credentials for accessing the repository.
 void setLogger(org.apache.commons.logging.Log logger)
          Sets the current logger.
 void setPath(java.lang.String path)
          Sets the path of the mail repository within the workspace.
 void setRepository(javax.jcr.Repository repository)
          Sets the JCR content repository to be used as the mail repository.
 void setWorkspace(java.lang.String workspace)
          Sets the name of the workspace used as the mail repository.
 boolean test(java.lang.String username, java.lang.String password)
          Test if user with name 'name' has password 'password'.
protected  java.lang.String toSafeName(java.lang.String key)
           
 boolean updateUser(User user)
          Update the repository with the specified user object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected org.apache.commons.logging.Log logger

repository

protected javax.jcr.Repository repository
JCR content repository used as the mail repository. Must be set before the any mail operations are performed.


credentials

protected javax.jcr.Credentials credentials
Login credentials for accessing the repository. Set to null (the default) to use default credentials.


workspace

protected java.lang.String workspace
Name of the workspace used as the mail repository. Set to null (the default) to use the default workspace.


path

protected java.lang.String path
Path (relative to root) of the mail repository within the workspace.

Constructor Detail

JCRUsersRepository

public JCRUsersRepository()
For setter injection.


JCRUsersRepository

public JCRUsersRepository(javax.jcr.Repository repository,
                          javax.jcr.Credentials credentials,
                          java.lang.String workspace,
                          java.lang.String path,
                          org.apache.commons.logging.Log logger)
Maximal constructor for injection.

Parameters:
repository - not null
credentials - login credentials for accessing the repository or null to use default credentials
workspace - name of the workspace used as the mail repository. or null to use default workspace
path - path (relative to root) of the user node within the workspace, or null to use default.

JCRUsersRepository

public JCRUsersRepository(javax.jcr.Repository repository)
Minimal constructor for injection.

Parameters:
repository - not null
Method Detail

addUser

public boolean addUser(User user)
Deprecated. James 2.4 user should be added using username/password because specific implementations of UsersRepository will support specific implementations of users object.

Adds a user to the repository with the specified User object.

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(java.lang.String name,
                    java.lang.Object attributes)
Deprecated. James 2.4 user is always added using username/password and eventually modified by retrieving it later.

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 - see decription

addUser

public boolean addUser(java.lang.String username,
                       java.lang.String password)
Adds a user to the repository with the specified password

Specified by:
addUser in interface UsersRepository
Parameters:
username - the username of the user to be added
password - the password of the user to add
Returns:
true if succesful, false otherwise
Since:
James 2.3.0

getUserByName

public User getUserByName(java.lang.String username)
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 being retrieved, null if the user doesn't exist
Since:
James 1.2.2

getUserByNameCaseInsensitive

public User getUserByNameCaseInsensitive(java.lang.String name)
Deprecated. James 2.4 now caseSensitive is a property of the repository implementations and the getUserByName will search according to this property.

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 being retrieved, null if the user doesn't exist
Since:
James 1.2.2

getRealName

public java.lang.String getRealName(java.lang.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 to case-correct
Returns:
the case-correct name of the user, null if the user doesn't exist

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
Returns:
true if successful.

removeUser

public void removeUser(java.lang.String username)
Removes a user from the repository

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

contains

public boolean contains(java.lang.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(java.lang.String name)
Deprecated. James 2.4 now caseSensitive is a property of the repository implementations and the contains will search according to this property.

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(java.lang.String username,
                    java.lang.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 user doesn't exist or if the password is incorrect
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 java.util.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.

getLogger

public final org.apache.commons.logging.Log getLogger()
Gets the current logger.

Returns:
the logger, not null

setLogger

public final void setLogger(org.apache.commons.logging.Log logger)
Sets the current logger.

Parameters:
logger - the logger to set, not null

getRepository

public javax.jcr.Repository getRepository()
Retuns the JCR content repository used as the mail repository.

Returns:
JCR content repository

setRepository

public void setRepository(javax.jcr.Repository repository)
Sets the JCR content repository to be used as the mail repository.

Parameters:
repository - JCR content repository

getCredentials

public javax.jcr.Credentials getCredentials()
Returns the login credentials for accessing the repository.

Returns:
login credentials, or null if using the default credentials

setCredentials

public void setCredentials(javax.jcr.Credentials credentials)
Sets the login credentials for accessing the repository.

Parameters:
credentials - login credentials, or null to use the default credentials

getWorkspace

public java.lang.String getWorkspace()
Returns the name of the workspace used as the mail repository.

Returns:
workspace name, or null if using the default workspace

setWorkspace

public void setWorkspace(java.lang.String workspace)
Sets the name of the workspace used as the mail repository.

Parameters:
workspace - workspace name, or null to use the default workspace

getPath

public java.lang.String getPath()
Returns the path of the mail repository within the workspace.

Returns:
repository path

setPath

public void setPath(java.lang.String path)
Sets the path of the mail repository within the workspace.

Parameters:
path - repository path

login

protected javax.jcr.Session login()
                           throws javax.jcr.LoginException,
                                  javax.jcr.NoSuchWorkspaceException,
                                  javax.jcr.RepositoryException
Logs into a new session.

Returns:
new session, not null
Throws:
javax.jcr.LoginException - when login fails
javax.jcr.NoSuchWorkspaceException - when workspace does not exist
javax.jcr.RepositoryException - when access fails

toSafeName

protected java.lang.String toSafeName(java.lang.String key)

query

protected javax.jcr.NodeIterator query(javax.jcr.Session session,
                                       java.lang.String xpath)
                                throws javax.jcr.RepositoryException,
                                       javax.jcr.query.InvalidQueryException
Throws:
javax.jcr.RepositoryException
javax.jcr.query.InvalidQueryException


Copyright ? 2002-2009 The Apache Software Foundation. All Rights Reserved.