ballerina-platform / module-ballerina-ldap

Ballerina LDAP Module

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ballerina LDAP Connector

Build codecov Trivy GraalVM Check GitHub Last Commit Github issues

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.

APIs associated with LDAP

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

Creates an entry in a directory server.

import ballerina/ldap;

public function main() returns error? {
    anydata user = {
        "objectClass": "user",
        "sn": "New User",
        "cn": "New User",
        "givenName": "New User",
        "displayName": "New User",
        "userPrincipalName": "newuser@ad.windows",
        "userAccountControl": "544"
    };
    ldap:LdapResponse val = check ldapClient->add(userDN, user);
}

modify API

Updates information of an entry.

import ballerina/ldap;

public function main() returns error? {
    anydata user = {
        "sn": "User",
        "givenName": "Updated User",
        "displayName": "Updated User"
    };
    _ = check ldapClient->modify(userDN, user);
}

modifyDN API

Renames an entry in a directory server.

import ballerina/ldap;

public function main() returns error? {
    ldap:LdapResponse modifyDN = check ldapClient->modifyDN(userDN, "CN=Test User2", true);
}

compare API

Determines whether a given entry has a specified attribute value.

import ballerina/ldap;

public function main() returns error? {
    ldap:LdapResponse compare = check ldapClient->compare(userDN, "givenName", "Test User1");
}

search API

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

import ballerina/ldap;

public function main() returns error? {
    ldap:SearchResult value = check ldapClient->search("DC=ad,DC=windows", "(givenName=Test User1)", SUB);
}

searchWithType API

Returns a list of entries that match the given search parameters.

import ballerina/ldap;

public function main() returns error? {
    anydata[] value = check ldapClient->searchWithType("DC=ad,DC=com", "(givenName=Test User1)", ldap:SUB);
}

getEntry API

Gets information about an entry in a directory server.

import ballerina/ldap;

public function main() returns error? {
    anydata value = check ldapClient->getEntry(userDN);
}

delete API

Removes an entry from a directory server.

import ballerina/ldap;

public function main() returns error? {
    ldap:LdapResponse val = check ldapClient->delete(userDN);
}

close API

Unbinds from the server and closes the LDAP connection.

import ballerina/ldap;

public function main() {
    ldapClient->close();
}

Issues and projects

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.

Building from the source

Prerequisites

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

  2. Download and install Ballerina Swan Lake.

  3. Download and install Docker.

    Note: Ensure that the Docker daemon is running before executing any tests.

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

Build options

Execute the commands below to build from the source.

  1. To build the package:

    ./gradlew clean build
  2. To run the tests:

    ./gradlew clean test
  3. To build the without the tests:

    ./gradlew clean build -x test
  4. To debug package with a remote debugger:

    ./gradlew clean build -Pdebug=<port>
  5. To debug with Ballerina language:

    ./gradlew clean build -PbalJavaDebug=<port>
  6. Publish the generated artifacts to the local Ballerina central repository:

    ./gradlew clean build -PpublishToLocalCentral=true
  7. Publish the generated artifacts to the Ballerina central repository:

    ./gradlew clean build -PpublishToCentral=true

Contributing to Ballerina

As an open source project, Ballerina welcomes contributions from the community.

For more information, go to the contribution guidelines.

Code of conduct

All contributors are encouraged to read the Ballerina Code of Conduct.

Useful links

About

Ballerina LDAP Module

License:Apache License 2.0


Languages

Language:Java 57.1%Language:Ballerina 42.9%