org.lsc.jndi
Class JndiServices

java.lang.Object
  extended by org.lsc.jndi.JndiServices

public final class JndiServices
extends Object

General LDAP services wrapper. This class is designed to manage all the needed operations to the directory

Author:
Sebastien Bahloul <seb@lsc-project.org>, Jonathan Clarke <jon@lsc-project.org>

Field Summary
static String DEFAULT_FILTER
          Default LDAP filter.
 
Method Summary
 boolean apply(JndiModifications jm)
          Apply directory modifications.
 boolean exists(String dn)
          Check if the entry with the specified distinguish name exists (or not).
 boolean exists(String dn, String filter)
          Check if the entry with the specified distinguish name exists (or not).
 Map<String,LscAttributes> getAttrsList(String base, String filter, int scope, List<String> attrsNames)
          Search for a list of attribute values This method is a simple LDAP search operation which is attended to return a list of the attribute values in all returned entries
 LdapContext getContext()
          Get the JNDI context.
 String getContextDn()
           
 List<String> getDnList(String base, String filter, int scope)
          Search for a list of DN.
static JndiServices getDstInstance()
          Get the target directory connected service.
 SearchResult getEntry(String base, String filter)
          Search for an entry.
 SearchResult getEntry(String base, String filter, SearchControls sc)
          Search for an entry.
 SearchResult getEntry(String base, String filter, SearchControls sc, int scope)
          Search for an entry.
static JndiServices getInstance(Properties props)
          Instance getter.
 Map<String,List<String>> getSchema(String[] attrsToReturn)
          Return the LDAP schema.
static JndiServices getSrcInstance()
          Get the source directory connected service.
 SearchResult readEntry(String base, boolean allowError)
          Search for an entry.
 SearchResult readEntry(String base, String filter, boolean allowError)
           
 SearchResult readEntry(String base, String filter, boolean allowError, SearchControls sc)
           
 String rewriteBase(String base)
           
 List<String> sup(String dn, int level)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_FILTER

public static final String DEFAULT_FILTER
Default LDAP filter.

See Also:
Constant Field Values
Method Detail

getSrcInstance

public static JndiServices getSrcInstance()
Get the source directory connected service.

Returns:
the source directory connected service

getDstInstance

public static JndiServices getDstInstance()
Get the target directory connected service.

Returns:
the target directory connected service

getInstance

public static JndiServices getInstance(Properties props)
                                throws NamingException,
                                       IOException
Instance getter. Manage a connections cache and return the good service

Parameters:
props - the connection properties
Returns:
the instance
Throws:
IOException
NamingException

getEntry

public SearchResult getEntry(String base,
                             String filter)
                      throws NamingException
Search for an entry. This method is a simple LDAP search operation with SUBTREE search control

Parameters:
base - the base of the search operation
filter - the filter of the search operation
Returns:
the entry or null if not found
Throws:
NamingException - thrown if something goes wrong

getEntry

public SearchResult getEntry(String base,
                             String filter,
                             SearchControls sc)
                      throws NamingException
Search for an entry. This method is a simple LDAP search operation with SUBTREE search control

Parameters:
base - the base of the search operation
filter - the filter of the search operation
sc - the search controls
Returns:
the entry or null if not found
Throws:
NamingException - thrown if something goes wrong

getEntry

public SearchResult getEntry(String base,
                             String filter,
                             SearchControls sc,
                             int scope)
                      throws NamingException
Search for an entry. This method is a simple LDAP search operation with SUBTREE search control

Parameters:
base - the base of the search operation
filter - the filter of the search operation
sc - the search controls
scope - the search scope to use
Returns:
the entry or null if not found
Throws:
SizeLimitExceededException - thrown if more than one entry is returned by the search
NamingException - thrown if something goes wrong

exists

public boolean exists(String dn,
                      String filter)
Check if the entry with the specified distinguish name exists (or not).

Parameters:
dn - the entry's distinguish name
filter - look at the dn according this filter
Returns:
entry existence (or false if something goes wrong)

exists

public boolean exists(String dn)
Check if the entry with the specified distinguish name exists (or not).

Parameters:
dn - the entry's distinguish name
Returns:
entry existence (or false if something goes wrong)

readEntry

public SearchResult readEntry(String base,
                              boolean allowError)
                       throws NamingException
Search for an entry. This method is a simple LDAP search operation with BASE search scope

Parameters:
base - the base of the search operation
allowError - log error if not found or not
Returns:
the entry or null if not found
Throws:
NamingException - thrown if something goes wrong

readEntry

public SearchResult readEntry(String base,
                              String filter,
                              boolean allowError)
                       throws NamingException
Throws:
NamingException

rewriteBase

public String rewriteBase(String base)

readEntry

public SearchResult readEntry(String base,
                              String filter,
                              boolean allowError,
                              SearchControls sc)
                       throws NamingException
Throws:
NamingException

getDnList

public List<String> getDnList(String base,
                              String filter,
                              int scope)
                       throws NamingException
Search for a list of DN. This method is a simple LDAP search operation which is attended to return a list of the entries DN

Parameters:
base - the base of the search operation
filter - the filter of the search operation
scope - the scope of the search operation
Returns:
the dn of each entry that is returned by the directory
Throws:
NamingException - thrown if something goes wrong

apply

public boolean apply(JndiModifications jm)
              throws CommunicationException
Apply directory modifications. If no exception is thrown, modifications were done successfully

Parameters:
jm - modifications to apply
Returns:
operation status
Throws:
CommunicationException - If the connection to the directory is lost

getSchema

public Map<String,List<String>> getSchema(String[] attrsToReturn)
                                   throws NamingException
Return the LDAP schema.

Parameters:
attrsToReturn - list of attribute names to return (or null for all 'standard' attributes)
Returns:
the map of name => attribute
Throws:
NamingException - thrown if something goes wrong (bad

sup

public List<String> sup(String dn,
                        int level)
                 throws NamingException
Throws:
NamingException

getAttrsList

public Map<String,LscAttributes> getAttrsList(String base,
                                              String filter,
                                              int scope,
                                              List<String> attrsNames)
                                       throws NamingException
Search for a list of attribute values This method is a simple LDAP search operation which is attended to return a list of the attribute values in all returned entries

Parameters:
base - the base of the search operation
filter - the filter of the search operation
scope - the scope of the search operation
attrsNames - table of attribute names to get
Returns:
Map of DNs of all entries that are returned by the directory with an associated map of attribute names and values (never null)
Throws:
NamingException - thrown if something goes wrong

getContextDn

public String getContextDn()
Returns:
the contextDn

getContext

public LdapContext getContext()
Get the JNDI context.

Returns:
The LDAP context object in use by this class.


Copyright © 2005-2010 LSC project. All Rights Reserved.