/*
* 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 2007-2008 Sun Microsystems, Inc.
* Portions Copyright 2014-2015 ForgeRock AS
*/
/**
* Registry for maintaining the set of registered base DN's, associated backends
* and naming context information.
*/
public class BaseDnRegistry {
/** The set of base DNs registered with the server. */
/** The set of private naming contexts registered with the server. */
/** The set of public naming contexts registered with the server. */
/**
* Indicates whether or not this base DN registry is in test mode.
* A registry instance that is in test mode will not modify backend
* objects referred to in the above maps.
*/
private boolean testOnly;
/**
* Registers a base DN with this registry.
*
* @param baseDN to register
* @param backend with which the base DN is associated
* @param isPrivate indicates whether or not this base DN is private
* @return list of error messages generated by registering the base DN
* that should be logged if the changes to this registry are
* committed to the server
* @throws DirectoryException if the base DN cannot be registered
*/
throws DirectoryException
{
// Check to see if the base DN is already registered with the server.
if (existingBackend != null)
{
}
// Check to see if the backend is already registered with the server for
// any other base DN(s). The new base DN must not have any hierarchical
// relationship with any other base Dns for the same backend.
{
{
{
}
}
}
// Check to see if the new base DN is subordinate to any other base DN
// already defined. If it is, then any other base DN(s) for the same
// backend must also be subordinate to the same base DN.
final Backend<?> superiorBackend = getSuperiorBackend(baseDN, otherBaseDNs, backend.getBackendID());
{
}
// Check to see if the new base DN should be the superior base DN for any
// other base DN(s) already defined.
{
{
{
break;
}
{
break;
}
}
}
// If we've gotten here, then the new base DN is acceptable. If we should
// actually apply the changes then do so now.
// Check to see if any of the registered backends already contain an
// entry with the DN specified as the base DN. This could happen if
// we're creating a new subordinate backend in an existing directory
// (e.g., moving the "ou=People,dc=example,dc=com" branch to its own
// backend when that data already exists under the "dc=example,dc=com"
// backend). This condition shouldn't prevent the new base DN from
// being registered, but it's definitely important enough that we let
// the administrator know about it and remind them that the existing
// backend will need to be reinitialized.
{
}
if (superiorBackend == null)
{
if (!testOnly)
{
}
if (isPrivate)
{
}
else
{
}
}
{
}
if (!testOnly)
{
for (Backend<?> b : subordinateBackends)
{
if (oldParentBackend != null)
{
}
}
}
{
}
return errors;
}
throws DirectoryException
{
{
{
{
{
}
}
break;
}
}
return superiorBackend;
}
/**
* Deregisters a base DN with this registry.
*
* @param baseDN to deregister
* @return list of error messages generated by deregistering the base DN
* that should be logged if the changes to this registry are
* committed to the server
* @throws DirectoryException if the base DN could not be deregistered
*/
throws DirectoryException
{
// Make sure that the Directory Server actually contains a backend with
// the specified base DN.
{
}
// Check to see if the backend has a parent backend, and whether it has
// any subordinates with base DNs that are below the base DN to remove.
{
{
{
{
break;
}
}
}
}
// See if there are any other base DNs registered within the same backend.
{
{
continue;
}
{
}
}
// If we've gotten here, then it's OK to make the changes.
// Get rid of the references to this base DN in the mapping tree
// information.
if (superiorBackend == null)
{
// If there were any subordinate backends, then all of their base DNs
// will now be promoted to naming contexts.
for (Backend<?> b : subordinateBackends)
{
if (!testOnly)
{
b.setParentBackend(null);
}
{
if (b.isPrivateBackend())
{
}
else
{
}
}
}
}
else
{
// If there are no other base DNs for the associated backend, then
// remove this backend as a subordinate of the parent backend.
{
}
// If there are any subordinate backends, then they need to be made
// subordinate to the parent backend. Also, we should log a warning
// message indicating that there may be inconsistent search results
// because some of the structural entries will be missing.
if (! subordinateBackends.isEmpty())
{
// Suppress this warning message on server shutdown.
}
if (!testOnly)
{
for (Backend<?> b : subordinateBackends)
{
}
}
}
}
return errors;
}
/**
* Creates a default instance.
*/
{
this(false);
}
/**
* Returns a copy of this registry.
*
* @return copy of this registry
*/
{
return registry;
}
/**
* Creates a parameterized instance.
*
* @param testOnly indicates whether this registry will be used for testing;
* when <code>true</code> this registry will not modify backends
*/
{
}
/**
* Gets the mapping of registered base DNs to their associated backend.
*
* @return mapping from base DN to backend
*/
return this.baseDNs;
}
/**
* Gets the mapping of registered public naming contexts to their
* associated backend.
*
* @return mapping from naming context to backend
*/
return this.publicNamingContexts;
}
/**
* Gets the mapping of registered private naming contexts to their
* associated backend.
*
* @return mapping from naming context to backend
*/
return this.privateNamingContexts;
}
/**
* Indicates whether the specified DN is contained in this registry as
* a naming contexts.
*
* @param dn The DN for which to make the determination.
*
* @return {@code true} if the specified DN is a naming context in this
* registry, or {@code false} if it is not.
*/
{
}
/**
* Clear and nullify this registry's internal state.
*/
void clear() {
}
}