public class ReadOnlyUsersLDAPRepository extends Object implements org.apache.james.user.api.UsersRepository, org.apache.james.lifecycle.api.Configurable, org.apache.james.lifecycle.api.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"
administratorId="ldapAdmin"
</users-store>
Its constituent attributes are defined as follows:
Example Schedules
Exception
causing the fault is thrown:
Exception causing the fault is thrown:
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.
com.sun.jndi.ldap.connect.pool to the specified boolean value
com.sun.jndi.ldap.connect.timeout to the specified integer value
com.sun.jndi.ldap.read.timeout to the specified integer value.
Applicable to Java 6 and above.
The supportsVirtualHosting tag allows you to define this repository as supporing
virtual hosting. For this LDAP repository, it means users will be looked for by their email
address instead of their unique identifier.
Generally to make it work, you need to configure userIdAttribute attribute to map
to a mail attribute such as mail instead of an unique id identifier.
ReadOnlyLDAPUser,
ReadOnlyLDAPGroupRestriction| Modifier and Type | Field and Description |
|---|---|
static String |
SUPPORTS_VIRTUAL_HOSTING |
| Constructor and Description |
|---|
ReadOnlyUsersLDAPRepository()
Creates a new instance of ReadOnlyUsersLDAPRepository.
|
| Modifier and Type | Method and Description |
|---|---|
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) |
String |
getUser(org.apache.mailet.MailAddress mailAddress) |
org.apache.james.user.api.model.User |
getUserByName(String name) |
org.apache.james.user.api.model.User |
getUserByNameCaseInsensitive(String name) |
void |
init()
Initialises the user-repository instance.
|
boolean |
isAdministrator(String username) |
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(org.apache.james.user.api.model.User user) |
public static final String SUPPORTS_VIRTUAL_HOSTING
public ReadOnlyUsersLDAPRepository()
public void configure(org.apache.commons.configuration.HierarchicalConfiguration configuration) throws org.apache.commons.configuration.ConfigurationException
ldapHost, userIdAttribute, userBase,
principal, credentials and restriction.configure in interface org.apache.james.lifecycle.api.Configurableconfiguration - An encapsulation of the James server configuration data.org.apache.commons.configuration.ConfigurationException@PostConstruct public void init() throws Exception
Exception - If an error occurs authenticating or connecting to the
specified LDAP host.protected LdapContext getLdapContext() throws NamingException
LdapContextNamingExceptionprotected void updateLdapContext() throws NamingException
NamingExceptionprotected LdapContext computeLdapContext() throws NamingException
NamingException - Propagated from underlying LDAP communication API.protected Properties getContextEnvironment()
public boolean contains(String name) throws org.apache.james.user.api.UsersRepositoryException
contains in interface org.apache.james.user.api.UsersRepositoryorg.apache.james.user.api.UsersRepositoryExceptionUsersRepository.contains(java.lang.String)public boolean containsCaseInsensitive(String name) throws org.apache.james.user.api.UsersRepositoryException
org.apache.james.user.api.UsersRepositoryExceptionpublic int countUsers() throws org.apache.james.user.api.UsersRepositoryException
countUsers in interface org.apache.james.user.api.UsersRepositoryorg.apache.james.user.api.UsersRepositoryExceptionUsersRepository.countUsers()public String getRealName(String name) throws org.apache.james.user.api.UsersRepositoryException
org.apache.james.user.api.UsersRepositoryExceptionpublic org.apache.james.user.api.model.User getUserByName(String name) throws org.apache.james.user.api.UsersRepositoryException
getUserByName in interface org.apache.james.user.api.UsersRepositoryorg.apache.james.user.api.UsersRepositoryExceptionUsersRepository.getUserByName(java.lang.String)public org.apache.james.user.api.model.User getUserByNameCaseInsensitive(String name) throws org.apache.james.user.api.UsersRepositoryException
org.apache.james.user.api.UsersRepositoryExceptionpublic Iterator<String> list() throws org.apache.james.user.api.UsersRepositoryException
list in interface org.apache.james.user.api.UsersRepositoryorg.apache.james.user.api.UsersRepositoryExceptionUsersRepository.list()public void removeUser(String name) throws org.apache.james.user.api.UsersRepositoryException
removeUser in interface org.apache.james.user.api.UsersRepositoryorg.apache.james.user.api.UsersRepositoryExceptionUsersRepository.removeUser(java.lang.String)public boolean test(String name, String password) throws org.apache.james.user.api.UsersRepositoryException
test in interface org.apache.james.user.api.UsersRepositoryorg.apache.james.user.api.UsersRepositoryExceptionUsersRepository.test(java.lang.String, java.lang.String)public void addUser(String username, String password) throws org.apache.james.user.api.UsersRepositoryException
addUser in interface org.apache.james.user.api.UsersRepositoryorg.apache.james.user.api.UsersRepositoryExceptionUsersRepository.addUser(java.lang.String, java.lang.String)public void updateUser(org.apache.james.user.api.model.User user) throws org.apache.james.user.api.UsersRepositoryException
updateUser in interface org.apache.james.user.api.UsersRepositoryorg.apache.james.user.api.UsersRepositoryExceptionpublic void setLog(org.slf4j.Logger log)
setLog in interface org.apache.james.lifecycle.api.LogEnabledLogEnabled.setLog(org.slf4j.Logger)public boolean supportVirtualHosting()
supportVirtualHosting in interface org.apache.james.user.api.UsersRepositorypublic String getUser(org.apache.mailet.MailAddress mailAddress) throws org.apache.james.user.api.UsersRepositoryException
getUser in interface org.apache.james.user.api.UsersRepositoryorg.apache.james.user.api.UsersRepositoryExceptionpublic boolean isAdministrator(String username) throws org.apache.james.user.api.UsersRepositoryException
isAdministrator in interface org.apache.james.user.api.UsersRepositoryorg.apache.james.user.api.UsersRepositoryExceptionCopyright © 2002-2017 The Apache Software Foundation. All Rights Reserved.