BBjAPI::getLDAPConnection

Description

In BBj 11.00 and higher, this method returns a connection to an LDAP or Active Directory server. Use this method to connect to a specific LDAP server by specifying host, port, bind DN, and password. The method taking no parameters returns a connection to the LDAP server used for authentication.

Syntax

Return Value

Method

BBjLDAPConnection

getLDAPConnection()

BBjLDAPConnection

getLDAPConnection(string host, int port, string bindDN, string password)

Parameters

Variable

Description

host

Host name or IP address of the LDAP or Active Directory server.

port

Port number the LDAP server is running on.

bindDN

Full DN (distinguished name) for authentication.  Depending on the way the LDAP server is configured, this might be just the user name or it may be something like:  uid=admin,ou=system

password

Password required for authentication.

Return Value

Returns a BBjLDAPConnection object which provides access to the available LDAP operations on the server.

Remarks

Use this method to acquire a connection to a generic LDAP server, or a Microsoft Active Directory server since Active Directory uses LDAP as its foundational protocol.  

Only use the method taking no parameters when:

  • User authentication is enabled in BBjServices
  • LDAP is the authentication mechanism used

Use the method taking host, port, bind DN, and password for connecting to any available LDAP server on the network.

Example 1

rem ' getLDAPConnection sample 1

use com.basis.bbj.proxies.ldap.BBjLDAPSearchResult
use com.basis.bbj.proxies.ldap.BBjLDAPConnection
declare BBjLDAPConnection ldapCon!
declare BBjLDAPSearchResult searchResults!
declare BBjVector entries!
declare BBjVector attrs!

rem 'Get a connection to a specific LDAP server
host$ = "localhost"
port = 10389
authDN$ = "uid = admin,ou = system"
pwd$ = "secret"
ldapCon! = BBjAPI().getLDAPConnection(host$, port, authDN$, pwd$)

rem 'return a list of all immediate children of the ou = system object
searchResults! = ldapCon!.search("ou = system",BBjLDAPSearchResult.SCOPE_ONE, 100, 100, "(objectClass=*)"
entries! = searchResults!.getSearchEntries()
for e = 0 to entries!.size() - 1
    entry! = entries!.getItem(e)
    print "ENTRY - dn: " + entry!.getDN()
    attrs! = entry!.getAttributeNames()
    for i = 0 to attrs!.size() - 1
        attr$ = attrs!.getItem(i)
        print "     " + attr$
    next i
next e

rem 'Unbind and close the connection
ldapCon!.close()

Example 2

rem ' getLDAPConnection sample 2

use com.basis.bbj.proxies.ldap.BBjLDAPConnection
declare BBjLDAPConnection ldapCon!

rem 'Get a connection to the LDAP server used to authenticate the currently
rem 'logged in user.  This will only work if user authentication is enabled,
rem 'and LDAP authentication is used as the authentication mechanism.
ldapCon! = BBjAPI().getLDAPConnection()

See Also

BBjAPI

BBjLDAPConnection

BBjLDAPEntry

BBjLDAPSearchResult

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.