Package com.storedobject.common
Class LDAP
java.lang.Object
com.storedobject.common.LDAP
The
LDAP class provides an interface for interacting with an LDAP server.
It allows authentication, user information retrieval, and user management within an LDAP domain.
This class is designed to establish a connection to the LDAP server, fetch user data, and
modify user attributes such as passwords.- Author:
- Syam
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassRepresents an LDAP user with attributes fetched from an LDAP directory. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an LDAP instance for connecting to an LDAP server using the specified credentials and domain name.Constructs an LDAP instance for connecting to an LDAP server using the specified credentials, domain name, and LDAP server address. -
Method Summary
-
Constructor Details
-
LDAP
Constructs an LDAP instance for connecting to an LDAP server using the specified credentials and domain name. This constructor assumes no specific server is provided.- Parameters:
username- the username for authentication.password- the password for authentication.domainName- the domain name of the LDAP server.- Throws:
NamingException- if an error occurs during the LDAP connection setup.
-
LDAP
public LDAP(String username, String password, String domainName, String server) throws NamingException Constructs an LDAP instance for connecting to an LDAP server using the specified credentials, domain name, and LDAP server address.- Parameters:
username- the username used for authentication.password- the password associated with the username for authentication.domainName- the domain name of the LDAP server.server- the address of the LDAP server. If null, a default server is assumed based on the domain name.- Throws:
NamingException- if an error occurs during the LDAP connection setup.
-
-
Method Details
-
close
public void close()Closes the LDAP connection and releases associated resources. This method checks if the internal LDAP context is initialized and, if so, attempts to close it. AnyNamingExceptionthat occurs during closure is caught and ignored. Once the context is closed, the internal reference to it is nullified to prevent further usage. -
getUser
Retrieves a user by their username. This method searches for the user in the LDAP directory based on the provided username and returns an instance of theLDAP.Userclass if found.- Parameters:
username- the username of the user to retrieve. It may include a domain in the format "username@domain" or "domain\\username." If the domain is not provided, the domain from the current authenticated context or instance configuration is used.- Returns:
- an instance of the
LDAP.Userclass representing the user if found, ornullif the user could not be found or an error occurred during the search.
-
getUsers
Retrieves a list of users from the LDAP directory based on the current authenticated user's domain. This method searches for users of the object class "user" within the LDAP directory under the domain derived from the authenticated user's principal. If the authenticated user's principal contains a domain (e.g., "username@domain"), the domain is extracted and used within the query. The search includes attributes defined by the `userAttributes` field of the containing class.- Returns:
- an
ArrayListofLDAP.Userinstances representing users in the LDAP directory, ornullif an error occurs during authentication or directory search.
-