public class LDAPUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
LDAPUtil.AttrNameValue
This class builds a attribute name/value pair.
|
Modifier and Type | Method and Description |
---|---|
static void |
addClassToAttrSet(LDAPAttributeSet attrSet,
ClassDefinition classDef)
Adds the 'objectclass' attribute for the given class definition and its super classes
to the given attribute set.
|
static LDAPAttributeSet |
buildAttrSet(ClassDefinition classDef,
LDAPUtil.AttrNameValue[] nameValuePairs)
Builds an attribute set given a class definition and a set of attribute name/value pairs.
|
static LDAPModification[] |
buildLDAPModificationArray(ClassDefinition classDef,
int modificationType,
LDAPUtil.AttrNameValue[] nameValuePairs)
Builds an LDAP modification array a class definition and a set of attribute name/value pairs.
|
static LDAPEntry |
cloneEntry(LDAPEntry entry)
Return a copy of an LDAPEntry.
|
static java.lang.String |
CN(java.lang.String value) |
static java.lang.String |
CN(java.lang.String value,
java.lang.String parentDN) |
static boolean |
containsStringValue(LDAPAttribute attribute,
java.lang.String expectedValue,
boolean caseSensitive)
Indicates whether the entry contains an attribute that contains the expected value.
|
static boolean |
containsStringValue(LDAPEntry entry,
AttributeDefinition attrDef,
java.lang.String expected,
boolean caseSensitive)
Indicates whether the entry contains an attribute that contains the expected value.
|
static boolean |
containsStringValue(LDAPEntry entry,
java.lang.String attributeName,
java.lang.String expectedValue,
boolean caseSensitive)
Indicates whether the entry contains an attribute that contains the expected value.
|
static byte[] |
getBytesValue(LDAPEntry entry,
AttributeDefinition attrDef)
Returns the first byte-array value of the attribute in entry that has the specified name.
|
static byte[] |
getBytesValue(LDAPEntry entry,
java.lang.String attributeName)
Returns the first byte-array value of the attribute in entry that has the specified name.
|
static java.lang.String |
getCN(java.lang.String dn)
Deprecated.
|
static java.lang.String |
getDirectorySearchRoot() |
static LDAPEntry |
getEntry(LDAPDirectoryReader directoryReader,
java.lang.String dn)
Searches for an LDAP entry with the given DN
|
static LDAPEntry |
getEntry(LDAPDirectoryReader directoryReader,
java.lang.String dn,
java.lang.String filter)
Searches for an LDAP entry with the given DN
|
static java.lang.String |
getEscapedFilter(java.lang.String filter) |
static LDAPDirectory |
getLdapDirectory() |
static java.lang.String |
getLDAPDisplayNameOnCurrentSchema(AttributeDefinition attribute) |
static java.lang.String |
getParentDn(java.lang.String dn) |
static java.lang.String |
getRDNString(java.lang.String dn) |
static java.lang.String |
getRDNType(java.lang.String dn) |
static java.lang.String |
getRDNValue(java.lang.String dn) |
static java.lang.String |
getStringValue(LDAPEntry entry,
AttributeDefinition attrDef,
java.lang.String defaultValue)
Returns the first String value of the attribute in the entry, if it there is one, otherwise the
default value.
|
static java.lang.String |
getStringValue(LDAPEntry entry,
java.lang.String attributeName,
java.lang.String defaultValue)
Returns the first String value of the attribute in the entry, if it there is one, otherwise the
default value.
|
static java.lang.String[] |
getStringValues(LDAPEntry entry,
AttributeDefinition attrDef)
Returns a String array containing all the String values of the attribute in entry that has
the specified name.
|
static java.lang.String[] |
getStringValues(LDAPEntry entry,
java.lang.String attributeName)
Returns a String array containing all the String values of the attribute in entry that has
the specified name.
|
static int |
getXMLNode(LDAPEntry entry,
AttributeDefinition attrDef,
Document document)
Tries to parse the value of the attribute into an XML tree.
|
static int |
getXMLNode(LDAPEntry entry,
java.lang.String attributeName,
Document document)
Tries to parse the value of the attribute into an XML tree.
|
static boolean |
isDN(java.lang.String possibleDN)
Returns true if the
possibleDN is an actual LDAP Distinguished Name. |
static boolean |
ldapDNEqualIgnoreCase(java.lang.String firstDN,
java.lang.String secondDN)
Compare two ldap dns if they are equal ignoring case according to the LDAP specification (http://www.ietf.org/rfc/rfc4518.txt) and case
ignoring (http://www.ietf.org/rfc/rfc3454.txt) matching rules.
|
static boolean |
ldapEqualIgnoreCase(java.lang.String firstValue,
java.lang.String secondValue)
Compare two ldap attribute values if they are equal ignoring case according to the LDAP specification
(http://www.ietf.org/rfc/rfc4518.txt) and case ignoring (http://www.ietf.org/rfc/rfc3454.txt) matching rules.
|
static java.lang.String |
normalizeValueIgnoreCase(java.lang.String value)
Normalizes an ldap attribute values according to the LDAP specification (http://www.ietf.org/rfc/rfc4518.txt) and case ignoring
(http://www.ietf.org/rfc/rfc3454.txt) matching rules.
|
static java.lang.String |
O(java.lang.String value) |
static java.lang.String |
O(java.lang.String value,
java.lang.String parentDN) |
static void |
setBytesValue(LDAPEntry entry,
AttributeDefinition attrDef,
byte[] value)
Sets / adds a new byte value to the ldap attribute for the given entry.
|
public static java.lang.String[] getStringValues(LDAPEntry entry, java.lang.String attributeName)
entry
- The LDAP entry from which to retrieve the attribute (can be null
).attributeName
- The name of the attribute to retrieve from the entry.public static java.lang.String[] getStringValues(LDAPEntry entry, AttributeDefinition attrDef)
entry
- The LDAP entry from which to retrieve the attribute (can be null
).attrDef
- The attribute to retrieve from the entry.public static byte[] getBytesValue(LDAPEntry entry, java.lang.String attributeName)
entry
- The LDAP entry from which to retrieve the attribute (can be null
).attributeName
- The name of the attribute to retrieve from the entry.public static byte[] getBytesValue(LDAPEntry entry, AttributeDefinition attrDef)
entry
- The LDAP entry from which to retrieve the attribute (can be null
).attrDef
- The attribute to retrieve from the entry.public static void setBytesValue(LDAPEntry entry, AttributeDefinition attrDef, byte[] value)
entry
- The LDAP entry where to set the attributeattrDef
- The attribute to set the byte for.value
- the byte[] value for the entry.public static LDAPEntry cloneEntry(LDAPEntry entry)
AttributeDefinition attrDef = SchemaDefinition.getCurrent().attrKeystore;
LDAPEntry clonedEntry = LDAPUtil.cloneEntry(foundEntry);
LDAPAttribute attribute = clonedEntry.getAttributeSet().getAttribute(getLDAPDisplayNameOnCurrentSchema(attrDef));
if (attribute != null) {
clonedEntry.getAttributeSet().remove(attribute);
}
LDAPAttribute newAttribute = new LDAPAttribute(getLDAPDisplayNameOnCurrentSchema(attrDef), storeInBytes.toByteArray());
clonedEntry.getAttributeSet().add(newAttribute);
try
{
directory.modify(clonedEntry);
}
catch (LDAPException e)
{
throw new DirectoryException("Failed to modify",e);
}
entry
- the LDAPEntry to be clonedpublic static java.lang.String getStringValue(LDAPEntry entry, java.lang.String attributeName, java.lang.String defaultValue)
entry
- The LDAP entry from which to retrieve the attribute (can be null
).attributeName
- The name of the attribute to retrieve from the entry.defaultValue
- The value returned if the entry is null, or the attribute is not in there, or
there are no values in the attribute.public static java.lang.String getStringValue(LDAPEntry entry, AttributeDefinition attrDef, java.lang.String defaultValue)
entry
- The LDAP entry from which to retrieve the attribute (can be null
).attrDef
- The attribute to retrieve from the entry.defaultValue
- The value returned if the entry is null, or the attribute is not in there, or
there are no values in the attribute.public static void addClassToAttrSet(LDAPAttributeSet attrSet, ClassDefinition classDef)
attrSet
- the attribute set to be extended.classDef
- the class to addpublic static LDAPAttributeSet buildAttrSet(ClassDefinition classDef, LDAPUtil.AttrNameValue[] nameValuePairs)
classDef
- the definition of the LDAP classnameValuePairs
- the attribute name/value pairspublic static LDAPModification[] buildLDAPModificationArray(ClassDefinition classDef, int modificationType, LDAPUtil.AttrNameValue[] nameValuePairs)
classDef
- the definition of the LDAP classnameValuePairs
- the attribute name/value pairspublic static boolean containsStringValue(LDAPEntry entry, java.lang.String attributeName, java.lang.String expectedValue, boolean caseSensitive)
entry
- The LDAP entry from which to check the attribute values (can be null
).attributeName
- The name of the attribute to search in the entry.expectedValue
- The value to search for in the attributecaseSensitive
- Determines whether the comparison of values should be case-sensitive or not.null
, or if it does not contain an attribute with the specified name, or
if the attribute does not contain the specified value.public static boolean containsStringValue(LDAPEntry entry, AttributeDefinition attrDef, java.lang.String expected, boolean caseSensitive)
entry
- The LDAP entry from which to check the attribute values (can be null
).attrDef
- The attribute to search in the entry.expected
- The value to search for in the attributecaseSensitive
- Determines whether the comparison of values should be case-sensitive or not.null
, or if it does not contain an attribute with the specified name, or
if the attribute does not contain the specified value.public static boolean containsStringValue(LDAPAttribute attribute, java.lang.String expectedValue, boolean caseSensitive)
attribute
- The LDAP attribute from which to check the attribute values (can be null
).expectedValue
- The value to search for in the attributecaseSensitive
- Determines whether the comparison of values should be case-sensitive or not.null
, or if it does not contain an attribute with the specified name, or
if the attribute does not contain the specified value.public static boolean ldapDNEqualIgnoreCase(java.lang.String firstDN, java.lang.String secondDN)
firstDN
- a DNsecondDN
- a DNpublic static boolean ldapEqualIgnoreCase(java.lang.String firstValue, java.lang.String secondValue)
firstValue
- an ldap attribute valuesecondValue
- an ldap attribute valuepublic static java.lang.String normalizeValueIgnoreCase(java.lang.String value)
value
- an ldap attribute valuepublic static int getXMLNode(LDAPEntry entry, java.lang.String attributeName, Document document)
entry
- The LDAP entry from which to retrieve the attribute (can be null
).attributeName
- The name of the attribute to retrieve from the entry.document
- The document context used to parse the XML tree.public static int getXMLNode(LDAPEntry entry, AttributeDefinition attrDef, Document document)
entry
- The LDAP entry from which to retrieve the attribute (can be null
).attrDef
- The attribute to retrieve from the entry.document
- The document context used to parse the XML tree.public static boolean isDN(java.lang.String possibleDN)
possibleDN
is an actual LDAP Distinguished Name. That is, it
should be of the form 'cn=abc,cn=xyz, etc.'
possibleDN
- the string that possibly contains an DNpublic static java.lang.String getEscapedFilter(java.lang.String filter)
@Deprecated public static java.lang.String getCN(java.lang.String dn)
getRDNValue(java.lang.String)
public static java.lang.String CN(java.lang.String value)
public static java.lang.String O(java.lang.String value)
public static java.lang.String CN(java.lang.String value, java.lang.String parentDN)
public static java.lang.String O(java.lang.String value, java.lang.String parentDN)
public static java.lang.String getRDNValue(java.lang.String dn)
public static java.lang.String getRDNString(java.lang.String dn)
public static java.lang.String getRDNType(java.lang.String dn)
public static java.lang.String getParentDn(java.lang.String dn)
public static java.lang.String getLDAPDisplayNameOnCurrentSchema(AttributeDefinition attribute)
public static LDAPDirectory getLdapDirectory()
public static java.lang.String getDirectorySearchRoot()
public static LDAPEntry getEntry(LDAPDirectoryReader directoryReader, java.lang.String dn)
directoryReader
- the reader to use for searchingdn
- The dn to fetch.public static LDAPEntry getEntry(LDAPDirectoryReader directoryReader, java.lang.String dn, java.lang.String filter)
directoryReader
- the reader to use for searchingdn
- the dn to fetch.filter
- ldap filter dn have to conform to