ballerina/ldap Ballerina library

1.4.1

Overview

This module provides the capability to connect, authenticate, and interact with LDAP (Lightweight Directory Access Protocol) directory servers, supporting authentication, authorization, and directory-based operations such as searching, adding, and modifying entries.

Key Features

  • Connect and authenticate to LDAP directory servers
  • Add, modify, and delete directory entries
  • Search directory entries with configurable search scope
  • Compare attribute values and rename entries via modifyDN

Client

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.

Instantiate a new LDAP client

Copy
import ballerina/ldap;

public function main() returns error? {
    ldap:Client ldapClient = check new ({
        hostName,
        port,
        domainName,
        password
    });
}

Remote methods in ldap:Client

  • 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.

Add a new entry in the directory server

Creates an entry in a directory server.

Copy
anydata user = {
    "objectClass": "user",
    "sn": "New User",
    "cn": "New User",
    "givenName": "New User",
    "displayName": "New User",
    "userPrincipalName": "newuser@ad.windows",
    "userAccountControl": "544"
};
ldap:LdapResponse addResult = check ldapClient->add("DC=ldap,DC=com", user);

Search for an entry in the directory server

Returns a record containing search result entries and references that match the given search parameters.

Copy
ldap:SearchResult searchResult = check ldapClient->search("DC=ldap,DC=com", "(givenName=Test User1)", ldap:SUB);

Modify a new entry in the directory server

Updates information of an entry.

Copy
anydata user = {
    "sn": "User",
    "givenName": "Updated User",
    "displayName": "Updated User"
};
ldap:LdapResponse modifyResult = check ldapClient->modify("DC=ldap,DC=com", user);

Delete an entry in the directory server

Removes an entry from a directory server.

Copy
ldap:LdapResponse deleteResult = check ldapClient->delete("DC=ldap,DC=com");

Examples

The Ballerina Ldap library provides practical examples illustrating usage in various scenarios. Explore these examples.

  1. Access directory server This example shows how to integrate with a directory server to manage employees in a corporation.

  2. Manage entries in a library This example demonstrates how to integrate with a directory server for managing users and books in a library.

Import

import ballerina/ldap;Copy

Other versions

See more...

Metadata

Released date: 3 days ago

Version: 1.4.1

License: Apache-2.0


Compatibility

Platform: java21

Ballerina version: 2201.12.0

GraalVM compatible: Yes


Pull count

Total: 2081

Current verison: 39


Weekly downloads


Source repository


Keywords

ldap

Type/Library

Area/Built-in

Area/Security & Identity

Name/LDAP


Contributors