Module ldap
ballerina/ldap Ballerina library
Clients
ldap: Client
Consists of APIs to integrate with LDAP.
Constructor
Gets invoked to initialize the LDAP client.
init (*ConnectionConfig config)- config *ConnectionConfig - The configurations to be used when initializing the client
add
function add(string dN, Entry entry) returns LdapResponse|ErrorCreates an entry in a directory server.
anydata user = { "objectClass": "user", "sn": "New User", "cn": "New User" }; ldap:LdapResponse result = check ldapClient->add(userDN, user);
Return Type
- LdapResponse|Error - A
ldap:Errorif the operation fails orldap:LdapResponseif successfully created
delete
function delete(string dN) returns LdapResponse|ErrorRemoves an entry in a directory server.
ldap:LdapResponse result = check ldapClient->delete(userDN);
Parameters
- dN string - The distinguished name of the entry to remove
Return Type
- LdapResponse|Error - A
ldap:Errorif the operation fails orldap:LdapResponseif successfully removed
modify
function modify(string dN, Entry entry) returns LdapResponse|ErrorUpdates information of an entry.
anydata user = { "sn": "User", "givenName": "Updated User", "displayName": "Updated User" }; ldap:LdapResponse result = check ldapClient->modify(userDN, user);
Return Type
- LdapResponse|Error - A
ldap:Errorif the operation fails orLdapResponseif successfully updated
modifyDn
function modifyDn(string currentDn, string newRdn, boolean deleteOldRdn) returns LdapResponse|ErrorRenames an entry in a directory server.
ldap:LdapResponse modifyDN = check ldapClient->modifyDn(userDN, "CN=Test User2", true);
Parameters
- currentDn string - The current distinguished name of the entry
- newRdn string - The new relative distinguished name
- deleteOldRdn boolean (default false) - A boolean value to determine whether to delete the old RDN
Return Type
- LdapResponse|Error - A
ldap:Errorif the operation fails orldap:LdapResponseif successfully renamed
compare
Determines whether a given entry has a specified attribute value.
boolean compare = check ldapClient->compare(userDN, "givenName", "New User");
Parameters
- dN string - The distinguished name of the entry
- attributeName string - The name of the target attribute for which the comparison is to be performed
- assertionValue string - The assertion value to verify within the entry
Return Type
getEntry
Gets information of an entry.
anydata value = check ldapClient->getEntry(userDN);
Parameters
- dN string - The distinguished name of the entry
- targetType typedesc<anydata> (default <>) - Default parameter use to infer the user specified type
Return Type
- targetType|Error - An entry result with the given type or else
ldap:Error
searchWithType
function searchWithType(string baseDn, string filter, SearchScope scope, typedesc<record {}[]> targetType) returns targetType|ErrorReturns a list of entries that match the given search parameters.
anydata[] value = check ldapClient->searchWithType("DC=ldap,DC=com", "(givenName=New User)", ldap:SUB);
Parameters
- baseDn string - The base distinguished name of the entry
- filter string - The filter to be used in the search
- scope SearchScope - The scope of the search
- targetType typedesc<record {}[]> (default <>) - Default parameter use to infer the user specified type
Return Type
- targetType|Error - An array of entries with the given type or else
ldap:Error
search
function search(string baseDn, string filter, SearchScope scope) returns SearchResult|ErrorReturns a record containing search result entries and references that match the given search parameters.
ldap:SearchResult value = check ldapClient->search("DC=ldap,DC=windows", "(givenName=New User)", ldap:SUB);
Parameters
- baseDn string - The base distinguished name of the entry
- filter string - The filter to be used in the search
- scope SearchScope - The scope of the search
Return Type
- SearchResult|Error - An
ldap:SearchResultif successful, or elseldap:Error
close
function close()Unbinds from the server and closes the LDAP connection.
ldapClient->close();
isConnected
function isConnected() returns booleanDetermines whether the client is connected to the server.
boolean isConnected = ldapClient->isConnected();
Return Type
- boolean - A boolean value indicating the connection status
Enums
ldap: ObjectClass
Standard values for ObjectClass attribute type.
Members
ldap: SearchScope
Scope of the search operation.
Members
ldap: Status
Represents the status of the operation
Members
Records
ldap: ClientSecureSocket
Provides configurations for facilitating secure communication with a remote ldap server.
Fields
- enable boolean(default true) - Enable SSL validation
- cert? TrustStore|string - Configurations associated with
crypto:TrustStoreor single certificate file that the client trusts
- verifyHostName boolean(default true) - Enable/disable host name verification
- tlsVersions string[](default []) - The TLS versions to be used
ldap: ConnectionConfig
Provides a set of configurations to connect with a directory server.
Fields
- hostName string - The host name of the Active Directory server
- port int - The port of the Active Directory server
- domainName string - The domain name of the Active Directory
- password string - The password of the Active Directory
- clientSecureSocket? ClientSecureSocket - Client secure socket configurations
ldap: Control
LDAP control type.
Fields
- oid string - The OID of the control
- isCritical boolean - The criticality of the control
- value string - The value of the control
ldap: DcObject
A record for an entry to contain domain component information
Fields
- dc string - name of the domain component
ldap: Entry
LDAP entry type.
Fields
- AttributeType... - Rest field
ldap: ErrorDetails
The error details type for the Ballerina LDAP module.
Fields
- resultCode? string - The status of the error
ldap: LdapResponse
LDAP response type.
Fields
- matchedDN string? - The matched DN from the response
- resultCode Status - The operation status of the response
- diagnosticMessage string? - The diagnostic message from the response
- operationType string? - The protocol operation type
- referral string[]? - The referral URIs
ldap: Person
A record for an entry that represents a person.
Fields
- objectClass? string|string[]|ObjectClass|ObjectClass[] - object class of the person
- sn? string - surname of the person
- cn? string - common name of the person
- userPassword? string - password of the person
- telephoneNumber? string - telephone number of the person
ldap: SearchReference
LDAP search reference type.
Fields
- messageId int - The message ID
- uris string[] - The referral URIs
- controls Control[] - The controls
ldap: SearchResult
LDAP search result type.
Fields
- resultCode Status - The result status of the response
- searchReferences? SearchReference[] - search references
- entries? Entry[] - The entries returned from the search
Errors
ldap: Error
Represents any error related to Ballerina LDAP module
Union types
Import
import ballerina/ldap;Metadata
Released date: 11 months ago
Version: 1.2.0
License: Apache-2.0
Compatibility
Platform: java21
Ballerina version: 2201.11.0-20241209-162400-0c015833
GraalVM compatible: Yes
Pull count
Total: 0
Current verison: 0
Weekly downloads
Keywords
ldap
Contributors
Dependencies