com.xpn.xwiki.plugin.ldap
Class XWikiLDAPConnection

java.lang.Object
  extended by com.xpn.xwiki.plugin.ldap.XWikiLDAPConnection

public class XWikiLDAPConnection
extends Object

LDAP communication tool.

Since:
1.3 M2
Version:
$Id: 1c4ce319515de774a7e67a553c4d53b467f7def9 $

Constructor Summary
XWikiLDAPConnection()
           
 
Method Summary
 void bind(String loginDN, String password)
          Bind to LDAP server.
 boolean checkPassword(String userDN, String password)
          Check if provided password is correct provided users's password.
 boolean checkPassword(String userDN, String password, String passwordField)
          Check if provided password is correct provided users's password.
 void close()
          Close LDAP connection.
static String escapeLDAPDNValue(String value)
          Fully escape DN value (the part after the =).
static String escapeLDAPSearchFilter(String value)
          Escape part of a LDAP query filter.
 com.novell.ldap.LDAPConnection getConnection()
           
protected  void ldapToXWikiAttribute(List<XWikiLDAPSearchAttribute> searchAttributeList, com.novell.ldap.LDAPAttributeSet attributeSet)
          Fill provided searchAttributeList with provided LDAP attributes.
 boolean open(String ldapHost, int ldapPort, String loginDN, String password, String pathToKeys, boolean ssl, XWikiContext context)
          Open LDAP connection.
 boolean open(String ldapUserName, String password, XWikiContext context)
          Open a LDAP connection.
 com.novell.ldap.LDAPSearchResults search(String baseDN, String filter, String[] attr, int ldapScope)
           
 List<XWikiLDAPSearchAttribute> searchLDAP(String baseDN, String filter, String[] attr, int ldapScope)
          Execute a LDAP search query and return the first entry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XWikiLDAPConnection

public XWikiLDAPConnection()
Method Detail

getConnection

public com.novell.ldap.LDAPConnection getConnection()
Returns:
the LDAPConnection.

open

public boolean open(String ldapUserName,
                    String password,
                    XWikiContext context)
             throws XWikiLDAPException
Open a LDAP connection.

Parameters:
ldapUserName - the user name to connect to LDAP server.
password - the password to connect to LDAP server.
context - the XWiki context.
Returns:
true if connection succeed, false otherwise.
Throws:
XWikiLDAPException - error when trying to open connection.

open

public boolean open(String ldapHost,
                    int ldapPort,
                    String loginDN,
                    String password,
                    String pathToKeys,
                    boolean ssl,
                    XWikiContext context)
             throws XWikiLDAPException
Open LDAP connection.

Parameters:
ldapHost - the host of the server to connect to.
ldapPort - the port of the server to connect to.
loginDN - the user DN to connect to LDAP server.
password - the password to connect to LDAP server.
pathToKeys - the path to SSL keystore to use.
ssl - if true connect using SSL.
context - the XWiki context.
Returns:
true if the connection succeed, false otherwise.
Throws:
XWikiLDAPException - error when trying to open connection.

bind

public void bind(String loginDN,
                 String password)
          throws UnsupportedEncodingException,
                 com.novell.ldap.LDAPException
Bind to LDAP server.

Parameters:
loginDN - the user DN to connect to LDAP server.
password - the password to connect to LDAP server.
Throws:
UnsupportedEncodingException - error when converting provided password to UTF-8 table.
com.novell.ldap.LDAPException - error when trying to bind.

close

public void close()
Close LDAP connection.


checkPassword

public boolean checkPassword(String userDN,
                             String password)
Check if provided password is correct provided users's password.

Parameters:
userDN - the user.
password - the password.
Returns:
true if the password is valid, false otherwise.

checkPassword

public boolean checkPassword(String userDN,
                             String password,
                             String passwordField)
Check if provided password is correct provided users's password.

Parameters:
userDN - the user.
password - the password.
passwordField - the name of the LDAP field containing the password.
Returns:
true if the password is valid, false otherwise.

searchLDAP

public List<XWikiLDAPSearchAttribute> searchLDAP(String baseDN,
                                                 String filter,
                                                 String[] attr,
                                                 int ldapScope)
Execute a LDAP search query and return the first entry.

Parameters:
baseDN - the root DN from where to search.
filter - the LDAP filter.
attr - the attributes names of values to return.
ldapScope - the scope of the entries to search. The following are the valid options:
  • SCOPE_BASE - searches only the base DN
  • SCOPE_ONE - searches only entries under the base DN
  • SCOPE_SUB - searches the base DN and all entries within its subtree
Returns:
the found LDAP attributes.

search

public com.novell.ldap.LDAPSearchResults search(String baseDN,
                                                String filter,
                                                String[] attr,
                                                int ldapScope)
                                         throws com.novell.ldap.LDAPException
Parameters:
baseDN - the root DN from where to search.
filter - filter the LDAP filter
attr - the attributes names of values to return
ldapScope - the scope of the entries to search. The following are the valid options:
  • SCOPE_BASE - searches only the base DN
  • SCOPE_ONE - searches only entries under the base DN
  • SCOPE_SUB - searches the base DN and all entries within its subtree
Returns:
a result stream. LDAPConnection#abandon should be called when it's not needed anymore.
Throws:
com.novell.ldap.LDAPException - error when searching
Since:
3.3M1

ldapToXWikiAttribute

protected void ldapToXWikiAttribute(List<XWikiLDAPSearchAttribute> searchAttributeList,
                                    com.novell.ldap.LDAPAttributeSet attributeSet)
Fill provided searchAttributeList with provided LDAP attributes.

Parameters:
searchAttributeList - the XWiki attributes.
attributeSet - the LDAP attributes.

escapeLDAPDNValue

public static String escapeLDAPDNValue(String value)
Fully escape DN value (the part after the =).

For example, for the dn value "Acme, Inc", the escapeLDAPDNValue method returns "Acme\, Inc".

Parameters:
value - the DN value to escape
Returns:
the escaped version o the DN value

escapeLDAPSearchFilter

public static String escapeLDAPSearchFilter(String value)
Escape part of a LDAP query filter.

Parameters:
value - the value to escape
Returns:
the escaped version


Copyright © 2004-2013 XWiki. All Rights Reserved.