LDAP (Lightweight Directory Access Protocol) is a vendor-neutral software protocol for accessing and maintaining distributed directory information services. It allows users to locate organizations, individuals, and other resources such as files and devices in a network. LDAP is used in various applications for directory-based authentication and authorization.
The Ballerina LDAP module provides the capability to efficiently connect, authenticate, and interact with directory servers. It allows users to perform operations such as searching for entries, and modifying entries in an LDAP directory, providing better support for directory-based operations.
The ldap:Client
connects to a directory server and performs various operations on directories. Currently, it supports the generic LDAP operations; add
, modify
, modifyDN
, compare
, search
, searchWithType
, delete
, and close
.
import ballerina/ldap;
public function main() returns error? {
ldap:Client ldapClient = check new ({
hostName,
port,
domainName,
password
});
}
- add: Creates an entry in a directory server.
- modify: Updates information of an entry in a directory server.
- modifyDN: Renames an entry in a directory server.
- compare: Determines whether a given entry has a specified attribute value.
- search: Returns a record containing search result entries and references that match the given search parameters.
- searchWithType: Returns a list of entries that match the given search parameters.
- delete: Removes an entry from a directory server.
- close: Unbinds from the server and closes the LDAP connection.
Creates an entry in a directory server.
anydata user = {
"objectClass": "user",
"sn": "New User",
"cn": "New User",
"givenName": "New User",
"displayName": "New User",
"userPrincipalName": "[email protected]",
"userAccountControl": "544"
};
ldap:LdapResponse addResult = check ldapClient->add("DC=ldap,DC=com", user);
Returns a record containing search result entries and references that match the given search parameters.
ldap:SearchResult searchResult = check ldapClient->search("DC=ldap,DC=com", "(givenName=Test User1)", ldap:SUB);
Updates information of an entry.
anydata user = {
"sn": "User",
"givenName": "Updated User",
"displayName": "Updated User"
};
ldap:LdapResponse modifyResult = check ldapClient->modify("DC=ldap,DC=com", user);
Removes an entry from a directory server.
ldap:LdapResponse deleteResult = check ldapClient->delete("DC=ldap,DC=com");
The Ballerina Ldap library provides practical examples illustrating usage in various scenarios. Explore these examples.
-
Access directory server This example shows how to integrate with a directory server to manage employees in a corporation.
-
Manage entries in a library This example demonstrates how to integrate with a directory server for managing users and books in a library.
The Issues and Projects tabs are disabled for this repository as this is part of the Ballerina library. To report bugs, request new features, start new discussions, view project boards, etc., visit the Ballerina library parent repository.
This repository only contains the source code for the package.
-
Download and install Java SE Development Kit (JDK) version 17. You can download it from either of the following sources:
Note: After installation, remember to set the
JAVA_HOME
environment variable to the directory where JDK was installed. -
Download and install Ballerina Swan Lake.
-
Download and install Docker.
Note: Ensure that the Docker daemon is running before executing any tests.
-
Generate a Github access token with read package permissions, then set the following
env
variables:export packageUser=<Your GitHub Username> export packagePAT=<GitHub Personal Access Token>
Execute the commands below to build from the source.
-
To build the package:
./gradlew clean build
-
To run the tests:
./gradlew clean test
-
To build the without the tests:
./gradlew clean build -x test
-
To debug package with a remote debugger:
./gradlew clean build -Pdebug=<port>
-
To debug with Ballerina language:
./gradlew clean build -PbalJavaDebug=<port>
-
Publish the generated artifacts to the local Ballerina central repository:
./gradlew clean build -PpublishToLocalCentral=true
-
Publish the generated artifacts to the Ballerina central repository:
./gradlew clean build -PpublishToCentral=true
As an open source project, Ballerina welcomes contributions from the community.
For more information, go to the contribution guidelines.
All contributors are encouraged to read the Ballerina Code of Conduct.
- Discuss code changes of the Ballerina project in [email protected].
- Chat live with us via our Discord server.
- Post all technical questions on Stack Overflow with the #ballerina tag.