|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.jndi.ldap.obj.GroupOfNames
public class GroupOfNames
A representation of the LDAP groupOfNames object class. This is a static group: its members are listed in the group's member LDAP attribute.
Note that when a GroupOfNames object is created by the application
program then most of its methods throw IllegalStateException
until the program binds the object in the directory. However, when a
GroupOfNames object is returned to the application program then the
object is already bound in the directory and its methods function normally.
A GroupOfNames instance is not synchronized against concurrent multithreaded access. Multiple threads trying to access and modify a GroupOfNames should lock the object.
In order to bind a GroupOfNames object in the directory, the following LDAP object class definition (RFC 2256) must be supported in the directory schema:
( 2.5.6.9 NAME 'groupOfNames' SUP top STRUCTURAL MUST ( member $ cn ) MAY ( businessCategory $ seeAlso $ owner $ ou $ o $ description ) )See
DirContext.bind
for details on binding an object in the directory.
The following code sample shows how the class may be used:
// set the java.naming.factory.object property env.put(Context.OBJECT_FACTORIES, "com.sun.jndi.ldap.obj.LdapGroupFactory"); // set the java.naming.factory.state property env.put(Context.STATE_FACTORIES, "com.sun.jndi.ldap.obj.LdapGroupFactory"); // create an initial context using the supplied environment properties DirContext ctx = new InitialDirContext(env); // create a set of members Set members = new HashSet(); members.add("cn=bill,ou=people"); members.add("cn=ben,ou=people"); members.add("cn=sysadmins,ou=groups"); Group administrators = new GroupOfNames(members); // bind the group in the directory ctx.bind("cn=administrators,ou=groups", administrators); // list all of the group's members listMembers(administrators); ... // list the members of a group (subgroups are expanded, by default) void listMembers(Group group) { for (Enumeration members = group.members(); members.hasMoreElements(); ) { Object object = members.nextElement(); if (object instanceof Group) { System.out.println("+" + ((Group) object).getName()); } else if (object instanceof Principal) { System.out.println(" " + ((Principal) object).getName()); } } }
Nested Class Summary | |
---|---|
(package private) class |
GroupOfNames.Members
The members of a static group. |
Field Summary | |
---|---|
private javax.naming.directory.Attributes |
attributes
|
private static javax.naming.directory.SearchControls |
BASE_SEARCH_NO_ATTRS
|
private javax.naming.directory.DirContext |
bindCtx
|
private java.lang.String |
bindDN
|
private javax.naming.Name |
bindName
|
private javax.naming.directory.DirContext |
ctx
|
private static boolean |
debug
|
private java.util.Hashtable |
env
|
private static java.lang.String |
EXPAND_GROUP
|
private boolean |
expandGroup
|
private java.lang.Object[] |
filterArgs
|
private java.lang.String |
groupDN
|
private static java.lang.String |
MEMBER_ATTR_ID
|
private static java.lang.String |
MEMBER_FILTER_EXPR
|
private javax.naming.directory.Attribute |
memberAttr
|
private java.lang.String |
memberAttrId
|
private java.lang.String |
memberFilterExpr
|
private javax.naming.directory.ModificationItem[] |
modification
|
private javax.naming.Name |
name
|
private static java.lang.String |
OBJECT_CLASS
|
private static javax.naming.directory.Attribute |
OBJECT_CLASS_ATTR
|
private boolean |
objectIsBound
|
private javax.naming.directory.DirContext |
rootCtx
|
Constructor Summary | |
---|---|
GroupOfNames()
Create an empty group object. |
|
GroupOfNames(javax.naming.directory.Attribute objectClass,
java.lang.String memberAttrId,
java.lang.String memberFilterExpr,
java.util.Set members)
Create a group object. |
|
GroupOfNames(javax.naming.directory.Attribute objectClass,
java.lang.String memberAttrId,
java.lang.String memberFilterExpr,
java.util.Set members,
java.lang.String groupDN,
javax.naming.directory.DirContext ctx,
javax.naming.Name name,
java.util.Hashtable env,
javax.naming.directory.Attributes attributes)
Create a group object from its entry in the directory. |
|
GroupOfNames(java.util.Set members)
Create a group object with an initial set of members. |
Method Summary | |
---|---|
boolean |
addMember(java.security.Principal member)
Adds a member to the group. |
boolean |
addMember(java.lang.String dn)
Adds a member to the group. |
void |
close()
Releases the naming context created by this group. |
(package private) static java.util.Hashtable |
generateRootContextProperties(java.util.Hashtable env)
|
(package private) javax.naming.directory.Attributes |
getAttributes()
Retrieves the group's attributes. |
java.lang.String |
getName()
Retrieves the distinguished name of the group. |
(package private) static java.lang.Object |
getObjectInstance(java.lang.String groupDN,
javax.naming.directory.DirContext ctx,
javax.naming.Name name,
java.util.Hashtable env,
javax.naming.directory.Attributes attributes)
Create a group object from its entry in the directory. |
private void |
initializeBoundState(java.lang.String groupDN,
javax.naming.directory.DirContext ctx,
javax.naming.Name name,
java.util.Hashtable env,
javax.naming.directory.Attributes attributes)
|
private void |
initializeState(javax.naming.directory.Attribute objectClass,
java.lang.String memberAttrId,
java.lang.String memberFilterExpr,
java.util.Set members)
|
private boolean |
isBound()
|
boolean |
isMember(java.security.Principal member)
Checks if the supplied name is a member of the group. |
boolean |
isMember(java.lang.String dn)
Checks if the supplied name is a member of the group. |
private boolean |
isSubgroupMember(java.lang.String dn)
|
(package private) static boolean |
matches(javax.naming.directory.Attribute objectClass)
Determines whether the supplied LDAP objectClass attribute matches that of the group. |
java.util.Enumeration |
members()
Returns the members of the group. |
private boolean |
modifyMember(java.lang.String member,
int mod_op)
|
boolean |
removeMember(java.security.Principal member)
Removes a member from the group. |
boolean |
removeMember(java.lang.String dn)
Removes a member from the group. |
(package private) void |
setName(java.lang.String groupDN,
javax.naming.directory.DirContext ctx,
javax.naming.Name name)
Sets the distinguished name of the group. |
java.lang.String |
toString()
Creates a string representation of the group. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.security.Principal |
---|
equals, hashCode |
Field Detail |
---|
private static final boolean debug
private static final java.lang.String OBJECT_CLASS
private static final java.lang.String MEMBER_ATTR_ID
private static final java.lang.String MEMBER_FILTER_EXPR
private static final java.lang.String EXPAND_GROUP
private static final javax.naming.directory.Attribute OBJECT_CLASS_ATTR
private static final javax.naming.directory.SearchControls BASE_SEARCH_NO_ATTRS
private boolean objectIsBound
private boolean expandGroup
private javax.naming.directory.Attributes attributes
private javax.naming.directory.Attribute memberAttr
private java.lang.String memberAttrId
private java.lang.String memberFilterExpr
private java.lang.Object[] filterArgs
private javax.naming.directory.ModificationItem[] modification
private java.lang.String groupDN
private java.lang.String bindDN
private javax.naming.directory.DirContext rootCtx
private javax.naming.directory.DirContext ctx
private javax.naming.directory.DirContext bindCtx
private javax.naming.Name name
private javax.naming.Name bindName
private java.util.Hashtable env
Constructor Detail |
---|
public GroupOfNames()
Note that the newly constructed object does not represent a group in
the directory until it is bound by using
DirContext.bind
.
public GroupOfNames(java.util.Set members)
Note that the newly constructed object does not represent a group in
the directory until it is bound by using
DirContext.bind
.
members
- The set of initial members. It may be null.
Each element is of class String
or
Principal
.GroupOfNames(javax.naming.directory.Attribute objectClass, java.lang.String memberAttrId, java.lang.String memberFilterExpr, java.util.Set members)
GroupOfUniqueNames
.
objectClass
- The LDAP objectClass attribute.memberAttrId
- The LDAP attribute ID which identifies the members.memberfilterExpr
- The filter expression used to find a member.members
- The set of initial members. It may be null.GroupOfNames(javax.naming.directory.Attribute objectClass, java.lang.String memberAttrId, java.lang.String memberFilterExpr, java.util.Set members, java.lang.String groupDN, javax.naming.directory.DirContext ctx, javax.naming.Name name, java.util.Hashtable env, javax.naming.directory.Attributes attributes)
GroupOfUniqueNames
.
objectClass
- The LDAP objectClass attribute.memberAttrId
- The LDAP attribute ID which identifies the members.memberfilterExpr
- The filter expression used to find a member.members
- The set of initial members. It may be null.groupDN
- The group's distinguished name.name
- The group's LDAP distinguished name.ctx
- An LDAP context.name
- The group's name relative to the context.env
- The context's environment properties.attributes
- The group's LDAP attributes.Method Detail |
---|
static java.lang.Object getObjectInstance(java.lang.String groupDN, javax.naming.directory.DirContext ctx, javax.naming.Name name, java.util.Hashtable env, javax.naming.directory.Attributes attributes)
LdapGroupFactory
.
groupDN
- The group's distinguished name.ctx
- An LDAP context.name
- The group's name relative to the context.env
- The context's environment properties.attributes
- The group's LDAP attributes.
public boolean addMember(java.security.Principal member)
addMember
in interface java.security.acl.Group
member
- The name of the member to be added.
java.lang.IllegalStateException
- The exception is thrown if the
group does not represent a group in the directory.public boolean addMember(java.lang.String dn) throws javax.naming.NamingException
dn
- The distinguished name (RFC 2253) of the member to be added.
javax.naming.NamingException
- The exception is thrown if an error occurs while
performing LDAP modify.
java.lang.IllegalStateException
- The exception is thrown if the
group does not represent a group in the directory.public boolean isMember(java.security.Principal member)
By default, subgroups are also checked. As subgroup expansion is potentially an expensive activity the feature may be disabled by setting the environment property "com.sun.jndi.ldap.obj.expandGroup" to the string value "false".
isMember
in interface java.security.acl.Group
member
- The name of the member to be checked.
java.lang.IllegalStateException
- The exception is thrown if the
group does not represent a group in the directory.public boolean isMember(java.lang.String dn) throws javax.naming.NamingException
By default, subgroups are also checked. As subgroup expansion is potentially an expensive activity the feature may be disabled by setting the environment property "com.sun.jndi.ldap.obj.expandGroup" to the string value "false".
dn
- The distinguished name (RFC 2253) of the member to be checked.
javax.naming.NamingException
- The exception is thrown if an error occurs while
performing LDAP search.
java.lang.IllegalStateException
- The exception is thrown if the
group does not represent a group in the directory.public java.util.Enumeration members()
By default, subgroups and their members are also included. As subgroup expansion is potentially an expensive activity the feature may be disabled by setting the environment property "com.sun.jndi.ldap.obj.expandGroup" to the string value "false". When the feature is disabled only the group's direct members are returned.
members
in interface java.security.acl.Group
LdapGroupFactory
object factory is active
then each element in the enumeration is of class
Group
or
Principal
. However, when additional
object factories are active then the enumeration may contain
elements of a different class.
java.lang.IllegalStateException
- The exception is thrown if the
group does not represent a group in the directory.public boolean removeMember(java.security.Principal member)
removeMember
in interface java.security.acl.Group
member
- The name of the member to be removed.
java.lang.IllegalStateException
- The exception is thrown if the
group does not represent a group in the directory.public boolean removeMember(java.lang.String dn) throws javax.naming.NamingException
dn
- The distinguished name (RFC 2253) of the member to be removed.
javax.naming.NamingException
- The exception is thrown if an error occurs while
performing LDAP modify.
java.lang.IllegalStateException
- The exception is thrown if the
group does not represent a group in the directory.public java.lang.String getName()
getName
in interface java.security.Principal
java.lang.IllegalStateException
- The exception is thrown if the
group does not represent a group in the directory.void setName(java.lang.String groupDN, javax.naming.directory.DirContext ctx, javax.naming.Name name)
LdapGroupFactory
.
groupDN
- The group's distinguished name.ctx
- An LDAP context.name
- The group's name relative to the context.public java.lang.String toString()
toString
in interface java.security.Principal
toString
in class java.lang.Object
BasicAttributes.toString()
for details. The name is omitted if the group is not bound in
the directory and null is returned if no attributes are
available.javax.naming.directory.Attributes getAttributes()
LdapGroupFactory
.
static boolean matches(javax.naming.directory.Attribute objectClass)
objectClass
- The non-null objectClass attribute to check against.
private boolean isBound()
public void close() throws javax.naming.NamingException
javax.naming.NamingException
- The exception is thrown if a problem is
encountered while closing the naming context.private void initializeState(javax.naming.directory.Attribute objectClass, java.lang.String memberAttrId, java.lang.String memberFilterExpr, java.util.Set members)
private void initializeBoundState(java.lang.String groupDN, javax.naming.directory.DirContext ctx, javax.naming.Name name, java.util.Hashtable env, javax.naming.directory.Attributes attributes)
private boolean modifyMember(java.lang.String member, int mod_op) throws javax.naming.NamingException
javax.naming.NamingException
private boolean isSubgroupMember(java.lang.String dn) throws javax.naming.NamingException
javax.naming.NamingException
static java.util.Hashtable generateRootContextProperties(java.util.Hashtable env)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |