org.apache.james.user.ldap
Class ReadOnlyUsersLDAPRepository

java.lang.Object
  extended by org.apache.james.user.ldap.ReadOnlyUsersLDAPRepository
All Implemented Interfaces:
Configurable, LogEnabled, UsersRepository

public class ReadOnlyUsersLDAPRepository
extends Object
implements UsersRepository, Configurable, LogEnabled

This repository implementation serves as a bridge between Apache James and LDAP. It allows James to authenticate users against an LDAP compliant server such as Apache DS or Microsoft AD. It also enables role/group based access restriction based on LDAP groups.

It is intended for organisations that already have a user-authentication and authorisation mechanism in place, and want to leverage this when deploying James. The assumption inherent here is that such organisations would not want to manage user details via James, but will do so externally using whatever mechanism provided by, or built on top off, their LDAP implementation.

Based on this assumption, this repository is strictly read-only. As a consequence, user modification, deletion and creation requests will be ignored when using this repository.

The following fragment of XML provides an example configuration to enable this repository:

  <users-store>
      <repository name="LDAPUsers" 
      class="org.apache.james.userrepository.ReadOnlyUsersLDAPRepository" 
      ldapHost="ldap://myldapserver:389"
      principal="uid=ldapUser,ou=system"
      credentials="password"
      userBase="ou=People,o=myorg.com,ou=system"
      userIdAttribute="uid"
      userObjectClass="inetOrgPerson"
      maxRetries="20"
      retryStartInterval="0"
      retryMaxInterval="30"
      retryIntervalScale="1000"
  </users-store>
 

Its constituent attributes are defined as follows:

Example Schedules

In order to enable group/role based access restrictions, you can use the "<restriction>" configuration element. An example of this is shown below:

 <restriction
        memberAttribute="uniqueMember">
                <group>cn=PermanentStaff,ou=Groups,o=myorg.co.uk,ou=system</group>
                <group>cn=TemporaryStaff,ou=Groups,o=myorg.co.uk,ou=system</group>
 </restriction>
 
Its constituent attributes and elements are defined as follows:

The following parameters may be used to adjust the underlying com.sun.jndi.ldap.LdapCtxFactory. See LDAP Naming Service Provider for the Java Naming and Directory InterfaceTM (JNDI) : Provider-specific Properties for details.

See Also:
ReadOnlyLDAPUser, ReadOnlyLDAPGroupRestriction

Constructor Summary
ReadOnlyUsersLDAPRepository()
          Creates a new instance of ReadOnlyUsersLDAPRepository.
 
Method Summary
 void addUser(String username, String password)
           
protected  LdapContext computeLdapContext()
          Answers a new LDAP/JNDI context using the specified user credentials.
 void configure(org.apache.commons.configuration.HierarchicalConfiguration configuration)
          Extracts the parameters required by the repository instance from the James server configuration data.
 boolean contains(String name)
           
 boolean containsCaseInsensitive(String name)
           
 int countUsers()
           
protected  Properties getContextEnvironment()
           
protected  LdapContext getLdapContext()
          Answer the LDAP context used to connect with the LDAP server.
 String getRealName(String name)
           
 User getUserByName(String name)
           
 User getUserByNameCaseInsensitive(String name)
           
 void init()
          Initialises the user-repository instance.
 Iterator<String> list()
           
 void removeUser(String name)
           
 void setLog(org.slf4j.Logger log)
           
 boolean supportVirtualHosting()
          VirtualHosting not supported
 boolean test(String name, String password)
           
protected  void updateLdapContext()
           
 void updateUser(User user)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReadOnlyUsersLDAPRepository

public ReadOnlyUsersLDAPRepository()
Creates a new instance of ReadOnlyUsersLDAPRepository.

Method Detail

configure

public void configure(org.apache.commons.configuration.HierarchicalConfiguration configuration)
               throws org.apache.commons.configuration.ConfigurationException
Extracts the parameters required by the repository instance from the James server configuration data. The fields extracted include ldapHost, userIdAttribute, userBase, principal, credentials and restriction.

Specified by:
configure in interface Configurable
Parameters:
configuration - An encapsulation of the James server configuration data.
Throws:
org.apache.commons.configuration.ConfigurationException

init

@PostConstruct
public void init()
          throws Exception
Initialises the user-repository instance. It will create a connection to the LDAP host using the supplied configuration.

Throws:
Exception - If an error occurs authenticating or connecting to the specified LDAP host.

getLdapContext

protected LdapContext getLdapContext()
                              throws NamingException
Answer the LDAP context used to connect with the LDAP server.

Returns:
an LdapContext
Throws:
NamingException

updateLdapContext

protected void updateLdapContext()
                          throws NamingException
Throws:
NamingException

computeLdapContext

protected LdapContext computeLdapContext()
                                  throws NamingException
Answers a new LDAP/JNDI context using the specified user credentials.

Returns:
an LDAP directory context
Throws:
NamingException - Propagated from underlying LDAP communication API.

getContextEnvironment

protected Properties getContextEnvironment()

contains

public boolean contains(String name)
                 throws UsersRepositoryException
Specified by:
contains in interface UsersRepository
Throws:
UsersRepositoryException
See Also:
UsersRepository.contains(java.lang.String)

containsCaseInsensitive

public boolean containsCaseInsensitive(String name)
                                throws UsersRepositoryException
Throws:
UsersRepositoryException

countUsers

public int countUsers()
               throws UsersRepositoryException
Specified by:
countUsers in interface UsersRepository
Throws:
UsersRepositoryException
See Also:
UsersRepository.countUsers()

getRealName

public String getRealName(String name)
                   throws UsersRepositoryException
Throws:
UsersRepositoryException

getUserByName

public User getUserByName(String name)
                   throws UsersRepositoryException
Specified by:
getUserByName in interface UsersRepository
Throws:
UsersRepositoryException
See Also:
UsersRepository.getUserByName(java.lang.String)

getUserByNameCaseInsensitive

public User getUserByNameCaseInsensitive(String name)
                                  throws UsersRepositoryException
Throws:
UsersRepositoryException

list

public Iterator<String> list()
                      throws UsersRepositoryException
Specified by:
list in interface UsersRepository
Throws:
UsersRepositoryException
See Also:
UsersRepository.list()

removeUser

public void removeUser(String name)
                throws UsersRepositoryException
Specified by:
removeUser in interface UsersRepository
Throws:
UsersRepositoryException
See Also:
UsersRepository.removeUser(java.lang.String)

test

public boolean test(String name,
                    String password)
             throws UsersRepositoryException
Specified by:
test in interface UsersRepository
Throws:
UsersRepositoryException
See Also:
UsersRepository.test(java.lang.String, java.lang.String)

addUser

public void addUser(String username,
                    String password)
             throws UsersRepositoryException
Specified by:
addUser in interface UsersRepository
Throws:
UsersRepositoryException
See Also:
UsersRepository.addUser(java.lang.String, java.lang.String)

updateUser

public void updateUser(User user)
                throws UsersRepositoryException
Specified by:
updateUser in interface UsersRepository
Throws:
UsersRepositoryException
See Also:
UsersRepository#updateUser(org.apache.james.api.user.User)

setLog

public void setLog(org.slf4j.Logger log)
Specified by:
setLog in interface LogEnabled
See Also:
LogEnabled.setLog(org.slf4j.Logger)

supportVirtualHosting

public boolean supportVirtualHosting()
                              throws UsersRepositoryException
VirtualHosting not supported

Specified by:
supportVirtualHosting in interface UsersRepository
Throws:
UsersRepositoryException


Copyright © 2002-2012 The Apache Software Foundation. All Rights Reserved.