|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ca.jcs.util.LdapUtil
public abstract class LdapUtil
LDAP related utilities.
| Field Summary | |||
|---|---|---|---|
static String |
LDAP_DN_ONLY_OID
Object IDentifier (OID) which means "DN-only" in search results: refer |
static String |
LDAP_OBJECT_CLASS
Reserved name to represent an object's type in LDAP. |
static String[] |
LDAP_OBJECT_CLASS_ARR
Array that can be passed in to lookup() / search return attrs when only interested in object's type. |
||
static String |
LDAP_OBJECT_CLASS_OID
Object IDentifier (OID) for LDAP_OBJECT_CLASS. |
||
static String |
LDAP_OP_ATTR_SPEC
Specifier which means "operational attrs only" in search results: refer |
static String |
LDAP_REF_ATTR
Special attribute meaning "reference". |
static String |
LDAP_USER_ATTR_SPEC
Specifier which means "user attrs only" in search results: refer |
static String |
NOT_SHOWN
Should be output to show that sensitive attributes have a value, without showing the value itself. |
static String[] |
TEST_EXISTANCE_ATTRS
Array that can be passed in to lookup() / search return attrs when only interested in whether an object exists or not. |
||
static String |
TOP_OBJECT_CLASS
The top object class is ancestor of all LDAP classes. |
||
| Constructor Summary | |
|---|---|
LdapUtil()
|
|
| Method Summary | |
|---|---|
static void |
addAttributeValues(Attribute attr,
Collection vals)
Calls addAttributeValues(Attribute, Collection, boolean) with toString=false. |
static void |
addAttributeValues(Attribute attr,
Collection vals,
boolean toString)
Adds values in vals to attr. |
static void |
addAttrValue(Attribute attr,
Object val)
|
static void |
addAttrValue(Attributes attrs,
String attrId,
Object val)
|
static boolean |
allAttributesExist(Attributes attrs,
Collection<String> attrIds)
|
static String |
appendCompositeNameComponent(Name parentDn,
String namingAttr,
String attrValue)
append the rdn formed by namingAttr and attrValue to the domainDn and return a string that comes from a CompositeName |
static String |
appendNameComponent(String baseName,
String addComponent)
|
static void |
checkAttrsNotNull(Logger log,
Object name,
Attributes attrs,
boolean strict)
Attributes with no values upset connectors on the way in and cause the ApacheDS LDAP codec to hang on the way out. |
static void |
checkAttrsValid(Logger log,
Object name,
Attributes attrs)
the default behaviour is to report error if any bad attributes found |
static void |
checkAttrsValid(Logger log,
Object name,
Attributes attrs,
boolean strict)
Attributes with no values upset connectors on the way in and cause the ApacheDS LDAP codec to hang on the way out. |
static SearchControls |
cloneSearchControls(SearchControls sc)
|
static Attribute |
computeAddedDelta(Attribute currValue,
Attribute newValue)
Compute values which need to be added to currValue in order for it to
match newValue. |
static Attribute |
computeDeletedDelta(Attribute currValue,
Attribute newValue)
Compute values which need to be deleted from currValue in order for it to
match newValue. |
static Attribute |
copyAttribute(String newId,
Attribute attr)
Return a copy of attr with a new id, if newId is null then attr's id will be used. |
static Attribute |
createAttributeFromValue(String attrId,
Object val)
|
static Attribute |
createAttributeFromValueList(String attrId,
List vals)
|
static Attributes |
deepCloneAttributes(Attributes attrs)
|
static boolean |
dnStartsWith(Name name,
Name subName,
boolean caseSensitive)
Compare two DNs, and see whether it starts with the specified base DN. |
static String[] |
ensureAttrIdInList(String[] attrIds,
String attrId)
Check if attrId is in the provided array, and if not then add it. |
static String |
escapeCompositeName(String compName)
Implements escaping rules described in CompositeName. |
static String |
escapeNonAscii(String input)
Escapes non-ascii characters in LDAP filters, as per RFC2254 |
static String |
extractDeepestRdnValue(String dn)
Extract deepest RDN value in the DN and strip of RDN name attribute |
static String |
filterEscape(String val)
Simply wraps JNDIUtil.filterEscape(String) to make life easier for scripts and code in general by avoiding import,
and also calls escapeNonAscii(String). |
static String |
getAttrFromDN(Name baseName,
String attrId)
Helper method to search an Ldap DN and return a specific attributes values from the rdn list |
static List<String> |
getAttributeIds(Attributes attrs)
Attributes to List of attribute Ids |
static List<String> |
getAttributeIds(ModificationItem[] items)
Modification items to List of attribute Ids |
static String |
getAttributeNameFromRDN(String rdnStr)
Get "var" in a var=val component of an
LDAP JNDI Name, accounting for RDN quoting rules. |
static Attributes |
getAttributes(Attributes attrs,
String[] ldapAttrIds)
|
static Attributes |
getAttributes(ModificationItem[] items)
Lossy conversion of ModificationItems into Attributes |
static String |
getAttributeValueFromRDN(String rdnStr)
Get "val" in a var=val component of an
LDAP JNDI Name, accounting for RDN quoting rules. |
static String |
getAttributeValueFromRDN(String rdnStr,
String attrId,
boolean deepest)
Get "val" in a var=val component of an
LDAP JNDI Name, accounting for RDN quoting rules but look for
user specified RDN name match. |
static List |
getAttributeValueList(Attribute attr)
Calls getAttributeValueList(Attribute, boolean) with toString=false. |
static List |
getAttributeValueList(Attribute attr,
boolean toString)
Return list with length attr.size() containing attr's values (may be 0 length). |
static String[] |
getAttributeValues(Attribute attr)
Return array with length attr.size() containing attr's values (may be 0 length). |
static String[] |
getAttributeValues(Attribute attr,
boolean lowercase)
|
static String |
getAttrValue(Attributes attrs,
String attrId)
Return string value for named attribute. |
static String[] |
getAttrValues(Attributes attrs,
String attrId)
|
static String |
getDeepestRDN(String dn)
|
static int |
getIntAttr(Attributes attrs,
String attrId,
int def)
Return int value of attribute named attrId in attrs, or def if it is not present. |
static Rdn |
getRDN(String rdnStr)
Return RDN containing both attribute name and value for LDAP name component, accounting for RDN quoting rules and also extra flexible SimpleLdapName support. |
static Rdn |
getRDN(String rdnStr,
boolean deepest)
Return both attribute name and value for LDAP name component, accounting for RDN quoting rules, deepest controls whether most deeply nested RDN is requested. |
static Rdn |
getRDN(String rdnStr,
String attrId,
boolean deepest)
Same as getRDN(String), but look for and return user specified RDN component in a DN identified by attrId. |
static String |
getRDNString(String attrId,
String attrValue)
Create an RDN (Relative Distinguished Name) using the provided attrId, and applying
RFC 2253 quoting rules to the provided attrValue. |
static String |
getRDNString(String attrId,
String attrValue,
boolean composite)
|
static String |
getRDNString(String attrId,
String attrValue,
boolean fullDn,
boolean trim)
Deprecated. Rather than using the trim parameter, a better approach is to put the MetaDataDefs.MD_IS_TRIM_REQUIRED metadata
setting on any naming attributes which require trimming. |
static String |
getStrAttr(Attributes attrs,
String attrId,
String def)
Return value of attribute named attrId in attrs as a string, or def if it is not present. |
static String |
getValueCommaList(Attribute attr)
|
static String |
getValueList(Attribute attr)
|
static String |
getValueList(Attribute attr,
String sep,
String quote)
|
static boolean |
isAttributeRequested(String[] attrIds,
String attr)
|
static boolean |
isAttributeRequested(String[] attrIds,
String attr,
boolean ignoreCase)
Returns true if the 'attr' is contained within the 'attrIds'. |
static boolean |
isAttrIdInList(String ldapAttrId,
List<String> attrIdList)
|
static boolean |
isExistanceAttrs(String[] attrIds)
Test if attrIds corresponds to TEST_EXISTANCE_ATTRS |
static boolean |
isLdapSpecAttr(String attrId)
|
static boolean |
isObjectClass(String attrId)
|
static String |
joinAttrs(Attributes attrs,
String sep,
String[] joinAttrIds)
Joins the values of the attribute ids named in joinAttrIds, within attrs, separated by sep. |
static void |
main(String[] args)
|
static void |
mergeAttribute(Attribute attr,
Attribute deltaAttr)
|
static void |
mergeAttributes(Attributes origAttrs,
Attributes newAttrs)
|
static Attribute |
modifyAttribute(Attribute attr,
ModificationItem item)
Handle applying item to attr, which it
targets. |
static Attributes |
modifyAttributes(Attributes attrs,
ModificationItem[] items)
Handle applying the provided items to
attrs. |
static String |
normalize(String s)
The ADS codec converts all strings to lowercase. |
static Attribute |
normalizeAttrValueCase(Attribute attr,
boolean lowercase)
Normalizes the case of all attribute values in an attribute to either lower or upper |
static Attribute |
normalizeRdnCaseInAttr(Attribute attr,
boolean lowerCase)
Normalizes the case of all RDNs in a DN to either lower or upper. |
static Name |
normalizeRdnCaseInDn(Name ldapDn,
boolean lowerCase)
Change the case of all RDNs in a DN to either lower or upper Expects an instance of LdapName or SimpleLdapName otherwise throws InvalidNameException |
static String |
normalizeRdnCaseInDn(String value,
boolean lowerCase)
Change the case of all RDNs in a DN to either lower or upper, String DN is expected to be parseable as LdapName. |
static String |
removeAttrValue(Attribute attrToUpdate,
String value)
Needed for cases like where CA directory is queried for groups matching '(member=myDn)' but then returned group.member value contains myDn with a different case (ie searched for cn=BLB,ou=LOFBE01,ou=eTrust Admin,o=democorp,c=AU and resulting DN considered to match was
cn=BLB,ou=LOFBE01,ou=eTrust Admin,o=DEMOCORP,c=AU. |
static String |
searchControlsToString(SearchControls sc)
Simply wraps JNDIUtil.searchControlsToString(SearchControls) to make life easier for scripts and code in general by avoiding import. |
static void |
setAttrValue(Attribute attr,
Object val)
|
static void |
setAttrValueList(Attribute attr,
List vals)
|
static void |
setDefensiveLimits(SearchControls searchControls)
Lotus Notes Directory (LND) seems to treat countLimit=0 as countLimit=1, so we'll program defensively. |
static String |
unescapeCompositeName(String compName)
Does reverse of escaping rules described in CompositeName, required as JNDI client returns
composite names for search results. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String NOT_SHOWN
public static final String LDAP_OBJECT_CLASS
public static final String[] LDAP_OBJECT_CLASS_ARR
public static final String LDAP_OBJECT_CLASS_OID
LDAP_OBJECT_CLASS.
public static final String LDAP_DN_ONLY_OID
public static final String LDAP_USER_ATTR_SPEC
public static final String LDAP_OP_ATTR_SPEC
public static final String LDAP_REF_ATTR
public static final String TOP_OBJECT_CLASS
public static final String[] TEST_EXISTANCE_ATTRS
isExistanceAttrs(String[])
| Constructor Detail |
|---|
public LdapUtil()
| Method Detail |
|---|
public static void checkAttrsValid(Logger log,
Object name,
Attributes attrs,
boolean strict)
throws NamingException
NamingException
public static void checkAttrsNotNull(Logger log,
Object name,
Attributes attrs,
boolean strict)
throws NamingException
NamingException
public static void checkAttrsValid(Logger log,
Object name,
Attributes attrs)
throws NamingException
NamingException
public static String[] getAttributeValues(Attribute attr,
boolean lowercase)
public static String[] getAttributeValues(Attribute attr)
public static List getAttributeValueList(Attribute attr)
getAttributeValueList(Attribute, boolean) with toString=false.
public static List<String> getAttributeIds(Attributes attrs)
public static List<String> getAttributeIds(ModificationItem[] items)
public static Attributes getAttributes(ModificationItem[] items)
@NotNull
public static List getAttributeValueList(Attribute attr,
boolean toString)
public static Attribute createAttributeFromValue(String attrId,
Object val)
public static void setAttrValue(Attribute attr,
Object val)
public static Attribute createAttributeFromValueList(String attrId,
List vals)
public static void setAttrValueList(Attribute attr,
List vals)
public static void addAttributeValues(@NotNull
Attribute attr,
@Nullable
Collection vals,
boolean toString)
public static void addAttributeValues(@NotNull
Attribute attr,
@Nullable
Collection vals)
addAttributeValues(Attribute, Collection, boolean) with toString=false.
public static void mergeAttribute(Attribute attr,
Attribute deltaAttr)
throws NamingException
NamingException
public static boolean allAttributesExist(Attributes attrs,
Collection<String> attrIds)
public static void setDefensiveLimits(SearchControls searchControls)
public static boolean isAttrIdInList(String ldapAttrId,
List<String> attrIdList)
public static boolean isExistanceAttrs(String[] attrIds)
TEST_EXISTANCE_ATTRS
public static String[] ensureAttrIdInList(String[] attrIds,
String attrId)
public static String getAttrValue(Attributes attrs,
String attrId)
getStrAttr(Attributes, String, String)
public static String[] getAttrValues(Attributes attrs,
String attrId)
public static void addAttrValue(Attribute attr,
Object val)
public static void addAttrValue(Attributes attrs,
String attrId,
Object val)
public static String removeAttrValue(Attribute attrToUpdate,
String value)
throws NamingException
cn=BLB,ou=LOFBE01,ou=eTrust Admin,o=democorp,c=AU and resulting DN considered to match was
cn=BLB,ou=LOFBE01,ou=eTrust Admin,o=DEMOCORP,c=AU. Note that Sun and
ApacheDS implementations of Attribute.remove(Object) don't ignore case, hence the
need for this method to handle the described case.
attrToUpdate - Attribute which should have a value removed.value - Value to remove.
NamingException
public static String getValueList(Attribute attr,
String sep,
String quote)
public static String getValueCommaList(Attribute attr)
public static String getValueList(Attribute attr)
public static Attribute computeAddedDelta(Attribute currValue,
Attribute newValue)
currValue in order for it to
match newValue.
currValue - Current value.newValue - Desired value.
public static Attribute computeDeletedDelta(Attribute currValue,
Attribute newValue)
currValue in order for it to
match newValue.
currValue - Current value.newValue - Desired value.
public static boolean isObjectClass(String attrId)
public static boolean isLdapSpecAttr(String attrId)
public static String getAttributeNameFromRDN(String rdnStr)
throws InvalidNameException
var=val component of an
LDAP JNDI Name, accounting for RDN quoting rules.
InvalidNameException
public static String getAttributeValueFromRDN(String rdnStr)
throws InvalidNameException
var=val component of an
LDAP JNDI Name, accounting for RDN quoting rules.
InvalidNameException
public static String getAttributeValueFromRDN(String rdnStr,
String attrId,
boolean deepest)
throws InvalidNameException
var=val component of an
LDAP JNDI Name, accounting for RDN quoting rules but look for
user specified RDN name match.
InvalidNameException
public static Rdn getRDN(String rdnStr)
throws InvalidNameException
SimpleLdapName support.
InvalidNameException
public static Rdn getRDN(String rdnStr,
boolean deepest)
throws InvalidNameException
InvalidNameException
public static Rdn getRDN(String rdnStr,
String attrId,
boolean deepest)
throws InvalidNameException
InvalidNameException
public static String getRDNString(String attrId,
String attrValue,
boolean composite)
@Deprecated
public static String getRDNString(String attrId,
String attrValue,
boolean fullDn,
boolean trim)
MetaDataDefs.MD_IS_TRIM_REQUIRED metadata
setting on any naming attributes which require trimming.
attrId, and applying
RFC 2253 quoting rules to the provided attrValue. Also applies the same quoting rules
to attrId to handle connectors using more flexible SimpleLdapName which will
never result in changes for RFC 2253 case. It is very important that connectors
create RDNs using this method rather then trying to do a simple concatenation themselves, due to the
need to escape attrValue (and possibly attrId)!
attrId - Attribute identifier to be used in RDN.attrValue - Value to be used in RDN (escaping may be required)fullDn - Whether the value is a full DN or an RDNtrim - Flag to determine if trimming of the value should be performed
public static boolean dnStartsWith(Name name,
Name subName,
boolean caseSensitive)
name - the long DNsubName - the sub DNcaseSensitive - is case sensitive?
public static String getRDNString(String attrId,
String attrValue)
attrId, and applying
RFC 2253 quoting rules to the provided attrValue. It is very important that connectors
create RDNs using this method rather then trying to do a simple concatenation themselves, due to the
need to escape attrValue!
attrId - Attribute identifier to be used in RDN.attrValue - Value to be used in RDN (escaping may be required)
public static String normalize(String s)
public static String getDeepestRDN(String dn)
public static String extractDeepestRdnValue(String dn)
dn - DN to extract from
public static String appendNameComponent(String baseName,
String addComponent)
public static void mergeAttributes(Attributes origAttrs,
Attributes newAttrs)
public static Attribute copyAttribute(String newId,
Attribute attr)
attr with a new id, if newId is null then attr's id will be used. Returns null if attr==null.
public static Attribute modifyAttribute(Attribute attr,
ModificationItem item)
throws NamingException
item to attr, which it
targets.
NamingException
public static Attributes modifyAttributes(Attributes attrs,
ModificationItem[] items)
throws NamingException
items to
attrs.
NamingException
public static Attributes getAttributes(Attributes attrs,
String[] ldapAttrIds)
throws NamingException
NamingException
public static String getAttrFromDN(Name baseName,
String attrId)
baseName - attrId -
public static boolean isAttributeRequested(String[] attrIds,
String attr,
boolean ignoreCase)
attrIds - attr -
public static boolean isAttributeRequested(String[] attrIds,
String attr)
isAttributeRequested(String[], String, boolean) with false as the
last argument.
public static Attributes deepCloneAttributes(Attributes attrs)
throws NamingException
NamingExceptionpublic static SearchControls cloneSearchControls(SearchControls sc)
public static String searchControlsToString(SearchControls sc)
JNDIUtil.searchControlsToString(SearchControls) to make life easier for scripts and code in general by avoiding import.
public static String escapeNonAscii(String input)
public static String filterEscape(String val)
JNDIUtil.filterEscape(String) to make life easier for scripts and code in general by avoiding import,
and also calls escapeNonAscii(String).
public static String escapeCompositeName(String compName)
CompositeName.
eg. cn=foo/bar to be escaped to be "cn=foo/bar"
to avoid it to be interpreted as a composite name consisting of
"foo" and "bar" otherwise.
compName - Composite name to be escaped.
compNamepublic static String unescapeCompositeName(String compName)
CompositeName, required as JNDI client returns
composite names for search results.
Note that unescaping a composite name which is not been escaped is considered
an error and will return null
compName - String representation composite name to be unescaped.
compNamepublic static void main(String[] args)
public static int getIntAttr(Attributes attrs,
String attrId,
int def)
public static String getStrAttr(Attributes attrs,
String attrId,
String def)
getAttrValue(Attributes, String)
public static String joinAttrs(Attributes attrs,
String sep,
String[] joinAttrIds)
throws NamingException
NamingException
public static Name normalizeRdnCaseInDn(Name ldapDn,
boolean lowerCase)
throws InvalidNameException
ldapDn - lowerCase -
InvalidNameException
public static String normalizeRdnCaseInDn(String value,
boolean lowerCase)
throws InvalidNameException
value - lowerCase -
InvalidNameException
public static Attribute normalizeRdnCaseInAttr(Attribute attr,
boolean lowerCase)
throws NamingException
attr - lowerCase -
NamingException
public static Attribute normalizeAttrValueCase(Attribute attr,
boolean lowercase)
throws NamingException
attr - lowercase -
NamingException
public static String appendCompositeNameComponent(Name parentDn,
String namingAttr,
String attrValue)
throws InvalidNameException
parentDn - namingAttr - attrValue -
InvalidNameException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||