LDAPDriver.java revision ca669ae54f86dbeea277280690584d9f591c7571
/*
* 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-2009 Sun Microsystems, Inc.
* Portions Copyright 2013-2015 ForgeRock AS.
*/
/**
* The LDAP management context driver implementation.
*/
final class LDAPDriver extends Driver {
/**
* A visitor which is used to decode property LDAP values.
*/
private static final class ValueDecoder extends
/**
* Decodes the provided property LDAP value.
*
* @param
* The type of the property.
* @param pd
* 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.
*/
throws PropertyException {
}
// Prevent instantiation.
private ValueDecoder() {
// No implementation required.
}
/**
* {@inheritDoc}
*/
public <C extends ConfigurationClient, S extends Configuration>
// Aggregations values are stored as full DNs in LDAP, but
// just their common name is exposed in the admin framework.
try {
.getRelationDefinition(), p);
} catch (IllegalArgumentException e) {
throw PropertyException.illegalPropertyValueException(d, p);
}
}
/**
* {@inheritDoc}
*/
throws PropertyException {
// By default the property definition's decoder will do.
return d.decodeValue(p);
}
}
// The LDAP connection.
private final LDAPConnection connection;
// The LDAP management context.
private final LDAPManagementContext context;
// The LDAP profile which should be used to construct LDAP
// requests and decode LDAP responses.
private final LDAPProfile profile;
/**
* Creates a new LDAP driver using the specified LDAP connection and
* profile.
*
* @param context
* The LDAP management context.
* @param connection
* The LDAP connection.
* @param profile
* The LDAP profile.
*/
this.connection = connection;
}
/**
* {@inheritDoc}
*/
public void close() {
connection.unbind();
}
/**
* {@inheritDoc}
*/
public <C extends ConfigurationClient, S extends Configuration>
ManagedObject<? extends C> getManagedObject(
if (!managedObjectExists(path)) {
throw new ManagedObjectNotFoundException();
}
try {
// Read the entry associated with the managed object.
AbstractManagedObjectDefinition<C, S> d = path
ManagedObjectDefinition<? extends C, ? extends S> mod =
getEntryDefinition(d, dn);
}
// Build the managed object's properties.
try {
} catch (PropertyException e) {
exceptions.add(e);
}
}
// If there were no decoding problems then return the object,
// otherwise throw an operations exception.
if (exceptions.isEmpty()) {
return mo;
} else {
}
} catch (NameNotFoundException e) {
throw new ManagedObjectNotFoundException();
} catch (NoPermissionException e) {
throw new AuthorizationException(e);
} catch (NamingException e) {
throw new CommunicationException(e);
}
}
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
// Check that the requested property is from the definition
// associated with the path.
+ " is not associated with a " + d.getName());
}
if (!managedObjectExists(path)) {
throw new ManagedObjectNotFoundException();
}
try {
// Read the entry associated with the managed object.
ManagedObjectDefinition<? extends C, ? extends S> mod;
// Make sure we use the correct property definition, the
// provided one might have been overridden in the resolved
// definition.
// Decode the values.
while (ldapValues.hasMore()) {
}
}
}
// Sanity check the returned values.
}
}
// Use the property's default values.
}
return values;
} catch (NameNotFoundException e) {
throw new ManagedObjectNotFoundException();
} catch (NoPermissionException e) {
throw new AuthorizationException(e);
} catch (NamingException e) {
throw new CommunicationException(e);
}
}
/**
* {@inheritDoc}
*/
return new LDAPManagedObject<RootCfgClient>(this,
new PropertySet(), true, null);
}
/**
* {@inheritDoc}
*/
public <C extends ConfigurationClient, S extends Configuration>
AbstractManagedObjectDefinition<? extends C, ? extends S> d)
if (!managedObjectExists(parent)) {
throw new ManagedObjectNotFoundException();
}
// Get the search base DN.
// Retrieve only those entries which are sub-types of the
// specified definition.
try {
}
} catch (NameNotFoundException e) {
// Ignore this - it means that the base entry does not exist
// (which it might not if this managed object has just been
// created.
} catch (NamingException e) {
}
}
/**
* {@inheritDoc}
*/
public <C extends ConfigurationClient, S extends Configuration>
AbstractManagedObjectDefinition<? extends C, ? extends S> d)
if (!managedObjectExists(parent)) {
throw new ManagedObjectNotFoundException();
}
// Get the search base DN.
// Retrieve only those entries which are sub-types of the
// specified definition.
try {
}
} catch (NameNotFoundException e) {
// Ignore this - it means that the base entry does not exist
// (which it might not if this managed object has just been
// created.
} catch (NamingException e) {
}
}
/**
* {@inheritDoc}
*/
return true;
}
if (!entryExists(dn)) {
throw new ManagedObjectNotFoundException();
}
return entryExists(dn);
}
/**
* {@inheritDoc}
*/
protected <C extends ConfigurationClient, S extends Configuration>
void deleteManagedObject(
// Delete the entry and any subordinate entries.
try {
} catch (OperationNotSupportedException e) {
// Unwilling to perform.
AbstractManagedObjectDefinition<?, ?> d =
if (e.getMessage() == null) {
.getUserFriendlyName());
} else {
.getUserFriendlyName(), m);
}
} catch (NamingException e) {
}
}
/**
* {@inheritDoc}
*/
protected LDAPManagementContext getManagementContext() {
return context;
}
/**
* Adapts a naming exception to an appropriate admin client
* exception.
*
* @param ne
* The naming exception.
* @throws CommunicationException
* If the naming exception mapped to a communication
* exception.
* @throws AuthorizationException
* If the naming exception mapped to an authorization
* exception.
*/
try {
throw ne;
throw new CommunicationException(e);
throw new CommunicationException(e);
throw new AuthorizationException(e);
} catch (NamingException e) {
// Just treat it as a communication problem.
throw new CommunicationException(e);
}
}
/**
* Determines whether the named LDAP entry exists.
*
* @param dn
* The LDAP entry name.
* @return Returns <code>true</code> if the named LDAP entry
* exists.
* @throws AuthorizationException
* If the server refuses to make the determination because
* the client does not have the correct privileges.
* @throws CommunicationException
* If the client cannot contact the server due to an
* underlying communication problem.
*/
try {
} catch (NamingException e) {
}
return false;
}
/**
* Gets the LDAP connection used for interacting with the server.
*
* @return Returns the LDAP connection used for interacting with the
* server.
*/
return connection;
}
/**
* Gets the LDAP profile which should be used to construct LDAP
* requests and decode LDAP responses.
*
* @return Returns the LDAP profile which should be used to
* construct LDAP requests and decode LDAP responses.
*/
return profile;
}
// Create a managed object which already exists on the server.
private <M extends ConfigurationClient, N extends Configuration>
ManagedObjectDefinition<M, N> d,
if (rd instanceof InstantiableRelationDefinition) {
InstantiableRelationDefinition<?, ?> ird =
(InstantiableRelationDefinition<?, ?>) rd;
}
pd);
}
// Create a property using the provided string values.
// Get the property's active values.
while (ldapValues.hasMore()) {
}
}
}
// This exception takes precedence over previous exceptions.
}
// Get the property's default values.
try {
} catch (PropertyException e) {
exception = e;
}
if (activeValues.isEmpty()
&& defaultValues.isEmpty()
// The active values maybe empty because of a previous exception.
}
throw exception;
}
}
// Determine the type of managed object associated with the named
// entry.
private <C extends ConfigurationClient, S extends Configuration>
ManagedObjectDefinition<? extends C, ? extends S> getEntryDefinition(
throws NamingException, DefinitionDecodingException {
.singleton("objectclass"));
// No object classes.
}
}
}
if (objectClasses.isEmpty()) {
// No object classes.
}
// Resolve the appropriate sub-type based on the object classes.
public boolean matches(AbstractManagedObjectDefinition<?, ?> d) {
}
};
return d.resolveManagedObjectDefinition(resolver);
}
}