|
Spring LDAP | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.ldap.core.DirContextAdapter
public class DirContextAdapter
Adapter that implements the interesting methods of the DirContext interface.
In particular it contains utility methods for getting and setting attributes.
Using the
DefaultDirObjectFactory
in your
ContextSource
(which is the default) you will receive instances
of this class from searches and lookups. This can be particularly useful when
updating data, since this class implements
AttributeModificationsAware
, providing a
getModificationItems()
method. When in update mode, an object of
this class keeps track of the changes made to its attributes, making them
available as an array of ModificationItem
objects, suitable as
input to LdapTemplate.modifyAttributes(DirContextOperations)
.
This class is aware of the specifics of Name
instances with regards
to equality when working with attribute values. This comes in very handy
when working with e.g. security groups and modifications of them. If
Name
instances are supplied to one of the Attribute manipulation
methods (e.g. addAttributeValue(String, Object)
,
removeAttributeValue(String, Object)
, setAttributeValue(String, Object)
,
or setAttributeValues(String, Object[])
), the produced modifications
will be calculated using Name
equality. This means that if an the member
has a value of "cn=John Doe,ou=People"
, and we call
addAttributeValue("member", LdapUtils.newLdapName("CN=John Doe,OU=People")
,
this will not be considered a modification since the two DN
strings represent the same distinguished name (case and spacing between attributes is
disregarded).
Note that this is not a complete implementation of DirContext. Several methods are not relevant for the intended usage of this class, so they throw UnsupportOperationException.
setAttributeValue(String, Object)
,
setAttributeValues(String, Object[])
,
getStringAttribute(String)
,
getStringAttributes(String)
,
getObjectAttribute(String)
,
addAttributeValue(String, Object)
,
removeAttributeValue(String, Object)
,
setUpdateMode(boolean)
,
isUpdateMode()
Field Summary |
---|
Fields inherited from interface javax.naming.directory.DirContext |
---|
ADD_ATTRIBUTE, REMOVE_ATTRIBUTE, REPLACE_ATTRIBUTE |
Fields inherited from interface javax.naming.Context |
---|
APPLET, AUTHORITATIVE, BATCHSIZE, DNS_URL, INITIAL_CONTEXT_FACTORY, LANGUAGE, OBJECT_FACTORIES, PROVIDER_URL, REFERRAL, SECURITY_AUTHENTICATION, SECURITY_CREDENTIALS, SECURITY_PRINCIPAL, SECURITY_PROTOCOL, STATE_FACTORIES, URL_PKG_PREFIXES |
Constructor Summary | |
---|---|
|
DirContextAdapter()
Default constructor. |
|
DirContextAdapter(Attributes attrs,
Name dn)
Create a new adapter from the supplied attributes and dn. |
|
DirContextAdapter(Attributes attrs,
Name dn,
Name base)
Create a new adapter from the supplied attributes, dn, and base. |
|
DirContextAdapter(Attributes attrs,
Name dn,
Name base,
String referralUrl)
Create a new adapter from the supplied attributes, dn, base, and referral url. |
protected |
DirContextAdapter(DirContextAdapter master)
Constructor for cloning an existing adapter. |
|
DirContextAdapter(Name dn)
Create a new adapter from the supplied dn. |
|
DirContextAdapter(String dnString)
Create a new DirContextAdapter from the supplied DN String. |
Method Summary | |
---|---|
void |
addAttributeValue(String name,
Object value)
Add a value to the Attribute with the specified name. |
void |
addAttributeValue(String name,
Object value,
boolean addIfDuplicateExists)
Add a value to the Attribute with the specified name. |
Object |
addToEnvironment(String propName,
Object propVal)
|
boolean |
attributeExists(String name)
Check if an Object attribute exists, regardless of whether it has a value or not. |
void |
bind(Name name,
Object obj)
|
void |
bind(Name name,
Object obj,
Attributes attrs)
|
void |
bind(String name,
Object obj)
|
void |
bind(String name,
Object obj,
Attributes attrs)
|
void |
close()
|
Name |
composeName(Name name,
Name prefix)
|
String |
composeName(String name,
String prefix)
|
Context |
createSubcontext(Name name)
|
DirContext |
createSubcontext(Name name,
Attributes attrs)
|
Context |
createSubcontext(String name)
|
DirContext |
createSubcontext(String name,
Attributes attrs)
|
void |
destroySubcontext(Name name)
|
void |
destroySubcontext(String name)
|
boolean |
equals(Object o)
|
protected boolean |
exists(Attribute attr)
Checks if an entry has a specific attribute. |
protected boolean |
exists(String attrId)
Checks if the attribute exists in this entry, either it was read or it has been added and update() has been called. |
Attributes |
getAttributes()
Get all attributes. |
Attributes |
getAttributes(Name name)
|
Attributes |
getAttributes(Name name,
String[] attrIds)
|
Attributes |
getAttributes(String name)
|
Attributes |
getAttributes(String name,
String[] attrIds)
|
SortedSet<String> |
getAttributeSortedStringSet(String name)
Get all String values of the attribute as a SortedSet . |
Name |
getDn()
Returns the DN relative to the base path. |
Hashtable<?,?> |
getEnvironment()
|
ModificationItem[] |
getModificationItems()
Creates an array of which attributes have been changed, added or removed since the initialization of this object. |
String |
getNameInNamespace()
|
NameParser |
getNameParser(Name name)
|
NameParser |
getNameParser(String name)
|
String[] |
getNamesOfModifiedAttributes()
Creates a String array of the names of the attributes which have been changed. |
Object |
getObjectAttribute(String name)
Get the value of an Object attribute. |
Object[] |
getObjectAttributes(String name)
Get all values of an Object attribute. |
String |
getReferralUrl()
If this instance results from a referral, this method returns the url of the referred server. |
DirContext |
getSchema(Name name)
|
DirContext |
getSchema(String name)
|
DirContext |
getSchemaClassDefinition(Name name)
|
DirContext |
getSchemaClassDefinition(String name)
|
String |
getStringAttribute(String name)
Get the value of a String attribute. |
String[] |
getStringAttributes(String name)
Get all values of a String attribute. |
int |
hashCode()
|
boolean |
isReferral()
Checks whether this instance results from a referral. |
boolean |
isUpdateMode()
Gets the update mode. |
NamingEnumeration<NameClassPair> |
list(Name name)
|
NamingEnumeration<NameClassPair> |
list(String name)
|
NamingEnumeration<Binding> |
listBindings(Name name)
|
NamingEnumeration<Binding> |
listBindings(String name)
|
Object |
lookup(Name name)
|
Object |
lookup(String name)
|
Object |
lookupLink(Name name)
|
Object |
lookupLink(String name)
|
void |
modifyAttributes(Name name,
int modOp,
Attributes attrs)
|
void |
modifyAttributes(Name name,
ModificationItem[] mods)
|
void |
modifyAttributes(String name,
int modOp,
Attributes attrs)
|
void |
modifyAttributes(String name,
ModificationItem[] mods)
|
void |
rebind(Name name,
Object obj)
|
void |
rebind(Name name,
Object obj,
Attributes attrs)
|
void |
rebind(String name,
Object obj)
|
void |
rebind(String name,
Object obj,
Attributes attrs)
|
void |
removeAttributeValue(String name,
Object value)
Remove a value from the Attribute with the specified name. |
Object |
removeFromEnvironment(String propName)
|
void |
rename(Name oldName,
Name newName)
|
void |
rename(String oldName,
String newName)
|
NamingEnumeration<SearchResult> |
search(Name name,
Attributes matchingAttributes)
|
NamingEnumeration<SearchResult> |
search(Name name,
Attributes matchingAttributes,
String[] attributesToReturn)
|
NamingEnumeration<SearchResult> |
search(Name name,
String filterExpr,
Object[] filterArgs,
SearchControls cons)
|
NamingEnumeration<SearchResult> |
search(Name name,
String filter,
SearchControls cons)
|
NamingEnumeration<SearchResult> |
search(String name,
Attributes matchingAttributes)
|
NamingEnumeration<SearchResult> |
search(String name,
Attributes matchingAttributes,
String[] attributesToReturn)
|
NamingEnumeration<SearchResult> |
search(String name,
String filterExpr,
Object[] filterArgs,
SearchControls cons)
|
NamingEnumeration<SearchResult> |
search(String name,
String filter,
SearchControls cons)
|
void |
setAttribute(Attribute attribute)
Set the supplied attribute. |
void |
setAttributeValue(String name,
Object value)
Set the with the name name to the value . |
void |
setAttributeValues(String name,
Object[] values)
Sets a multivalue attribute, disregarding the order of the values. |
void |
setAttributeValues(String name,
Object[] values,
boolean orderMatters)
Sets a multivalue attribute. |
void |
setDn(Name dn)
Set the dn of this entry. |
void |
setUpdateMode(boolean mode)
Sets the update mode. |
String |
toString()
|
void |
unbind(Name name)
|
void |
unbind(String name)
|
void |
update()
Update the attributes.This will mean that the getters ( getStringAttribute methods) will return the updated values,
and the modifications will be forgotten (i.e. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public DirContextAdapter()
public DirContextAdapter(String dnString)
dnString
- the DN string. Must be syntactically correct, or an
exception will be thrown.public DirContextAdapter(Name dn)
dn
- the dn.public DirContextAdapter(Attributes attrs, Name dn)
attrs
- the attributes.dn
- the dn.public DirContextAdapter(Attributes attrs, Name dn, Name base)
attrs
- the attributes.dn
- the dn.base
- the base name.public DirContextAdapter(Attributes attrs, Name dn, Name base, String referralUrl)
attrs
- the attributes.dn
- the dn.base
- the base.referralUrl
- the referral url (if this instance results from a
referral).protected DirContextAdapter(DirContextAdapter master)
master
- The adapter to be copied.Method Detail |
---|
public void setUpdateMode(boolean mode)
false
for a
new entry and true
for an existing entry that is being
updated.
mode
- Update mode.public boolean isUpdateMode()
AttributeModificationsAware.getModificationItems()
. The update
mode should be true
for a new entry and true
for an existing entry that is being updated.
isUpdateMode
in interface DirContextOperations
public String[] getNamesOfModifiedAttributes()
getNamesOfModifiedAttributes
in interface DirContextOperations
public ModificationItem[] getModificationItems()
getModificationItems
in interface AttributeModificationsAware
protected final boolean exists(Attribute attr)
attr
- the attribute to check.
protected final boolean exists(String attrId)
attrId
- id of the attribute to check.
public String getStringAttribute(String name)
null
will be returned.
getStringAttribute
in interface LdapDataEntry
name
- name of the attribute.
null
if
the attribute doesn't exist or if it exists but with no value.public Object getObjectAttribute(String name)
null
will be returned.
getObjectAttribute
in interface LdapDataEntry
name
- name of the attribute.
null
if the attribute doesn't exist or if it exists but with
no value.public boolean attributeExists(String name)
attributeExists
in interface LdapDataEntry
name
- name of the attribute
true
if the attribute exists, false
otherwisepublic void setAttributeValue(String name, Object value)
name
to the value
.
If the value is a Name
instance, equality for Distinguished
Names will be used for calculating attribute modifications.
setAttributeValue
in interface LdapDataEntry
name
- name of the attribute.value
- value to set the attribute to.public void addAttributeValue(String name, Object value)
Name
instance, equality for Distinguished
Names will be used for calculating attribute modifications.
addAttributeValue
in interface LdapDataEntry
name
- the name of the Attribute to which the specified value should
be added.value
- the Attribute value to add.public void addAttributeValue(String name, Object value, boolean addIfDuplicateExists)
addIfDuplicateExists
parameter controls the handling of duplicates. It false
,
this method makes sure that the there will be no duplicates of an added
value - it the value exists it will not be added again.
If the value is a Name
instance, equality for Distinguished
Names will be used for calculating attribute modifications.
addAttributeValue
in interface LdapDataEntry
name
- the name of the Attribute to which the specified value should
be added.value
- the Attribute value to add.addIfDuplicateExists
- true
will add the value
regardless of whether there is an identical value already, allowing for
duplicate attribute values; false
will not add the value if
it already exists.public void removeAttributeValue(String name, Object value)
Name
instance, equality for Distinguished
Names will be used for calculating attribute modifications.
removeAttributeValue
in interface LdapDataEntry
name
- the name of the Attribute from which the specified value
should be removed.value
- the value to remove.public void setAttributeValues(String name, Object[] values)
Name
instances, equality for Distinguished
Names will be used for calculating attribute modifications.
setAttributeValues
in interface LdapDataEntry
name
- The id of the attribute.values
- Attribute values.public void setAttributeValues(String name, Object[] values, boolean orderMatters)
Name
instances, equality for Distinguished
Names will be used for calculating attribute modifications.
setAttributeValues
in interface LdapDataEntry
name
- The id of the attribute.values
- Attribute values.orderMatters
- If true
, it will be changed even if data
was just reordered.public void update()
getStringAttribute
methods) will return the updated values,
and the modifications will be forgotten (i.e.
AttributeModificationsAware.getModificationItems()
will return an
empty array.
update
in interface DirContextOperations
public String[] getStringAttributes(String name)
getStringAttributes
in interface LdapDataEntry
name
- name of the attribute.
null
otherwise.public Object[] getObjectAttributes(String name)
getObjectAttributes
in interface LdapDataEntry
name
- name of the attribute.
null
otherwise.public SortedSet<String> getAttributeSortedStringSet(String name)
SortedSet
.
getAttributeSortedStringSet
in interface LdapDataEntry
name
- name of the attribute.
SortedSet
containing all values of the attribute,
or null
if the attribute does not exist.public void setAttribute(Attribute attribute)
attribute
- the attribute to set.public Attributes getAttributes()
getAttributes
in interface LdapDataEntry
public Attributes getAttributes(Name name) throws NamingException
getAttributes
in interface DirContext
NamingException
public Attributes getAttributes(String name) throws NamingException
getAttributes
in interface DirContext
NamingException
public Attributes getAttributes(Name name, String[] attrIds) throws NamingException
getAttributes
in interface DirContext
NamingException
public Attributes getAttributes(String name, String[] attrIds) throws NamingException
getAttributes
in interface DirContext
NamingException
public void modifyAttributes(Name name, int modOp, Attributes attrs) throws NamingException
modifyAttributes
in interface DirContext
NamingException
public void modifyAttributes(String name, int modOp, Attributes attrs) throws NamingException
modifyAttributes
in interface DirContext
NamingException
public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException
modifyAttributes
in interface DirContext
NamingException
public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException
modifyAttributes
in interface DirContext
NamingException
public void bind(Name name, Object obj, Attributes attrs) throws NamingException
bind
in interface DirContext
NamingException
public void bind(String name, Object obj, Attributes attrs) throws NamingException
bind
in interface DirContext
NamingException
public void rebind(Name name, Object obj, Attributes attrs) throws NamingException
rebind
in interface DirContext
NamingException
public void rebind(String name, Object obj, Attributes attrs) throws NamingException
rebind
in interface DirContext
NamingException
public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException
createSubcontext
in interface DirContext
NamingException
public DirContext createSubcontext(String name, Attributes attrs) throws NamingException
createSubcontext
in interface DirContext
NamingException
public DirContext getSchema(Name name) throws NamingException
getSchema
in interface DirContext
NamingException
public DirContext getSchema(String name) throws NamingException
getSchema
in interface DirContext
NamingException
public DirContext getSchemaClassDefinition(Name name) throws NamingException
getSchemaClassDefinition
in interface DirContext
NamingException
public DirContext getSchemaClassDefinition(String name) throws NamingException
getSchemaClassDefinition
in interface DirContext
NamingException
public NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException
search
in interface DirContext
NamingException
public NamingEnumeration<SearchResult> search(String name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException
search
in interface DirContext
NamingException
public NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes) throws NamingException
search
in interface DirContext
NamingException
public NamingEnumeration<SearchResult> search(String name, Attributes matchingAttributes) throws NamingException
search
in interface DirContext
NamingException
public NamingEnumeration<SearchResult> search(Name name, String filter, SearchControls cons) throws NamingException
search
in interface DirContext
NamingException
public NamingEnumeration<SearchResult> search(String name, String filter, SearchControls cons) throws NamingException
search
in interface DirContext
NamingException
public NamingEnumeration<SearchResult> search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException
search
in interface DirContext
NamingException
public NamingEnumeration<SearchResult> search(String name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException
search
in interface DirContext
NamingException
public Object lookup(Name name) throws NamingException
lookup
in interface Context
NamingException
public Object lookup(String name) throws NamingException
lookup
in interface Context
NamingException
public void bind(Name name, Object obj) throws NamingException
bind
in interface Context
NamingException
public void bind(String name, Object obj) throws NamingException
bind
in interface Context
NamingException
public void rebind(Name name, Object obj) throws NamingException
rebind
in interface Context
NamingException
public void rebind(String name, Object obj) throws NamingException
rebind
in interface Context
NamingException
public void unbind(Name name) throws NamingException
unbind
in interface Context
NamingException
public void unbind(String name) throws NamingException
unbind
in interface Context
NamingException
public void rename(Name oldName, Name newName) throws NamingException
rename
in interface Context
NamingException
public void rename(String oldName, String newName) throws NamingException
rename
in interface Context
NamingException
public NamingEnumeration<NameClassPair> list(Name name) throws NamingException
list
in interface Context
NamingException
public NamingEnumeration<NameClassPair> list(String name) throws NamingException
list
in interface Context
NamingException
public NamingEnumeration<Binding> listBindings(Name name) throws NamingException
listBindings
in interface Context
NamingException
public NamingEnumeration<Binding> listBindings(String name) throws NamingException
listBindings
in interface Context
NamingException
public void destroySubcontext(Name name) throws NamingException
destroySubcontext
in interface Context
NamingException
public void destroySubcontext(String name) throws NamingException
destroySubcontext
in interface Context
NamingException
public Context createSubcontext(Name name) throws NamingException
createSubcontext
in interface Context
NamingException
public Context createSubcontext(String name) throws NamingException
createSubcontext
in interface Context
NamingException
public Object lookupLink(Name name) throws NamingException
lookupLink
in interface Context
NamingException
public Object lookupLink(String name) throws NamingException
lookupLink
in interface Context
NamingException
public NameParser getNameParser(Name name) throws NamingException
getNameParser
in interface Context
NamingException
public NameParser getNameParser(String name) throws NamingException
getNameParser
in interface Context
NamingException
public Name composeName(Name name, Name prefix) throws NamingException
composeName
in interface Context
NamingException
public String composeName(String name, String prefix) throws NamingException
composeName
in interface Context
NamingException
public Object addToEnvironment(String propName, Object propVal) throws NamingException
addToEnvironment
in interface Context
NamingException
public Object removeFromEnvironment(String propName) throws NamingException
removeFromEnvironment
in interface Context
NamingException
public Hashtable<?,?> getEnvironment() throws NamingException
getEnvironment
in interface Context
NamingException
public void close() throws NamingException
close
in interface Context
NamingException
public String getNameInNamespace()
getNameInNamespace
in interface Context
getNameInNamespace
in interface DirContextOperations
public Name getDn()
getDn
in interface LdapDataEntry
getNameInNamespace()
public final void setDn(Name dn)
setDn
in interface DirContextOperations
dn
- the dn.public boolean equals(Object o)
equals
in class Object
public int hashCode()
hashCode
in class Object
public String toString()
toString
in class Object
public String getReferralUrl()
getReferralUrl
in interface DirContextOperations
ldap://localhost:389
, or the empty string if this is not a
referral.public boolean isReferral()
isReferral
in interface DirContextOperations
true
if this instance results from a referral,
false
otherwise.
|
Spring LDAP | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |