StaticGroup.java revision ea1068c292e9b341af6d6b563cd8988a96be20a9
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2008-2010 Sun Microsystems, Inc.
* Portions Copyright 2011-2015 ForgeRock AS
*/
/**
* A static group implementation, in which the DNs of all members are explicitly
* listed.
* <p>
* There are three variants of static groups:
* <ul>
* <li>one based on the {@code groupOfNames} object class: which stores the
* member list in the {@code member} attribute</li>
* <li>one based on the {@code groupOfEntries} object class, which also stores
* the member list in the {@code member} attribute</li>
* <li>one based on the {@code groupOfUniqueNames} object class, which stores
* the member list in the {@code uniqueMember} attribute.</li>
* </ul>
*/
{
/** The attribute type used to hold the membership list for this group. */
private AttributeType memberAttributeType;
/** The DN of the entry that holds the definition for this group. */
private DN groupEntryDN;
/** The set of the DNs of the members for this group. */
/** The list of nested group DNs for this group. */
/** Passed to the group manager to see if the nested group list needs to be refreshed. */
private ServerContext serverContext;
/**
* Creates an uninitialized static group. This is intended for internal use
* only, to allow {@code GroupManager} to dynamically create a group.
*/
public StaticGroup()
{
super();
}
/**
* Creates a new static group instance with the provided information.
*
* @param groupEntryDN The DN of the entry that holds the definition
* for this group.
* @param memberAttributeType The attribute type used to hold the membership
* list for this group.
* @param memberDNs The set of the DNs of the members for this
* group.
*/
private StaticGroup(ServerContext serverContext, DN groupEntryDN, AttributeType memberAttributeType,
{
super();
this.serverContext = serverContext;
this.groupEntryDN = groupEntryDN;
}
/** {@inheritDoc} */
{
// No additional initialization is required.
}
/** {@inheritDoc} */
public StaticGroup newInstance(ServerContext serverContext, Entry groupEntry) throws DirectoryException
{
// Determine whether it is a groupOfNames, groupOfEntries or
// groupOfUniqueNames entry. If not, then that's a problem.
ObjectClass groupOfUniqueNamesClass = DirectoryConfig.getObjectClass(OC_GROUP_OF_UNIQUE_NAMES_LC, true);
{
{
}
{
}
}
{
{
}
}
{
}
else
{
}
int membersCount = 0;
if (memberAttrList != null)
{
for (Attribute a : memberAttrList)
{
membersCount += a.size();
}
}
if (memberAttrList != null)
{
for (Attribute a : memberAttrList)
{
for (ByteString v : a)
{
try
{
}
catch (LocalizedIllegalArgumentException e)
{
logger.traceException(e);
}
}
}
}
return new StaticGroup(serverContext, groupEntry.getName(), someMemberAttributeType, someMemberDNs);
}
/** {@inheritDoc} */
public SearchFilter getGroupDefinitionFilter()
throws DirectoryException
{
// FIXME -- This needs to exclude enhanced groups once we have support for them.
"(&(|(objectClass=groupOfNames)(objectClass=groupOfUniqueNames)" +
"(objectClass=groupOfEntries))" +
"(!(objectClass=ds-virtual-static-group)))";
}
/** {@inheritDoc} */
{
// FIXME -- This needs to exclude enhanced groups once we have support for them.
{
return false;
}
{
{
return false;
}
return true;
}
{
{
return false;
}
return true;
}
{
return true;
}
else
{
return false;
}
}
/** {@inheritDoc} */
public DN getGroupDN()
{
return groupEntryDN;
}
/** {@inheritDoc} */
{
}
/** {@inheritDoc} */
public boolean supportsNestedGroups()
{
return true;
}
/** {@inheritDoc} */
{
try {
} catch (DirectoryException ex) {
}
return nestedGroups;
}
/** {@inheritDoc} */
{
synchronized (this)
{
{
LocalizableMessage msg = ERR_STATICGROUP_ADD_NESTED_GROUP_ALREADY_EXISTS.get(nestedGroupDN, groupEntryDN);
}
{
}
//Add it to the member DN list.
}
}
/** {@inheritDoc} */
{
synchronized (this)
{
{
}
{
}
//Remove it from the member DN list.
}
}
/** {@inheritDoc} */
{
{
return true;
}
{
return false;
}
else
{
{
{
return true;
}
}
}
return false;
}
/** {@inheritDoc} */
throws DirectoryException
{
}
/**
* Check if the group manager has registered a new group instance or removed a
* a group instance that might impact this group's membership list.
*/
private void reloadIfNeeded() throws DirectoryException
{
//Check if group instances have changed by passing the group manager
//the current token.
{
synchronized (this)
{
// Check if the group itself has been removed
} else if (thisGroup != this) {
while (memberList.hasMoreMembers())
{
try
{
}
catch (MembershipException ex)
{
// TODO: should we throw an exception there instead of silently fail ?
}
}
}
{
{
}
}
}
}
}
/** {@inheritDoc} */
{
}
/** {@inheritDoc} */
public MemberList getMembers(DN baseDN, SearchScope scope, SearchFilter filter) throws DirectoryException
{
{
}
}
/** {@inheritDoc} */
public boolean mayAlterMemberList()
{
return true;
}
/** {@inheritDoc} */
{
synchronized (this)
{
{
}
{
ERR_STATICGROUP_ADD_MEMBER_UPDATE_FAILED.get(userDN, groupEntryDN, modifyOperation.getErrorMessage()));
}
}
}
/** {@inheritDoc} */
{
synchronized (this)
{
{
LocalizableMessage message = ERR_STATICGROUP_REMOVE_MEMBER_NO_SUCH_MEMBER.get(userDN, groupEntryDN);
}
{
ERR_STATICGROUP_REMOVE_MEMBER_UPDATE_FAILED.get(userDN, groupEntryDN, modifyOperation.getErrorMessage()));
}
//If it is in the nested group list remove it.
}
}
}
/** {@inheritDoc} */
{
}
/**
* Convert the provided DN to a compact DN.
*
* @param dn
* The DN
* @return the compact representation of the DN
*/
{
}
/**
* Convert the provided compact DN to a DN.
*
* @param compactDn
* Compact representation of a DN
* @return the regular DN
*/
{
}
}