Package com.jalios.ldap
Class LDAPUtil
java.lang.Object
com.jalios.ldap.LDAPUtil
Utilily methods to perform miscelleanous operation related to LDAP.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringentryUUID Operational Attribute name.static final String"objectClass"static final StringThe Active Directory unique identifier for an object.static final StringThe Active Directory security identifier (SID) of a user.
The SID is a unique value used to identify the user as a security principal. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanTry a LDAP connection using the given host information and credential.static StringEscape certain meta-characters in LDAP DN.static final StringescapeLDAPSearchFilter(String filter) Escape certain meta-characters of a name for use in LDAP search filter.static StringextractSAMAccountName(String login) Retrieve the sAMAccountName from the specified login (if possible).static StringRetrieve the first domain controler available for query for the specified windows domain.static LDAPUtil.SRVRecordgetFirstSrvRecord(String srvRecordName) Retrieve the first SRV record value for the specified SRV record name.static StringgetGUID(com.unboundid.ldap.sdk.Attribute objectGUIDAttribute) Retrieve a string representation of the specifiedobjectGUIDLDAP attribute which contains a globally unique identifier assigned by Active Directory Domain Services when the object instance is created.
A GUID is a 128-bit number guaranteed to be unique in space and time.static byte[]Retrieve a byte array of the specified 16-byte string representation of aGUID.static StringgetGUIDByteString(String guidStr) Retrieve a LDAP byte string representation of aGUID, such as \xx\xx\xx\xx\xx\xx\xx\xx\xx\xx\xx\xx\xx\xx\xx\xx.static StringgetSid(com.unboundid.ldap.sdk.Attribute objectSidAttribute) Retrieve a string representation of the specifiedobjectSidLDAP attribute which contains a value that specifies the security identifier (SID) of the user.
The SID is a unique value used to identify the user as a security principal.static List<LDAPUtil.SRVRecord> getSrvRecords(String srvRecordName) Retrieve all SRV record values for the specified SRV record name.static StringReturn first available value ofAttributeattr, or defaultValue if not available.static booleanisDescendant(String parentDN, String dn) Check if the specified DN is a descendant (or the same) as the specified parent DN.static booleanisGroupEntry(com.unboundid.ldap.sdk.SearchResultEntry entry, LDAPConfiguration conf) Determines if the givenSearchResultEntryis a group entry according to parameters specified by the givenLDAPConfigurationobject.static booleanisUserEntry(com.unboundid.ldap.sdk.SearchResultEntry entry, LDAPConfiguration conf) Determines if the givenSearchResultEntryis a user entry according to parameters specified by the givenLDAPConfigurationobject.static booleanCheck if the specified string is a 16-byte string representation of a UUID.
-
Field Details
-
OBJECT_CLASS_ATTR
"objectClass"- See Also:
-
OBJECT_SID_ATTR
The Active Directory security identifier (SID) of a user.
The SID is a unique value used to identify the user as a security principal."objectSid"
MSDN : Object-Sid attribute- See Also:
-
OBJECT_GUID_ATTR
The Active Directory unique identifier for an object."objectGUID"
MSDN : Object-Guid attribute- See Also:
-
ENTRY_UUID_ATTR
entryUUID Operational Attribute name."entryUUID"
RFC 4530 : entryUUID Operational Attribute- Since:
- jcms-10.0.3 - JCMS-7454
- See Also:
-
-
Constructor Details
-
LDAPUtil
public LDAPUtil()
-
-
Method Details
-
getString
Return first available value ofAttributeattr, or defaultValue if not available.- Parameters:
attribute-Attributefrom which to retrieve value.defaultValue- the default value to use if none could be read- Returns:
- a the first value of attr or defaultValue (never return null unless defaultValue is null).
-
isGroupEntry
public static boolean isGroupEntry(com.unboundid.ldap.sdk.SearchResultEntry entry, LDAPConfiguration conf) Determines if the givenSearchResultEntryis a group entry according to parameters specified by the givenLDAPConfigurationobject.- Parameters:
entry- the SearchResultEntry to checkconf- theLDAPConfigurationto use, MUST NOT be null- Returns:
- true if the entry is a group, false otherwise
- Since:
- jcms-5.7
-
isUserEntry
public static boolean isUserEntry(com.unboundid.ldap.sdk.SearchResultEntry entry, LDAPConfiguration conf) Determines if the givenSearchResultEntryis a user entry according to parameters specified by the givenLDAPConfigurationobject.- Parameters:
entry- the SearchResultEntry to checkconf- theLDAPConfigurationto use, MUST NOT be null- Returns:
- true if the entry is a user, false otherwise
- Since:
- jcms-5.7
-
checkConnect
public static boolean checkConnect(String hostname, String port, String isSSL, String bindDN, String bindPassword) Try a LDAP connection using the given host information and credential.- Parameters:
hostname- the hostname of the ldap server to connect to.port- the port of the ldap server to connect to.isSSL- whether the connection should be made using SSL.bindDN- the Distinguished Name to use to bind to the ldap server to connect to.bindPassword- the password to use to bind to the ldap server to connect to.- Returns:
- true if the connection was successful, false if an error occured
- Since:
- jcms-5.7
-
escapeDN
Escape certain meta-characters in LDAP DN.- Parameters:
name- the name to escape- Returns:
- the escaped name
-
escapeLDAPSearchFilter
Escape certain meta-characters of a name for use in LDAP search filter.- Parameters:
filter- the filter to escape- Returns:
- the escaped filter
-
extractSAMAccountName
Retrieve the sAMAccountName from the specified login (if possible).Support login in Down-Level logon name formats (eg
DOMAIN\sAMAccountName).- Parameters:
login- a user login- Returns:
- the extracted sAMAccountName or the original login, never return null.
-
getSid
Retrieve a string representation of the specifiedobjectSidLDAP attribute which contains a value that specifies the security identifier (SID) of the user.
The SID is a unique value used to identify the user as a security principal.
- Parameters:
objectSidAttribute- theobjectSidas retrieved from- Returns:
- a SID string such as "S-1-5-21-2029357233-986718560-1400240716-2155", or null if it could not be extracted
-
getFirstDomainControllerHostname
Retrieve the first domain controler available for query for the specified windows domain.This methods looks for all SRV record "_ldap._tcp.dc._msdcs.{domain}" and return the first one as defined by priority and weight in all records.
- Parameters:
domain- a windows domain name- Returns:
- the hostname of the first domain controler available, or null if it could not be found
- Since:
- jcms-8.0.1
-
getFirstSrvRecord
Retrieve the first SRV record value for the specified SRV record name.- Parameters:
srvRecordName- the name of the SRV record to query, ie "_sip._tcp.example.com."- Returns:
- the first SRVRecord in the order of the priority and weight defined in all srv results, or null if none could not be found
- Since:
- jcms-8.0.1
-
getSrvRecords
Retrieve all SRV record values for the specified SRV record name.- Parameters:
srvRecordName- the name of the SRV record to query, ie "_sip._tcp.example.com."- Returns:
- a SortedSet of all SRVRecord, in the order of the priority and weight defined in all srv results, never return null
- Since:
- jcms-8.0.1
-
getGUID
Retrieve a string representation of the specifiedobjectGUIDLDAP attribute which contains a globally unique identifier assigned by Active Directory Domain Services when the object instance is created.
A GUID is a 128-bit number guaranteed to be unique in space and time.
sing objectGUID to Bind to an Object- Parameters:
objectGUIDAttribute- theobjectGUIDas retrieved from AD- Returns:
- a GUID string such as "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", or null if it could not be extracted
-
isUUID
Check if the specified string is a 16-byte string representation of a UUID.- Parameters:
str- any value to check- Returns:
- true if specified string is a UUID, false otherwise
-
getGUID
Retrieve a byte array of the specified 16-byte string representation of aGUID.- Parameters:
guidStr- 16-byte string representation of aGUIDsuch as "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"- Returns:
- a byte array of the GUID or null if it could not be extracted
-
getGUIDByteString
Retrieve a LDAP byte string representation of aGUID, such as \xx\xx\xx\xx\xx\xx\xx\xx\xx\xx\xx\xx\xx\xx\xx\xx.- Parameters:
guidStr- 16-byte string representation of aGUIDsuch as "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"- Returns:
- a byte array of the GUID or null if it could not be extracted
-
isDescendant
Check if the specified DN is a descendant (or the same) as the specified parent DN.- Parameters:
parentDN- the DN used as possible ancestor, must not be null or emptydn- the DN verified to be a descendant (or the same) of the first one, must not be null or empty- Returns:
- true if specified DN is a descendant of specified parent, false if dn is NOT a descendant of the specified parent DN
- Since:
- 10.0.3 - JCMS-7453
-