BBjAPI::getLDAPConnection

 

Description

In BBj 11.0 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.