| | |
| | | import javax.naming.directory.Attributes; |
| | | import javax.naming.ldap.LdapName; |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.opends.server.admin.AbstractManagedObjectDefinition; |
| | | import org.opends.server.admin.Configuration; |
| | | import org.opends.server.admin.ConfigurationClient; |
| | |
| | | import org.opends.server.admin.ManagedObjectDefinition; |
| | | import org.opends.server.admin.ManagedObjectNotFoundException; |
| | | import org.opends.server.admin.ManagedObjectPath; |
| | | import org.opends.server.admin.OptionalRelationDefinition; |
| | | import org.opends.server.admin.PropertyDefinition; |
| | | import org.opends.server.admin.PropertyException; |
| | | import org.opends.server.admin.PropertyIsMandatoryException; |
| | |
| | | import org.opends.server.admin.client.OperationRejectedException; |
| | | import org.opends.server.admin.client.spi.Driver; |
| | | import org.opends.server.admin.client.spi.PropertySet; |
| | | import org.opends.server.admin.std.client.RootCfgClient; |
| | | import org.opends.server.admin.std.meta.RootCfgDefn; |
| | | |
| | | |
| | | |
| | |
| | | // 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. |
| | | */ |
| | | public LDAPDriver(LDAPConnection connection, LDAPProfile profile) { |
| | | public LDAPDriver(LDAPManagementContext context, LDAPConnection connection, |
| | | LDAPProfile profile) { |
| | | this.context = context; |
| | | this.connection = connection; |
| | | this.profile = profile; |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public <C extends ConfigurationClient, S extends Configuration> |
| | | boolean deleteManagedObject( |
| | | ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd, |
| | | String name) throws IllegalArgumentException, |
| | | ManagedObjectNotFoundException, OperationRejectedException, |
| | | AuthorizationException, CommunicationException { |
| | | validateRelationDefinition(parent, rd); |
| | | |
| | | if (!managedObjectExists(parent)) { |
| | | throw new ManagedObjectNotFoundException(); |
| | | } |
| | | |
| | | return removeManagedObject(parent.child(rd, name)); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public <C extends ConfigurationClient, S extends Configuration> |
| | | boolean deleteManagedObject( |
| | | ManagedObjectPath<?, ?> parent, OptionalRelationDefinition<C, S> rd) |
| | | throws IllegalArgumentException, ManagedObjectNotFoundException, |
| | | OperationRejectedException, AuthorizationException, |
| | | CommunicationException { |
| | | validateRelationDefinition(parent, rd); |
| | | |
| | | if (!managedObjectExists(parent)) { |
| | | throw new ManagedObjectNotFoundException(); |
| | | } |
| | | |
| | | return removeManagedObject(parent.child(rd)); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public <C extends ConfigurationClient, S extends Configuration> |
| | | ManagedObject<? extends C> getManagedObject( |
| | | ManagedObjectPath<C, S> path) throws DefinitionDecodingException, |
| | | ManagedObjectDecodingException, ManagedObjectNotFoundException, |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public ManagedObject<RootCfgClient> getRootConfigurationManagedObject() { |
| | | return new LDAPManagedObject<RootCfgClient>(this, |
| | | RootCfgDefn.getInstance(), ManagedObjectPath.emptyPath(), |
| | | new PropertySet(), true, null); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public <C extends ConfigurationClient, S extends Configuration> |
| | | String[] listManagedObjects( |
| | | ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd, |
| | |
| | | return true; |
| | | } |
| | | |
| | | ManagedObjectPath<?,?> parent = path.parent(); |
| | | ManagedObjectPath<?, ?> parent = path.parent(); |
| | | LdapName dn = LDAPNameBuilder.create(parent, profile); |
| | | if (!entryExists(dn)) { |
| | | throw new ManagedObjectNotFoundException(); |
| | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | protected <C extends ConfigurationClient, S extends Configuration> |
| | | void deleteManagedObject( |
| | | ManagedObjectPath<C, S> path) throws OperationRejectedException, |
| | | AuthorizationException, CommunicationException { |
| | | // Delete the entry and any subordinate entries. |
| | | LdapName dn = LDAPNameBuilder.create(path, profile); |
| | | try { |
| | | connection.deleteSubtree(dn); |
| | | } catch (OperationNotSupportedException e) { |
| | | // Unwilling to perform. |
| | | if (e.getMessage() != null) { |
| | | throw new OperationRejectedException(); |
| | | } else { |
| | | Message m = Message.raw("%s", e.getMessage()); |
| | | throw new OperationRejectedException(m); |
| | | } |
| | | } catch (NamingException e) { |
| | | adaptNamingException(e); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | protected LDAPManagementContext getManagementContext() { |
| | | return context; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Adapts a naming exception to an appropriate admin client |
| | | * exception. |
| | | * |
| | |
| | | |
| | | return d.resolveManagedObjectDefinition(resolver); |
| | | } |
| | | |
| | | |
| | | |
| | | // Remove the named managed object. |
| | | private boolean removeManagedObject(ManagedObjectPath<?, ?> path) |
| | | throws CommunicationException, AuthorizationException, |
| | | OperationRejectedException, ManagedObjectNotFoundException { |
| | | if (!managedObjectExists(path)) { |
| | | return false; |
| | | } |
| | | |
| | | // Delete the entry and any subordinate entries. |
| | | LdapName dn = LDAPNameBuilder.create(path, profile); |
| | | try { |
| | | connection.deleteSubtree(dn); |
| | | } catch (OperationNotSupportedException e) { |
| | | // Unwilling to perform. |
| | | throw new OperationRejectedException(e); |
| | | } catch (NamingException e) { |
| | | adaptNamingException(e); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | |
| | | |
| | | // Validate that a relation definition belongs to this managed |
| | | // object. |
| | | private void validateRelationDefinition(ManagedObjectPath<?, ?> path, |
| | | RelationDefinition<?, ?> rd) throws IllegalArgumentException { |
| | | AbstractManagedObjectDefinition<?, ?> d = path.getManagedObjectDefinition(); |
| | | RelationDefinition<?, ?> tmp = d.getRelationDefinition(rd.getName()); |
| | | if (tmp != rd) { |
| | | throw new IllegalArgumentException("The relation " + rd.getName() |
| | | + " is not associated with a " + d.getName()); |
| | | } |
| | | } |
| | | } |