/*
* 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 2009 Sun Microsystems, Inc.
* Portions copyright 2014-2015 ForgeRock AS.
*/
/**
* Server management connection context.
*/
public final class ServerManagementContext {
/**
* A default behavior visitor used for retrieving the default values of a
* property.
*
* @param <T>
* The type of the property.
*/
private final class DefaultValueFinder<T> implements DefaultBehaviorProviderVisitor<T, Collection<T>, Void> {
/** Any exception that occurred whilst retrieving inherited default values. */
/**
* Optional new configuration entry which does not yet exist in
* the configuration back-end.
*/
/** The path of the managed object containing the next property. */
/** The next property whose default values were required. */
/** Private constructor. */
this.newConfigEntry = newConfigEntry;
}
/** {@inheritDoc} */
public Collection<T> visitAbsoluteInherited(AbsoluteInheritedDefaultBehaviorProvider<T> d, Void p) {
try {
d.getPropertyName());
} catch (PropertyException e) {
exception = e;
return Collections.emptySet();
}
}
/** {@inheritDoc} */
return Collections.emptySet();
}
/** {@inheritDoc} */
try {
} catch (PropertyException e) {
break;
}
}
return values;
}
/** {@inheritDoc} */
public Collection<T> visitRelativeInherited(RelativeInheritedDefaultBehaviorProvider<T> d, Void p) {
try {
d.getPropertyName());
} catch (PropertyException e) {
exception = e;
return Collections.emptySet();
}
}
/** {@inheritDoc} */
return Collections.emptySet();
}
throw exception;
}
}
return values;
}
/** Get an inherited property value. */
@SuppressWarnings("unchecked")
// First check that the requested type of managed object corresponds to the path.
throw PropertyException.defaultBehaviorException(nextProperty, new DefinitionDecodingException(actual,
}
// Save the current property in case of recursion.
try {
// Get the actual managed object definition.
} else {
}
try {
} catch (IllegalArgumentException | ClassCastException e) {
throw new PropertyNotFoundException(propertyName);
}
}
return pvalues;
} else {
// Recursively retrieve this property's default values.
}
return pvalues;
}
} catch (Exception e) {
}
}
}
/**
* A definition resolver that determines the managed object definition from
* the object classes of a ConfigEntry.
*/
/** The config entry. */
/** Private constructor. */
}
/** {@inheritDoc} */
// TODO : use the schema to get object class and check it in the entry
// Commented because reject any config entry without proper schema loading
// Previous code was
// ObjectClass oc = DirectoryServer.getObjectClass(name.toLowerCase());
// if (oc == null) {
// oc = DirectoryServer.getDefaultObjectClass(name);
// }
// return Entries.containsObjectClass(entry, oc);
}
}
/**
* A visitor which is used to decode property LDAP values.
*/
/**
* Decodes the provided property LDAP value.
*
* @param <P>
* The type of the property.
* @param propertyDef
* The property definition.
* @param value
* The LDAP string representation.
* @return Returns the decoded LDAP value.
* @throws PropertyException
* If the property value could not be decoded because it was
* invalid.
*/
}
/** Prevent instantiation. */
private ValueDecoder() {
// Do nothing.
}
/** {@inheritDoc} */
AggregationPropertyDefinition<C, S> d, String p) {
// Aggregations values are stored as full DNs in LDAP, but
// just their common name is exposed in the admin framework.
try {
} catch (IllegalArgumentException e) {
throw PropertyException.illegalPropertyValueException(d, p);
}
}
/** {@inheritDoc} */
// By default the property definition's decoder will do.
return d.decodeValue(p);
}
}
/**
* The root server managed object, lazily initialized.
*/
/** Repository of configuration entries. */
/**
* Creates a context from the provided configuration repository.
*
* @param repository
* The repository of configuration entries.
*/
}
/**
* Gets the named managed object.
*
* @param <C>
* The type of client managed object configuration that the path
* definition refers to.
* @param <S>
* The type of server managed object configuration that the path
* definition refers to.
* @param path
* The path of the managed object.
* @return Returns the named managed object.
* @throws ConfigException
* If the named managed object could not be found or if it could
* not be decoded.
*/
@SuppressWarnings("unchecked")
public <C extends ConfigurationClient, S extends Configuration> ServerManagedObject<? extends S> getManagedObject(
// Be careful to handle the root configuration.
return (ServerManagedObject<S>) getRootConfigurationManagedObject();
}
// Get the configuration entry.
try {
ServerManagedObject<? extends S> managedObject;
// Enforce any constraints.
return managedObject;
} catch (DefinitionDecodingException e) {
} catch (ServerManagedObjectDecodingException e) {
} catch (ConstraintViolationException e) {
}
}
/**
* Gets the effective value of a property in the named managed object.
*
* @param <C>
* The type of client managed object configuration that the path
* definition refers to.
* @param <S>
* The type of server managed object configuration that the path
* definition refers to.
* @param <P>
* The type of the property to be retrieved.
* @param path
* The path of the managed object containing the property.
* @param pd
* The property to be retrieved.
* @return Returns the property's effective value, or <code>null</code> if
* there are no values defined.
* @throws IllegalArgumentException
* If the property definition is not associated with the
* referenced managed object's definition.
* @throws PropertyException
* If the managed object was found but the requested property
* could not be decoded.
* @throws ConfigException
* If the named managed object could not be found or if it could
* not be decoded.
*/
}
return null;
}
/**
* Gets the effective values of a property in the named managed object.
*
* @param <C>
* The type of client managed object configuration that the path
* definition refers to.
* @param <S>
* The type of server managed object configuration that the path
* definition refers to.
* @param <P>
* The type of the property to be retrieved.
* @param path
* The path of the managed object containing the property.
* @param propertyDef
* The property to be retrieved.
* @return Returns the property's effective values, or an empty set if there
* are no values defined.
* @throws IllegalArgumentException
* If the property definition is not associated with the
* referenced managed object's definition.
* @throws PropertyException
* If the managed object was found but the requested property
* could not be decoded.
* @throws ConfigException
* If the named managed object could not be found or if it could
* not be decoded.
*/
@SuppressWarnings("unchecked")
// Check that the requested property is from the definition
// associated with the path.
if (tmpPropertyDef != propertyDef) {
throw new IllegalArgumentException("The property " + propertyDef.getName() + " is not associated with a "
+ definition.getName());
}
// Determine the exact type of managed object referenced by the path.
ManagedObjectDefinition<? extends C, ? extends S> managedObjDef;
try {
} catch (DefinitionDecodingException e) {
}
// Make sure we use the correct property definition, the
// provided one might have been overridden in the resolved definition.
}
/**
* Get the root configuration manager associated with this management
* context.
*
* @return the root configuration manager associated with this
* management context.
*/
return getRootConfigurationManagedObject().getConfiguration();
}
/**
* Get the root configuration server managed object associated with this
* management context.
*
* @return the root configuration server managed object
*/
// Use lazy initialisation
// because it needs a reference to this server context.
if (rootObject == null) {
synchronized (this) {
rootObject = root;
if (rootObject == null) {
root = rootObject =
}
}
}
return rootObject;
}
/**
* Lists the child managed objects of the named parent managed object.
*
* @param <C>
* The type of client managed object configuration that the
* relation definition refers to.
* @param <S>
* The type of server managed object configuration that the
* relation definition refers to.
* @param parent
* The path of the parent managed object.
* @param relationDef
* The relation definition.
* @return Returns the names of the child managed objects.
* @throws IllegalArgumentException
* If the relation definition is not associated with the parent
* managed object's definition.
*/
// Get the target entry.
try {
} catch (ConfigException e) {
return new String[0];
}
// Assume that RDNs are single-valued and can be trimmed.
}
}
/**
* Determines whether or not the named managed object exists.
*
* @param path
* The path of the named managed object.
* @return Returns <code>true</code> if the named managed object exists,
* <code>false</code> otherwise.
*/
// Get the configuration entry.
try {
} catch (ConfigException e) {
// Assume it doesn't exist.
return false;
}
}
/**
* Decodes a configuration entry into the required type of server managed
* object.
*
* @param <C>
* The type of client managed object configuration that the path
* definition refers to.
* @param <S>
* The type of server managed object configuration that the path
* definition refers to.
* @param path
* The location of the server managed object.
* @param configEntry
* The configuration entry that should be decoded.
* @return Returns the new server-side managed object from the provided
* definition and configuration entry.
* @throws DefinitionDecodingException
* If the managed object's type could not be determined.
* @throws ServerManagedObjectDecodingException
* If one or more of the managed object's properties could not
* be decoded.
*/
}
/**
* Decodes a configuration entry into the required type of server managed
* object.
*
* @param <C>
* The type of client managed object configuration that the path
* definition refers to.
* @param <S>
* The type of server managed object configuration that the path
* definition refers to.
* @param path
* The location of the server managed object.
* @param configEntry
* The configuration entry that should be decoded.
* @param newConfigEntry
* Optional new configuration that does not exist yet in the
* configuration back-end. This will be used for resolving
* inherited default values.
* @return Returns the new server-side managed object from the provided
* definition and configuration entry.
* @throws DefinitionDecodingException
* If the managed object's type could not be determined.
* @throws ServerManagedObjectDecodingException
* If one or more of the managed object's properties could not
* be decoded.
*/
// First determine the correct definition to use for the entry.
// This could either be the provided definition, or one of its
// sub-definitions.
// Build the managed object's properties.
try {
} catch (PropertyException e) {
exceptions.add(e);
}
}
// If there were no decoding problems then return the managed
// object, otherwise throw an operations exception.
ServerManagedObject<? extends S> managedObject = decodeAux(path, mod, properties, configEntry.getName());
if (exceptions.isEmpty()) {
return managedObject;
} else {
}
}
/** Decode helper method required to avoid generics warning. */
}
/** Decode a property using the provided attribute values. */
private <T> SortedSet<T> decodeProperty(ManagedObjectPath<?, ?> path, PropertyDefinition<T> propertyDef,
// The property has values defined for it.
try {
} catch (PropertyException e) {
exception = e;
}
}
} else {
// No values defined so get the defaults.
try {
} catch (PropertyException e) {
exception = e;
}
}
// This exception takes precedence over previous exceptions.
}
}
throw exception;
}
return pvalues;
}
/** Gets the attribute values associated with a property from a ConfigEntry. */
Entry configEntry) {
// TODO: we create a default attribute type if it is undefined.
// We should log a warning here if this is the case
// since the attribute should have been defined.
}
}
return values;
}
/** Get the default values for the specified property. */
}
/**
* Retrieves a configuration entry corresponding to the provided DN.
*
* @param dn
* DN of the configuration entry.
* @return the configuration entry
* @throws ConfigException
* If a problem occurs.
*/
}
/**
* Returns the repository containing all configuration entries.
*
* @return the repository
*/
return configRepository;
}
/**
* Gets a config entry required for a managed object and throws a
* config exception on failure.
*/
try {
} catch (ConfigException e) {
stackTraceToSingleLineString(e, true));
throw new ConfigException(message, e);
}
// The configuration handler is free to return null indicating
// that the entry does not exist.
if (configEntry == null) {
throw new ConfigException(message);
}
return configEntry;
}
/** Validate that a relation definition belongs to the path. */
private void validateRelationDefinition(ManagedObjectPath<?, ?> path, RelationDefinition<?, ?> rd) {
+ d.getName());
}
}
}