Package com.jalios.ldap
Class LDAPUtil
- java.lang.Object
-
- com.jalios.ldap.LDAPUtil
-
public class LDAPUtil extends java.lang.ObjectUtilily methods to perform miscelleanous operation related to LDAP.- Version:
- $Revision: 124679 $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLDAPUtil.SRVRecordSRV record entry
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringENTRY_UUID_ATTRentryUUID Operational Attribute name.static java.lang.StringOBJECT_CLASS_ATTR"objectClass"static java.lang.StringOBJECT_GUID_ATTRThe Active Directory unique identifier for an object.static java.lang.StringOBJECT_SID_ATTRThe Active Directory security identifier (SID) of a user.
The SID is a unique value used to identify the user as a security principal.static java.lang.StringREVISION
-
Constructor Summary
Constructors Constructor Description LDAPUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancheckConnect(java.lang.String hostname, java.lang.String port, java.lang.String isSSL, java.lang.String bindDN, java.lang.String bindPassword)Try a LDAP connection using the given host information and credential.static java.lang.StringescapeDN(java.lang.String name)Escape certain meta-characters in LDAP DN.static java.lang.StringescapeLDAPSearchFilter(java.lang.String filter)Escape certain meta-characters of a name for use in LDAP search filter.static java.lang.StringextractSAMAccountName(java.lang.String login)Retrieve the sAMAccountName from the specified login (if possible).static java.lang.StringgetFirstDomainControllerHostname(java.lang.String domain)Retrieve the first domain controler available for query for the specified windows domain.static LDAPUtil.SRVRecordgetFirstSrvRecord(java.lang.String srvRecordName)Retrieve the first SRV record value for the specified SRV record name.static java.lang.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[]getGUID(java.lang.String guidStr)Retrieve a byte array of the specified 16-byte string representation of aGUID.static java.lang.StringgetGUIDByteString(java.lang.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 java.lang.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 java.util.List<LDAPUtil.SRVRecord>getSrvRecords(java.lang.String srvRecordName)Retrieve all SRV record values for the specified SRV record name.static java.lang.StringgetString(com.unboundid.ldap.sdk.Attribute attribute, java.lang.String defaultValue)Return first available value ofAttributeattr, or defaultValue if not available.static booleanisDescendant(java.lang.String parentDN, java.lang.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 booleanisUUID(java.lang.String str)Check if the specified string is a 16-byte string representation of a UUID.
-
-
-
Field Detail
-
REVISION
public static final java.lang.String REVISION
- See Also:
- Constant Field Values
-
OBJECT_CLASS_ATTR
public static final java.lang.String OBJECT_CLASS_ATTR
"objectClass"- See Also:
- Constant Field Values
-
OBJECT_SID_ATTR
public static final java.lang.String 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:
getSid(Attribute), Constant Field Values
-
OBJECT_GUID_ATTR
public static final java.lang.String OBJECT_GUID_ATTR
The Active Directory unique identifier for an object."objectGUID"
MSDN : Object-Guid attribute- See Also:
getGUID(Attribute), Constant Field Values
-
ENTRY_UUID_ATTR
public static final java.lang.String ENTRY_UUID_ATTR
entryUUID Operational Attribute name."entryUUID"
RFC 4530 : entryUUID Operational Attribute- Since:
- jcms-10.0.3 - JCMS-7454
- See Also:
getGUID(Attribute), Constant Field Values
-
-
Method Detail
-
getString
public static java.lang.String getString(com.unboundid.ldap.sdk.Attribute attribute, java.lang.String defaultValue)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(java.lang.String hostname, java.lang.String port, java.lang.String isSSL, java.lang.String bindDN, java.lang.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
public static java.lang.String escapeDN(java.lang.String name)
Escape certain meta-characters in LDAP DN.- Parameters:
name- the name to escape- Returns:
- the escaped name
-
escapeLDAPSearchFilter
public static final java.lang.String escapeLDAPSearchFilter(java.lang.String filter)
Escape certain meta-characters of a name for use in LDAP search filter.- Parameters:
filter- the filter to escape- Returns:
- the escaped filter
-
extractSAMAccountName
public static java.lang.String extractSAMAccountName(java.lang.String login)
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
public static java.lang.String getSid(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.
- 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
public static java.lang.String getFirstDomainControllerHostname(java.lang.String domain)
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
public static LDAPUtil.SRVRecord getFirstSrvRecord(java.lang.String srvRecordName)
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
public static java.util.List<LDAPUtil.SRVRecord> getSrvRecords(java.lang.String srvRecordName)
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
public static java.lang.String getGUID(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.
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
public static boolean isUUID(java.lang.String str)
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
public static byte[] getGUID(java.lang.String guidStr)
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
public static java.lang.String getGUIDByteString(java.lang.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.- 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
public static boolean isDescendant(java.lang.String parentDN, java.lang.String dn)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
-
-