org.lsc.jndi
Class ScriptableJndiServices

java.lang.Object
  extended by org.lsc.jndi.ScriptableObject
      extended by org.lsc.jndi.ScriptableJndiServices

public class ScriptableJndiServices
extends ScriptableObject

Simple interface to some methods to access an LDAP directory.

This class is available as "ldap" or "srcLdap" in several JavaScript enabled parameters in the LSC configuration. The methods allow you to interact with an LDAP directory.

Based on Rhino (JavaScript interpreter), this class is able to understand your LQL requests.

All methods in the class use methods from JndiServices.

Author:
Sebastien Bahloul <seb@lsc-project.org>

Constructor Summary
ScriptableJndiServices()
          Default constructor.
 
Method Summary
 List<String> and(Object a, Object b)
          Performs an intersection on two Lists of Strings.
 List<String> attribute(Object base, Object attrName)
          Reads the entry given by a DN, and returns the values of the given attribute.
 List<String> exists(Object dn)
          Tests if an entry exists with the given DN.
 List<String> exists(Object dn, Object filter)
          Tests if an entry exists with the given DN and if it matches a given LDAP filter.
 List<String> fsup(Object dn, Object filter)
          Returns a List containing the given DN and all parent DNs that exist and match a given LDAP filter.
 String getContextDn()
          Get the context DN configured for this instance.
 List<String> list(Object base, Object filter)
          Performs a search with one level scope on a given base DN with a given filter.
 List<String> or(Object a, Object b)
          Performs a union on two Lists of Strings.
 List<String> read(Object base, Object filter)
          Performs a search with base level scope on a given base DN with a given filter.
 List<String> retain(Object a, Object b)
          Removes all elements of a List of Strings b from a List of Strings a.
 List<String> search(Object base, Object filter)
          Performs a search with subtree scope on a given base DN with a given filter.
 void setJndiServices(JndiServices jndiServices)
          Default jndiServices setter.
 List<String> sup(Object dn, Object level)
          Returns the parent DN on the n-th level of a given DN, in a List of Strings.
 
Methods inherited from class org.lsc.jndi.ScriptableObject
getList, wrap, wrapList, wrapString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScriptableJndiServices

public ScriptableJndiServices()

Default constructor.

Default directory properties are based on destination.

Method Detail

setJndiServices

public final void setJndiServices(JndiServices jndiServices)

Default jndiServices setter.

Parameters:
jndiServices - the new value

search

public final List<String> search(Object base,
                                 Object filter)
                          throws NamingException

Performs a search with subtree scope on a given base DN with a given filter.

Parameters:
base - The base DN to search from.
filter - The LDAP filter to use.
Returns:
List List of DNs returned by the search.
Throws:
NamingException

list

public final List<String> list(Object base,
                               Object filter)
                        throws NamingException

Performs a search with one level scope on a given base DN with a given filter.

Parameters:
base - The base DN to search from.
filter - The LDAP filter to use.
Returns:
List List of DNs returned by the search.
Throws:
NamingException

read

public final List<String> read(Object base,
                               Object filter)
                        throws NamingException

Performs a search with base level scope on a given base DN with a given filter.

Parameters:
base - The base DN to search from.
filter - The LDAP filter to use.
Returns:
List List of DNs returned by the search.
Throws:
NamingException

exists

public final List<String> exists(Object dn,
                                 Object filter)
                          throws NamingException

Tests if an entry exists with the given DN and if it matches a given LDAP filter.

Parameters:
dn - The DN of the entry to check.
filter - The LDAP filter to check on the above DN.
Returns:
List List containing the DN if it exists and matches the filter, or null otherwise.
Throws:
NamingException

exists

public final List<String> exists(Object dn)
                          throws NamingException

Tests if an entry exists with the given DN.

Parameters:
dn - The DN of the entry to check.
Returns:
List List containing the DN if it exists and matches the filter, or null otherwise.
Throws:
NamingException

or

public final List<String> or(Object a,
                             Object b)
                      throws NamingException

Performs a union on two Lists of Strings.

Parameters:
a - List of Strings
b - List of Strings
Returns:
List List of Strings containing all elements from a and b.
Throws:
NamingException

attribute

public final List<String> attribute(Object base,
                                    Object attrName)
                             throws NamingException

Reads the entry given by a DN, and returns the values of the given attribute.

Parameters:
base - The DN of the entry to read.
attrName - The name of the attribute to read.
Returns:
List List of values of the attribute, as Strings.
Throws:
NamingException

and

public final List<String> and(Object a,
                              Object b)
                       throws NamingException

Performs an intersection on two Lists of Strings.

Parameters:
a - List of Strings
b - List of Strings
Returns:
List List of Strings containing elements that are in both a and b.
Throws:
NamingException

retain

public final List<String> retain(Object a,
                                 Object b)
                          throws NamingException

Removes all elements of a List of Strings b from a List of Strings a.

Parameters:
a - List of Strings
b - List of Strings
Returns:
List List of Strings containing all elements from a not in b.
Throws:
NamingException

sup

public final List<String> sup(Object dn,
                              Object level)
                       throws NamingException

Returns the parent DN on the n-th level of a given DN, in a List of Strings.

For example, given ("uid=1234,ou=People,dc=normation,dc=com", 2), returns "dc=normation,dc=com" (in a List of Strings).

As a special case, if the requested level is 0, the result is a List of the given DN and all it's parent DNs until the context DN. In the above example, this List would be ["uid=1234,ou=People,dc=normation,dc=com", "ou=People,dc=normation,dc=com", "dc=normation,dc=com"], assuming that the context DN is "dc=normation,dc=com".

This method returns null if a negative level is given.

Parameters:
dn - The DN whose parent we want.
level - The number of levels to go up, or 0 to return all parent DNs.
Returns:
List List containing the parent DN, or all parent DNs if level is 0, or null if level is negative.
Throws:
NamingException

fsup

public final List<String> fsup(Object dn,
                               Object filter)
                        throws NamingException

Returns a List containing the given DN and all parent DNs that exist and match a given LDAP filter.

This method returns the same result as sup(dn, 0), with validation that each object exists and matches the given filter.

Parameters:
dn - The DN whose parents we want.
filter - The LDAP filter to check.
Returns:
List List of DNs as Strings that are this entry's DN, or it's parents DN, that exist and match the given filter.
Throws:
NamingException

getContextDn

public String getContextDn()

Get the context DN configured for this instance.

Returns:
The context DN as a String.


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