Checkpoint commit for OPENDJ-1536: Rename ErrorResultException to LdapException and remove ErrorResultIOException
1 files deleted
1 files renamed
180 files modified
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS. |
| | | * Portions Copyright 2011-2014 ForgeRock AS. |
| | | */ |
| | | package com.forgerock.opendj.cli; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.AbstractConnectionWrapper; |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ConnectionFactory; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.FutureResult; |
| | | import org.forgerock.opendj.ldap.IntermediateResponseHandler; |
| | | import org.forgerock.opendj.ldap.requests.BindRequest; |
| | |
| | | * {@code rebind} method. |
| | | * <p> |
| | | * If the Bind request fails for some reason (e.g. invalid credentials), then |
| | | * the connection attempt will fail and an {@code ErrorResultException} will be |
| | | * thrown. |
| | | * the connection attempt will fail and an {@link LdapException} will be thrown. |
| | | */ |
| | | public final class AuthenticatedConnectionFactory implements ConnectionFactory { |
| | | |
| | |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public BindResult bind(BindRequest request) throws ErrorResultException { |
| | | public BindResult bind(BindRequest request) throws LdapException { |
| | | throw new UnsupportedOperationException(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public BindResult bind(String name, char[] password) throws ErrorResultException { |
| | | public BindResult bind(String name, char[] password) throws LdapException { |
| | | throw new UnsupportedOperationException(); |
| | | } |
| | | |
| | |
| | | // Save the result. |
| | | AuthenticatedConnection.this.result = result; |
| | | } |
| | | }).onFailure(new FailureHandler<ErrorResultException>() { |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | /* |
| | | * This connection is now unauthenticated so prevent further use. |
| | | */ |
| | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Connection getConnection() throws ErrorResultException { |
| | | public Connection getConnection() throws LdapException { |
| | | final Connection connection = parentFactory.getConnection(); |
| | | BindResult bindResult = null; |
| | | try { |
| | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Promise<Connection, ErrorResultException> getConnectionAsync() { |
| | | public Promise<Connection, LdapException> getConnectionAsync() { |
| | | final AtomicReference<Connection> connectionHolder = new AtomicReference<Connection>(); |
| | | return parentFactory.getConnectionAsync() |
| | | .thenAsync( |
| | | new AsyncFunction<Connection, BindResult, ErrorResultException>() { |
| | | new AsyncFunction<Connection, BindResult, LdapException>() { |
| | | @Override |
| | | public Promise<BindResult, ErrorResultException> apply(final Connection connection) |
| | | throws ErrorResultException { |
| | | public Promise<BindResult, LdapException> apply(final Connection connection) |
| | | throws LdapException { |
| | | connectionHolder.set(connection); |
| | | return connection.bindAsync(request); |
| | | } |
| | | } |
| | | ).then( |
| | | new Function<BindResult, Connection, ErrorResultException>() { |
| | | new Function<BindResult, Connection, LdapException>() { |
| | | @Override |
| | | public Connection apply(BindResult result) throws ErrorResultException { |
| | | public Connection apply(BindResult result) throws LdapException { |
| | | // FIXME: should make the result unmodifiable. |
| | | return new AuthenticatedConnection(connectionHolder.get(), request, result); |
| | | } |
| | | }, |
| | | new Function<ErrorResultException, Connection, ErrorResultException>() { |
| | | new Function<LdapException, Connection, LdapException>() { |
| | | @Override |
| | | public Connection apply(ErrorResultException errorResult) throws ErrorResultException { |
| | | public Connection apply(LdapException errorResult) throws LdapException { |
| | | closeSilently(connectionHolder.get()); |
| | | throw errorResult; |
| | | } |
| | |
| | | ! |
| | | ! |
| | | ! Copyright 2008-2009 Sun Microsystems, Inc. |
| | | ! Portions Copyright 2014 ForgeRock AS |
| | | ! --> |
| | | <xsl:stylesheet version="1.0" xmlns:adm="http://opendj.forgerock.org/admin" |
| | | xmlns:admpp="http://opendj.forgerock.org/admin-preprocessor" |
| | |
| | | ' If the ', $ufn, ' could not be found on the server.
', |
| | | '@throws ConcurrentModificationException
', |
| | | ' If this ', $this-ufn, ' has been removed from the server by another client.
', |
| | | '@throws ErrorResultException
', |
| | | '@throws LdapException
', |
| | | ' If any other error occurs.')" /> |
| | | </xsl:call-template> |
| | | <xsl:value-of |
| | | select="concat(' ', $java-class-name, 'CfgClient get', $java-relation-name, '()
', |
| | | ' throws DefinitionDecodingException, ManagedObjectDecodingException,
', |
| | | ' ManagedObjectNotFoundException, ConcurrentModificationException,
', |
| | | ' ErrorResultException;
')" /> |
| | | ' LdapException;
')" /> |
| | | </xsl:when> |
| | | <xsl:when test="adm:one-to-zero-or-one"> |
| | | <xsl:call-template name="add-java-comment2"> |
| | |
| | | '@return Returns <true> if the ', $ufn,' exists.
', |
| | | '@throws ConcurrentModificationException
', |
| | | ' If this ', $this-ufn, ' has been removed from the server by another client.
', |
| | | '@throws ErrorResultException
', |
| | | '@throws LdapException
', |
| | | ' If any other error occurs.')" /> |
| | | </xsl:call-template> |
| | | <xsl:value-of |
| | | select="concat(' boolean has', |
| | | $java-relation-name, '() throws ConcurrentModificationException,
', |
| | | ' ErrorResultException;
')" /> |
| | | ' LdapException;
')" /> |
| | | <xsl:text>
</xsl:text> |
| | | <xsl:text>
</xsl:text> |
| | | <xsl:text>
</xsl:text> |
| | |
| | | ' If the ', $ufn, ' is not present.
', |
| | | '@throws ConcurrentModificationException
', |
| | | ' If this ', $this-ufn, ' has been removed from the server by another client.
', |
| | | '@throws ErrorResultException
', |
| | | '@throws LdapException
', |
| | | ' If any other error occurs.')" /> |
| | | </xsl:call-template> |
| | | <xsl:value-of |
| | | select="concat(' ', $java-class-name, 'CfgClient get', $java-relation-name, '()
', |
| | | ' throws DefinitionDecodingException, ManagedObjectDecodingException,
', |
| | | ' ManagedObjectNotFoundException, ConcurrentModificationException,
', |
| | | ' ErrorResultException;
')" /> |
| | | ' LdapException;
')" /> |
| | | <xsl:text>
</xsl:text> |
| | | <xsl:text>
</xsl:text> |
| | | <xsl:text>
</xsl:text> |
| | |
| | | ' If the server refuses to remove the ', $ufn, ' due to some server-side constraint which cannot be satisfied (for example, if it is referenced by another managed object).
', |
| | | '@throws ConcurrentModificationException
', |
| | | ' If this ', $this-ufn, ' has been removed from the server by another client.
', |
| | | '@throws ErrorResultException
', |
| | | '@throws LdapException
', |
| | | ' If any other error occurs.')" /> |
| | | </xsl:call-template> |
| | | <xsl:value-of |
| | | select="concat(' void remove', $java-relation-name, '()
', |
| | | ' throws ManagedObjectNotFoundException, OperationRejectedException,
', |
| | | ' ConcurrentModificationException, ErrorResultException;
')" /> |
| | | ' ConcurrentModificationException, LdapException;
')" /> |
| | | </xsl:when> |
| | | <xsl:when test="adm:one-to-many"> |
| | | <xsl:variable name="plural-name" |
| | |
| | | '@return Returns an array containing the names of the ', $ufpn,'.
', |
| | | '@throws ConcurrentModificationException
', |
| | | ' If this ', $this-ufn, ' has been removed from the server by another client.
', |
| | | '@throws ErrorResultException
', |
| | | '@throws LdapException
', |
| | | ' If any other error occurs.')" /> |
| | | </xsl:call-template> |
| | | <xsl:value-of |
| | | select="concat(' String[] list', |
| | | $java-relation-plural-name, '() throws ConcurrentModificationException,
', |
| | | ' ErrorResultException;
')" /> |
| | | ' LdapException;
')" /> |
| | | <xsl:text>
</xsl:text> |
| | | <xsl:text>
</xsl:text> |
| | | <xsl:text>
</xsl:text> |
| | |
| | | ' If the named ', $ufn, ' was not found on the server.
', |
| | | '@throws ConcurrentModificationException
', |
| | | ' If this ', $this-ufn, ' has been removed from the server by another client.
', |
| | | '@throws ErrorResultException
', |
| | | '@throws LdapException
', |
| | | ' If any other error occurs.')" /> |
| | | </xsl:call-template> |
| | | <xsl:value-of |
| | | select="concat(' ', $java-class-name, 'CfgClient get', $java-relation-name, '(String name)
', |
| | | ' throws DefinitionDecodingException, ManagedObjectDecodingException,
', |
| | | ' ManagedObjectNotFoundException, ConcurrentModificationException,
', |
| | | ' ErrorResultException;
')" /> |
| | | ' LdapException;
')" /> |
| | | <xsl:text>
</xsl:text> |
| | | <xsl:text>
</xsl:text> |
| | | <xsl:text>
</xsl:text> |
| | |
| | | ' If the server refuses to remove the ', $ufn, ' due to some server-side constraint which cannot be satisfied (for example, if it is referenced by another managed object).
', |
| | | '@throws ConcurrentModificationException
', |
| | | ' If this ', $this-ufn, ' has been removed from the server by another client.
', |
| | | '@throws ErrorResultException
', |
| | | '@throws LdapException
', |
| | | ' If any other error occurs.')" /> |
| | | </xsl:call-template> |
| | | <xsl:value-of |
| | | select="concat(' void remove', $java-relation-name, '(String name)
', |
| | | ' throws ManagedObjectNotFoundException, OperationRejectedException,
', |
| | | ' ConcurrentModificationException, ErrorResultException;
')" /> |
| | | ' ConcurrentModificationException, LdapException;
')" /> |
| | | </xsl:when> |
| | | <xsl:otherwise> |
| | | <xsl:message terminate="yes"> |
| | |
| | | org.forgerock.opendj.config.client.ConcurrentModificationException |
| | | </import> |
| | | <import> |
| | | org.forgerock.opendj.ldap.ErrorResultException |
| | | org.forgerock.opendj.ldap.LdapException |
| | | </import> |
| | | </xsl:if> |
| | | <xsl:for-each |
| | |
| | | ! |
| | | ! |
| | | ! Copyright 2007-2010 Sun Microsystems, Inc. |
| | | ! Portions copyright 2011 ForgeRock AS. |
| | | ! Portions copyright 2011-2014 ForgeRock AS. |
| | | ! --> |
| | | <xsl:stylesheet version="1.0" xmlns:adm="http://opendj.forgerock.org/admin" |
| | | xmlns:admpp="http://opendj.forgerock.org/admin-preprocessor" |
| | |
| | | ' */
', |
| | | ' public void commit() throws ManagedObjectAlreadyExistsException,
', |
| | | ' MissingMandatoryPropertiesException, ConcurrentModificationException,
', |
| | | ' OperationRejectedException, ErrorResultException {
', |
| | | ' OperationRejectedException, LdapException {
', |
| | | ' impl.commit();
', |
| | | ' }
')" /> |
| | | <xsl:text>
</xsl:text> |
| | |
| | | ' public ', $java-class-name, 'CfgClient get', $java-relation-name, '()
', |
| | | ' throws DefinitionDecodingException, ManagedObjectDecodingException,
', |
| | | ' ManagedObjectNotFoundException, ConcurrentModificationException,
', |
| | | ' ErrorResultException {
', |
| | | ' LdapException {
', |
| | | ' return impl.getChild(INSTANCE.get', $java-relation-name,'RelationDefinition()).getConfiguration();
', |
| | | ' }
')" /> |
| | | </xsl:when> |
| | |
| | | ' * {@inheritDoc}
', |
| | | ' */
', |
| | | ' public boolean has', $java-relation-name, '() throws ConcurrentModificationException,
', |
| | | ' ErrorResultException {
', |
| | | ' LdapException {
', |
| | | ' return impl.hasChild(INSTANCE.get', $java-relation-name,'RelationDefinition());
', |
| | | ' }
')" /> |
| | | <xsl:text>
</xsl:text> |
| | |
| | | ' public ', $java-class-name, 'CfgClient get', $java-relation-name, '()
', |
| | | ' throws DefinitionDecodingException, ManagedObjectDecodingException,
', |
| | | ' ManagedObjectNotFoundException, ConcurrentModificationException,
', |
| | | ' ErrorResultException {
', |
| | | ' LdapException {
', |
| | | ' return impl.getChild(INSTANCE.get', $java-relation-name,'RelationDefinition()).getConfiguration();
', |
| | | ' }
')" /> |
| | | <xsl:text>
</xsl:text> |
| | |
| | | ' */
', |
| | | ' public void remove', $java-relation-name, '()
', |
| | | ' throws ManagedObjectNotFoundException, ConcurrentModificationException,
', |
| | | ' OperationRejectedException, ErrorResultException {
', |
| | | ' OperationRejectedException, LdapException {
', |
| | | ' impl.removeChild(INSTANCE.get', $java-relation-name,'RelationDefinition());
', |
| | | ' }
')" /> |
| | | </xsl:when> |
| | |
| | | ' * {@inheritDoc}
', |
| | | ' */
', |
| | | ' public String[] list', $java-relation-plural-name, '() throws ConcurrentModificationException,
', |
| | | ' ErrorResultException {
', |
| | | ' LdapException {
', |
| | | ' return impl.listChildren(INSTANCE.get', $java-relation-plural-name,'RelationDefinition());
', |
| | | ' }
')" /> |
| | | <xsl:text>
</xsl:text> |
| | |
| | | ' public ', $java-class-name, 'CfgClient get', $java-relation-name, '(String name)
', |
| | | ' throws DefinitionDecodingException, ManagedObjectDecodingException,
', |
| | | ' ManagedObjectNotFoundException, ConcurrentModificationException,
', |
| | | ' ErrorResultException {
', |
| | | ' LdapException {
', |
| | | ' return impl.getChild(INSTANCE.get', $java-relation-plural-name,'RelationDefinition(), name).getConfiguration();
', |
| | | ' }
')" /> |
| | | <xsl:text>
</xsl:text> |
| | |
| | | ' */
', |
| | | ' public void remove', $java-relation-name, '(String name)
', |
| | | ' throws ManagedObjectNotFoundException, ConcurrentModificationException,
', |
| | | ' OperationRejectedException, ErrorResultException {
', |
| | | ' OperationRejectedException, LdapException {
', |
| | | ' impl.removeChild(INSTANCE.get', $java-relation-plural-name,'RelationDefinition(), name);
', |
| | | ' }
')" /> |
| | | </xsl:when> |
| | |
| | | org.forgerock.opendj.config.ManagedObjectAlreadyExistsException |
| | | </import> |
| | | <import> |
| | | org.forgerock.opendj.ldap.ErrorResultException |
| | | org.forgerock.opendj.ldap.LdapException |
| | | </import> |
| | | <import> |
| | | org.forgerock.opendj.config.client.ConcurrentModificationException |
| | |
| | | * |
| | | * |
| | | * Copyright 2007-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.config; |
| | | |
| | |
| | | import org.forgerock.opendj.config.server.ServerManagedObjectChangeListener; |
| | | import org.forgerock.opendj.config.server.ServerManagementContext; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public boolean isAddAcceptable(ManagementContext context, ManagedObject<?> managedObject, |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | Collection<LocalizableMessage> unacceptableReasons) throws LdapException { |
| | | // If all of this managed object's "enabled" properties are true |
| | | // then any referenced managed objects must also be enabled. |
| | | boolean needsEnabling = targetNeedsEnablingCondition.evaluate(context, managedObject); |
| | |
| | | */ |
| | | @Override |
| | | public boolean isModifyAcceptable(ManagementContext context, ManagedObject<?> managedObject, |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | Collection<LocalizableMessage> unacceptableReasons) throws LdapException { |
| | | // The same constraint applies as for adds. |
| | | return isAddAcceptable(context, managedObject, unacceptableReasons); |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public boolean isDeleteAcceptable(ManagementContext context, ManagedObjectPath<?, ?> path, |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | Collection<LocalizableMessage> unacceptableReasons) throws LdapException { |
| | | // Any references to the deleted managed object should cause a |
| | | // constraint violation. |
| | | boolean isAcceptable = true; |
| | |
| | | */ |
| | | @Override |
| | | public boolean isModifyAcceptable(ManagementContext context, ManagedObject<?> managedObject, |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | Collection<LocalizableMessage> unacceptableReasons) throws LdapException { |
| | | // If the modified managed object is disabled and there are some |
| | | // active references then refuse the change. |
| | | if (targetIsEnabledCondition.evaluate(context, managedObject)) { |
| | |
| | | // object using this property. |
| | | private <C1 extends ConfigurationClient> List<ManagedObject<? extends C1>> findReferences( |
| | | ManagementContext context, AbstractManagedObjectDefinition<C1, ?> mod, String name) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | List<ManagedObject<? extends C1>> instances = findInstances(context, mod); |
| | | |
| | | Iterator<ManagedObject<? extends C1>> i = instances.iterator(); |
| | |
| | | // Find all instances of a specific type of managed object. |
| | | @SuppressWarnings("unchecked") |
| | | private <C1 extends ConfigurationClient> List<ManagedObject<? extends C1>> findInstances( |
| | | ManagementContext context, AbstractManagedObjectDefinition<C1, ?> mod) throws ErrorResultException { |
| | | ManagementContext context, AbstractManagedObjectDefinition<C1, ?> mod) throws LdapException { |
| | | List<ManagedObject<? extends C1>> instances = new LinkedList<ManagedObject<? extends C1>>(); |
| | | |
| | | if (mod == RootCfgDefn.getInstance()) { |
| | |
| | | * |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.config; |
| | |
| | | import org.forgerock.opendj.config.client.ConcurrentModificationException; |
| | | import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; |
| | | import org.forgerock.opendj.config.client.OperationRejectedException; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | |
| | | /** |
| | | * A common base interface for all managed object configuration clients. |
| | |
| | | * @throws OperationRejectedException |
| | | * If the server refuses to add or modify this configuration due |
| | | * to some server-side constraint which cannot be satisfied. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | void commit() throws ManagedObjectAlreadyExistsException, MissingMandatoryPropertiesException, |
| | | ConcurrentModificationException, OperationRejectedException, ErrorResultException; |
| | | ConcurrentModificationException, OperationRejectedException, LdapException; |
| | | |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.config; |
| | | |
| | |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.config.server.ServerConstraintHandler; |
| | | import org.forgerock.opendj.config.server.ServerManagedObject; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | |
| | | /** |
| | | * A generic constraint which comprises of an underlying condition and a |
| | |
| | | */ |
| | | @Override |
| | | public boolean isAddAcceptable(ManagementContext context, ManagedObject<?> managedObject, |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | Collection<LocalizableMessage> unacceptableReasons) throws LdapException { |
| | | if (!condition.evaluate(context, managedObject)) { |
| | | unacceptableReasons.add(getSynopsis()); |
| | | return false; |
| | |
| | | */ |
| | | @Override |
| | | public boolean isModifyAcceptable(ManagementContext context, ManagedObject<?> managedObject, |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | Collection<LocalizableMessage> unacceptableReasons) throws LdapException { |
| | | if (!condition.evaluate(context, managedObject)) { |
| | | unacceptableReasons.add(getSynopsis()); |
| | | return false; |
| | |
| | | * |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.config.client; |
| | | |
| | |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.config.ManagedObjectPath; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | |
| | | /** |
| | | * An interface for performing client-side constraint validation. |
| | |
| | | * A list of messages to which error messages should be added. |
| | | * @return Returns <code>true</code> if this constraint is satisfied, or |
| | | * <code>false</code> if it is not. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If an error occurs. |
| | | */ |
| | | public boolean isAddAcceptable(ManagementContext context, ManagedObject<?> managedObject, |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | Collection<LocalizableMessage> unacceptableReasons) throws LdapException { |
| | | return true; |
| | | } |
| | | |
| | |
| | | * A list of messages to which error messages should be added. |
| | | * @return Returns <code>true</code> if this modify is satisfied, or |
| | | * <code>false</code> if it is not. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If an error occurs. |
| | | */ |
| | | public boolean isModifyAcceptable(ManagementContext context, ManagedObject<?> managedObject, |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | Collection<LocalizableMessage> unacceptableReasons) throws LdapException { |
| | | return true; |
| | | } |
| | | |
| | |
| | | * A list of messages to which error messages should be added. |
| | | * @return Returns <code>true</code> if this constraint is satisfied, or |
| | | * <code>false</code> if it is not. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If an error occurs. |
| | | */ |
| | | public boolean isDeleteAcceptable(ManagementContext context, ManagedObjectPath<?, ?> path, |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | Collection<LocalizableMessage> unacceptableReasons) throws LdapException { |
| | | return true; |
| | | } |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2007-2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.config.client; |
| | |
| | | import org.forgerock.opendj.config.PropertyProvider; |
| | | import org.forgerock.opendj.config.SetRelationDefinition; |
| | | import org.forgerock.opendj.config.SingletonRelationDefinition; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | |
| | | /** |
| | | * A generic interface for accessing client-side managed objects. |
| | |
| | | * If this managed object cannot be added or modified due to |
| | | * some client-side or server-side constraint which cannot be |
| | | * satisfied. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | void commit() throws ManagedObjectAlreadyExistsException, MissingMandatoryPropertiesException, |
| | | ConcurrentModificationException, OperationRejectedException, ErrorResultException; |
| | | ConcurrentModificationException, OperationRejectedException, LdapException; |
| | | |
| | | /** |
| | | * Determines whether or not this managed object has been modified since it |
| | |
| | | * @throws ConcurrentModificationException |
| | | * If this managed object has been removed from the server by |
| | | * another client. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getChild( |
| | | InstantiableRelationDefinition<C, S> r, String name) throws |
| | | DefinitionDecodingException, ManagedObjectDecodingException, ManagedObjectNotFoundException, |
| | | ConcurrentModificationException, ErrorResultException; |
| | | ConcurrentModificationException, LdapException; |
| | | |
| | | /** |
| | | * Retrieves an optional child managed object. |
| | |
| | | * @throws ConcurrentModificationException |
| | | * If this managed object has been removed from the server by |
| | | * another client. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getChild( |
| | | OptionalRelationDefinition<C, S> r) throws DefinitionDecodingException, |
| | | ManagedObjectDecodingException, ManagedObjectNotFoundException, ConcurrentModificationException, |
| | | ErrorResultException; |
| | | LdapException; |
| | | |
| | | /** |
| | | * Retrieves a singleton child managed object. |
| | |
| | | * @throws ConcurrentModificationException |
| | | * If this managed object has been removed from the server by |
| | | * another client. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getChild( |
| | | SingletonRelationDefinition<C, S> r) throws DefinitionDecodingException, |
| | | ManagedObjectDecodingException, ManagedObjectNotFoundException, ConcurrentModificationException, |
| | | ErrorResultException; |
| | | LdapException; |
| | | |
| | | /** |
| | | * Retrieves a set child managed object. |
| | |
| | | * @throws ConcurrentModificationException |
| | | * If this managed object has been removed from the server by |
| | | * another client. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getChild( |
| | | SetRelationDefinition<C, S> r, String name) throws DefinitionDecodingException, |
| | | ManagedObjectDecodingException, ManagedObjectNotFoundException, ConcurrentModificationException, |
| | | ErrorResultException; |
| | | LdapException; |
| | | |
| | | /** |
| | | * Creates a client configuration view of this managed object. Modifications |
| | |
| | | * @throws ConcurrentModificationException |
| | | * If this managed object has been removed from the server by |
| | | * another client. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If there is any other error. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> boolean hasChild(OptionalRelationDefinition<C, S> r) |
| | | throws ConcurrentModificationException, ErrorResultException; |
| | | throws ConcurrentModificationException, LdapException; |
| | | |
| | | /** |
| | | * Lists the child managed objects associated with the specified |
| | |
| | | * @throws ConcurrentModificationException |
| | | * If this managed object has been removed from the server by |
| | | * another client. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> String[] listChildren( |
| | | InstantiableRelationDefinition<C, S> r) throws ConcurrentModificationException, |
| | | ErrorResultException; |
| | | LdapException; |
| | | |
| | | /** |
| | | * Lists the child managed objects associated with the specified |
| | |
| | | * @throws ConcurrentModificationException |
| | | * If this managed object has been removed from the server by |
| | | * another client. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> String[] listChildren( |
| | | InstantiableRelationDefinition<C, S> r, AbstractManagedObjectDefinition<? extends C, ? extends S> d) |
| | | throws ConcurrentModificationException, ErrorResultException; |
| | | throws ConcurrentModificationException, LdapException; |
| | | |
| | | /** |
| | | * Lists the child managed objects associated with the specified set |
| | |
| | | * @throws ConcurrentModificationException |
| | | * If this managed object has been removed from the server by |
| | | * another client. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> String[] listChildren(SetRelationDefinition<C, S> r) |
| | | throws ConcurrentModificationException, ErrorResultException; |
| | | throws ConcurrentModificationException, LdapException; |
| | | |
| | | /** |
| | | * Lists the child managed objects associated with the specified set |
| | |
| | | * @throws ConcurrentModificationException |
| | | * If this managed object has been removed from the server by |
| | | * another client. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> String[] listChildren(SetRelationDefinition<C, S> r, |
| | | AbstractManagedObjectDefinition<? extends C, ? extends S> d) throws |
| | | ConcurrentModificationException, ErrorResultException; |
| | | ConcurrentModificationException, LdapException; |
| | | |
| | | /** |
| | | * Removes the named instantiable child managed object. |
| | |
| | | * @throws ConcurrentModificationException |
| | | * If this managed object has been removed from the server by |
| | | * another client. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> void removeChild(InstantiableRelationDefinition<C, S> r, |
| | | String name) throws ManagedObjectNotFoundException, OperationRejectedException, |
| | | ConcurrentModificationException, ErrorResultException; |
| | | ConcurrentModificationException, LdapException; |
| | | |
| | | /** |
| | | * Removes an optional child managed object. |
| | |
| | | * @throws ConcurrentModificationException |
| | | * If this managed object has been removed from the server by |
| | | * another client. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> void removeChild(OptionalRelationDefinition<C, S> r) |
| | | throws ManagedObjectNotFoundException, OperationRejectedException, |
| | | ConcurrentModificationException, ErrorResultException; |
| | | ConcurrentModificationException, LdapException; |
| | | |
| | | /** |
| | | * Removes s set child managed object. |
| | |
| | | * @throws ConcurrentModificationException |
| | | * If this managed object has been removed from the server by |
| | | * another client. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | <C extends ConfigurationClient, S extends Configuration> void removeChild(SetRelationDefinition<C, S> r, |
| | | String name) throws ManagedObjectNotFoundException, OperationRejectedException, |
| | | ConcurrentModificationException, ErrorResultException; |
| | | ConcurrentModificationException, LdapException; |
| | | |
| | | /** |
| | | * Sets a new pending value for the specified property. |
| | |
| | | import org.forgerock.opendj.config.PropertyException; |
| | | import org.forgerock.opendj.config.SetRelationDefinition; |
| | | import org.forgerock.opendj.config.client.spi.Driver; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | |
| | | /** |
| | | * Client management connection context. |
| | |
| | | * client-side or server-side constraint which cannot be |
| | | * satisfied (for example, if it is referenced by another |
| | | * managed object). |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | public final <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject( |
| | | ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd, String name) |
| | | throws ManagedObjectNotFoundException, OperationRejectedException, |
| | | ErrorResultException { |
| | | LdapException { |
| | | return getDriver().deleteManagedObject(parent, rd, name); |
| | | } |
| | | |
| | |
| | | * client-side or server-side constraint which cannot be |
| | | * satisfied (for example, if it is referenced by another |
| | | * managed object). |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | public final <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject( |
| | | ManagedObjectPath<?, ?> parent, OptionalRelationDefinition<C, S> rd) throws |
| | | ManagedObjectNotFoundException, OperationRejectedException, ErrorResultException { |
| | | ManagedObjectNotFoundException, OperationRejectedException, LdapException { |
| | | return getDriver().deleteManagedObject(parent, rd); |
| | | } |
| | | |
| | |
| | | * client-side or server-side constraint which cannot be |
| | | * satisfied (for example, if it is referenced by another |
| | | * managed object). |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | public final <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject( |
| | | ManagedObjectPath<?, ?> parent, SetRelationDefinition<C, S> rd, String name) |
| | | throws ManagedObjectNotFoundException, OperationRejectedException, |
| | | ErrorResultException { |
| | | throws ManagedObjectNotFoundException, OperationRejectedException, LdapException { |
| | | return getDriver().deleteManagedObject(parent, rd, name); |
| | | } |
| | | |
| | |
| | | * @throws ManagedObjectNotFoundException |
| | | * If the requested managed object could not be found on the |
| | | * server. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public final <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getManagedObject( |
| | | ManagedObjectPath<C, S> path) throws DefinitionDecodingException, ManagedObjectDecodingException, |
| | | ManagedObjectNotFoundException, ErrorResultException { |
| | | ManagedObjectNotFoundException, LdapException { |
| | | // Be careful to handle the root configuration. |
| | | if (path.isEmpty()) { |
| | | return (ManagedObject<C>) getRootConfigurationManagedObject(); |
| | |
| | | * @throws ManagedObjectNotFoundException |
| | | * If the requested managed object could not be found on the |
| | | * server. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | public final <P> P getPropertyValue(ManagedObjectPath<?, ?> path, PropertyDefinition<P> pd) |
| | | throws DefinitionDecodingException, ErrorResultException, ManagedObjectNotFoundException { |
| | | throws DefinitionDecodingException, LdapException, ManagedObjectNotFoundException { |
| | | Set<P> values = getPropertyValues(path, pd); |
| | | if (values.isEmpty()) { |
| | | return null; |
| | |
| | | * @throws ManagedObjectNotFoundException |
| | | * If the requested managed object could not be found on the |
| | | * server. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | public final <P> SortedSet<P> getPropertyValues(ManagedObjectPath<?, ?> path, PropertyDefinition<P> pd) |
| | | throws DefinitionDecodingException, ErrorResultException, ManagedObjectNotFoundException { |
| | | throws DefinitionDecodingException, LdapException, ManagedObjectNotFoundException { |
| | | return getDriver().getPropertyValues(path, pd); |
| | | } |
| | | |
| | |
| | | * managed object's definition. |
| | | * @throws ManagedObjectNotFoundException |
| | | * If the parent managed object could not be found. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | public final <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects( |
| | | ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd) throws |
| | | ManagedObjectNotFoundException, ErrorResultException { |
| | | ManagedObjectNotFoundException, LdapException { |
| | | return listManagedObjects(parent, rd, rd.getChildDefinition()); |
| | | } |
| | | |
| | |
| | | * managed object's definition. |
| | | * @throws ManagedObjectNotFoundException |
| | | * If the parent managed object could not be found. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | public final <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects( |
| | | ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd, |
| | | AbstractManagedObjectDefinition<? extends C, ? extends S> d) throws |
| | | ManagedObjectNotFoundException, ErrorResultException { |
| | | ManagedObjectNotFoundException, LdapException { |
| | | return getDriver().listManagedObjects(parent, rd, d); |
| | | } |
| | | |
| | |
| | | * managed object's definition. |
| | | * @throws ManagedObjectNotFoundException |
| | | * If the parent managed object could not be found. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | public final <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects( |
| | | ManagedObjectPath<?, ?> parent, SetRelationDefinition<C, S> rd) throws |
| | | ManagedObjectNotFoundException, ErrorResultException { |
| | | ManagedObjectNotFoundException, LdapException { |
| | | return getDriver().listManagedObjects(parent, rd, rd.getChildDefinition()); |
| | | } |
| | | |
| | |
| | | * <code>false</code> otherwise. |
| | | * @throws ManagedObjectNotFoundException |
| | | * If the parent managed object could not be found. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | public final boolean managedObjectExists(ManagedObjectPath<?, ?> path) throws ManagedObjectNotFoundException, |
| | | ErrorResultException { |
| | | LdapException { |
| | | return getDriver().managedObjectExists(path); |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2008-2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2013-2014 ForgeRock, AS. |
| | | * Portions Copyright 2013-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.config.client.ldap; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.EntryNotFoundException; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.ErrorResultIOException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.Filter; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchResultReferenceIOException; |
| | |
| | | @Override |
| | | public <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getManagedObject( |
| | | ManagedObjectPath<C, S> path) throws DefinitionDecodingException, ManagedObjectDecodingException, |
| | | ManagedObjectNotFoundException, ErrorResultException { |
| | | ManagedObjectNotFoundException, LdapException { |
| | | if (!managedObjectExists(path)) { |
| | | throw new ManagedObjectNotFoundException(); |
| | | } |
| | |
| | | } else { |
| | | throw new ManagedObjectDecodingException(mo, exceptions); |
| | | } |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | if (e.getResult().getResultCode() == ResultCode.NO_SUCH_OBJECT) { |
| | | throw new ManagedObjectNotFoundException(); |
| | | } |
| | |
| | | @Override |
| | | public <C extends ConfigurationClient, S extends Configuration, P> SortedSet<P> getPropertyValues( |
| | | ManagedObjectPath<C, S> path, PropertyDefinition<P> propertyDef) throws DefinitionDecodingException, |
| | | ManagedObjectNotFoundException, ErrorResultException { |
| | | ManagedObjectNotFoundException, LdapException { |
| | | // Check that the requested property is from the definition |
| | | // associated with the path. |
| | | AbstractManagedObjectDefinition<C, S> d = path.getManagedObjectDefinition(); |
| | |
| | | } |
| | | |
| | | return values; |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | if (e.getResult().getResultCode() == ResultCode.NO_SUCH_OBJECT) { |
| | | throw new ManagedObjectNotFoundException(); |
| | | } |
| | |
| | | public <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects( |
| | | ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd, |
| | | AbstractManagedObjectDefinition<? extends C, ? extends S> d) throws ManagedObjectNotFoundException, |
| | | ErrorResultException { |
| | | LdapException { |
| | | validateRelationDefinition(parent, rd); |
| | | |
| | | if (!managedObjectExists(parent)) { |
| | |
| | | for (DN child : listEntries(dn, filter)) { |
| | | children.add(child.rdn().getFirstAVA().getAttributeValue().toString()); |
| | | } |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | if (e.getResult().getResultCode() == ResultCode.NO_SUCH_OBJECT) { |
| | | // Ignore this |
| | | // It means that the base entry does not exist |
| | |
| | | public <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects( |
| | | ManagedObjectPath<?, ?> parent, SetRelationDefinition<C, S> rd, |
| | | AbstractManagedObjectDefinition<? extends C, ? extends S> d) throws ManagedObjectNotFoundException, |
| | | ErrorResultException { |
| | | LdapException { |
| | | validateRelationDefinition(parent, rd); |
| | | |
| | | if (!managedObjectExists(parent)) { |
| | |
| | | for (DN child : listEntries(dn, filter)) { |
| | | children.add(child.rdn().getFirstAVA().getAttributeValue().toString()); |
| | | } |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | if (e.getResult().getResultCode() == ResultCode.NO_SUCH_OBJECT) { |
| | | // Ignore this |
| | | // It means that the base entry does not exist |
| | |
| | | */ |
| | | @Override |
| | | public boolean managedObjectExists(ManagedObjectPath<?, ?> path) throws ManagedObjectNotFoundException, |
| | | ErrorResultException { |
| | | LdapException { |
| | | if (path.isEmpty()) { |
| | | return true; |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | protected <C extends ConfigurationClient, S extends Configuration> void deleteManagedObject( |
| | | ManagedObjectPath<C, S> path) throws OperationRejectedException, ErrorResultException { |
| | | ManagedObjectPath<C, S> path) throws OperationRejectedException, LdapException { |
| | | // Delete the entry and any subordinate entries. |
| | | DN dn = DNBuilder.create(path, profile); |
| | | try { |
| | | deleteSubtree(dn); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | if (e.getResult().getResultCode() == ResultCode.UNWILLING_TO_PERFORM) { |
| | | AbstractManagedObjectDefinition<?, ?> d = path.getManagedObjectDefinition(); |
| | | LocalizableMessage m = LocalizableMessage.raw("%s", e.getMessage()); |
| | |
| | | * @param dn |
| | | * The LDAP entry name. |
| | | * @return Returns <code>true</code> if the named LDAP entry exists. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * if a problem occurs. |
| | | */ |
| | | boolean entryExists(DN dn) throws ErrorResultException { |
| | | boolean entryExists(DN dn) throws LdapException { |
| | | try { |
| | | connection.readEntry(dn, "1.1"); |
| | | return true; |
| | |
| | | // entry. |
| | | // @Checkstyle:off |
| | | private <C extends ConfigurationClient, S extends Configuration> ManagedObjectDefinition<? extends C, ? extends S> |
| | | getEntryDefinition(AbstractManagedObjectDefinition<C, S> d, DN dn) throws ErrorResultException, |
| | | getEntryDefinition(AbstractManagedObjectDefinition<C, S> d, DN dn) throws LdapException, |
| | | DefinitionDecodingException { |
| | | // @Checkstyle:on |
| | | SearchResultEntry searchResultEntry = connection.readEntry(dn, "objectclass"); |
| | |
| | | * Delete a subtree of entries. We cannot use the subtree delete control because it is not supported by the config |
| | | * backend. |
| | | */ |
| | | private void deleteSubtree(DN dn) throws ErrorResultException { |
| | | private void deleteSubtree(DN dn) throws LdapException { |
| | | // Delete the children first. |
| | | for (DN child : listEntries(dn, Filter.objectClassPresent())) { |
| | | deleteSubtree(child); |
| | |
| | | connection.delete(dn.toString()); |
| | | } |
| | | |
| | | private Collection<DN> listEntries(DN dn, Filter filter) throws ErrorResultException { |
| | | private Collection<DN> listEntries(DN dn, Filter filter) throws LdapException { |
| | | List<DN> names = new LinkedList<DN>(); |
| | | ConnectionEntryReader reader = |
| | | connection.search(dn.toString(), SearchScope.SINGLE_LEVEL, filter.toString()); |
| | |
| | | while (reader.hasNext()) { |
| | | names.add(reader.readEntry().getName()); |
| | | } |
| | | } catch (ErrorResultIOException e) { |
| | | throw e.getCause(); |
| | | } catch (SearchResultReferenceIOException e) { |
| | | // Ignore. |
| | | } finally { |
| | |
| | | * |
| | | * |
| | | * Copyright 2007-2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2014 ForgeRock AS. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.config.client.ldap; |
| | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LinkedAttribute; |
| | | import org.forgerock.opendj.ldap.LinkedHashMapEntry; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | protected void addNewManagedObject() throws ErrorResultException, OperationRejectedException, |
| | | protected void addNewManagedObject() throws LdapException, OperationRejectedException, |
| | | ConcurrentModificationException, ManagedObjectAlreadyExistsException { |
| | | // First make sure that the parent managed object still exists. |
| | | ManagedObjectDefinition<?, ?> d = getManagedObjectDefinition(); |
| | |
| | | // Create the entry. |
| | | try { |
| | | driver.getLDAPConnection().add(entry); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | if (e.getResult().getResultCode() == ResultCode.UNWILLING_TO_PERFORM) { |
| | | LocalizableMessage m = LocalizableMessage.raw("%s", e.getLocalizedMessage()); |
| | | throw new OperationRejectedException(OperationType.CREATE, d.getUserFriendlyName(), m); |
| | |
| | | try { |
| | | // Create the entry. |
| | | driver.getLDAPConnection().add(entry); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | if (e.getResult().getResultCode() == ResultCode.ENTRY_ALREADY_EXISTS) { |
| | | throw new ManagedObjectAlreadyExistsException(); |
| | | } else if (e.getResult().getResultCode() == ResultCode.UNWILLING_TO_PERFORM) { |
| | |
| | | */ |
| | | @Override |
| | | protected void modifyExistingManagedObject() throws ConcurrentModificationException, OperationRejectedException, |
| | | ErrorResultException { |
| | | LdapException { |
| | | // Build the modify request |
| | | ManagedObjectPath<?, ?> path = getManagedObjectPath(); |
| | | DN dn = DNBuilder.create(path, driver.getLDAPProfile()); |
| | |
| | | if (!request.getModifications().isEmpty()) { |
| | | try { |
| | | driver.getLDAPConnection().modify(request); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | if (e.getResult().getResultCode() == ResultCode.UNWILLING_TO_PERFORM) { |
| | | LocalizableMessage m = LocalizableMessage.raw("%s", e.getLocalizedMessage()); |
| | | throw new OperationRejectedException(OperationType.MODIFY, d.getUserFriendlyName(), m); |
| | |
| | | * |
| | | * |
| | | * Copyright 2008-2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.config.client.spi; |
| | | |
| | |
| | | import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; |
| | | import org.forgerock.opendj.config.client.OperationRejectedException; |
| | | import org.forgerock.opendj.config.client.OperationRejectedException.OperationType; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | |
| | | /** |
| | | * An abstract managed object implementation. |
| | |
| | | |
| | | private OperationRejectedException ore = null; |
| | | |
| | | private ErrorResultException ere = null; |
| | | private LdapException ere = null; |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | |
| | | cme = e; |
| | | } catch (OperationRejectedException e) { |
| | | ore = e; |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | ere = e; |
| | | } |
| | | } |
| | |
| | | * @param rd |
| | | * The relation definition. |
| | | */ |
| | | private void createDefaultManagedObjects(RelationDefinition<?, ?> rd) throws ErrorResultException, |
| | | private void createDefaultManagedObjects(RelationDefinition<?, ?> rd) throws LdapException, |
| | | ConcurrentModificationException, MissingMandatoryPropertiesException, |
| | | ManagedObjectAlreadyExistsException, OperationRejectedException { |
| | | rd.accept(this, null); |
| | |
| | | */ |
| | | @Override |
| | | public final void commit() throws ManagedObjectAlreadyExistsException, MissingMandatoryPropertiesException, |
| | | ConcurrentModificationException, OperationRejectedException, ErrorResultException { |
| | | ConcurrentModificationException, OperationRejectedException, LdapException { |
| | | // First make sure all mandatory properties are defined. |
| | | List<PropertyException> exceptions = new LinkedList<PropertyException>(); |
| | | |
| | |
| | | public final <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getChild( |
| | | InstantiableRelationDefinition<C, S> r, String name) throws DefinitionDecodingException, |
| | | ManagedObjectDecodingException, ManagedObjectNotFoundException, ConcurrentModificationException, |
| | | ErrorResultException { |
| | | LdapException { |
| | | validateRelationDefinition(r); |
| | | ensureThisManagedObjectExists(); |
| | | Driver ctx = getDriver(); |
| | |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getChild( |
| | | OptionalRelationDefinition<C, S> r) throws DefinitionDecodingException, ManagedObjectDecodingException, |
| | | ManagedObjectNotFoundException, ConcurrentModificationException, ErrorResultException { |
| | | ManagedObjectNotFoundException, ConcurrentModificationException, LdapException { |
| | | validateRelationDefinition(r); |
| | | ensureThisManagedObjectExists(); |
| | | Driver ctx = getDriver(); |
| | |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getChild( |
| | | SingletonRelationDefinition<C, S> r) throws DefinitionDecodingException, ManagedObjectDecodingException, |
| | | ManagedObjectNotFoundException, ConcurrentModificationException, ErrorResultException { |
| | | ManagedObjectNotFoundException, ConcurrentModificationException, LdapException { |
| | | validateRelationDefinition(r); |
| | | ensureThisManagedObjectExists(); |
| | | Driver ctx = getDriver(); |
| | |
| | | public final <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getChild( |
| | | SetRelationDefinition<C, S> r, String name) throws DefinitionDecodingException, |
| | | ManagedObjectDecodingException, ManagedObjectNotFoundException, ConcurrentModificationException, |
| | | ErrorResultException { |
| | | LdapException { |
| | | validateRelationDefinition(r); |
| | | ensureThisManagedObjectExists(); |
| | | Driver ctx = getDriver(); |
| | |
| | | */ |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration> boolean hasChild( |
| | | OptionalRelationDefinition<C, S> r) throws ConcurrentModificationException, ErrorResultException { |
| | | OptionalRelationDefinition<C, S> r) throws ConcurrentModificationException, LdapException { |
| | | validateRelationDefinition(r); |
| | | Driver ctx = getDriver(); |
| | | try { |
| | |
| | | */ |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration> String[] listChildren( |
| | | InstantiableRelationDefinition<C, S> r) throws ConcurrentModificationException, ErrorResultException { |
| | | InstantiableRelationDefinition<C, S> r) throws ConcurrentModificationException, LdapException { |
| | | return listChildren(r, r.getChildDefinition()); |
| | | } |
| | | |
| | |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration> String[] listChildren( |
| | | InstantiableRelationDefinition<C, S> r, AbstractManagedObjectDefinition<? extends C, ? extends S> d) |
| | | throws ConcurrentModificationException, ErrorResultException { |
| | | throws ConcurrentModificationException, LdapException { |
| | | validateRelationDefinition(r); |
| | | Driver ctx = getDriver(); |
| | | try { |
| | |
| | | */ |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration> String[] listChildren( |
| | | SetRelationDefinition<C, S> r) throws ConcurrentModificationException, ErrorResultException { |
| | | SetRelationDefinition<C, S> r) throws ConcurrentModificationException, LdapException { |
| | | return listChildren(r, r.getChildDefinition()); |
| | | } |
| | | |
| | |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration> String[] listChildren( |
| | | SetRelationDefinition<C, S> r, AbstractManagedObjectDefinition<? extends C, ? extends S> d) |
| | | throws ConcurrentModificationException, ErrorResultException { |
| | | throws ConcurrentModificationException, LdapException { |
| | | validateRelationDefinition(r); |
| | | Driver ctx = getDriver(); |
| | | try { |
| | |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration> void removeChild( |
| | | InstantiableRelationDefinition<C, S> r, String name) throws ManagedObjectNotFoundException, |
| | | OperationRejectedException, ConcurrentModificationException, ErrorResultException { |
| | | OperationRejectedException, ConcurrentModificationException, LdapException { |
| | | validateRelationDefinition(r); |
| | | Driver ctx = getDriver(); |
| | | boolean found; |
| | |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration> void removeChild( |
| | | OptionalRelationDefinition<C, S> r) throws ManagedObjectNotFoundException, OperationRejectedException, |
| | | ConcurrentModificationException, ErrorResultException { |
| | | ConcurrentModificationException, LdapException { |
| | | validateRelationDefinition(r); |
| | | Driver ctx = getDriver(); |
| | | boolean found; |
| | |
| | | @Override |
| | | public final <C extends ConfigurationClient, S extends Configuration> void removeChild( |
| | | SetRelationDefinition<C, S> r, String name) throws ManagedObjectNotFoundException, |
| | | OperationRejectedException, ConcurrentModificationException, ErrorResultException { |
| | | OperationRejectedException, ConcurrentModificationException, LdapException { |
| | | validateRelationDefinition(r); |
| | | Driver ctx = getDriver(); |
| | | boolean found; |
| | |
| | | * @throws OperationRejectedException |
| | | * If the managed object cannot be added due to some client-side |
| | | * or server-side constraint which cannot be satisfied. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | protected abstract void addNewManagedObject() throws ErrorResultException, OperationRejectedException, |
| | | protected abstract void addNewManagedObject() throws LdapException, OperationRejectedException, |
| | | ConcurrentModificationException, ManagedObjectAlreadyExistsException; |
| | | |
| | | /** |
| | |
| | | * @throws OperationRejectedException |
| | | * If the managed object cannot be added due to some client-side |
| | | * or server-side constraint which cannot be satisfied. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | protected abstract void modifyExistingManagedObject() throws ConcurrentModificationException, |
| | | OperationRejectedException, ErrorResultException; |
| | | OperationRejectedException, LdapException; |
| | | |
| | | /** |
| | | * Creates a new managed object. |
| | |
| | | } |
| | | |
| | | // Makes sure that this managed object exists. |
| | | private void ensureThisManagedObjectExists() throws ConcurrentModificationException, ErrorResultException { |
| | | private void ensureThisManagedObjectExists() throws ConcurrentModificationException, LdapException { |
| | | if (!path.isEmpty()) { |
| | | Driver ctx = getDriver(); |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2008-2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.config.client.spi; |
| | | |
| | |
| | | import org.forgerock.opendj.config.client.ManagementContext; |
| | | import org.forgerock.opendj.config.client.OperationRejectedException; |
| | | import org.forgerock.opendj.config.client.OperationRejectedException.OperationType; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | |
| | | /** |
| | | * An abstract management connection context driver which should form the basis |
| | |
| | | throw PropertyException.defaultBehaviorException(pd1, e); |
| | | } catch (PropertyNotFoundException e) { |
| | | throw PropertyException.defaultBehaviorException(pd1, e); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | throw PropertyException.defaultBehaviorException(pd1, e); |
| | | } catch (ManagedObjectNotFoundException e) { |
| | | throw PropertyException.defaultBehaviorException(pd1, e); |
| | |
| | | * client-side or server-side constraint which cannot be |
| | | * satisfied (for example, if it is referenced by another |
| | | * managed object). |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | public final <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject( |
| | | ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd, String name) |
| | | throws ManagedObjectNotFoundException, OperationRejectedException, ErrorResultException { |
| | | throws ManagedObjectNotFoundException, OperationRejectedException, LdapException { |
| | | validateRelationDefinition(parent, rd); |
| | | ManagedObjectPath<?, ?> child = parent.child(rd, name); |
| | | return doDeleteManagedObject(child); |
| | |
| | | * client-side or server-side constraint which cannot be |
| | | * satisfied (for example, if it is referenced by another |
| | | * managed object). |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | public final <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject( |
| | | ManagedObjectPath<?, ?> parent, OptionalRelationDefinition<C, S> rd) throws ManagedObjectNotFoundException, |
| | | OperationRejectedException, ErrorResultException { |
| | | OperationRejectedException, LdapException { |
| | | validateRelationDefinition(parent, rd); |
| | | ManagedObjectPath<?, ?> child = parent.child(rd); |
| | | return doDeleteManagedObject(child); |
| | |
| | | * client-side or server-side constraint which cannot be |
| | | * satisfied (for example, if it is referenced by another |
| | | * managed object). |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | public final <C extends ConfigurationClient, S extends Configuration> boolean deleteManagedObject( |
| | | ManagedObjectPath<?, ?> parent, SetRelationDefinition<C, S> rd, String name) |
| | | throws ManagedObjectNotFoundException, OperationRejectedException, ErrorResultException { |
| | | throws ManagedObjectNotFoundException, OperationRejectedException, LdapException { |
| | | validateRelationDefinition(parent, rd); |
| | | ManagedObjectPath<?, ?> child = parent.child(rd, name); |
| | | return doDeleteManagedObject(child); |
| | |
| | | * @throws ManagedObjectNotFoundException |
| | | * If the requested managed object could not be found on the |
| | | * server. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | // @Checkstyle:ignore |
| | | public abstract <C extends ConfigurationClient, S extends Configuration> ManagedObject<? extends C> getManagedObject( |
| | | ManagedObjectPath<C, S> path) throws DefinitionDecodingException, ManagedObjectDecodingException, |
| | | ManagedObjectNotFoundException, ErrorResultException; |
| | | ManagedObjectNotFoundException, LdapException; |
| | | |
| | | /** |
| | | * Gets the effective values of a property in the named managed object. |
| | |
| | | * @throws ManagedObjectNotFoundException |
| | | * If the requested managed object could not be found on the |
| | | * server. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | public abstract <C extends ConfigurationClient, S extends Configuration, P> SortedSet<P> getPropertyValues( |
| | | ManagedObjectPath<C, S> path, PropertyDefinition<P> pd) throws DefinitionDecodingException, |
| | | ManagedObjectNotFoundException, ErrorResultException; |
| | | ManagedObjectNotFoundException, LdapException; |
| | | |
| | | /** |
| | | * Gets the root configuration managed object associated with this |
| | |
| | | * managed object's definition. |
| | | * @throws ManagedObjectNotFoundException |
| | | * If the parent managed object could not be found. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | public abstract <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects( |
| | | ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd, |
| | | AbstractManagedObjectDefinition<? extends C, ? extends S> d) throws ManagedObjectNotFoundException, |
| | | ErrorResultException; |
| | | LdapException; |
| | | |
| | | /** |
| | | * Lists the child managed objects of the named parent managed object which |
| | |
| | | * managed object's definition. |
| | | * @throws ManagedObjectNotFoundException |
| | | * If the parent managed object could not be found. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | public abstract <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects( |
| | | ManagedObjectPath<?, ?> parent, SetRelationDefinition<C, S> rd, |
| | | AbstractManagedObjectDefinition<? extends C, ? extends S> d) throws ManagedObjectNotFoundException, |
| | | ErrorResultException; |
| | | LdapException; |
| | | |
| | | /** |
| | | * Determines whether or not the named managed object exists. |
| | |
| | | * <code>false</code> otherwise. |
| | | * @throws ManagedObjectNotFoundException |
| | | * If the parent managed object could not be found. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | public abstract boolean managedObjectExists(ManagedObjectPath<?, ?> path) throws ManagedObjectNotFoundException, |
| | | ErrorResultException; |
| | | LdapException; |
| | | |
| | | /** |
| | | * Deletes the named managed object. |
| | |
| | | * If the managed object cannot be removed due to some |
| | | * server-side constraint which cannot be satisfied (for |
| | | * example, if it is referenced by another managed object). |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | protected abstract <C extends ConfigurationClient, S extends Configuration> void deleteManagedObject( |
| | | ManagedObjectPath<C, S> path) throws OperationRejectedException, ErrorResultException; |
| | | ManagedObjectPath<C, S> path) throws OperationRejectedException, LdapException; |
| | | |
| | | /** |
| | | * Gets the default values for the specified property. |
| | |
| | | // constraints are satisfied. |
| | | private <C extends ConfigurationClient, S extends Configuration> boolean doDeleteManagedObject( |
| | | ManagedObjectPath<C, S> path) throws ManagedObjectNotFoundException, OperationRejectedException, |
| | | ErrorResultException { |
| | | LdapException { |
| | | // First make sure that the parent exists. |
| | | if (!managedObjectExists(path.parent())) { |
| | | throw new ManagedObjectNotFoundException(); |
| | |
| | | * |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.config.conditions; |
| | | |
| | |
| | | import org.forgerock.opendj.config.client.ManagementContext; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.config.server.ServerManagedObject; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.util.Reject; |
| | | |
| | | /** |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws ErrorResultException { |
| | | public boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws LdapException { |
| | | for (Condition condition : conditions) { |
| | | if (!condition.evaluate(context, managedObject)) { |
| | | return false; |
| | |
| | | * |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.config.conditions; |
| | | |
| | |
| | | import org.forgerock.opendj.config.client.ManagementContext; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.config.server.ServerManagedObject; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | |
| | | /** |
| | | * An interface for evaluating conditions. |
| | |
| | | * @param managedObject |
| | | * The client managed object. |
| | | * @return Returns <code>true</code> if this condition is satisfied. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the condition could not be evaluated. |
| | | */ |
| | | boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws ErrorResultException; |
| | | boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws LdapException; |
| | | |
| | | /** |
| | | * Evaluates this condition against the provided server managed object. |
| | |
| | | * |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.config.conditions; |
| | | |
| | |
| | | import org.forgerock.opendj.config.client.ManagementContext; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.config.server.ServerManagedObject; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | |
| | | /** |
| | | * This class consists exclusively of static methods that operate on or return |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws ErrorResultException { |
| | | public boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws LdapException { |
| | | return false; |
| | | } |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws ErrorResultException { |
| | | public boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws LdapException { |
| | | return true; |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.config.conditions; |
| | | |
| | |
| | | import org.forgerock.opendj.config.client.ManagementContext; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.config.server.ServerManagedObject; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.util.Reject; |
| | | |
| | | /** |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws ErrorResultException { |
| | | public boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws LdapException { |
| | | SortedSet<T> values = managedObject.getPropertyValues(pd); |
| | | return values.contains(value); |
| | | } |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws ErrorResultException { |
| | | public boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws LdapException { |
| | | return impl.evaluate(context, managedObject); |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.config.conditions; |
| | | |
| | |
| | | import org.forgerock.opendj.config.client.ManagementContext; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.config.server.ServerManagedObject; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.util.Reject; |
| | | |
| | | /** |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws ErrorResultException { |
| | | public boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws LdapException { |
| | | SortedSet<?> values = managedObject.getPropertyValues(pd); |
| | | return !values.isEmpty(); |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.config.conditions; |
| | | |
| | |
| | | import org.forgerock.opendj.config.client.ManagementContext; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.config.server.ServerManagedObject; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.util.Reject; |
| | | |
| | | /** |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws ErrorResultException { |
| | | public boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws LdapException { |
| | | return !condition.evaluate(context, managedObject); |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.config.conditions; |
| | | |
| | |
| | | import org.forgerock.opendj.config.client.ManagementContext; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.config.server.ServerManagedObject; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.util.Reject; |
| | | |
| | | /** |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws ErrorResultException { |
| | | public boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws LdapException { |
| | | for (Condition condition : conditions) { |
| | | if (condition.evaluate(context, managedObject)) { |
| | | return true; |
| | |
| | | * |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions copyright 2013-2014 ForgeRock AS. |
| | | * Portions Copyright 2013-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.config.dsconfig; |
| | | |
| | |
| | | import org.forgerock.opendj.config.ConfigurationFramework; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | |
| | | /** |
| | |
| | | try { |
| | | final SearchResultEntry entry = connection.readEntry("", "fullVendorVersion"); |
| | | return valueOf(entry.getAttribute("fullVendorVersion").firstValueAsString()); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | throw new ConfigException(ERR_CONFIGVERSION_NOT_FOUND.get()); |
| | | } |
| | | } |
| | |
| | | import org.forgerock.opendj.config.conditions.Condition; |
| | | import org.forgerock.opendj.config.conditions.ContainsCondition; |
| | | import org.forgerock.opendj.ldap.AuthorizationException; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | |
| | | import com.forgerock.opendj.cli.Argument; |
| | | import com.forgerock.opendj.cli.ArgumentException; |
| | |
| | | } catch (AuthorizationException e) { |
| | | LocalizableMessage msg = ERR_DSCFG_ERROR_CREATE_AUTHZ.get(ufn); |
| | | throw new ClientException(ReturnCode.INSUFFICIENT_ACCESS_RIGHTS, msg); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | LocalizableMessage msg = ERR_DSCFG_ERROR_CREATE_CE.get(ufn, e.getMessage()); |
| | | throw new ClientException(ReturnCode.OTHER, msg); |
| | | } |
| | |
| | | } else { |
| | | throw new ClientException(ReturnCode.CONSTRAINT_VIOLATION, e.getMessageObject(), e); |
| | | } |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | final LocalizableMessage msg = ERR_DSCFG_ERROR_CREATE_CE.get(ufn, e.getMessage()); |
| | | if (app.isInteractive()) { |
| | | app.println(); |
| | |
| | | } catch (ConcurrentModificationException e) { |
| | | LocalizableMessage msg = ERR_DSCFG_ERROR_CREATE_CME.get(irelation.getUserFriendlyName()); |
| | | throw new ClientException(ReturnCode.CONSTRAINT_VIOLATION, msg); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | LocalizableMessage msg = ERR_DSCFG_ERROR_CREATE_CE.get(irelation.getUserFriendlyName(), |
| | | e.getMessage()); |
| | | throw new ClientException(ReturnCode.APPLICATION_ERROR, msg); |
| | |
| | | } else { |
| | | throw new ClientException(ReturnCode.NO_SUCH_OBJECT, msg); |
| | | } |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | throw new ClientException(ReturnCode.OTHER, LocalizableMessage.raw(e.getLocalizedMessage())); |
| | | } |
| | | |
| | |
| | | } catch (ConcurrentModificationException e) { |
| | | LocalizableMessage msg = ERR_DSCFG_ERROR_CREATE_CME.get(ufn); |
| | | throw new ClientException(ReturnCode.CONSTRAINT_VIOLATION, msg); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | LocalizableMessage msg = ERR_DSCFG_ERROR_CREATE_CE.get(ufn, e.getMessage()); |
| | | throw new ClientException(ReturnCode.CLIENT_SIDE_SERVER_DOWN, msg); |
| | | } |
| | |
| | | import org.forgerock.opendj.config.client.ManagementContext; |
| | | import org.forgerock.opendj.config.client.OperationRejectedException; |
| | | import org.forgerock.opendj.ldap.AuthorizationException; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | |
| | | import com.forgerock.opendj.cli.ArgumentException; |
| | | import com.forgerock.opendj.cli.BooleanArgument; |
| | |
| | | } else { |
| | | return MenuResult.success(0); |
| | | } |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | throw new ClientException(ReturnCode.OTHER, LocalizableMessage.raw(e.getLocalizedMessage())); |
| | | } |
| | | |
| | |
| | | } catch (ConcurrentModificationException e) { |
| | | LocalizableMessage msg = ERR_DSCFG_ERROR_DELETE_CME.get(ufn); |
| | | throw new ClientException(ReturnCode.CONSTRAINT_VIOLATION, msg); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | LocalizableMessage msg = ERR_DSCFG_ERROR_DELETE_CE.get(ufn, e.getMessage()); |
| | | throw new ClientException(ReturnCode.CLIENT_SIDE_SERVER_DOWN, msg); |
| | | } |
| | |
| | | import org.forgerock.opendj.config.client.ManagedObjectDecodingException; |
| | | import org.forgerock.opendj.config.client.ManagementContext; |
| | | import org.forgerock.opendj.ldap.AuthorizationException; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | |
| | | import com.forgerock.opendj.cli.ArgumentException; |
| | | import com.forgerock.opendj.cli.ReturnCode; |
| | |
| | | } catch (ManagedObjectNotFoundException e) { |
| | | LocalizableMessage msg = ERR_DSCFG_ERROR_GET_CHILD_MONFE.get(ufn); |
| | | throw new ClientException(ReturnCode.NO_SUCH_OBJECT, msg); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | throw new ClientException(ReturnCode.OTHER, LocalizableMessage.raw(e.getLocalizedMessage())); |
| | | } |
| | | |
| | |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ConnectionFactory; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | |
| | | import com.forgerock.opendj.cli.ArgumentException; |
| | | import com.forgerock.opendj.cli.ClientException; |
| | |
| | | try { |
| | | connection = factory.getConnection(); |
| | | BuildVersion.checkVersionMismatch(connection); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | if (e.getCause() instanceof SSLException) { |
| | | throw new ClientException(ReturnCode.CLIENT_SIDE_CONNECT_ERROR, |
| | | ERR_FAILED_TO_CONNECT_NOT_TRUSTED.get(hostName, String.valueOf(port))); |
| | |
| | | import org.forgerock.opendj.config.client.ManagedObjectDecodingException; |
| | | import org.forgerock.opendj.config.client.ManagementContext; |
| | | import org.forgerock.opendj.ldap.AuthorizationException; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | |
| | | import com.forgerock.opendj.cli.ArgumentException; |
| | | import com.forgerock.opendj.cli.ClientException; |
| | |
| | | } else { |
| | | throw new ClientException(ReturnCode.NO_SUCH_OBJECT, msg); |
| | | } |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | throw new ClientException(ReturnCode.OTHER, LocalizableMessage.raw(e.getLocalizedMessage())); |
| | | } |
| | | |
| | |
| | | } catch (ConcurrentModificationException e) { |
| | | LocalizableMessage msg = ERR_DSCFG_ERROR_LIST_CME.get(ufn); |
| | | throw new ClientException(ReturnCode.CONSTRAINT_VIOLATION, msg); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | LocalizableMessage msg = ERR_DSCFG_ERROR_LIST_CE.get(ufn, e.getMessage()); |
| | | throw new ClientException(ReturnCode.CLIENT_SIDE_SERVER_DOWN, msg); |
| | | } |
| | |
| | | } catch (ConcurrentModificationException e) { |
| | | LocalizableMessage msg = ERR_DSCFG_ERROR_LIST_CME.get(ufn); |
| | | throw new ClientException(ReturnCode.CONSTRAINT_VIOLATION, msg); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | LocalizableMessage msg = ERR_DSCFG_ERROR_LIST_CE.get(ufn, e.getMessage()); |
| | | throw new ClientException(ReturnCode.CLIENT_SIDE_SERVER_DOWN, msg); |
| | | } |
| | |
| | | } catch (ConcurrentModificationException e) { |
| | | LocalizableMessage msg = ERR_DSCFG_ERROR_LIST_CME.get(ufn); |
| | | throw new ClientException(ReturnCode.CONSTRAINT_VIOLATION, msg); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | LocalizableMessage msg = ERR_DSCFG_ERROR_LIST_CE.get(ufn, e.getMessage()); |
| | | throw new ClientException(ReturnCode.CLIENT_SIDE_SERVER_DOWN, msg); |
| | | } catch (ManagedObjectNotFoundException e) { |
| | |
| | | import org.forgerock.opendj.config.client.ManagedObjectDecodingException; |
| | | import org.forgerock.opendj.config.client.ManagementContext; |
| | | import org.forgerock.opendj.ldap.AuthorizationException; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.util.Reject; |
| | | |
| | | import com.forgerock.opendj.cli.ClientException; |
| | |
| | | LocalizableMessage pufn = path.getManagedObjectDefinition().getUserFriendlyName(); |
| | | LocalizableMessage msg = ERR_DSCFG_ERROR_GET_PARENT_MODE.get(pufn); |
| | | throw new ClientException(ReturnCode.OTHER, msg, e); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | LocalizableMessage msg = ERR_DSCFG_ERROR_CREATE_CE.get(ufn, e.getMessage()); |
| | | throw new ClientException(ReturnCode.CLIENT_SIDE_SERVER_DOWN, msg); |
| | | } catch (ManagedObjectNotFoundException e) { |
| | |
| | | } catch (ManagedObjectNotFoundException e) { |
| | | this.e = new ClientException(ReturnCode.NO_SUCH_OBJECT, e.getMessageObject()); |
| | | return MenuResult.cancel(); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | this.e = new ClientException(ReturnCode.APPLICATION_ERROR, LocalizableMessage.raw(e.getMessage())); |
| | | return MenuResult.quit(); |
| | | } |
| | |
| | | } catch (ManagedObjectNotFoundException e) { |
| | | this.e = new ClientException(ReturnCode.NO_SUCH_OBJECT, e.getMessageObject()); |
| | | return MenuResult.cancel(); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | this.e = new ClientException(ReturnCode.APPLICATION_ERROR, LocalizableMessage.raw(e.getMessage())); |
| | | return MenuResult.quit(); |
| | | } |
| | |
| | | } catch (ManagedObjectNotFoundException e) { |
| | | this.e = new ClientException(ReturnCode.NO_SUCH_OBJECT, e.getMessageObject()); |
| | | return MenuResult.cancel(); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | this.e = new ClientException(ReturnCode.APPLICATION_ERROR, LocalizableMessage.raw(e.getMessage())); |
| | | return MenuResult.quit(); |
| | | } |
| | |
| | | import org.forgerock.opendj.config.conditions.Condition; |
| | | import org.forgerock.opendj.config.conditions.ContainsCondition; |
| | | import org.forgerock.opendj.ldap.AuthorizationException; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | |
| | | import com.forgerock.opendj.cli.Argument; |
| | | import com.forgerock.opendj.cli.ArgumentException; |
| | |
| | | } else { |
| | | throw new ClientException(ReturnCode.CONSTRAINT_VIOLATION, e.getMessageObject(), e); |
| | | } |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | LocalizableMessage msg = ERR_DSCFG_ERROR_MODIFY_CE.get(ufn, e.getMessage()); |
| | | throw new ClientException(ReturnCode.OTHER, msg); |
| | | } catch (ManagedObjectAlreadyExistsException e) { |
| | |
| | | } catch (AuthorizationException e) { |
| | | LocalizableMessage msg = ERR_DSCFG_ERROR_MODIFY_AUTHZ.get(ufn); |
| | | throw new ClientException(ReturnCode.INSUFFICIENT_ACCESS_RIGHTS, msg); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | LocalizableMessage msg = ERR_DSCFG_ERROR_MODIFY_CE.get(ufn, e.getMessage()); |
| | | throw new ClientException(ReturnCode.OTHER, msg); |
| | | } |
| | |
| | | } else { |
| | | throw except; |
| | | } |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | throw new ClientException(ReturnCode.OTHER, LocalizableMessage.raw(e.getLocalizedMessage())); |
| | | } |
| | | |
| | |
| | | import org.forgerock.opendj.config.client.ManagedObjectDecodingException; |
| | | import org.forgerock.opendj.config.client.ManagementContext; |
| | | import org.forgerock.opendj.ldap.AuthorizationException; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | |
| | | import com.forgerock.opendj.cli.Argument; |
| | | import com.forgerock.opendj.cli.ArgumentException; |
| | |
| | | |
| | | private AuthorizationException authze; |
| | | |
| | | private ErrorResultException ere; |
| | | private LdapException ere; |
| | | |
| | | /** Any CLI exception that was caught when attempting to find the managed object. */ |
| | | private ClientException clie; |
| | |
| | | } catch (ConcurrentModificationException e) { |
| | | cme = e; |
| | | result = MenuResult.quit(); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | ere = e; |
| | | result = MenuResult.quit(); |
| | | } |
| | |
| | | } catch (ConcurrentModificationException e) { |
| | | cme = e; |
| | | result = MenuResult.quit(); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | ere = e; |
| | | result = MenuResult.quit(); |
| | | } |
| | |
| | | } catch (ConcurrentModificationException e) { |
| | | cme = e; |
| | | result = MenuResult.quit(); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | ere = e; |
| | | result = MenuResult.quit(); |
| | | } |
| | |
| | | } catch (ConcurrentModificationException e) { |
| | | cme = e; |
| | | result = MenuResult.quit(); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | ere = e; |
| | | result = MenuResult.quit(); |
| | | } |
| | |
| | | * @throws AuthorizationException |
| | | * If the server refuses to retrieve the managed object because the client does not have the correct |
| | | * privileges. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | public MenuResult<ManagedObject<?>> find(ConsoleApplication app, ManagementContext context, |
| | | ManagedObjectPath<?, ?> path, List<String> args) throws ClientException, AuthorizationException, |
| | | ConcurrentModificationException, DefinitionDecodingException, ManagedObjectDecodingException, |
| | | ManagedObjectNotFoundException, ErrorResultException { |
| | | ManagedObjectNotFoundException, LdapException { |
| | | this.result = MenuResult.<ManagedObject<?>> success(context.getRootConfigurationManagedObject()); |
| | | this.app = app; |
| | | this.args = args; |
| | |
| | | * privileges. |
| | | * @throws ClientException |
| | | * If one of the naming arguments referenced a managed object of the wrong type. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If any other error occurs. |
| | | */ |
| | | protected final MenuResult<ManagedObject<?>> getManagedObject(ConsoleApplication app, ManagementContext context, |
| | | ManagedObjectPath<?, ?> path, List<String> args) throws ClientException, AuthorizationException, |
| | | DefinitionDecodingException, ManagedObjectDecodingException, ConcurrentModificationException, |
| | | ManagedObjectNotFoundException, ErrorResultException { |
| | | ManagedObjectNotFoundException, LdapException { |
| | | ManagedObjectFinder finder = new ManagedObjectFinder(); |
| | | return finder.find(app, context, path, args); |
| | | } |
| | |
| | | } else { |
| | | childNames = parent.listChildren((SetRelationDefinition<C, S>) r, d); |
| | | } |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | // FIXME check exceptions |
| | | System.out.println(String.format("An error occured %s", e.getMessage())); |
| | | } |
| | |
| | | children.put(childName, childName); |
| | | } catch (ManagedObjectNotFoundException e) { |
| | | // Skip it - the managed object has been concurrently removed. |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | // Add it anyway: maybe the user is trying to fix the problem. |
| | | children.put(childName, childName); |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2007-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.config; |
| | | |
| | |
| | | import org.forgerock.opendj.config.server.ConfigurationChangeListener; |
| | | import org.forgerock.opendj.config.server.ServerManagedObject; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.opendj.server.config.client.ConnectionHandlerCfgClient; |
| | | import org.forgerock.opendj.server.config.server.ConnectionHandlerCfg; |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public void commit() throws ManagedObjectAlreadyExistsException, MissingMandatoryPropertiesException, |
| | | ConcurrentModificationException, OperationRejectedException, ErrorResultException { |
| | | ConcurrentModificationException, OperationRejectedException, LdapException { |
| | | impl.commit(); |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.config; |
| | | |
| | |
| | | import org.forgerock.opendj.config.client.ManagedObjectDecodingException; |
| | | import org.forgerock.opendj.config.client.OperationRejectedException; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | |
| | | /** |
| | |
| | | * @throws ConcurrentModificationException |
| | | * If this Test Parent has been removed from the server by |
| | | * another client. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If an error occurs |
| | | */ |
| | | String[] listTestChildren() throws ConcurrentModificationException, ErrorResultException; |
| | | String[] listTestChildren() throws ConcurrentModificationException, LdapException; |
| | | |
| | | /** |
| | | * Gets the named Test Child. |
| | |
| | | * @throws ConcurrentModificationException |
| | | * If this Test Parent has been removed from the server by |
| | | * another client. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If an error occurs. |
| | | */ |
| | | TestChildCfgClient getTestChild(String name) throws DefinitionDecodingException, ManagedObjectDecodingException, |
| | | ManagedObjectNotFoundException, ConcurrentModificationException, ErrorResultException; |
| | | ManagedObjectNotFoundException, ConcurrentModificationException, LdapException; |
| | | |
| | | /** |
| | | * Creates a new Test Child. The new Test Child will initially not contain |
| | |
| | | * @throws ConcurrentModificationException |
| | | * If this Test Parent has been removed from the server by |
| | | * another client. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If an errors occurs. |
| | | */ |
| | | void removeTestChild(String name) throws ManagedObjectNotFoundException, OperationRejectedException, |
| | | ConcurrentModificationException, ErrorResultException; |
| | | ConcurrentModificationException, LdapException; |
| | | |
| | | /** |
| | | * Determines whether or not the Optional Test Child exists. |
| | |
| | | * @throws ConcurrentModificationException |
| | | * If this Test Parent has been removed from the server by |
| | | * another client. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If an errors occurs. |
| | | */ |
| | | boolean hasOptionalTestChild() throws ConcurrentModificationException, ErrorResultException; |
| | | boolean hasOptionalTestChild() throws ConcurrentModificationException, LdapException; |
| | | |
| | | /** |
| | | * Gets the Optional Test Child if it is present. |
| | |
| | | * @throws ConcurrentModificationException |
| | | * If this Test Parent has been removed from the server by |
| | | * another client. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If an errors occurs. |
| | | */ |
| | | TestChildCfgClient getOptionalChild() throws DefinitionDecodingException, ManagedObjectDecodingException, |
| | | ManagedObjectNotFoundException, ConcurrentModificationException, ErrorResultException; |
| | | ManagedObjectNotFoundException, ConcurrentModificationException, LdapException; |
| | | |
| | | /** |
| | | * Creates a new Optional Test Child. The new Optional Test Child will |
| | |
| | | * @throws ConcurrentModificationException |
| | | * If this Test Parent has been removed from the server by |
| | | * another client. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If an errors occurs. |
| | | */ |
| | | void removeOptionalTestChild() throws ManagedObjectNotFoundException, OperationRejectedException, |
| | | ConcurrentModificationException, ErrorResultException; |
| | | ConcurrentModificationException, LdapException; |
| | | |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2007-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.config; |
| | | |
| | |
| | | import org.forgerock.opendj.config.server.ConfigurationDeleteListener; |
| | | import org.forgerock.opendj.config.server.ServerManagedObject; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | |
| | | /** |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public String[] listTestChildren() throws ConcurrentModificationException, ErrorResultException { |
| | | public String[] listTestChildren() throws ConcurrentModificationException, LdapException { |
| | | return impl.listChildren(INSTANCE.getTestChildrenRelationDefinition()); |
| | | } |
| | | |
| | |
| | | */ |
| | | public TestChildCfgClient getTestChild(String name) throws DefinitionDecodingException, |
| | | ManagedObjectDecodingException, ManagedObjectNotFoundException, ConcurrentModificationException, |
| | | ErrorResultException { |
| | | LdapException { |
| | | return impl.getChild(INSTANCE.getTestChildrenRelationDefinition(), name).getConfiguration(); |
| | | } |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public void removeTestChild(String name) throws ManagedObjectNotFoundException, |
| | | ConcurrentModificationException, OperationRejectedException, ErrorResultException { |
| | | ConcurrentModificationException, OperationRejectedException, LdapException { |
| | | impl.removeChild(INSTANCE.getTestChildrenRelationDefinition(), name); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean hasOptionalTestChild() throws ConcurrentModificationException, ErrorResultException { |
| | | public boolean hasOptionalTestChild() throws ConcurrentModificationException, LdapException { |
| | | return impl.hasChild(INSTANCE.getOptionalTestChildRelationDefinition()); |
| | | } |
| | | |
| | |
| | | */ |
| | | public TestChildCfgClient getOptionalChild() throws DefinitionDecodingException, |
| | | ManagedObjectDecodingException, ManagedObjectNotFoundException, ConcurrentModificationException, |
| | | ErrorResultException { |
| | | LdapException { |
| | | return impl.getChild(INSTANCE.getOptionalTestChildRelationDefinition()).getConfiguration(); |
| | | } |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public void removeOptionalTestChild() throws ManagedObjectNotFoundException, ConcurrentModificationException, |
| | | OperationRejectedException, ErrorResultException { |
| | | OperationRejectedException, LdapException { |
| | | impl.removeChild(INSTANCE.getOptionalTestChildRelationDefinition()); |
| | | } |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public void commit() throws ManagedObjectAlreadyExistsException, MissingMandatoryPropertiesException, |
| | | ConcurrentModificationException, OperationRejectedException, ErrorResultException { |
| | | ConcurrentModificationException, OperationRejectedException, LdapException { |
| | | impl.commit(); |
| | | } |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LinkedHashMapEntry; |
| | | import org.forgerock.opendj.ldap.MemoryBackend; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | |
| | | return new Object[][] { |
| | | // result code corresponding to exception thrown, expected |
| | | // exception, expected code result |
| | | { ResultCode.PROTOCOL_ERROR, ErrorResultException.class, ResultCode.PROTOCOL_ERROR }, |
| | | { ResultCode.UNAVAILABLE, ErrorResultException.class, ResultCode.UNAVAILABLE }, |
| | | { ResultCode.PROTOCOL_ERROR, LdapException.class, ResultCode.PROTOCOL_ERROR }, |
| | | { ResultCode.UNAVAILABLE, LdapException.class, ResultCode.UNAVAILABLE }, |
| | | { ResultCode.ENTRY_ALREADY_EXISTS, ManagedObjectAlreadyExistsException.class, null }, |
| | | { ResultCode.INSUFFICIENT_ACCESS_RIGHTS, ErrorResultException.class, |
| | | ResultCode.INSUFFICIENT_ACCESS_RIGHTS }, |
| | | { ResultCode.INSUFFICIENT_ACCESS_RIGHTS, LdapException.class, ResultCode.INSUFFICIENT_ACCESS_RIGHTS }, |
| | | { ResultCode.UNWILLING_TO_PERFORM, OperationRejectedException.class, null } }; |
| | | } |
| | | |
| | |
| | | return new Object[][] { |
| | | // result code corresponding to exception thrown, expected |
| | | // exception, expected code result |
| | | { ResultCode.PROTOCOL_ERROR, ErrorResultException.class, ResultCode.PROTOCOL_ERROR }, |
| | | { ResultCode.UNAVAILABLE, ErrorResultException.class, ResultCode.UNAVAILABLE }, |
| | | { ResultCode.PROTOCOL_ERROR, LdapException.class, ResultCode.PROTOCOL_ERROR }, |
| | | { ResultCode.UNAVAILABLE, LdapException.class, ResultCode.UNAVAILABLE }, |
| | | { ResultCode.NO_SUCH_OBJECT, ManagedObjectNotFoundException.class, null }, |
| | | { ResultCode.INSUFFICIENT_ACCESS_RIGHTS, ErrorResultException.class, |
| | | ResultCode.INSUFFICIENT_ACCESS_RIGHTS }, |
| | | { ResultCode.UNWILLING_TO_PERFORM, ErrorResultException.class, |
| | | ResultCode.UNWILLING_TO_PERFORM } }; |
| | | { ResultCode.INSUFFICIENT_ACCESS_RIGHTS, LdapException.class, ResultCode.INSUFFICIENT_ACCESS_RIGHTS }, |
| | | { ResultCode.UNWILLING_TO_PERFORM, LdapException.class, ResultCode.UNWILLING_TO_PERFORM } }; |
| | | } |
| | | |
| | | @BeforeClass |
| | |
| | | MemoryBackend backend = new MemoryBackend(new LDIFEntryReader(TEST_LDIF)); |
| | | Connection c = new AbstractConnectionWrapper<Connection>(newInternalConnection(backend)) { |
| | | @Override |
| | | public Result add(Entry entry) throws ErrorResultException { |
| | | throw ErrorResultException.newErrorResult(resultCodeOfThrownException); |
| | | public Result add(Entry entry) throws LdapException { |
| | | throw LdapException.newErrorResult(resultCodeOfThrownException); |
| | | } |
| | | }; |
| | | ManagementContext ctx = |
| | |
| | | parent.setMandatoryReadOnlyAttributeTypeProperty(getAttributeType("description")); |
| | | parent.commit(); |
| | | } catch (Exception e) { |
| | | if (expectedExceptionClass.equals(ErrorResultException.class)) { |
| | | assertThat(e).isInstanceOf(ErrorResultException.class); |
| | | assertThat(((ErrorResultException) e).getResult().getResultCode()).isEqualTo( |
| | | expectedCode); |
| | | if (expectedExceptionClass.equals(LdapException.class)) { |
| | | assertThat(e).isInstanceOf(LdapException.class); |
| | | assertThat(((LdapException) e).getResult().getResultCode()).isEqualTo(expectedCode); |
| | | } else { |
| | | assertThat(e).isInstanceOf(expectedExceptionClass); |
| | | } |
| | |
| | | |
| | | /** |
| | | * Tests retrieval of a top-level managed object fails when an underlying |
| | | * ErrorResultException occurs. |
| | | * LdapException occurs. |
| | | * |
| | | * @param cause |
| | | * The ErrorResultException cause of the failure. |
| | | * @param expected |
| | | * @param expectedExceptionClass |
| | | * The expected client API exception class. |
| | | */ |
| | | @Test(dataProvider = "getManagedObjectExceptions") |
| | |
| | | MemoryBackend backend = new MemoryBackend(new LDIFEntryReader(TEST_LDIF)); |
| | | Connection c = new AbstractConnectionWrapper<Connection>(newInternalConnection(backend)) { |
| | | @Override |
| | | public SearchResultEntry readEntry(DN name, String... attributeDescriptions) |
| | | throws ErrorResultException { |
| | | throw ErrorResultException.newErrorResult(resultCodeOfThrownException); |
| | | public SearchResultEntry readEntry(DN name, String... attributeDescriptions) throws LdapException { |
| | | throw LdapException.newErrorResult(resultCodeOfThrownException); |
| | | } |
| | | }; |
| | | ManagementContext ctx = |
| | |
| | | try { |
| | | getTestParent(ctx, "test parent 2"); |
| | | } catch (Exception e) { |
| | | if (expectedExceptionClass.equals(ErrorResultException.class)) { |
| | | assertThat(e).isInstanceOf(ErrorResultException.class); |
| | | assertThat(((ErrorResultException) e).getResult().getResultCode()).isEqualTo( |
| | | expectedCode); |
| | | if (expectedExceptionClass.equals(LdapException.class)) { |
| | | assertThat(e).isInstanceOf(LdapException.class); |
| | | assertThat(((LdapException) e).getResult().getResultCode()).isEqualTo(expectedCode); |
| | | } else { |
| | | assertThat(e).isInstanceOf(expectedExceptionClass); |
| | | } |
| | |
| | | final AtomicBoolean isModified = new AtomicBoolean(); |
| | | Connection c = new AbstractConnectionWrapper<Connection>(newInternalConnection(backend)) { |
| | | @Override |
| | | public Result modify(ModifyRequest request) throws ErrorResultException { |
| | | public Result modify(ModifyRequest request) throws LdapException { |
| | | isModified.set(true); |
| | | return super.modify(request); |
| | | } |
| | |
| | | final AtomicBoolean isModified = new AtomicBoolean(); |
| | | Connection c = new AbstractConnectionWrapper<Connection>(newInternalConnection(backend)) { |
| | | @Override |
| | | public Result modify(ModifyRequest request) throws ErrorResultException { |
| | | public Result modify(ModifyRequest request) throws LdapException { |
| | | isModified.set(true); |
| | | return super.modify(request); |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.config.client.ldap; |
| | | |
| | |
| | | import org.forgerock.opendj.config.client.ManagedObject; |
| | | import org.forgerock.opendj.config.client.ManagementContext; |
| | | import org.forgerock.opendj.config.server.ServerConstraintHandler; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | |
| | | /** |
| | | * A mock constraint which can be configured to refuse various types of |
| | |
| | | */ |
| | | @Override |
| | | public boolean isAddAcceptable(ManagementContext context, ManagedObject<?> managedObject, |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | Collection<LocalizableMessage> unacceptableReasons) throws LdapException { |
| | | if (!allowAdds) { |
| | | unacceptableReasons.add(LocalizableMessage.raw("Adds not allowed")); |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public boolean isDeleteAcceptable(ManagementContext context, ManagedObjectPath<?, ?> path, |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | Collection<LocalizableMessage> unacceptableReasons) throws LdapException { |
| | | if (!allowDeletes) { |
| | | unacceptableReasons.add(LocalizableMessage.raw("Deletes not allowed")); |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public boolean isModifyAcceptable(ManagementContext context, ManagedObject<?> managedObject, |
| | | Collection<LocalizableMessage> unacceptableReasons) throws ErrorResultException { |
| | | Collection<LocalizableMessage> unacceptableReasons) throws LdapException { |
| | | if (!allowModifies) { |
| | | unacceptableReasons.add(LocalizableMessage.raw("Modifies not allowed")); |
| | | } |
| | |
| | | <method>org.forgerock.opendj.ldap.FutureResult addSchema*Async(*)</method> |
| | | <justification>OPENDJ-1285 Migrate SDK from Futures to Promises</justification> |
| | | </difference> |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/*Exception</className> |
| | | <differenceType>5001</differenceType> |
| | | <to>org/forgerock/opendj/ldap/ErrorResultException</to> |
| | | <justification>OPENDJ-1536 Rename FutureResult and ErrorResultException classes hierarchy in the SDK to enhance code consistency</justification> |
| | | </difference> |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/*Exception</className> |
| | | <differenceType>5001</differenceType> |
| | | <to>java/util/concurrent/ExecutionException</to> |
| | | <justification>OPENDJ-1536 Rename FutureResult and ErrorResultException classes hierarchy in the SDK to enhance code consistency</justification> |
| | | </difference> |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/ConnectionEventListener</className> |
| | | <differenceType>7005</differenceType> |
| | | <method>*handleConnectionError(boolean, org.forgerock.opendj.ldap.ErrorResultException)</method> |
| | | <to>*handleConnectionError(boolean, org.forgerock.opendj.ldap.LdapException)</to> |
| | | <justification>OPENDJ-1536 Rename FutureResult and ErrorResultException classes hierarchy in the SDK to enhance code consistency</justification> |
| | | </difference> |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/ResultHandler</className> |
| | | <differenceType>7012</differenceType> |
| | | <method>*handleError(org.forgerock.opendj.ldap.LdapException)</method> |
| | | <justification>OPENDJ-1536 Rename FutureResult and ErrorResultException classes hierarchy in the SDK to enhance code consistency</justification> |
| | | </difference> |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/ErrorResult*Exception</className> |
| | | <differenceType>8001</differenceType> |
| | | <justification>OPENDJ-1536 Rename FutureResult and ErrorResultException classes hierarchy in the SDK to enhance code consistency</justification> |
| | | </difference> |
| | | </differences> |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | import org.forgerock.opendj.ldap.responses.ExtendedResult; |
| | | import org.forgerock.opendj.ldap.responses.Result; |
| | | |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.*; |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | |
| | | /** |
| | | * An abstract connection whose synchronous methods are implemented in terms of |
| | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Result add(final AddRequest request) throws ErrorResultException { |
| | | public Result add(final AddRequest request) throws LdapException { |
| | | return blockingGetOrThrow(addAsync(request)); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public BindResult bind(final BindRequest request) throws ErrorResultException { |
| | | public BindResult bind(final BindRequest request) throws LdapException { |
| | | return blockingGetOrThrow(bindAsync(request)); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public CompareResult compare(final CompareRequest request) throws ErrorResultException { |
| | | public CompareResult compare(final CompareRequest request) throws LdapException { |
| | | return blockingGetOrThrow(compareAsync(request)); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Result delete(final DeleteRequest request) throws ErrorResultException { |
| | | public Result delete(final DeleteRequest request) throws LdapException { |
| | | return blockingGetOrThrow(deleteAsync(request)); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public <R extends ExtendedResult> R extendedRequest(final ExtendedRequest<R> request, |
| | | final IntermediateResponseHandler handler) throws ErrorResultException { |
| | | final IntermediateResponseHandler handler) throws LdapException { |
| | | return blockingGetOrThrow(extendedRequestAsync(request, handler)); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Result modify(final ModifyRequest request) throws ErrorResultException { |
| | | public Result modify(final ModifyRequest request) throws LdapException { |
| | | return blockingGetOrThrow(modifyAsync(request)); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Result modifyDN(final ModifyDNRequest request) throws ErrorResultException { |
| | | public Result modifyDN(final ModifyDNRequest request) throws LdapException { |
| | | return blockingGetOrThrow(modifyDNAsync(request)); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Result search(final SearchRequest request, final SearchResultHandler handler) |
| | | throws ErrorResultException { |
| | | public Result search(final SearchRequest request, final SearchResultHandler handler) throws LdapException { |
| | | return blockingGetOrThrow(searchAsync(request, handler)); |
| | | } |
| | | |
| | | private <T extends Result> T blockingGetOrThrow(FutureResult<T> future) throws ErrorResultException { |
| | | private <T extends Result> T blockingGetOrThrow(FutureResult<T> future) throws LdapException { |
| | | try { |
| | | return future.getOrThrow(); |
| | | } catch (InterruptedException e) { |
| | |
| | | } |
| | | |
| | | // Handle thread interruption. |
| | | private ErrorResultException interrupted(InterruptedException e) { |
| | | private LdapException interrupted(InterruptedException e) { |
| | | return newErrorResult(ResultCode.CLIENT_SIDE_USER_CANCELLED, e); |
| | | } |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | import org.forgerock.util.Reject; |
| | | import org.forgerock.util.promise.Function; |
| | | |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.*; |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.*; |
| | |
| | | * error if provided error is |
| | | * <code>ResultCode.SIZE_LIMIT_EXCEEDED</code> |
| | | */ |
| | | private ErrorResultException filterError(final ErrorResultException error) { |
| | | private LdapException filterError(final LdapException error) { |
| | | if (error.getResult().getResultCode().equals(ResultCode.SIZE_LIMIT_EXCEEDED)) { |
| | | return newErrorResult(ResultCode.CLIENT_SIDE_UNEXPECTED_RESULTS_RETURNED, |
| | | ERR_UNEXPECTED_SEARCH_RESULT_ENTRIES_NO_COUNT.get().toString()); |
| | |
| | | * method should be called only after search operation is finished. |
| | | * |
| | | * @return The single search result entry. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If an error is detected. |
| | | */ |
| | | private SearchResultEntry getSingleEntry() throws ErrorResultException { |
| | | private SearchResultEntry getSingleEntry() throws LdapException { |
| | | if (entryCount == 0) { |
| | | // Did not find any entries. |
| | | throw newErrorResult(ResultCode.CLIENT_SIDE_NO_RESULTS_RETURNED, |
| | |
| | | public Object visitChangeRecord(final Connection p, final AddRequest change) { |
| | | try { |
| | | return p.add(change); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | return e; |
| | | } |
| | | } |
| | |
| | | public Object visitChangeRecord(final Connection p, final DeleteRequest change) { |
| | | try { |
| | | return p.delete(change); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | return e; |
| | | } |
| | | } |
| | |
| | | public Object visitChangeRecord(final Connection p, final ModifyDNRequest change) { |
| | | try { |
| | | return p.modifyDN(change); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | return e; |
| | | } |
| | | } |
| | |
| | | public Object visitChangeRecord(final Connection p, final ModifyRequest change) { |
| | | try { |
| | | return p.modify(change); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | return e; |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result add(final Entry entry) throws ErrorResultException { |
| | | public Result add(final Entry entry) throws LdapException { |
| | | return add(Requests.newAddRequest(entry)); |
| | | } |
| | | |
| | | @Override |
| | | public Result add(final String... ldifLines) throws ErrorResultException { |
| | | public Result add(final String... ldifLines) throws LdapException { |
| | | return add(Requests.newAddRequest(ldifLines)); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result applyChange(final ChangeRecord request) throws ErrorResultException { |
| | | public Result applyChange(final ChangeRecord request) throws LdapException { |
| | | final Object result = request.accept(SYNC_VISITOR, this); |
| | | if (result instanceof Result) { |
| | | return (Result) result; |
| | | } else { |
| | | throw (ErrorResultException) result; |
| | | throw (LdapException) result; |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public BindResult bind(final String name, final char[] password) throws ErrorResultException { |
| | | public BindResult bind(final String name, final char[] password) throws LdapException { |
| | | return bind(Requests.newSimpleBindRequest(name, password)); |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public CompareResult compare(final String name, final String attributeDescription, final String assertionValue) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | return compare(Requests.newCompareRequest(name, attributeDescription, assertionValue)); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result delete(final String name) throws ErrorResultException { |
| | | public Result delete(final String name) throws LdapException { |
| | | return delete(Requests.newDeleteRequest(name)); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result deleteSubtree(final String name) throws ErrorResultException { |
| | | public Result deleteSubtree(final String name) throws LdapException { |
| | | return delete(Requests.newDeleteRequest(name).addControl(SubtreeDeleteRequestControl.newControl(true))); |
| | | } |
| | | |
| | | @Override |
| | | public <R extends ExtendedResult> R extendedRequest(final ExtendedRequest<R> request) throws ErrorResultException { |
| | | public <R extends ExtendedResult> R extendedRequest(final ExtendedRequest<R> request) throws LdapException { |
| | | return extendedRequest(request, null); |
| | | } |
| | | |
| | | @Override |
| | | public GenericExtendedResult extendedRequest(final String requestName, final ByteString requestValue) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | return extendedRequest(Requests.newGenericExtendedRequest(requestName, requestValue)); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result modify(final String... ldifLines) throws ErrorResultException { |
| | | public Result modify(final String... ldifLines) throws LdapException { |
| | | return modify(Requests.newModifyRequest(ldifLines)); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result modifyDN(final String name, final String newRDN) throws ErrorResultException { |
| | | public Result modifyDN(final String name, final String newRDN) throws LdapException { |
| | | return modifyDN(Requests.newModifyDNRequest(name, newRDN)); |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public SearchResultEntry readEntry(final DN baseObject, final String... attributeDescriptions) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | final SearchRequest request = |
| | | Requests.newSingleEntrySearchRequest(baseObject, SearchScope.BASE_OBJECT, Filter.objectClassPresent(), |
| | | attributeDescriptions); |
| | |
| | | |
| | | @Override |
| | | public SearchResultEntry readEntry(final String baseObject, final String... attributeDescriptions) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | return readEntry(DN.valueOf(baseObject), attributeDescriptions); |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public Result search(final SearchRequest request, final Collection<? super SearchResultEntry> entries) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | return search(request, entries, null); |
| | | } |
| | | |
| | | @Override |
| | | public Result search(final SearchRequest request, final Collection<? super SearchResultEntry> entries, |
| | | final Collection<? super SearchResultReference> references) throws ErrorResultException { |
| | | final Collection<? super SearchResultReference> references) throws LdapException { |
| | | Reject.ifNull(request, entries); |
| | | // FIXME: does this need to be thread safe? |
| | | final SearchResultHandler handler = new SearchResultHandler() { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public SearchResultEntry searchSingleEntry(final SearchRequest request) throws ErrorResultException { |
| | | public SearchResultEntry searchSingleEntry(final SearchRequest request) throws LdapException { |
| | | final SingleEntryHandler handler = new SingleEntryHandler(); |
| | | try { |
| | | search(enforceSingleEntrySearchRequest(request), handler); |
| | | return handler.getSingleEntry(); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | throw handler.filterError(e); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public SearchResultEntry searchSingleEntry(final String baseObject, final SearchScope scope, final String filter, |
| | | final String... attributeDescriptions) throws ErrorResultException { |
| | | final String... attributeDescriptions) throws LdapException { |
| | | final SearchRequest request = |
| | | Requests.newSingleEntrySearchRequest(baseObject, scope, filter, attributeDescriptions); |
| | | return searchSingleEntry(request); |
| | |
| | | public FutureResult<SearchResultEntry> searchSingleEntryAsync(final SearchRequest request) { |
| | | final SingleEntryHandler handler = new SingleEntryHandler(); |
| | | return FutureResultWrapper.asFutureResult(searchAsync(enforceSingleEntrySearchRequest(request), handler).then( |
| | | new Function<Result, SearchResultEntry, ErrorResultException>() { |
| | | new Function<Result, SearchResultEntry, LdapException>() { |
| | | @Override |
| | | public SearchResultEntry apply(final Result value) throws ErrorResultException { |
| | | public SearchResultEntry apply(final Result value) throws LdapException { |
| | | return handler.getSingleEntry(); |
| | | } |
| | | }, new Function<ErrorResultException, SearchResultEntry, ErrorResultException>() { |
| | | }, new Function<LdapException, SearchResultEntry, LdapException>() { |
| | | @Override |
| | | public SearchResultEntry apply(final ErrorResultException error) throws ErrorResultException { |
| | | public SearchResultEntry apply(final LdapException error) throws LdapException { |
| | | throw handler.filterError(error); |
| | | } |
| | | })); |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * The default implementation is to delegate. |
| | | */ |
| | | @Override |
| | | public Result add(final AddRequest request) throws ErrorResultException { |
| | | public Result add(final AddRequest request) throws LdapException { |
| | | return connection.add(request); |
| | | } |
| | | |
| | |
| | | * The default implementation is to delegate. |
| | | */ |
| | | @Override |
| | | public Result add(final Entry entry) throws ErrorResultException { |
| | | public Result add(final Entry entry) throws LdapException { |
| | | return connection.add(entry); |
| | | } |
| | | |
| | |
| | | * The default implementation is to delegate. |
| | | */ |
| | | @Override |
| | | public Result add(final String... ldifLines) throws ErrorResultException { |
| | | public Result add(final String... ldifLines) throws LdapException { |
| | | return connection.add(ldifLines); |
| | | } |
| | | |
| | |
| | | * The default implementation is to delegate. |
| | | */ |
| | | @Override |
| | | public Result applyChange(final ChangeRecord request) throws ErrorResultException { |
| | | public Result applyChange(final ChangeRecord request) throws LdapException { |
| | | return connection.applyChange(request); |
| | | } |
| | | |
| | |
| | | * The default implementation is to delegate. |
| | | */ |
| | | @Override |
| | | public BindResult bind(final BindRequest request) throws ErrorResultException { |
| | | public BindResult bind(final BindRequest request) throws LdapException { |
| | | return connection.bind(request); |
| | | } |
| | | |
| | |
| | | * The default implementation is to delegate. |
| | | */ |
| | | @Override |
| | | public BindResult bind(final String name, final char[] password) throws ErrorResultException { |
| | | public BindResult bind(final String name, final char[] password) throws LdapException { |
| | | return connection.bind(name, password); |
| | | } |
| | | |
| | |
| | | * The default implementation is to delegate. |
| | | */ |
| | | @Override |
| | | public CompareResult compare(final CompareRequest request) throws ErrorResultException { |
| | | public CompareResult compare(final CompareRequest request) throws LdapException { |
| | | return connection.compare(request); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public CompareResult compare(final String name, final String attributeDescription, final String assertionValue) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | return connection.compare(name, attributeDescription, assertionValue); |
| | | } |
| | | |
| | |
| | | * The default implementation is to delegate. |
| | | */ |
| | | @Override |
| | | public Result delete(final DeleteRequest request) throws ErrorResultException { |
| | | public Result delete(final DeleteRequest request) throws LdapException { |
| | | return connection.delete(request); |
| | | } |
| | | |
| | |
| | | * The default implementation is to delegate. |
| | | */ |
| | | @Override |
| | | public Result delete(final String name) throws ErrorResultException { |
| | | public Result delete(final String name) throws LdapException { |
| | | return connection.delete(name); |
| | | } |
| | | |
| | |
| | | * The default implementation is to delegate. |
| | | */ |
| | | @Override |
| | | public Result deleteSubtree(final String name) throws ErrorResultException { |
| | | public Result deleteSubtree(final String name) throws LdapException { |
| | | return connection.deleteSubtree(name); |
| | | } |
| | | |
| | |
| | | * The default implementation is to delegate. |
| | | */ |
| | | @Override |
| | | public <R extends ExtendedResult> R extendedRequest(final ExtendedRequest<R> request) throws ErrorResultException { |
| | | public <R extends ExtendedResult> R extendedRequest(final ExtendedRequest<R> request) throws LdapException { |
| | | return connection.extendedRequest(request); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public <R extends ExtendedResult> R extendedRequest(final ExtendedRequest<R> request, |
| | | final IntermediateResponseHandler handler) throws ErrorResultException { |
| | | final IntermediateResponseHandler handler) throws LdapException { |
| | | return connection.extendedRequest(request, handler); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public GenericExtendedResult extendedRequest(final String requestName, final ByteString requestValue) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | return connection.extendedRequest(requestName, requestValue); |
| | | } |
| | | |
| | |
| | | * The default implementation is to delegate. |
| | | */ |
| | | @Override |
| | | public Result modify(final ModifyRequest request) throws ErrorResultException { |
| | | public Result modify(final ModifyRequest request) throws LdapException { |
| | | return connection.modify(request); |
| | | } |
| | | |
| | |
| | | * The default implementation is to delegate. |
| | | */ |
| | | @Override |
| | | public Result modify(final String... ldifLines) throws ErrorResultException { |
| | | public Result modify(final String... ldifLines) throws LdapException { |
| | | return connection.modify(ldifLines); |
| | | } |
| | | |
| | |
| | | * The default implementation is to delegate. |
| | | */ |
| | | @Override |
| | | public Result modifyDN(final ModifyDNRequest request) throws ErrorResultException { |
| | | public Result modifyDN(final ModifyDNRequest request) throws LdapException { |
| | | return connection.modifyDN(request); |
| | | } |
| | | |
| | |
| | | * The default implementation is to delegate. |
| | | */ |
| | | @Override |
| | | public Result modifyDN(final String name, final String newRDN) throws ErrorResultException { |
| | | public Result modifyDN(final String name, final String newRDN) throws LdapException { |
| | | return connection.modifyDN(name, newRDN); |
| | | } |
| | | |
| | |
| | | * The default implementation is to delegate. |
| | | */ |
| | | @Override |
| | | public SearchResultEntry readEntry(final DN name, final String... attributeDescriptions) |
| | | throws ErrorResultException { |
| | | public SearchResultEntry readEntry(final DN name, final String... attributeDescriptions) throws LdapException { |
| | | return connection.readEntry(name, attributeDescriptions); |
| | | } |
| | | |
| | |
| | | * The default implementation is to delegate. |
| | | */ |
| | | @Override |
| | | public SearchResultEntry readEntry(final String name, final String... attributeDescriptions) |
| | | throws ErrorResultException { |
| | | public SearchResultEntry readEntry(final String name, final String... attributeDescriptions) throws LdapException { |
| | | return connection.readEntry(name, attributeDescriptions); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public Result search(final SearchRequest request, |
| | | final Collection<? super SearchResultEntry> entries) throws ErrorResultException { |
| | | final Collection<? super SearchResultEntry> entries) throws LdapException { |
| | | return connection.search(request, entries); |
| | | } |
| | | |
| | |
| | | @Override |
| | | public Result search(final SearchRequest request, |
| | | final Collection<? super SearchResultEntry> entries, |
| | | final Collection<? super SearchResultReference> references) throws ErrorResultException { |
| | | final Collection<? super SearchResultReference> references) throws LdapException { |
| | | return connection.search(request, entries, references); |
| | | } |
| | | |
| | |
| | | * The default implementation is to delegate. |
| | | */ |
| | | @Override |
| | | public Result search(final SearchRequest request, final SearchResultHandler handler) |
| | | throws ErrorResultException { |
| | | public Result search(final SearchRequest request, final SearchResultHandler handler) throws LdapException { |
| | | return connection.search(request, handler); |
| | | } |
| | | |
| | |
| | | * The default implementation is to delegate. |
| | | */ |
| | | @Override |
| | | public SearchResultEntry searchSingleEntry(final SearchRequest request) throws ErrorResultException { |
| | | public SearchResultEntry searchSingleEntry(final SearchRequest request) throws LdapException { |
| | | return connection.searchSingleEntry(request); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public SearchResultEntry searchSingleEntry(final String baseObject, final SearchScope scope, final String filter, |
| | | final String... attributeDescriptions) throws ErrorResultException { |
| | | final String... attributeDescriptions) throws LdapException { |
| | | return connection.searchSingleEntry(baseObject, scope, filter, attributeDescriptions); |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS. |
| | | * Portions Copyright 2011-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | |
| | | |
| | | import com.forgerock.opendj.util.ReferenceCountedObject; |
| | | |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.*; |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.forgerock.util.promise.Promises.*; |
| | | |
| | | import static com.forgerock.opendj.util.StaticUtils.*; |
| | |
| | | |
| | | private final ConnectionFactory factory; |
| | | private final AtomicBoolean isOperational = new AtomicBoolean(true); |
| | | private volatile Promise<?, ErrorResultException> pendingConnectPromise; |
| | | private volatile Promise<?, LdapException> pendingConnectPromise; |
| | | private final int index; |
| | | |
| | | private MonitoredConnectionFactory(final ConnectionFactory factory, final int index) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Connection getConnection() throws ErrorResultException { |
| | | public Connection getConnection() throws LdapException { |
| | | final Connection connection; |
| | | try { |
| | | connection = factory.getConnection(); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | // Attempt failed - try next factory. |
| | | notifyOffline(e); |
| | | final int nextIndex = (index + 1) % monitoredFactories.size(); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Promise<Connection, ErrorResultException> getConnectionAsync() { |
| | | public Promise<Connection, LdapException> getConnectionAsync() { |
| | | return factory.getConnectionAsync().thenAsync( |
| | | new AsyncFunction<Connection, Connection, ErrorResultException>() { |
| | | new AsyncFunction<Connection, Connection, LdapException>() { |
| | | @Override |
| | | public Promise<Connection, ErrorResultException> apply(Connection value) |
| | | throws ErrorResultException { |
| | | public Promise<Connection, LdapException> apply(Connection value) throws LdapException { |
| | | notifyOnline(); |
| | | return newSuccessfulPromise(value); |
| | | } |
| | | }, |
| | | new AsyncFunction<ErrorResultException, Connection, ErrorResultException>() { |
| | | new AsyncFunction<LdapException, Connection, LdapException>() { |
| | | @Override |
| | | public Promise<Connection, ErrorResultException> apply(ErrorResultException error) |
| | | throws ErrorResultException { |
| | | public Promise<Connection, LdapException> apply(LdapException error) throws LdapException { |
| | | // Attempt failed - try next factory. |
| | | notifyOffline(error); |
| | | final int nextIndex = (index + 1) % monitoredFactories.size(); |
| | |
| | | * Handle monitoring connection request failure. |
| | | */ |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | notifyOffline(error); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | private void notifyOffline(final ErrorResultException error) { |
| | | private void notifyOffline(final LdapException error) { |
| | | // Save the error in case the load-balancer is exhausted. |
| | | lastFailure = error; |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleConnectionFactoryOffline(ConnectionFactory factory, ErrorResultException error) { |
| | | public void handleConnectionFactoryOffline(ConnectionFactory factory, LdapException error) { |
| | | // TODO: I18N |
| | | logger.warn(LocalizableMessage.raw("Connection factory '%s' is no longer operational: %s", |
| | | factory, error.getMessage())); |
| | |
| | | * marked offline. This is used in order to help diagnose problems when the |
| | | * load-balancer has exhausted all of its factories. |
| | | */ |
| | | private volatile ErrorResultException lastFailure = null; |
| | | private volatile LdapException lastFailure; |
| | | |
| | | /** |
| | | * The event listener which should be notified when connection factories go |
| | |
| | | } |
| | | |
| | | @Override |
| | | public final ConnectionFactory getConnectionFactory() throws ErrorResultException { |
| | | public final ConnectionFactory getConnectionFactory() throws LdapException { |
| | | final int index = getInitialConnectionFactoryIndex(); |
| | | return getMonitoredConnectionFactory(index); |
| | | } |
| | |
| | | abstract int getInitialConnectionFactoryIndex(); |
| | | |
| | | // Return the first factory after index which is operational. |
| | | private MonitoredConnectionFactory getMonitoredConnectionFactory(final int initialIndex) |
| | | throws ErrorResultException { |
| | | private MonitoredConnectionFactory getMonitoredConnectionFactory(final int initialIndex) throws LdapException { |
| | | int index = initialIndex; |
| | | final int maxIndex = monitoredFactories.size(); |
| | | do { |
| | |
| | | final IntermediateResponseHandler intermediateResponseHandler) { |
| | | try { |
| | | return onSuccess(add(request)); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | return onFailure(e); |
| | | } |
| | | } |
| | |
| | | final IntermediateResponseHandler intermediateResponseHandler) { |
| | | try { |
| | | return onSuccess(bind(request)); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | return onFailure(e); |
| | | } |
| | | } |
| | |
| | | final IntermediateResponseHandler intermediateResponseHandler) { |
| | | try { |
| | | return onSuccess(compare(request)); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | return onFailure(e); |
| | | } |
| | | } |
| | |
| | | final IntermediateResponseHandler intermediateResponseHandler) { |
| | | try { |
| | | return onSuccess(delete(request)); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | return onFailure(e); |
| | | } |
| | | } |
| | |
| | | final IntermediateResponseHandler intermediateResponseHandler) { |
| | | try { |
| | | return onSuccess(extendedRequest(request, intermediateResponseHandler)); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | return onFailure(e); |
| | | } |
| | | } |
| | |
| | | final IntermediateResponseHandler intermediateResponseHandler) { |
| | | try { |
| | | return onSuccess(modify(request)); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | return onFailure(e); |
| | | } |
| | | } |
| | |
| | | final IntermediateResponseHandler intermediateResponseHandler) { |
| | | try { |
| | | return onSuccess(modifyDN(request)); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | return onFailure(e); |
| | | } |
| | | } |
| | |
| | | final IntermediateResponseHandler intermediateResponseHandler, final SearchResultHandler entryHandler) { |
| | | try { |
| | | return onSuccess(search(request, entryHandler)); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | return onFailure(e); |
| | | } |
| | | } |
| | | |
| | | private <R extends Result> FutureResult<R> onFailure(final ErrorResultException e) { |
| | | private <R extends Result> FutureResult<R> onFailure(final LdapException e) { |
| | | return newFailedFutureResult(e); |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * {@link ResultCode#ASSERTION_FAILED ASSERTION_FAILED} result code. |
| | | */ |
| | | @SuppressWarnings("serial") |
| | | public class AssertionFailureException extends ErrorResultException { |
| | | public class AssertionFailureException extends LdapException { |
| | | AssertionFailureException(final Result result) { |
| | | super(result); |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS. |
| | | * Portions Copyright 2011-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * will result in an {@code UnsupportedOperationException}. |
| | | * <p> |
| | | * If the Bind request fails for some reason (e.g. invalid credentials), then |
| | | * the connection attempt will fail and an {@code ErrorResultException} will be |
| | | * thrown. |
| | | * the connection attempt will fail and an {@link LdapException} will be thrown. |
| | | */ |
| | | final class AuthenticatedConnectionFactory implements ConnectionFactory { |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public BindResult bind(BindRequest request) throws ErrorResultException { |
| | | public BindResult bind(BindRequest request) throws LdapException { |
| | | throw new UnsupportedOperationException(); |
| | | } |
| | | |
| | | @Override |
| | | public BindResult bind(String name, char[] password) throws ErrorResultException { |
| | | public BindResult bind(String name, char[] password) throws LdapException { |
| | | throw new UnsupportedOperationException(); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Connection getConnection() throws ErrorResultException { |
| | | public Connection getConnection() throws LdapException { |
| | | final Connection connection = parentFactory.getConnection(); |
| | | boolean bindSucceeded = false; |
| | | try { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Promise<Connection, ErrorResultException> getConnectionAsync() { |
| | | public Promise<Connection, LdapException> getConnectionAsync() { |
| | | final AtomicReference<Connection> connectionHolder = new AtomicReference<Connection>(); |
| | | return parentFactory.getConnectionAsync() |
| | | .thenAsync( |
| | | new AsyncFunction<Connection, BindResult, ErrorResultException>() { |
| | | new AsyncFunction<Connection, BindResult, LdapException>() { |
| | | @Override |
| | | public Promise<BindResult, ErrorResultException> apply(final Connection connection) |
| | | throws ErrorResultException { |
| | | public Promise<BindResult, LdapException> apply(final Connection connection) |
| | | throws LdapException { |
| | | connectionHolder.set(connection); |
| | | return connection.bindAsync(request); |
| | | } |
| | | } |
| | | ).then( |
| | | new Function<BindResult, Connection, ErrorResultException>() { |
| | | new Function<BindResult, Connection, LdapException>() { |
| | | @Override |
| | | public Connection apply(BindResult result) throws ErrorResultException { |
| | | public Connection apply(BindResult result) throws LdapException { |
| | | return new AuthenticatedConnection(connectionHolder.get()); |
| | | } |
| | | }, |
| | | new Function<ErrorResultException, Connection, ErrorResultException>() { |
| | | new Function<LdapException, Connection, LdapException>() { |
| | | @Override |
| | | public Connection apply(ErrorResultException error) throws ErrorResultException { |
| | | public Connection apply(LdapException error) throws LdapException { |
| | | closeSilently(connectionHolder.get()); |
| | | throw error; |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * </ul> |
| | | */ |
| | | @SuppressWarnings("serial") |
| | | public class AuthenticationException extends ErrorResultException { |
| | | public class AuthenticationException extends LdapException { |
| | | AuthenticationException(final Result result) { |
| | | super(result); |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * </ul> |
| | | */ |
| | | @SuppressWarnings("serial") |
| | | public class AuthorizationException extends ErrorResultException { |
| | | public class AuthorizationException extends LdapException { |
| | | AuthorizationException(final Result result) { |
| | | super(result); |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | |
| | | import com.forgerock.opendj.util.ReferenceCountedObject; |
| | | import com.forgerock.opendj.util.TimeSource; |
| | | |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.*; |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.forgerock.util.promise.Promises.*; |
| | | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.*; |
| | |
| | | * This failure handler is invoked when an attempt to add a new connection |
| | | * to the pool ended in error. |
| | | */ |
| | | private final class ConnectionFailureHandler implements FailureHandler<ErrorResultException> { |
| | | private final class ConnectionFailureHandler implements FailureHandler<LdapException> { |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | // Connection attempt failed, so decrease the pool size. |
| | | pendingConnectionAttempts.decrementAndGet(); |
| | | availableConnections.release(); |
| | |
| | | */ |
| | | class PooledConnection implements Connection, ConnectionEventListener { |
| | | private final Connection connection; |
| | | private ErrorResultException error = null; |
| | | private LdapException error; |
| | | private final AtomicBoolean isClosed = new AtomicBoolean(false); |
| | | private boolean isDisconnectNotification = false; |
| | | private List<ConnectionEventListener> listeners = null; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result add(final AddRequest request) throws ErrorResultException { |
| | | public Result add(final AddRequest request) throws LdapException { |
| | | return checkState().add(request); |
| | | } |
| | | |
| | | @Override |
| | | public Result add(final Entry entry) throws ErrorResultException { |
| | | public Result add(final Entry entry) throws LdapException { |
| | | return checkState().add(entry); |
| | | } |
| | | |
| | | @Override |
| | | public Result add(final String... ldifLines) throws ErrorResultException { |
| | | public Result add(final String... ldifLines) throws LdapException { |
| | | return checkState().add(ldifLines); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result applyChange(final ChangeRecord request) throws ErrorResultException { |
| | | public Result applyChange(final ChangeRecord request) throws LdapException { |
| | | return checkState().applyChange(request); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public BindResult bind(final BindRequest request) throws ErrorResultException { |
| | | public BindResult bind(final BindRequest request) throws LdapException { |
| | | return checkState().bind(request); |
| | | } |
| | | |
| | | @Override |
| | | public BindResult bind(final String name, final char[] password) |
| | | throws ErrorResultException { |
| | | public BindResult bind(final String name, final char[] password) throws LdapException { |
| | | return checkState().bind(name, password); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public CompareResult compare(final CompareRequest request) throws ErrorResultException { |
| | | public CompareResult compare(final CompareRequest request) throws LdapException { |
| | | return checkState().compare(request); |
| | | } |
| | | |
| | | @Override |
| | | public CompareResult compare(final String name, final String attributeDescription, |
| | | final String assertionValue) throws ErrorResultException { |
| | | final String assertionValue) throws LdapException { |
| | | return checkState().compare(name, attributeDescription, assertionValue); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result delete(final DeleteRequest request) throws ErrorResultException { |
| | | public Result delete(final DeleteRequest request) throws LdapException { |
| | | return checkState().delete(request); |
| | | } |
| | | |
| | | @Override |
| | | public Result delete(final String name) throws ErrorResultException { |
| | | public Result delete(final String name) throws LdapException { |
| | | return checkState().delete(name); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result deleteSubtree(final String name) throws ErrorResultException { |
| | | public Result deleteSubtree(final String name) throws LdapException { |
| | | return checkState().deleteSubtree(name); |
| | | } |
| | | |
| | | @Override |
| | | public <R extends ExtendedResult> R extendedRequest(final ExtendedRequest<R> request) |
| | | throws ErrorResultException { |
| | | public <R extends ExtendedResult> R extendedRequest(final ExtendedRequest<R> request) throws LdapException { |
| | | return checkState().extendedRequest(request); |
| | | } |
| | | |
| | | @Override |
| | | public <R extends ExtendedResult> R extendedRequest(final ExtendedRequest<R> request, |
| | | final IntermediateResponseHandler handler) throws ErrorResultException { |
| | | final IntermediateResponseHandler handler) throws LdapException { |
| | | return checkState().extendedRequest(request, handler); |
| | | } |
| | | |
| | | @Override |
| | | public GenericExtendedResult extendedRequest(final String requestName, |
| | | final ByteString requestValue) throws ErrorResultException { |
| | | final ByteString requestValue) throws LdapException { |
| | | return checkState().extendedRequest(requestName, requestValue); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleConnectionError(final boolean isDisconnectNotification, final ErrorResultException error) { |
| | | public void handleConnectionError(final boolean isDisconnectNotification, final LdapException error) { |
| | | final List<ConnectionEventListener> tmpListeners; |
| | | synchronized (stateLock) { |
| | | tmpListeners = listeners; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result modify(final ModifyRequest request) throws ErrorResultException { |
| | | public Result modify(final ModifyRequest request) throws LdapException { |
| | | return checkState().modify(request); |
| | | } |
| | | |
| | | @Override |
| | | public Result modify(final String... ldifLines) throws ErrorResultException { |
| | | public Result modify(final String... ldifLines) throws LdapException { |
| | | return checkState().modify(ldifLines); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result modifyDN(final ModifyDNRequest request) throws ErrorResultException { |
| | | public Result modifyDN(final ModifyDNRequest request) throws LdapException { |
| | | return checkState().modifyDN(request); |
| | | } |
| | | |
| | | @Override |
| | | public Result modifyDN(final String name, final String newRDN) throws ErrorResultException { |
| | | public Result modifyDN(final String name, final String newRDN) throws LdapException { |
| | | return checkState().modifyDN(name, newRDN); |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public SearchResultEntry readEntry(final DN name, final String... attributeDescriptions) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | return checkState().readEntry(name, attributeDescriptions); |
| | | } |
| | | |
| | | @Override |
| | | public SearchResultEntry readEntry(final String name, final String... attributeDescriptions) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | return checkState().readEntry(name, attributeDescriptions); |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public Result search(final SearchRequest request, final Collection<? super SearchResultEntry> entries) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | return checkState().search(request, entries); |
| | | } |
| | | |
| | | @Override |
| | | public Result search(final SearchRequest request, final Collection<? super SearchResultEntry> entries, |
| | | final Collection<? super SearchResultReference> references) throws ErrorResultException { |
| | | final Collection<? super SearchResultReference> references) throws LdapException { |
| | | return checkState().search(request, entries, references); |
| | | } |
| | | |
| | | @Override |
| | | public Result search(final SearchRequest request, final SearchResultHandler handler) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | return checkState().search(request, handler); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public SearchResultEntry searchSingleEntry(final SearchRequest request) throws ErrorResultException { |
| | | public SearchResultEntry searchSingleEntry(final SearchRequest request) throws LdapException { |
| | | return checkState().searchSingleEntry(request); |
| | | } |
| | | |
| | | @Override |
| | | public SearchResultEntry searchSingleEntry(final String baseObject, final SearchScope scope, |
| | | final String filter, final String... attributeDescriptions) throws ErrorResultException { |
| | | final String filter, final String... attributeDescriptions) throws LdapException { |
| | | return checkState().searchSingleEntry(baseObject, scope, filter, attributeDescriptions); |
| | | } |
| | | |
| | |
| | | |
| | | private final Semaphore availableConnections; |
| | | private final SuccessHandler<Connection> connectionSuccessHandler = new ConnectionSuccessHandler(); |
| | | private final FailureHandler<ErrorResultException> connectionFailureHandler = new ConnectionFailureHandler(); |
| | | private final FailureHandler<LdapException> connectionFailureHandler = new ConnectionFailureHandler(); |
| | | private final int corePoolSize; |
| | | private final ConnectionFactory factory; |
| | | private boolean isClosed = false; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Connection getConnection() throws ErrorResultException { |
| | | public Connection getConnection() throws LdapException { |
| | | try { |
| | | return getConnectionAsync().getOrThrow(); |
| | | } catch (final InterruptedException e) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Promise<Connection, ErrorResultException> getConnectionAsync() { |
| | | public Promise<Connection, LdapException> getConnectionAsync() { |
| | | // Loop while iterating through stale connections (see OPENDJ-590). |
| | | for (;;) { |
| | | final QueueElement holder; |
| | |
| | | currentPoolSize(), maxPoolSize)); |
| | | |
| | | if (holder != null) { |
| | | final ErrorResultException e = |
| | | ErrorResultException.newErrorResult(ResultCode.CLIENT_SIDE_USER_CANCELLED, |
| | | final LdapException e = |
| | | LdapException.newErrorResult(ResultCode.CLIENT_SIDE_USER_CANCELLED, |
| | | ERR_CONNECTION_POOL_CLOSING.get(toString()).toString()); |
| | | holder.getWaitingFuture().handleError(e); |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * </ul> |
| | | */ |
| | | @SuppressWarnings("serial") |
| | | public class CancelledResultException extends ErrorResultException { |
| | | public class CancelledResultException extends LdapException { |
| | | CancelledResultException(final Result result) { |
| | | super(result); |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * <p> |
| | | * Synchronous methods block until a response is received from the Directory |
| | | * Server, at which point an appropriate {@link Result} object is returned if |
| | | * the operation succeeded, or thrown as an {@link ErrorResultException} if the |
| | | * the operation succeeded, or thrown as an {@link LdapException} if the |
| | | * operation failed. |
| | | * <p> |
| | | * Since synchronous operations block the calling thread, the only way to |
| | |
| | | * non-blocking, returning a {@link FutureResult} or sub-type thereof which can |
| | | * be used for retrieving the result using the {@link FutureResult#get} method. |
| | | * Operation failures, for whatever reason, are signalled by the |
| | | * {@link FutureResult#get()} method throwing an {@link ErrorResultException}. |
| | | * {@link FutureResult#get()} method throwing an {@link LdapException}. |
| | | * <p> |
| | | * In addition to returning a {@code FutureResult}, all asynchronous methods |
| | | * accept a {@link ResultHandler} which will be notified upon completion of the |
| | |
| | | * {@link IllegalStateException} being thrown. Note that, if a fatal error is |
| | | * encountered on the connection, then the application can continue to use the |
| | | * connection. In this case all requests subsequent to the failure will fail |
| | | * with an appropriate {@link ErrorResultException} when their result is |
| | | * with an appropriate {@link LdapException} when their result is |
| | | * retrieved. |
| | | * <p> |
| | | * <h3>Event notification</h3> |
| | |
| | | * @param request |
| | | * The add request. |
| | | * @return The result of the operation. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws UnsupportedOperationException |
| | |
| | | * @throws NullPointerException |
| | | * If {@code request} was {@code null}. |
| | | */ |
| | | Result add(AddRequest request) throws ErrorResultException; |
| | | Result add(AddRequest request) throws LdapException; |
| | | |
| | | /** |
| | | * Adds the provided entry to the Directory Server. |
| | |
| | | * @param entry |
| | | * The entry to be added. |
| | | * @return The result of the operation. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws UnsupportedOperationException |
| | |
| | | * @throws NullPointerException |
| | | * If {@code entry} was {@code null} . |
| | | */ |
| | | Result add(Entry entry) throws ErrorResultException; |
| | | Result add(Entry entry) throws LdapException; |
| | | |
| | | /** |
| | | * Adds an entry to the Directory Server using the provided lines of LDIF. |
| | |
| | | * Lines of LDIF containing the an LDIF add change record or an |
| | | * LDIF entry record. |
| | | * @return The result of the operation. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws UnsupportedOperationException |
| | |
| | | * @throws NullPointerException |
| | | * If {@code ldifLines} was {@code null} . |
| | | */ |
| | | Result add(String... ldifLines) throws ErrorResultException; |
| | | Result add(String... ldifLines) throws LdapException; |
| | | |
| | | /** |
| | | * Asynchronously adds an entry to the Directory Server using the provided |
| | |
| | | * @param request |
| | | * The change request. |
| | | * @return The result of the operation. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws UnsupportedOperationException |
| | |
| | | * @throws NullPointerException |
| | | * If {@code request} was {@code null}. |
| | | */ |
| | | Result applyChange(ChangeRecord request) throws ErrorResultException; |
| | | Result applyChange(ChangeRecord request) throws LdapException; |
| | | |
| | | /** |
| | | * Asynchronously applies the provided change request to the Directory |
| | |
| | | * @param request |
| | | * The bind request. |
| | | * @return The result of the operation. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws UnsupportedOperationException |
| | |
| | | * @throws NullPointerException |
| | | * If {@code request} was {@code null}. |
| | | */ |
| | | BindResult bind(BindRequest request) throws ErrorResultException; |
| | | BindResult bind(BindRequest request) throws LdapException; |
| | | |
| | | /** |
| | | * Authenticates to the Directory Server using simple authentication and the |
| | |
| | | * The password of the Directory object that the client wishes to |
| | | * bind as, which may be empty. |
| | | * @return The result of the operation. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws LocalizedIllegalArgumentException |
| | |
| | | * @throws NullPointerException |
| | | * If {@code name} or {@code password} was {@code null}. |
| | | */ |
| | | BindResult bind(String name, char[] password) throws ErrorResultException; |
| | | BindResult bind(String name, char[] password) throws LdapException; |
| | | |
| | | /** |
| | | * Asynchronously authenticates to the Directory Server using the provided |
| | |
| | | * @param request |
| | | * The compare request. |
| | | * @return The result of the operation. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws UnsupportedOperationException |
| | |
| | | * @throws NullPointerException |
| | | * If {@code request} was {@code null}. |
| | | */ |
| | | CompareResult compare(CompareRequest request) throws ErrorResultException; |
| | | CompareResult compare(CompareRequest request) throws LdapException; |
| | | |
| | | /** |
| | | * Compares the named entry in the Directory Server against the provided |
| | |
| | | * @param assertionValue |
| | | * The assertion value to be compared. |
| | | * @return The result of the operation. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws LocalizedIllegalArgumentException |
| | |
| | | * {@code assertionValue} was {@code null}. |
| | | */ |
| | | CompareResult compare(String name, String attributeDescription, String assertionValue) |
| | | throws ErrorResultException; |
| | | throws LdapException; |
| | | |
| | | /** |
| | | * Asynchronously compares an entry in the Directory Server using the |
| | |
| | | * @param request |
| | | * The delete request. |
| | | * @return The result of the operation. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws UnsupportedOperationException |
| | |
| | | * @throws NullPointerException |
| | | * If {@code request} was {@code null}. |
| | | */ |
| | | Result delete(DeleteRequest request) throws ErrorResultException; |
| | | Result delete(DeleteRequest request) throws LdapException; |
| | | |
| | | /** |
| | | * Deletes the named entry from the Directory Server. |
| | |
| | | * @param name |
| | | * The distinguished name of the entry to be deleted. |
| | | * @return The result of the operation. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws LocalizedIllegalArgumentException |
| | |
| | | * @throws NullPointerException |
| | | * If {@code name} was {@code null}. |
| | | */ |
| | | Result delete(String name) throws ErrorResultException; |
| | | Result delete(String name) throws LdapException; |
| | | |
| | | /** |
| | | * Deletes the named entry and all of its subordinates from the Directory |
| | |
| | | * The distinguished name of the subtree base entry to be |
| | | * deleted. |
| | | * @return The result of the operation. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws LocalizedIllegalArgumentException |
| | |
| | | * @throws NullPointerException |
| | | * If {@code name} was {@code null}. |
| | | */ |
| | | Result deleteSubtree(String name) throws ErrorResultException; |
| | | Result deleteSubtree(String name) throws LdapException; |
| | | |
| | | /** |
| | | * Asynchronously deletes an entry from the Directory Server using the |
| | |
| | | * @param request |
| | | * The extended request. |
| | | * @return The result of the operation. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws UnsupportedOperationException |
| | |
| | | * @throws NullPointerException |
| | | * If {@code request} was {@code null}. |
| | | */ |
| | | <R extends ExtendedResult> R extendedRequest(ExtendedRequest<R> request) |
| | | throws ErrorResultException; |
| | | <R extends ExtendedResult> R extendedRequest(ExtendedRequest<R> request) throws LdapException; |
| | | |
| | | /** |
| | | * Requests that the Directory Server performs the provided extended |
| | |
| | | * any intermediate responses as they are received, may be |
| | | * {@code null}. |
| | | * @return The result of the operation. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws UnsupportedOperationException |
| | |
| | | * If {@code request} was {@code null}. |
| | | */ |
| | | <R extends ExtendedResult> R extendedRequest(ExtendedRequest<R> request, IntermediateResponseHandler handler) |
| | | throws ErrorResultException; |
| | | throws LdapException; |
| | | |
| | | /** |
| | | * Requests that the Directory Server performs the provided extended |
| | |
| | | * The content of the extended request in a form defined by the |
| | | * extended operation, or {@code null} if there is no content. |
| | | * @return The result of the operation. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws UnsupportedOperationException |
| | |
| | | * @throws NullPointerException |
| | | * If {@code requestName} was {@code null}. |
| | | */ |
| | | GenericExtendedResult extendedRequest(String requestName, ByteString requestValue) |
| | | throws ErrorResultException; |
| | | GenericExtendedResult extendedRequest(String requestName, ByteString requestValue) throws LdapException; |
| | | |
| | | /** |
| | | * Asynchronously performs the provided extended request in the Directory |
| | |
| | | * @param request |
| | | * The modify request. |
| | | * @return The result of the operation. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws UnsupportedOperationException |
| | |
| | | * @throws NullPointerException |
| | | * If {@code request} was {@code null}. |
| | | */ |
| | | Result modify(ModifyRequest request) throws ErrorResultException; |
| | | Result modify(ModifyRequest request) throws LdapException; |
| | | |
| | | /** |
| | | * Modifies an entry in the Directory Server using the provided lines of |
| | |
| | | * Lines of LDIF containing the a single LDIF modify change |
| | | * record. |
| | | * @return The result of the operation. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws UnsupportedOperationException |
| | |
| | | * @throws NullPointerException |
| | | * If {@code ldifLines} was {@code null} . |
| | | */ |
| | | Result modify(String... ldifLines) throws ErrorResultException; |
| | | Result modify(String... ldifLines) throws LdapException; |
| | | |
| | | /** |
| | | * Asynchronously modifies an entry in the Directory Server using the |
| | |
| | | * @param request |
| | | * The modify DN request. |
| | | * @return The result of the operation. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws UnsupportedOperationException |
| | |
| | | * @throws NullPointerException |
| | | * If {@code request} was {@code null}. |
| | | */ |
| | | Result modifyDN(ModifyDNRequest request) throws ErrorResultException; |
| | | Result modifyDN(ModifyDNRequest request) throws LdapException; |
| | | |
| | | /** |
| | | * Renames the named entry in the Directory Server using the provided new |
| | |
| | | * @param newRDN |
| | | * The new RDN of the entry. |
| | | * @return The result of the operation. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws LocalizedIllegalArgumentException |
| | |
| | | * @throws NullPointerException |
| | | * If {@code name} or {@code newRDN} was {@code null}. |
| | | */ |
| | | Result modifyDN(String name, String newRDN) throws ErrorResultException; |
| | | Result modifyDN(String name, String newRDN) throws LdapException; |
| | | |
| | | /** |
| | | * Asynchronously renames an entry in the Directory Server using the |
| | |
| | | * which may be {@code null} or empty indicating that all user |
| | | * attributes should be returned. |
| | | * @return The single search result entry returned from the search. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws UnsupportedOperationException |
| | |
| | | * @throws NullPointerException |
| | | * If the {@code name} was {@code null}. |
| | | */ |
| | | SearchResultEntry readEntry(DN name, String... attributeDescriptions) |
| | | throws ErrorResultException; |
| | | SearchResultEntry readEntry(DN name, String... attributeDescriptions) throws LdapException; |
| | | |
| | | /** |
| | | * Reads the named entry from the Directory Server. |
| | |
| | | * @param attributeDescriptions |
| | | * The names of the attributes to be included with the entry. |
| | | * @return The single search result entry returned from the search. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws LocalizedIllegalArgumentException |
| | |
| | | * @throws NullPointerException |
| | | * If the {@code name} was {@code null}. |
| | | */ |
| | | SearchResultEntry readEntry(String name, String... attributeDescriptions) |
| | | throws ErrorResultException; |
| | | SearchResultEntry readEntry(String name, String... attributeDescriptions) throws LdapException; |
| | | |
| | | /** |
| | | * Asynchronously reads the named entry from the Directory Server. |
| | |
| | | * @param entries |
| | | * The collection to which matching entries should be added. |
| | | * @return The result of the operation. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws UnsupportedOperationException |
| | |
| | | * @throws NullPointerException |
| | | * If {@code request} or {@code entries} was {@code null}. |
| | | */ |
| | | Result search(SearchRequest request, Collection<? super SearchResultEntry> entries) |
| | | throws ErrorResultException; |
| | | Result search(SearchRequest request, Collection<? super SearchResultEntry> entries) throws LdapException; |
| | | |
| | | /** |
| | | * Searches the Directory Server using the provided search request. Any |
| | |
| | | * The collection to which search result references should be |
| | | * added, or {@code null} if references are to be discarded. |
| | | * @return The result of the operation. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws UnsupportedOperationException |
| | |
| | | * If {@code request} or {@code entries} was {@code null}. |
| | | */ |
| | | Result search(SearchRequest request, Collection<? super SearchResultEntry> entries, |
| | | Collection<? super SearchResultReference> references) throws ErrorResultException; |
| | | Collection<? super SearchResultReference> references) throws LdapException; |
| | | |
| | | /** |
| | | * Searches the Directory Server using the provided search request. Any |
| | |
| | | * search result entries and references as they are received, may |
| | | * be {@code null}. |
| | | * @return The result of the operation. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws UnsupportedOperationException |
| | |
| | | * @throws NullPointerException |
| | | * If {@code request} was {@code null}. |
| | | */ |
| | | Result search(SearchRequest request, SearchResultHandler handler) throws ErrorResultException; |
| | | Result search(SearchRequest request, SearchResultHandler handler) throws LdapException; |
| | | |
| | | /** |
| | | * Searches the Directory Server using the provided search parameters. Any |
| | |
| | | * @param request |
| | | * The search request. |
| | | * @return The single search result entry returned from the search. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws UnsupportedOperationException |
| | |
| | | * @throws NullPointerException |
| | | * If the {@code request} was {@code null}. |
| | | */ |
| | | SearchResultEntry searchSingleEntry(SearchRequest request) throws ErrorResultException; |
| | | SearchResultEntry searchSingleEntry(SearchRequest request) throws LdapException; |
| | | |
| | | /** |
| | | * Searches the Directory Server for a single entry using the provided |
| | |
| | | * @param attributeDescriptions |
| | | * The names of the attributes to be included with each entry. |
| | | * @return The single search result entry returned from the search. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws LocalizedIllegalArgumentException |
| | |
| | | * were {@code null}. |
| | | */ |
| | | SearchResultEntry searchSingleEntry(String baseObject, SearchScope scope, String filter, |
| | | String... attributeDescriptions) throws ErrorResultException; |
| | | String... attributeDescriptions) throws LdapException; |
| | | |
| | | /** |
| | | * Asynchronously searches the Directory Server for a single entry using the |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * Notifies this connection event listener that a fatal error has occurred |
| | | * and the connection can no longer be used - the server has crashed, for |
| | | * example. The connection implementation makes this notification just |
| | | * before it throws the provided {@link ErrorResultException} to the |
| | | * before it throws the provided {@link LdapException} to the |
| | | * application. |
| | | * <p> |
| | | * <b>Note:</b> disconnect notifications are treated as fatal connection |
| | |
| | | * @param error |
| | | * The exception that is about to be thrown to the application. |
| | | */ |
| | | void handleConnectionError(boolean isDisconnectNotification, ErrorResultException error); |
| | | void handleConnectionError(boolean isDisconnectNotification, LdapException error); |
| | | |
| | | /** |
| | | * Notifies this connection event listener that the connection has just |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * was unsuccessful because of a connection failure. |
| | | */ |
| | | @SuppressWarnings("serial") |
| | | public class ConnectionException extends ErrorResultException { |
| | | public class ConnectionException extends LdapException { |
| | | ConnectionException(final Result result) { |
| | | super(result); |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS. |
| | | * Portions Copyright 2011-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * |
| | | * @return A promise which can be used to retrieve the connection. |
| | | */ |
| | | Promise<Connection, ErrorResultException> getConnectionAsync(); |
| | | Promise<Connection, LdapException> getConnectionAsync(); |
| | | |
| | | /** |
| | | * Returns a connection to the Directory Server associated with this |
| | |
| | | * |
| | | * @return A connection to the Directory Server associated with this |
| | | * connection factory. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the connection request failed for some reason. |
| | | */ |
| | | Connection getConnection() throws ErrorResultException; |
| | | Connection getConnection() throws LdapException; |
| | | } |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2011-2013 ForgeRock AS |
| | | * Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * If this connection pool has already been closed. |
| | | */ |
| | | @Override |
| | | Promise<Connection, ErrorResultException> getConnectionAsync(); |
| | | Promise<Connection, LdapException> getConnectionAsync(); |
| | | |
| | | /** |
| | | * Obtains a connection from this connection pool, potentially opening a new |
| | |
| | | * implementation, return the connection to this pool without closing it. |
| | | * |
| | | * @return A pooled connection. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the connection request failed for some reason. |
| | | * @throws IllegalStateException |
| | | * If this connection pool has already been closed. |
| | | */ |
| | | @Override |
| | | Connection getConnection() throws ErrorResultException; |
| | | Connection getConnection() throws LdapException; |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions Copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * @param len |
| | | * The number of bytes from {@code incoming} to be unwrapped. |
| | | * @return A non-{@code null} byte array containing the unwrapped bytes. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If {@code incoming} cannot be successfully unwrapped. |
| | | */ |
| | | byte[] unwrap(byte[] incoming, int offset, int len) throws ErrorResultException; |
| | | byte[] unwrap(byte[] incoming, int offset, int len) throws LdapException; |
| | | |
| | | /** |
| | | * Wraps a byte array to be sent to the peer. |
| | |
| | | * @param len |
| | | * The number of bytes from {@code outgoing} to be wrapped. |
| | | * @return A non-{@code null} byte array containing the wrapped bytes. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If {@code outgoing} cannot be successfully wrapped. |
| | | */ |
| | | byte[] wrap(byte[] outgoing, int offset, int len) throws ErrorResultException; |
| | | byte[] wrap(byte[] outgoing, int offset, int len) throws LdapException; |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * Bind will result in an {@code UnsupportedOperationException}. |
| | | * <p> |
| | | * If the Bind request fails for some reason (e.g. invalid credentials), |
| | | * then the connection attempt will fail and an {@code ErrorResultException} |
| | | * then the connection attempt will fail and an {@link LdapException} |
| | | * will be thrown. |
| | | * |
| | | * @param factory |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Connection getConnection() throws ErrorResultException { |
| | | public Connection getConnection() throws LdapException { |
| | | return factory.getConnection(); |
| | | } |
| | | |
| | | @Override |
| | | public Promise<Connection, ErrorResultException> getConnectionAsync() { |
| | | public Promise<Connection, LdapException> getConnectionAsync() { |
| | | return factory.getConnectionAsync(); |
| | | } |
| | | |
| | |
| | | return new ConnectionFactory() { |
| | | |
| | | @Override |
| | | public Promise<Connection, ErrorResultException> getConnectionAsync() { |
| | | public Promise<Connection, LdapException> getConnectionAsync() { |
| | | return factory.getConnectionAsync(); |
| | | } |
| | | |
| | | @Override |
| | | public Connection getConnection() throws ErrorResultException { |
| | | public Connection getConnection() throws LdapException { |
| | | return factory.getConnection(); |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2013 ForgeRock AS. |
| | | * Portions Copyright 2013-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * </ul> |
| | | */ |
| | | @SuppressWarnings("serial") |
| | | public class ConstraintViolationException extends ErrorResultException { |
| | | public class ConstraintViolationException extends LdapException { |
| | | ConstraintViolationException(final Result result) { |
| | | super(result); |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.*; |
| | | import static org.forgerock.opendj.ldap.AttributeDescription.objectClass; |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.newErrorResult; |
| | | import static org.forgerock.opendj.ldap.LdapException.newErrorResult; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | |
| | | * @param change |
| | | * The modification to be applied to the entry. |
| | | * @return A reference to the updated entry. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If an error occurred while performing the change such as an |
| | | * attempt to increment a value which is not a number. The entry |
| | | * will not have been modified. |
| | | */ |
| | | public static Entry modifyEntry(final Entry entry, final Modification change) |
| | | throws ErrorResultException { |
| | | public static Entry modifyEntry(final Entry entry, final Modification change) throws LdapException { |
| | | return modifyEntry(entry, change, null); |
| | | } |
| | | |
| | |
| | | * added, or {@code null} if conflicting values should not be |
| | | * saved. |
| | | * @return A reference to the updated entry. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If an error occurred while performing the change such as an |
| | | * attempt to increment a value which is not a number. The entry |
| | | * will not have been modified. |
| | | */ |
| | | public static Entry modifyEntry(final Entry entry, final Modification change, |
| | | final Collection<? super ByteString> conflictingValues) throws ErrorResultException { |
| | | final Collection<? super ByteString> conflictingValues) throws LdapException { |
| | | return modifyEntry0(entry, change, conflictingValues, true); |
| | | } |
| | | |
| | |
| | | * @param changes |
| | | * The modification request to be applied to the entry. |
| | | * @return A reference to the updated entry. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If an error occurred while performing the changes such as an |
| | | * attempt to add duplicate values, remove values which do not |
| | | * exist, or increment a value which is not a number. The entry |
| | | * may have been modified. |
| | | */ |
| | | public static Entry modifyEntry(final Entry entry, final ModifyRequest changes) |
| | | throws ErrorResultException { |
| | | public static Entry modifyEntry(final Entry entry, final ModifyRequest changes) throws LdapException { |
| | | final boolean isPermissive = changes.containsControl(PermissiveModifyRequestControl.OID); |
| | | return modifyEntry0(entry, changes.getModifications(), isPermissive); |
| | | } |
| | |
| | | * @param changes |
| | | * The modification request to be applied to the entry. |
| | | * @return A reference to the updated entry. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If an error occurred while performing the changes such as an |
| | | * attempt to increment a value which is not a number. The entry |
| | | * may have been modified. |
| | | */ |
| | | public static Entry modifyEntryPermissive(final Entry entry, |
| | | final Collection<Modification> changes) throws ErrorResultException { |
| | | final Collection<Modification> changes) throws LdapException { |
| | | return modifyEntry0(entry, changes, true); |
| | | } |
| | | |
| | |
| | | * @param changes |
| | | * The modification request to be applied to the entry. |
| | | * @return A reference to the updated entry. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If an error occurred while performing the changes such as an |
| | | * attempt to add duplicate values, remove values which do not |
| | | * exist, or increment a value which is not a number. The entry |
| | | * may have been modified. |
| | | */ |
| | | public static Entry modifyEntryStrict(final Entry entry, final Collection<Modification> changes) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | return modifyEntry0(entry, changes, false); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | private static void incrementAttribute(final Entry entry, final Attribute change) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | // First parse the change. |
| | | final AttributeDescription deltaAd = change.getAttributeDescription(); |
| | | if (change.size() != 1) { |
| | |
| | | } |
| | | |
| | | private static Entry modifyEntry0(final Entry entry, final Collection<Modification> changes, |
| | | final boolean isPermissive) throws ErrorResultException { |
| | | final boolean isPermissive) throws LdapException { |
| | | final Collection<ByteString> conflictingValues = |
| | | isPermissive ? null : new ArrayList<ByteString>(0); |
| | | for (final Modification change : changes) { |
| | |
| | | |
| | | private static Entry modifyEntry0(final Entry entry, final Modification change, |
| | | final Collection<? super ByteString> conflictingValues, final boolean isPermissive) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | final ModificationType modType = change.getModificationType(); |
| | | if (modType.equals(ModificationType.ADD)) { |
| | | entry.addAttribute(change.getAttribute(), conflictingValues); |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * sub-class. |
| | | */ |
| | | @SuppressWarnings("serial") |
| | | public class EntryNotFoundException extends ErrorResultException { |
| | | public class EntryNotFoundException extends LdapException { |
| | | EntryNotFoundException(final Result result) { |
| | | super(result); |
| | | } |
| | |
| | | * @param <S> |
| | | * The type of result returned by this future result. |
| | | */ |
| | | public interface FutureResult<S> extends Promise<S, ErrorResultException> { |
| | | public interface FutureResult<S> extends Promise<S, LdapException> { |
| | | /** |
| | | * Returns the request ID of the request if appropriate. |
| | | * |
| | |
| | | * @see Promise |
| | | * @see Promises |
| | | */ |
| | | public class FutureResultImpl<R> extends PromiseImpl<R, ErrorResultException> |
| | | public class FutureResultImpl<R> extends PromiseImpl<R, LdapException> |
| | | implements FutureResult<R>, ResultHandler<R> { |
| | | private final int requestID; |
| | | |
| | |
| | | */ |
| | | public final class FutureResultWrapper<R> { |
| | | private static class LdapPromiseWrapper<R> implements FutureResult<R> { |
| | | private final Promise<R, ErrorResultException> wrappedPromise; |
| | | private final Promise<R, LdapException> wrappedPromise; |
| | | private final int requestID; |
| | | |
| | | LdapPromiseWrapper(Promise<R, ErrorResultException> wrappedPromise, int requestID) { |
| | | LdapPromiseWrapper(Promise<R, LdapException> wrappedPromise, int requestID) { |
| | | this.wrappedPromise = wrappedPromise; |
| | | this.requestID = requestID; |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public R getOrThrow() throws InterruptedException, ErrorResultException { |
| | | public R getOrThrow() throws InterruptedException, LdapException { |
| | | return wrappedPromise.getOrThrow(); |
| | | } |
| | | |
| | | @Override |
| | | public R getOrThrow(long timeout, TimeUnit unit) throws InterruptedException, ErrorResultException, |
| | | public R getOrThrow(long timeout, TimeUnit unit) throws InterruptedException, LdapException, |
| | | TimeoutException { |
| | | return wrappedPromise.getOrThrow(timeout, unit); |
| | | } |
| | | |
| | | @Override |
| | | public R getOrThrowUninterruptibly() throws ErrorResultException { |
| | | public R getOrThrowUninterruptibly() throws LdapException { |
| | | return wrappedPromise.getOrThrowUninterruptibly(); |
| | | } |
| | | |
| | | @Override |
| | | public R getOrThrowUninterruptibly(long timeout, TimeUnit unit) throws ErrorResultException, TimeoutException { |
| | | public R getOrThrowUninterruptibly(long timeout, TimeUnit unit) throws LdapException, TimeoutException { |
| | | return wrappedPromise.getOrThrowUninterruptibly(timeout, unit); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Promise<R, ErrorResultException> onFailure(FailureHandler<? super ErrorResultException> onFailure) { |
| | | public Promise<R, LdapException> onFailure(FailureHandler<? super LdapException> onFailure) { |
| | | wrappedPromise.onFailure(onFailure); |
| | | return this; |
| | | } |
| | | |
| | | @Override |
| | | public Promise<R, ErrorResultException> onSuccess(SuccessHandler<? super R> onSuccess) { |
| | | public Promise<R, LdapException> onSuccess(SuccessHandler<? super R> onSuccess) { |
| | | wrappedPromise.onSuccess(onSuccess); |
| | | return this; |
| | | } |
| | | |
| | | @Override |
| | | public Promise<R, ErrorResultException> onSuccessOrFailure(Runnable onSuccessOrFailure) { |
| | | public Promise<R, LdapException> onSuccessOrFailure(Runnable onSuccessOrFailure) { |
| | | wrappedPromise.onSuccessOrFailure(onSuccessOrFailure); |
| | | return this; |
| | | } |
| | | |
| | | @Override |
| | | // @Checkstyle:ignore |
| | | public <VOUT> Promise<VOUT, ErrorResultException> then( |
| | | Function<? super R, VOUT, ErrorResultException> onSuccess) { |
| | | public <VOUT> Promise<VOUT, LdapException> then(Function<? super R, VOUT, LdapException> onSuccess) { |
| | | return new LdapPromiseWrapper<VOUT>(wrappedPromise.then(onSuccess), getRequestID()); |
| | | } |
| | | |
| | |
| | | @Override |
| | | // @Checkstyle:ignore |
| | | public <VOUT, EOUT extends Exception> Promise<VOUT, EOUT> then(Function<? super R, VOUT, EOUT> onSuccess, |
| | | Function<? super ErrorResultException, VOUT, EOUT> onFailure) { |
| | | Function<? super LdapException, VOUT, EOUT> onFailure) { |
| | | return new LdapPromiseWrapper(wrappedPromise.then(onSuccess, onFailure), getRequestID()); |
| | | } |
| | | |
| | | @Override |
| | | public Promise<R, ErrorResultException> then(SuccessHandler<? super R> onSuccess) { |
| | | public Promise<R, LdapException> then(SuccessHandler<? super R> onSuccess) { |
| | | wrappedPromise.then(onSuccess); |
| | | return this; |
| | | } |
| | | |
| | | @Override |
| | | public Promise<R, ErrorResultException> then(SuccessHandler<? super R> onSuccess, |
| | | FailureHandler<? super ErrorResultException> onFailure) { |
| | | public Promise<R, LdapException> then(SuccessHandler<? super R> onSuccess, |
| | | FailureHandler<? super LdapException> onFailure) { |
| | | wrappedPromise.then(onSuccess, onFailure); |
| | | return this; |
| | | } |
| | | |
| | | @Override |
| | | public Promise<R, ErrorResultException> thenAlways(Runnable onSuccessOrFailure) { |
| | | public Promise<R, LdapException> thenAlways(Runnable onSuccessOrFailure) { |
| | | wrappedPromise.thenAlways(onSuccessOrFailure); |
| | | return this; |
| | | } |
| | | |
| | | @Override |
| | | // @Checkstyle:ignore |
| | | public <VOUT> Promise<VOUT, ErrorResultException> thenAsync( |
| | | AsyncFunction<? super R, VOUT, ErrorResultException> onSuccess) { |
| | | public <VOUT> Promise<VOUT, LdapException> thenAsync(AsyncFunction<? super R, VOUT, LdapException> onSuccess) { |
| | | return new LdapPromiseWrapper<VOUT>(wrappedPromise.thenAsync(onSuccess), getRequestID()); |
| | | } |
| | | |
| | |
| | | // @Checkstyle:ignore |
| | | public <VOUT, EOUT extends Exception> Promise<VOUT, EOUT> thenAsync( |
| | | AsyncFunction<? super R, VOUT, EOUT> onSuccess, |
| | | AsyncFunction<? super ErrorResultException, VOUT, EOUT> onFailure) { |
| | | AsyncFunction<? super LdapException, VOUT, EOUT> onFailure) { |
| | | return new LdapPromiseWrapper(wrappedPromise.thenAsync(onSuccess, onFailure), getRequestID()); |
| | | } |
| | | } |
| | |
| | | * has already succeeded with the provided result. |
| | | */ |
| | | public static <R> FutureResult<R> newSuccessfulFutureResult(final R result) { |
| | | return new LdapPromiseWrapper<R>(Promises.<R, ErrorResultException> newSuccessfulPromise(result), -1); |
| | | return new LdapPromiseWrapper<R>(Promises.<R, LdapException> newSuccessfulPromise(result), -1); |
| | | } |
| | | |
| | | /** |
| | |
| | | * has already succeeded with the provided result. |
| | | */ |
| | | public static <R> FutureResult<R> newSuccessfulFutureResult(final R result, int requestID) { |
| | | return new LdapPromiseWrapper<R>(Promises.<R, ErrorResultException> newSuccessfulPromise(result), requestID); |
| | | return new LdapPromiseWrapper<R>(Promises.<R, LdapException> newSuccessfulPromise(result), requestID); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return A {@link FutureResult} representing an asynchronous task which |
| | | * has already failed with the provided error. |
| | | */ |
| | | public static <R, E extends ErrorResultException> FutureResult<R> newFailedFutureResult(final E error) { |
| | | return new LdapPromiseWrapper<R>(Promises.<R, ErrorResultException> newFailedPromise(error), -1); |
| | | public static <R, E extends LdapException> FutureResult<R> newFailedFutureResult(final E error) { |
| | | return new LdapPromiseWrapper<R>(Promises.<R, LdapException> newFailedPromise(error), -1); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return A {@link FutureResult} representing an asynchronous task which |
| | | * has already failed with the provided error. |
| | | */ |
| | | public static <R, E extends ErrorResultException> FutureResult<R> newFailedFutureResult(final E error, |
| | | int requestID) { |
| | | return new LdapPromiseWrapper<R>(Promises.<R, ErrorResultException> newFailedPromise(error), requestID); |
| | | public static <R, E extends LdapException> FutureResult<R> newFailedFutureResult(final E error, int requestID) { |
| | | return new LdapPromiseWrapper<R>(Promises.<R, LdapException> newFailedPromise(error), requestID); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return A {@link FutureResult} representing the same asynchronous task as |
| | | * the {@link Promise} provided. |
| | | */ |
| | | public static <R> FutureResult<R> asFutureResult(Promise<R, ErrorResultException> wrappedPromise) { |
| | | public static <R> FutureResult<R> asFutureResult(Promise<R, LdapException> wrappedPromise) { |
| | | return new LdapPromiseWrapper<R>(wrappedPromise, -1); |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS. |
| | | * Portions Copyright 2011-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | |
| | | import com.forgerock.opendj.util.ReferenceCountedObject; |
| | | import com.forgerock.opendj.util.TimeSource; |
| | | |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.*; |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.*; |
| | | import static com.forgerock.opendj.util.StaticUtils.*; |
| | |
| | | private final class ConnectionFutureResultImpl implements Runnable { |
| | | private Connection connection; |
| | | private Connection heartBeatConnection; |
| | | private ErrorResultException heartBeatError; |
| | | private LdapException heartBeatError; |
| | | |
| | | /** |
| | | * Due to a potential race between the heart beat timing out and the |
| | |
| | | */ |
| | | private final AtomicBoolean isComplete = new AtomicBoolean(); |
| | | |
| | | private final Function<Result, Connection, ErrorResultException> futureSearchSuccess; |
| | | private final Function<ErrorResultException, Connection, ErrorResultException> futureSearchError; |
| | | private final Function<Result, Connection, LdapException> futureSearchSuccess; |
| | | private final Function<LdapException, Connection, LdapException> futureSearchError; |
| | | |
| | | private ConnectionFutureResultImpl() { |
| | | this.futureSearchSuccess = new Function<Result, Connection, ErrorResultException>() { |
| | | this.futureSearchSuccess = new Function<Result, Connection, LdapException>() { |
| | | |
| | | @Override |
| | | public Connection apply(Result result) throws ErrorResultException { |
| | | public Connection apply(Result result) throws LdapException { |
| | | if (isComplete.compareAndSet(false, true)) { |
| | | heartBeatConnection = adaptConnection(connection); |
| | | } |
| | |
| | | } |
| | | }; |
| | | |
| | | this.futureSearchError = new Function<ErrorResultException, Connection, ErrorResultException>() { |
| | | this.futureSearchError = new Function<LdapException, Connection, LdapException>() { |
| | | @Override |
| | | public Connection apply(ErrorResultException error) throws ErrorResultException { |
| | | public Connection apply(LdapException error) throws LdapException { |
| | | manageError(error); |
| | | throw heartBeatError; |
| | | } |
| | |
| | | manageError(newHeartBeatTimeoutError()); |
| | | } |
| | | |
| | | private void manageError(ErrorResultException error) { |
| | | private void manageError(LdapException error) { |
| | | if (isComplete.compareAndSet(false, true)) { |
| | | // Ensure that the connection is closed. |
| | | if (connection != null) { |
| | |
| | | private final AtomicBoolean completed = new AtomicBoolean(); |
| | | |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | if (tryComplete()) { |
| | | timestamp(error); |
| | | } |
| | |
| | | protected abstract FutureResult<R> dispatch(); |
| | | |
| | | @Override |
| | | protected final ErrorResultException tryCancel(final boolean mayInterruptIfRunning) { |
| | | protected final LdapException tryCancel(final boolean mayInterruptIfRunning) { |
| | | if (innerFuture != null) { |
| | | innerFuture.cancel(mayInterruptIfRunning); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleConnectionError(final boolean isDisconnectNotification, |
| | | final ErrorResultException error) { |
| | | public void handleConnectionError(final boolean isDisconnectNotification, final LdapException error) { |
| | | if (state.notifyConnectionError(isDisconnectNotification, error)) { |
| | | failPendingResults(error); |
| | | } |
| | |
| | | return state.getConnectionError() == null; |
| | | } |
| | | |
| | | private void failPendingResults(final ErrorResultException error) { |
| | | private void failPendingResults(final LdapException error) { |
| | | /* |
| | | * Peek instead of pool because notification is responsible for |
| | | * removing the element from the queue. |
| | |
| | | timestamp(result); |
| | | releaseHeartBeatLock(); |
| | | } |
| | | }).onFailure(new FailureHandler<ErrorResultException>() { |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(ErrorResultException error) { |
| | | public void handleError(LdapException error) { |
| | | /* |
| | | * Connection failure will be handled by |
| | | * connection event listener. Ignore |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Connection getConnection() throws ErrorResultException { |
| | | public Connection getConnection() throws LdapException { |
| | | /* |
| | | * Immediately send a heart beat in order to determine if the connected |
| | | * server is responding. |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Promise<Connection, ErrorResultException> getConnectionAsync() { |
| | | public Promise<Connection, LdapException> getConnectionAsync() { |
| | | acquireScheduler(); // Protect scheduler. |
| | | |
| | | // Create a future responsible for chaining the initial heartbeat |
| | |
| | | |
| | | // Request a connection and return the future representing the |
| | | // heartbeat. |
| | | return factory.getConnectionAsync().thenAsync(new AsyncFunction<Connection, Result, ErrorResultException>() { |
| | | return factory.getConnectionAsync().thenAsync(new AsyncFunction<Connection, Result, LdapException>() { |
| | | @Override |
| | | public Promise<Result, ErrorResultException> apply(final Connection connectionResult) { |
| | | public Promise<Result, LdapException> apply(final Connection connectionResult) { |
| | | // Save the connection for later once the heart beat completes. |
| | | compositeFuture.connection = connectionResult; |
| | | scheduler.get().schedule(compositeFuture, timeoutMS, TimeUnit.MILLISECONDS); |
| | |
| | | return (FutureResult<R>) future.onSuccess(resultHandler).onFailure(resultHandler); |
| | | } |
| | | |
| | | private ErrorResultException adaptHeartBeatError(final Exception error) { |
| | | private LdapException adaptHeartBeatError(final Exception error) { |
| | | if (error instanceof ConnectionException) { |
| | | return (ErrorResultException) error; |
| | | return (LdapException) error; |
| | | } else if (error instanceof TimeoutResultException || error instanceof TimeoutException) { |
| | | return newHeartBeatTimeoutError(); |
| | | } else if (error instanceof InterruptedException) { |
| | |
| | | return tmp; |
| | | } |
| | | |
| | | private ErrorResultException newHeartBeatTimeoutError() { |
| | | private LdapException newHeartBeatTimeoutError() { |
| | | return newErrorResult(ResultCode.CLIENT_SIDE_SERVER_DOWN, HBCF_HEARTBEAT_TIMEOUT |
| | | .get(timeoutMS)); |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS. |
| | | * Portions Copyright 2011-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Connection getConnection() throws ErrorResultException { |
| | | public Connection getConnection() throws LdapException { |
| | | final ServerConnection<Integer> serverConnection = factory.handleAccept(clientContext); |
| | | return new InternalConnection(serverConnection); |
| | | } |
| | | |
| | | @Override |
| | | public Promise<Connection, ErrorResultException> getConnectionAsync() { |
| | | public Promise<Connection, LdapException> getConnectionAsync() { |
| | | final ServerConnection<Integer> serverConnection; |
| | | try { |
| | | serverConnection = factory.handleAccept(clientContext); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | return newFailedFutureResult(e); |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS. |
| | | * Portions Copyright 2011-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Promise<Connection, ErrorResultException> getConnectionAsync() { |
| | | public Promise<Connection, LdapException> getConnectionAsync() { |
| | | return impl.getConnectionAsync(); |
| | | } |
| | | |
| | | @Override |
| | | public Connection getConnection() throws ErrorResultException { |
| | | public Connection getConnection() throws LdapException { |
| | | return impl.getConnection(); |
| | | } |
| | | |
| File was renamed from opendj-core/src/main/java/org/forgerock/opendj/ldap/ErrorResultException.java |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2013 ForgeRock AS. |
| | | * Portions copyright 2011-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | | import java.util.concurrent.ExecutionException; |
| | | import java.io.IOException; |
| | | |
| | | import org.forgerock.opendj.ldap.responses.Responses; |
| | | import org.forgerock.opendj.ldap.responses.Result; |
| | |
| | | * application specific exceptions. |
| | | */ |
| | | @SuppressWarnings("serial") |
| | | public class ErrorResultException extends ExecutionException { |
| | | public class LdapException extends IOException { |
| | | |
| | | /** |
| | | * Creates a new error result exception with the provided result code and an |
| | |
| | | * @throws NullPointerException |
| | | * If {@code resultCode} was {@code null}. |
| | | */ |
| | | public static ErrorResultException newErrorResult(ResultCode resultCode) { |
| | | public static LdapException newErrorResult(ResultCode resultCode) { |
| | | return newErrorResult(resultCode, null, null); |
| | | } |
| | | |
| | |
| | | * @throws NullPointerException |
| | | * If {@code resultCode} was {@code null}. |
| | | */ |
| | | public static ErrorResultException newErrorResult(ResultCode resultCode, |
| | | public static LdapException newErrorResult(ResultCode resultCode, |
| | | CharSequence diagnosticMessage) { |
| | | return newErrorResult(resultCode, diagnosticMessage, null); |
| | | } |
| | |
| | | * @throws NullPointerException |
| | | * If {@code resultCode} was {@code null}. |
| | | */ |
| | | public static ErrorResultException newErrorResult(ResultCode resultCode, Throwable cause) { |
| | | public static LdapException newErrorResult(ResultCode resultCode, Throwable cause) { |
| | | return newErrorResult(resultCode, null, cause); |
| | | } |
| | | |
| | |
| | | * @throws NullPointerException |
| | | * If {@code resultCode} was {@code null}. |
| | | */ |
| | | public static ErrorResultException newErrorResult(ResultCode resultCode, |
| | | public static LdapException newErrorResult(ResultCode resultCode, |
| | | CharSequence diagnosticMessage, Throwable cause) { |
| | | final Result result = Responses.newResult(resultCode); |
| | | if (diagnosticMessage != null) { |
| | |
| | | * @throws NullPointerException |
| | | * If {@code result} was {@code null}. |
| | | */ |
| | | public static ErrorResultException newErrorResult(final Result result) { |
| | | public static LdapException newErrorResult(final Result result) { |
| | | if (!result.getResultCode().isExceptional()) { |
| | | throw new IllegalArgumentException("Attempted to wrap a successful result: " + result); |
| | | } |
| | |
| | | return new TimeoutResultException(result); |
| | | } |
| | | |
| | | return new ErrorResultException(result); |
| | | return new LdapException(result); |
| | | } |
| | | |
| | | private static String getMessage(final Result result) { |
| | |
| | | * @param result |
| | | * The error result. |
| | | */ |
| | | protected ErrorResultException(final Result result) { |
| | | protected LdapException(final Result result) { |
| | | super(getMessage(result), result.getCause()); |
| | | this.result = result; |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS. |
| | | * Portions Copyright 2011-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Connection getConnection() throws ErrorResultException { |
| | | public Connection getConnection() throws LdapException { |
| | | return algorithm.getConnectionFactory().getConnection(); |
| | | } |
| | | |
| | | @Override |
| | | public Promise<Connection, ErrorResultException> getConnectionAsync() { |
| | | public Promise<Connection, LdapException> getConnectionAsync() { |
| | | final ConnectionFactory factory; |
| | | |
| | | try { |
| | | factory = algorithm.getConnectionFactory(); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | return newFailedPromise(e); |
| | | } |
| | | |
| | |
| | | * |
| | | * CDDL HEADER END |
| | | * |
| | | * Copyright 2013 ForgeRock AS. |
| | | * Copyright 2013-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * @param error |
| | | * The last error that occurred. |
| | | */ |
| | | void handleConnectionFactoryOffline(ConnectionFactory factory, ErrorResultException error); |
| | | void handleConnectionFactoryOffline(ConnectionFactory factory, LdapException error); |
| | | |
| | | /** |
| | | * Invoked when the load-balancer detects that a previously offline |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2013 ForgeRock AS. |
| | | * Portions Copyright 2013-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * next connection request. |
| | | * |
| | | * @return The connection factory. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If no connection factories are available for use. |
| | | */ |
| | | ConnectionFactory getConnectionFactory() throws ErrorResultException; |
| | | ConnectionFactory getConnectionFactory() throws LdapException; |
| | | } |
| | |
| | | |
| | | import static org.forgerock.opendj.ldap.Attributes.singletonAttribute; |
| | | import static org.forgerock.opendj.ldap.Entries.modifyEntry; |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.newErrorResult; |
| | | import static org.forgerock.opendj.ldap.LdapException.newErrorResult; |
| | | import static org.forgerock.opendj.ldap.responses.Responses.newBindResult; |
| | | import static org.forgerock.opendj.ldap.responses.Responses.newCompareResult; |
| | | import static org.forgerock.opendj.ldap.responses.Responses.newResult; |
| | |
| | | } |
| | | } |
| | | resultHandler.handleResult(getResult(request, null, request)); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | resultHandler.handleError(e); |
| | | } |
| | | } |
| | |
| | | */ |
| | | resultHandler.handleError(newErrorResult(ResultCode.INVALID_CREDENTIALS, |
| | | "Unknown user")); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | resultHandler.handleError(e); |
| | | } |
| | | } |
| | |
| | | } |
| | | resultHandler.handleResult(getCompareResult(request, entry, entry.containsAttribute( |
| | | assertion, null))); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | resultHandler.handleError(e); |
| | | } |
| | | } |
| | |
| | | resultHandler.handleResult(getResult(request, entry, null)); |
| | | } catch (final DecodeException e) { |
| | | resultHandler.handleError(newErrorResult(ResultCode.PROTOCOL_ERROR, e)); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | resultHandler.handleError(e); |
| | | } |
| | | } |
| | |
| | | entries.put(dn, modifyEntry(newEntry, request)); |
| | | } |
| | | resultHandler.handleResult(getResult(request, entry, newEntry)); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | resultHandler.handleError(e); |
| | | } |
| | | } |
| | |
| | | throw newErrorResult(ResultCode.PROTOCOL_ERROR, "Search request contains an unsupported search scope"); |
| | | } |
| | | } catch (DecodeException e) { |
| | | resultHandler.handleError(ErrorResultException.newErrorResult(ResultCode.PROTOCOL_ERROR, e.getMessage(), |
| | | e)); |
| | | } catch (final ErrorResultException e) { |
| | | resultHandler.handleError(LdapException.newErrorResult(ResultCode.PROTOCOL_ERROR, e.getMessage(), e)); |
| | | } catch (final LdapException e) { |
| | | resultHandler.handleError(e); |
| | | } |
| | | } |
| | |
| | | final Entry entry = reader.readEntry(); |
| | | final DN dn = entry.getName(); |
| | | if (!overwrite && entries.containsKey(dn)) { |
| | | throw new ErrorResultIOException(newErrorResult( |
| | | ResultCode.ENTRY_ALREADY_EXISTS, "Attempted to add the entry '" |
| | | + dn.toString() + "' multiple times")); |
| | | throw newErrorResult(ResultCode.ENTRY_ALREADY_EXISTS, |
| | | "Attempted to add the entry '" + dn + "' multiple times"); |
| | | } else { |
| | | entries.put(dn, entry); |
| | | } |
| | |
| | | * @throws CancelledResultException |
| | | * If a cancellation request has been received and processing of |
| | | * the request should be aborted if possible. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the request is unsuccessful. |
| | | */ |
| | | private void searchWithSubordinates(final RequestContext requestContext, final SearchResultHandler entryHandler, |
| | | final ResultHandler<Result> resultHandler, final DN dn, final Matcher matcher, |
| | | final AttributeFilter attributeFilter, final int sizeLimit, SearchScope scope, |
| | | SimplePagedResultsControl pagedResults) throws CancelledResultException, ErrorResultException { |
| | | SimplePagedResultsControl pagedResults) throws CancelledResultException, LdapException { |
| | | final int pageSize = pagedResults != null ? pagedResults.getSize() : 0; |
| | | final int offset = (pagedResults != null && !pagedResults.getCookie().isEmpty()) |
| | | ? Integer.valueOf(pagedResults.getCookie().toString()) : 0; |
| | |
| | | } |
| | | |
| | | private <R extends Result> R addResultControls(final Request request, final Entry before, |
| | | final Entry after, final R result) throws ErrorResultException { |
| | | final Entry after, final R result) throws LdapException { |
| | | try { |
| | | // Add pre-read response control if requested. |
| | | final PreReadRequestControl preRead = |
| | |
| | | } |
| | | |
| | | private BindResult getBindResult(final BindRequest request, final Entry before, |
| | | final Entry after) throws ErrorResultException { |
| | | final Entry after) throws LdapException { |
| | | return addResultControls(request, before, after, newBindResult(ResultCode.SUCCESS)); |
| | | } |
| | | |
| | | private CompareResult getCompareResult(final CompareRequest request, final Entry entry, |
| | | final boolean compareResult) throws ErrorResultException { |
| | | final boolean compareResult) throws LdapException { |
| | | return addResultControls( |
| | | request, |
| | | entry, |
| | |
| | | newCompareResult(compareResult ? ResultCode.COMPARE_TRUE : ResultCode.COMPARE_FALSE)); |
| | | } |
| | | |
| | | private Entry getRequiredEntry(final Request request, final DN dn) throws ErrorResultException { |
| | | private Entry getRequiredEntry(final Request request, final DN dn) throws LdapException { |
| | | final Entry entry = entries.get(dn); |
| | | if (entry == null) { |
| | | noSuchObject(dn); |
| | |
| | | return entry; |
| | | } |
| | | |
| | | private Result getResult(final Request request, final Entry before, final Entry after) |
| | | throws ErrorResultException { |
| | | private Result getResult(final Request request, final Entry before, final Entry after) throws LdapException { |
| | | return addResultControls(request, before, after, newResult(ResultCode.SUCCESS)); |
| | | } |
| | | |
| | | private void noSuchObject(final DN dn) throws ErrorResultException { |
| | | private void noSuchObject(final DN dn) throws LdapException { |
| | | throw newErrorResult(ResultCode.NO_SUCH_OBJECT, "The entry '" + dn.toString() |
| | | + "' does not exist"); |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * CLIENT_SIDE_UNEXPECTED_RESULTS_RETURNED} error result codes. |
| | | */ |
| | | @SuppressWarnings("serial") |
| | | public class MultipleEntriesFoundException extends ErrorResultException { |
| | | public class MultipleEntriesFoundException extends LdapException { |
| | | MultipleEntriesFoundException(final Result result) { |
| | | super(result); |
| | | } |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2011 ForgeRock AS |
| | | * Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * of the client's connection. |
| | | * @return A {@code RequestHandler} which will be used to handle requests |
| | | * from a client connection. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If this request handler factory cannot accept the client |
| | | * connection. |
| | | */ |
| | | RequestHandler<R> handleAccept(C clientContext) throws ErrorResultException; |
| | | RequestHandler<R> handleAccept(C clientContext) throws LdapException; |
| | | } |
| | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.INFO_CANCELED_BY_SERVER_DISCONNECT; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.INFO_CLIENT_CONNECTION_CLOSING; |
| | | import static com.forgerock.opendj.ldap.CoreMessages.WARN_CLIENT_DUPLICATE_MESSAGE_ID; |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.newErrorResult; |
| | | import static org.forgerock.opendj.ldap.LdapException.newErrorResult; |
| | | |
| | | import java.util.Iterator; |
| | | import java.util.LinkedList; |
| | |
| | | final R cancelResult = |
| | | request.getResultDecoder().newExtendedErrorResult(ResultCode.TOO_LATE, "", |
| | | ""); |
| | | resultHandler.handleError(ErrorResultException.newErrorResult(cancelResult)); |
| | | resultHandler.handleError(LdapException.newErrorResult(cancelResult)); |
| | | } |
| | | } |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | if (clientConnection.removePendingRequest(this)) { |
| | | if (setResult(error.getResult())) { |
| | | /* |
| | |
| | | cancelResultHandler.handleResult(result); |
| | | } else { |
| | | final Result result = Responses.newGenericExtendedResult(ResultCode.TOO_LATE); |
| | | cancelResultHandler.handleError(ErrorResultException |
| | | .newErrorResult(result)); |
| | | cancelResultHandler.handleError(LdapException.newErrorResult(result)); |
| | | } |
| | | } |
| | | } |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public ServerConnection<Integer> handleAccept(final C clientContext) |
| | | throws ErrorResultException { |
| | | public ServerConnection<Integer> handleAccept(final C clientContext) throws LdapException { |
| | | return adaptRequestHandler(factory.handleAccept(clientContext)); |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS. |
| | | * Portions Copyright 2011-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * @param <S> |
| | | * The type of result handled by this result handler. |
| | | */ |
| | | public interface ResultHandler<S> extends SuccessHandler<S>, FailureHandler<ErrorResultException> { |
| | | public interface ResultHandler<S> extends SuccessHandler<S>, FailureHandler<LdapException> { |
| | | /** |
| | | * Invoked when the asynchronous operation has failed. |
| | | * |
| | |
| | | * The error result exception indicating why the asynchronous |
| | | * operation has failed. |
| | | */ |
| | | void handleError(ErrorResultException error); |
| | | void handleError(LdapException error); |
| | | |
| | | /** |
| | | * Invoked when the asynchronous operation has completed successfully. |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | public static FutureResult<RootDSE> readRootDSEAsync(final Connection connection, |
| | | final ResultHandler<? super RootDSE> handler) { |
| | | return FutureResultWrapper.asFutureResult(connection.searchSingleEntryAsync(SEARCH_REQUEST).then( |
| | | new Function<SearchResultEntry, RootDSE, ErrorResultException>() { |
| | | new Function<SearchResultEntry, RootDSE, LdapException>() { |
| | | @Override |
| | | public RootDSE apply(SearchResultEntry result) { |
| | | return valueOf(result); |
| | |
| | | * A connection to the Directory Server whose Root DSE is to be |
| | | * read. |
| | | * @return The Directory Server's Root DSE. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws UnsupportedOperationException |
| | |
| | | * @throws NullPointerException |
| | | * If the {@code connection} was {@code null}. |
| | | */ |
| | | public static RootDSE readRootDSE(final Connection connection) throws ErrorResultException { |
| | | public static RootDSE readRootDSE(final Connection connection) throws LdapException { |
| | | final Entry entry = connection.searchSingleEntry(SEARCH_REQUEST); |
| | | return valueOf(entry); |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * of the client's connection. |
| | | * @return A {@code ServerConnection} which will be used to handle requests |
| | | * from a client connection. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If this server connection factory cannot accept the client |
| | | * connection. |
| | | */ |
| | | ServerConnection<R> handleAccept(C clientContext) throws ErrorResultException; |
| | | ServerConnection<R> handleAccept(C clientContext) throws LdapException; |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * was aborted because it did not complete in the required time out period. |
| | | */ |
| | | @SuppressWarnings("serial") |
| | | public class TimeoutResultException extends ErrorResultException { |
| | | public class TimeoutResultException extends LdapException { |
| | | TimeoutResultException(final Result result) { |
| | | super(result); |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap.controls; |
| | | |
| | |
| | | * |
| | | * try { |
| | | * connection.bind(DN, password); |
| | | * } catch (ErrorResultException e) { |
| | | * } catch (LdapException e) { |
| | | * Result result = e.getResult(); |
| | | * try { |
| | | * PasswordExpiredResponseControl control = |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap.controls; |
| | | |
| | |
| | | * // Password policy warning, use control.getWarningType(), |
| | | * // and control.getWarningValue(). |
| | | * } |
| | | * } catch (ErrorResultException e) { |
| | | * } catch (LdapException e) { |
| | | * Result result = e.getResult(); |
| | | * try { |
| | | * PasswordPolicyResponseControl control = |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012-2014 ForgeRock AS. |
| | | * Portions Copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.controls; |
| | | |
| | |
| | | * // Password policy warning, use control.getWarningType(), |
| | | * // and control.getWarningValue(). |
| | | * } |
| | | * } catch (ErrorResultException e) { |
| | | * } catch (LdapException e) { |
| | | * Result result = e.getResult(); |
| | | * try { |
| | | * PasswordPolicyResponseControl control = |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012-2014 ForgeRock AS. |
| | | * Portions Copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.controls; |
| | | |
| | |
| | | * private static class MySearchResultHandler implements SearchResultHandler { |
| | | * |
| | | * {@literal @}Override |
| | | * public void handleErrorResult(ErrorResultException error) { |
| | | * public void handleErrorResult(LdapException error) { |
| | | * // Ignore. |
| | | * } |
| | | * |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | * Portions Copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.controls; |
| | | |
| | |
| | | * private static class MySearchResultHandler implements SearchResultHandler { |
| | | * |
| | | * {@literal @}Override |
| | | * public void handleErrorResult(ErrorResultException error) { |
| | | * public void handleErrorResult(LdapException error) { |
| | | * // Ignore. |
| | | * } |
| | | * |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | * Portions Copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.controls; |
| | | |
| | |
| | | * private static class MySearchResultHandler implements SearchResultHandler { |
| | | * |
| | | * {@literal @}Override |
| | | * public void handleErrorResult(ErrorResultException error) { |
| | | * public void handleErrorResult(LdapException error) { |
| | | * // Ignore. |
| | | * } |
| | | * |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | | |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | |
| | | /** |
| | | * An abstract unmodifiable Bind request which can be used as the basis for |
| | |
| | | } |
| | | |
| | | @Override |
| | | public BindClient createBindClient(final String serverName) throws ErrorResultException { |
| | | public BindClient createBindClient(final String serverName) throws LdapException { |
| | | return impl.createBindClient(serverName); |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions Copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | |
| | | |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.controls.Control; |
| | | import org.forgerock.opendj.ldap.controls.ControlDecoder; |
| | | |
| | |
| | | AnonymousSASLBindRequest addControl(Control control); |
| | | |
| | | @Override |
| | | BindClient createBindClient(String serverName) throws ErrorResultException; |
| | | BindClient createBindClient(String serverName) throws LdapException; |
| | | |
| | | /** |
| | | * Returns the authentication mechanism identifier for this SASL bind |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | | |
| | | import org.forgerock.opendj.ldap.ConnectionSecurityLayer; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.responses.BindResult; |
| | | |
| | | /** |
| | |
| | | * The bind result to be evaluated. |
| | | * @return {@code true} if authentication has completed successfully, of |
| | | * {@code false} if additional steps are required. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the evaluation failed for some reason and authentication |
| | | * cannot continue. |
| | | */ |
| | | boolean evaluateResult(BindResult result) throws ErrorResultException; |
| | | boolean evaluateResult(BindResult result) throws LdapException; |
| | | |
| | | /** |
| | | * Returns a connection security layer, but only if this bind client has |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | | |
| | | import org.forgerock.opendj.ldap.ConnectionSecurityLayer; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.controls.Control; |
| | | import org.forgerock.opendj.ldap.responses.BindResult; |
| | | |
| | |
| | | * Default implementation does nothing and always returns {@code true}. |
| | | */ |
| | | @Override |
| | | public boolean evaluateResult(final BindResult result) throws ErrorResultException { |
| | | public boolean evaluateResult(final BindResult result) throws LdapException { |
| | | return true; |
| | | } |
| | | |
| | |
| | | * Default implementation just returns the copy of the bytes. |
| | | */ |
| | | @Override |
| | | public byte[] unwrap(final byte[] incoming, final int offset, final int len) |
| | | throws ErrorResultException { |
| | | public byte[] unwrap(final byte[] incoming, final int offset, final int len) throws LdapException { |
| | | final byte[] copy = new byte[len]; |
| | | System.arraycopy(incoming, offset, copy, 0, len); |
| | | return copy; |
| | |
| | | * Default implementation just returns the copy of the bytes. |
| | | */ |
| | | @Override |
| | | public byte[] wrap(final byte[] outgoing, final int offset, final int len) |
| | | throws ErrorResultException { |
| | | public byte[] wrap(final byte[] outgoing, final int offset, final int len) throws LdapException { |
| | | final byte[] copy = new byte[len]; |
| | | System.arraycopy(outgoing, offset, copy, 0, len); |
| | | return copy; |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | * Portions Copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | |
| | | |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.controls.Control; |
| | | import org.forgerock.opendj.ldap.controls.ControlDecoder; |
| | | |
| | |
| | | * The non-null fully-qualified host name of the server to |
| | | * authenticate to. |
| | | * @return The new bind client. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If an error occurred while creating the bind client context. |
| | | */ |
| | | BindClient createBindClient(String serverName) throws ErrorResultException; |
| | | BindClient createBindClient(String serverName) throws LdapException; |
| | | |
| | | /** |
| | | * Returns the authentication mechanism identifier for this generic bind |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2012 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | |
| | | import org.forgerock.i18n.LocalizedIllegalArgumentException; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.controls.Control; |
| | | import org.forgerock.opendj.ldap.controls.ControlDecoder; |
| | | |
| | |
| | | CRAMMD5SASLBindRequest addControl(Control control); |
| | | |
| | | @Override |
| | | BindClient createBindClient(String serverName) throws ErrorResultException; |
| | | BindClient createBindClient(String serverName) throws LdapException; |
| | | |
| | | /** |
| | | * Returns the authentication ID of the user. The authentication ID usually |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | | |
| | | import static com.forgerock.opendj.util.StaticUtils.copyOfBytes; |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.newErrorResult; |
| | | import static org.forgerock.opendj.ldap.LdapException.newErrorResult; |
| | | |
| | | import javax.security.auth.callback.NameCallback; |
| | | import javax.security.auth.callback.PasswordCallback; |
| | |
| | | import javax.security.sasl.SaslException; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.responses.BindResult; |
| | | import org.forgerock.opendj.ldap.responses.Responses; |
| | |
| | | private final SaslClient saslClient; |
| | | |
| | | private Client(final CRAMMD5SASLBindRequestImpl initialBindRequest, final String serverName) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | super(initialBindRequest); |
| | | |
| | | this.authenticationID = initialBindRequest.getAuthenticationID(); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public boolean evaluateResult(final BindResult result) throws ErrorResultException { |
| | | public boolean evaluateResult(final BindResult result) throws LdapException { |
| | | if (saslClient.isComplete()) { |
| | | return true; |
| | | } |
| | |
| | | } catch (final SaslException e) { |
| | | // FIXME: I18N need to have a better error message. |
| | | // FIXME: Is this the best result code? |
| | | throw ErrorResultException.newErrorResult(Responses.newResult( |
| | | throw LdapException.newErrorResult(Responses.newResult( |
| | | ResultCode.CLIENT_SIDE_LOCAL_ERROR).setDiagnosticMessage( |
| | | "An error occurred during multi-stage authentication").setCause(e)); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public BindClient createBindClient(final String serverName) throws ErrorResultException { |
| | | public BindClient createBindClient(final String serverName) throws LdapException { |
| | | return new Client(this, serverName); |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2012 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | |
| | | import org.forgerock.i18n.LocalizedIllegalArgumentException; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.controls.Control; |
| | | import org.forgerock.opendj.ldap.controls.ControlDecoder; |
| | | |
| | |
| | | DigestMD5SASLBindRequest addQOP(String... qopValues); |
| | | |
| | | @Override |
| | | BindClient createBindClient(String serverName) throws ErrorResultException; |
| | | BindClient createBindClient(String serverName) throws LdapException; |
| | | |
| | | /** |
| | | * Returns a map containing the provided additional authentication |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.ERR_SASL_PROTOCOL_ERROR; |
| | | import static com.forgerock.opendj.util.StaticUtils.copyOfBytes; |
| | | import static com.forgerock.opendj.util.StaticUtils.getExceptionMessage; |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.newErrorResult; |
| | | import static org.forgerock.opendj.ldap.LdapException.newErrorResult; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.LinkedHashMap; |
| | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ConnectionSecurityLayer; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.responses.BindResult; |
| | | import org.forgerock.util.Reject; |
| | |
| | | private final SaslClient saslClient; |
| | | |
| | | private Client(final DigestMD5SASLBindRequestImpl initialBindRequest, |
| | | final String serverName) throws ErrorResultException { |
| | | final String serverName) throws LdapException { |
| | | super(initialBindRequest); |
| | | |
| | | this.authenticationID = initialBindRequest.getAuthenticationID(); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public boolean evaluateResult(final BindResult result) throws ErrorResultException { |
| | | public boolean evaluateResult(final BindResult result) throws LdapException { |
| | | if (saslClient.isComplete()) { |
| | | return true; |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public byte[] unwrap(final byte[] incoming, final int offset, final int len) |
| | | throws ErrorResultException { |
| | | public byte[] unwrap(final byte[] incoming, final int offset, final int len) throws LdapException { |
| | | try { |
| | | return saslClient.unwrap(incoming, offset, len); |
| | | } catch (final SaslException e) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public byte[] wrap(final byte[] outgoing, final int offset, final int len) |
| | | throws ErrorResultException { |
| | | public byte[] wrap(final byte[] outgoing, final int offset, final int len) throws LdapException { |
| | | try { |
| | | return saslClient.wrap(outgoing, offset, len); |
| | | } catch (final SaslException e) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public BindClient createBindClient(final String serverName) throws ErrorResultException { |
| | | public BindClient createBindClient(final String serverName) throws LdapException { |
| | | return new Client(this, serverName); |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions Copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | |
| | | import org.forgerock.i18n.LocalizedIllegalArgumentException; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.controls.Control; |
| | | import org.forgerock.opendj.ldap.controls.ControlDecoder; |
| | | |
| | |
| | | ExternalSASLBindRequest addControl(Control control); |
| | | |
| | | @Override |
| | | BindClient createBindClient(String serverName) throws ErrorResultException; |
| | | BindClient createBindClient(String serverName) throws LdapException; |
| | | |
| | | /** |
| | | * Returns the authentication mechanism identifier for this SASL bind |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2012 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | | |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.newErrorResult; |
| | | import static org.forgerock.opendj.ldap.LdapException.newErrorResult; |
| | | |
| | | import javax.security.sasl.Sasl; |
| | | import javax.security.sasl.SaslClient; |
| | | import javax.security.sasl.SaslException; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.responses.BindResult; |
| | | import org.forgerock.opendj.ldap.responses.Responses; |
| | |
| | | private final SaslClient saslClient; |
| | | |
| | | private Client(final ExternalSASLBindRequestImpl initialBindRequest, final String serverName) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | super(initialBindRequest); |
| | | |
| | | try { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public boolean evaluateResult(final BindResult result) throws ErrorResultException { |
| | | public boolean evaluateResult(final BindResult result) throws LdapException { |
| | | if (saslClient.isComplete()) { |
| | | return true; |
| | | } |
| | |
| | | } catch (final SaslException e) { |
| | | // FIXME: I18N need to have a better error message. |
| | | // FIXME: Is this the best result code? |
| | | throw ErrorResultException.newErrorResult(Responses.newResult( |
| | | throw LdapException.newErrorResult(Responses.newResult( |
| | | ResultCode.CLIENT_SIDE_LOCAL_ERROR).setDiagnosticMessage( |
| | | "An error occurred during multi-stage authentication").setCause(e)); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public BindClient createBindClient(final String serverName) throws ErrorResultException { |
| | | public BindClient createBindClient(final String serverName) throws LdapException { |
| | | return new Client(this, serverName); |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2012 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | |
| | | import org.forgerock.i18n.LocalizedIllegalArgumentException; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.controls.Control; |
| | | import org.forgerock.opendj.ldap.controls.ControlDecoder; |
| | | |
| | |
| | | GSSAPISASLBindRequest addQOP(String... qopValues); |
| | | |
| | | @Override |
| | | BindClient createBindClient(String serverName) throws ErrorResultException; |
| | | BindClient createBindClient(String serverName) throws LdapException; |
| | | |
| | | /** |
| | | * Returns a map containing the provided additional authentication |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | |
| | | import static com.forgerock.opendj.ldap.CoreMessages.ERR_SASL_PROTOCOL_ERROR; |
| | | import static com.forgerock.opendj.util.StaticUtils.copyOfBytes; |
| | | import static com.forgerock.opendj.util.StaticUtils.getExceptionMessage; |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.newErrorResult; |
| | | import static org.forgerock.opendj.ldap.LdapException.newErrorResult; |
| | | |
| | | import java.security.PrivilegedActionException; |
| | | import java.security.PrivilegedExceptionAction; |
| | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ConnectionSecurityLayer; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.responses.BindResult; |
| | | import org.forgerock.opendj.ldap.responses.Responses; |
| | |
| | | implements GSSAPISASLBindRequest { |
| | | private final static class Client extends SASLBindClientImpl { |
| | | private static Subject kerberos5Login(final String authenticationID, |
| | | final ByteString password, final String realm, final String kdc) |
| | | throws ErrorResultException { |
| | | final ByteString password, final String realm, final String kdc) throws LdapException { |
| | | if (authenticationID == null) { |
| | | // FIXME: I18N need to have a better error message. |
| | | // FIXME: Is this the best result code? |
| | | throw ErrorResultException.newErrorResult(Responses.newResult( |
| | | throw LdapException.newErrorResult(Responses.newResult( |
| | | ResultCode.CLIENT_SIDE_LOCAL_ERROR).setDiagnosticMessage( |
| | | "No authentication ID specified for GSSAPI SASL authentication")); |
| | | } |
| | |
| | | if (password == null) { |
| | | // FIXME: I18N need to have a better error message. |
| | | // FIXME: Is this the best result code? |
| | | throw ErrorResultException.newErrorResult(Responses.newResult( |
| | | throw LdapException.newErrorResult(Responses.newResult( |
| | | ResultCode.CLIENT_SIDE_LOCAL_ERROR).setDiagnosticMessage( |
| | | "No password specified for GSSAPI SASL authentication")); |
| | | } |
| | |
| | | final LocalizableMessage message = |
| | | ERR_LDAPAUTH_GSSAPI_LOCAL_AUTHENTICATION_FAILED.get(StaticUtils |
| | | .getExceptionMessage(e)); |
| | | throw ErrorResultException.newErrorResult(Responses.newResult( |
| | | throw LdapException.newErrorResult(Responses.newResult( |
| | | ResultCode.CLIENT_SIDE_LOCAL_ERROR) |
| | | .setDiagnosticMessage(message.toString()).setCause(e)); |
| | | } |
| | |
| | | private final PrivilegedExceptionAction<Boolean> evaluateAction = |
| | | new PrivilegedExceptionAction<Boolean>() { |
| | | @Override |
| | | public Boolean run() throws ErrorResultException { |
| | | public Boolean run() throws LdapException { |
| | | if (saslClient.isComplete()) { |
| | | return true; |
| | | } |
| | |
| | | } catch (final SaslException e) { |
| | | // FIXME: I18N need to have a better error message. |
| | | // FIXME: Is this the best result code? |
| | | throw ErrorResultException.newErrorResult(Responses.newResult( |
| | | throw LdapException.newErrorResult(Responses.newResult( |
| | | ResultCode.CLIENT_SIDE_LOCAL_ERROR).setDiagnosticMessage( |
| | | "An error occurred during multi-stage authentication") |
| | | .setCause(e)); |
| | |
| | | private final Subject subject; |
| | | |
| | | private Client(final GSSAPISASLBindRequestImpl initialBindRequest, final String serverName) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | super(initialBindRequest); |
| | | |
| | | this.authorizationID = initialBindRequest.getAuthorizationID(); |
| | |
| | | this.saslClient = |
| | | Subject.doAs(subject, new PrivilegedExceptionAction<SaslClient>() { |
| | | @Override |
| | | public SaslClient run() throws ErrorResultException { |
| | | public SaslClient run() throws LdapException { |
| | | /* |
| | | * Create property map containing all the |
| | | * parameters. |
| | |
| | | } |
| | | }); |
| | | } catch (final PrivilegedActionException e) { |
| | | if (e.getCause() instanceof ErrorResultException) { |
| | | throw (ErrorResultException) e.getCause(); |
| | | if (e.getCause() instanceof LdapException) { |
| | | throw (LdapException) e.getCause(); |
| | | } else { |
| | | // This should not happen. Must be a bug. |
| | | final LocalizableMessage msg = |
| | |
| | | } |
| | | |
| | | @Override |
| | | public boolean evaluateResult(final BindResult result) throws ErrorResultException { |
| | | public boolean evaluateResult(final BindResult result) throws LdapException { |
| | | this.lastResult = result; |
| | | try { |
| | | return Subject.doAs(subject, evaluateAction); |
| | | } catch (final PrivilegedActionException e) { |
| | | if (e.getCause() instanceof ErrorResultException) { |
| | | throw (ErrorResultException) e.getCause(); |
| | | if (e.getCause() instanceof LdapException) { |
| | | throw (LdapException) e.getCause(); |
| | | } else { |
| | | // This should not happen. Must be a bug. |
| | | final LocalizableMessage msg = |
| | |
| | | } |
| | | |
| | | @Override |
| | | public byte[] unwrap(final byte[] incoming, final int offset, final int len) |
| | | throws ErrorResultException { |
| | | public byte[] unwrap(final byte[] incoming, final int offset, final int len) throws LdapException { |
| | | try { |
| | | return saslClient.unwrap(incoming, offset, len); |
| | | } catch (final SaslException e) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public byte[] wrap(final byte[] outgoing, final int offset, final int len) |
| | | throws ErrorResultException { |
| | | public byte[] wrap(final byte[] outgoing, final int offset, final int len) throws LdapException { |
| | | try { |
| | | return saslClient.wrap(outgoing, offset, len); |
| | | } catch (final SaslException e) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public BindClient createBindClient(final String serverName) throws ErrorResultException { |
| | | public BindClient createBindClient(final String serverName) throws LdapException { |
| | | return new Client(this, serverName); |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2012 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | |
| | | |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.controls.Control; |
| | | import org.forgerock.opendj.ldap.controls.ControlDecoder; |
| | |
| | | GenericBindRequest addControl(Control control); |
| | | |
| | | @Override |
| | | BindClient createBindClient(String serverName) throws ErrorResultException; |
| | | BindClient createBindClient(String serverName) throws LdapException; |
| | | |
| | | @Override |
| | | byte getAuthenticationType(); |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2012 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | |
| | | import static com.forgerock.opendj.util.StaticUtils.copyOfBytes; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | |
| | | import org.forgerock.util.Reject; |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public BindClient createBindClient(final String serverName) throws ErrorResultException { |
| | | public BindClient createBindClient(final String serverName) throws LdapException { |
| | | if (bindClient == null) { |
| | | return new BindClientImpl(this).setNextAuthenticationValue(authenticationValue); |
| | | } else { |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2012 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | |
| | | import org.forgerock.i18n.LocalizedIllegalArgumentException; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.controls.Control; |
| | | import org.forgerock.opendj.ldap.controls.ControlDecoder; |
| | | |
| | |
| | | PlainSASLBindRequest addControl(Control control); |
| | | |
| | | @Override |
| | | BindClient createBindClient(String serverName) throws ErrorResultException; |
| | | BindClient createBindClient(String serverName) throws LdapException; |
| | | |
| | | /** |
| | | * Returns the authentication ID of the user. The authentication ID usually |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | | |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.newErrorResult; |
| | | import static org.forgerock.opendj.ldap.LdapException.newErrorResult; |
| | | |
| | | import javax.security.auth.callback.NameCallback; |
| | | import javax.security.auth.callback.PasswordCallback; |
| | |
| | | import javax.security.sasl.SaslException; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.responses.BindResult; |
| | | import org.forgerock.util.Reject; |
| | |
| | | private final SaslClient saslClient; |
| | | |
| | | private Client(final PlainSASLBindRequestImpl initialBindRequest, final String serverName) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | super(initialBindRequest); |
| | | |
| | | this.authenticationID = initialBindRequest.getAuthenticationID(); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public BindClient createBindClient(final String serverName) throws ErrorResultException { |
| | | public BindClient createBindClient(final String serverName) throws LdapException { |
| | | return new Client(this, serverName); |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | |
| | | |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.controls.Control; |
| | | import org.forgerock.opendj.ldap.controls.ControlDecoder; |
| | | |
| | |
| | | SASLBindRequest addControl(Control control); |
| | | |
| | | @Override |
| | | BindClient createBindClient(String serverName) throws ErrorResultException; |
| | | BindClient createBindClient(String serverName) throws LdapException; |
| | | |
| | | /** |
| | | * Returns the authentication mechanism identifier for this SASL bind |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2012 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | |
| | | |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.controls.Control; |
| | | import org.forgerock.opendj.ldap.controls.ControlDecoder; |
| | | |
| | |
| | | SimpleBindRequest addControl(Control control); |
| | | |
| | | @Override |
| | | BindClient createBindClient(String serverName) throws ErrorResultException; |
| | | BindClient createBindClient(String serverName) throws LdapException; |
| | | |
| | | /** |
| | | * Returns the authentication mechanism identifier for this simple bind |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.requests; |
| | | |
| | | import org.forgerock.opendj.io.LDAP; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | import org.forgerock.util.Reject; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public BindClient createBindClient(final String serverName) throws ErrorResultException { |
| | | public BindClient createBindClient(final String serverName) throws LdapException { |
| | | return new BindClientImpl(this).setNextAuthenticationValue(password); |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012-2014 ForgeRock AS. |
| | | * Portions Copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.responses; |
| | | |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.newErrorResult; |
| | | import static org.forgerock.opendj.ldap.LdapException.newErrorResult; |
| | | |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | | import org.forgerock.opendj.ldap.requests.ExtendedRequest; |
| | |
| | | return new ResultHandler<S>() { |
| | | |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | final Result result = error.getResult(); |
| | | final R adaptedResult = |
| | | request.getResultDecoder().newExtendedErrorResult(result.getResultCode(), |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2014 Manuel Gaupp |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | |
| | | import org.forgerock.opendj.ldap.Entries; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.EntryNotFoundException; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.FutureResult; |
| | | import org.forgerock.opendj.ldap.LinkedAttribute; |
| | | import org.forgerock.opendj.ldap.RDN; |
| | |
| | | * @param name |
| | | * The distinguished name of the subschema sub-entry. |
| | | * @return The schema from the Directory Server. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws UnsupportedOperationException |
| | |
| | | * @throws NullPointerException |
| | | * If the {@code connection} or {@code name} was {@code null}. |
| | | */ |
| | | public static Schema readSchema(final Connection connection, final DN name) |
| | | throws ErrorResultException { |
| | | public static Schema readSchema(final Connection connection, final DN name) throws LdapException { |
| | | return new SchemaBuilder().addSchema(connection, name, true).toSchema(); |
| | | } |
| | | |
| | |
| | | public static FutureResult<Schema> readSchemaAsync(final Connection connection, final DN name) { |
| | | final SchemaBuilder builder = new SchemaBuilder(); |
| | | return asFutureResult(builder.addSchemaAsync(connection, name, true).then( |
| | | new Function<SchemaBuilder, Schema, ErrorResultException>() { |
| | | new Function<SchemaBuilder, Schema, LdapException>() { |
| | | @Override |
| | | public Schema apply(SchemaBuilder builder) throws ErrorResultException { |
| | | public Schema apply(SchemaBuilder builder) throws LdapException { |
| | | return builder.toSchema(); |
| | | } |
| | | })); |
| | |
| | | * located. |
| | | * @return The schema from the Directory Server which applies to the named |
| | | * entry. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws UnsupportedOperationException |
| | |
| | | * If the {@code connection} or {@code name} was {@code null}. |
| | | */ |
| | | public static Schema readSchemaForEntry(final Connection connection, final DN name) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | return new SchemaBuilder().addSchemaForEntry(connection, name, true).toSchema(); |
| | | } |
| | | |
| | |
| | | public static FutureResult<Schema> readSchemaForEntryAsync(final Connection connection, final DN name) { |
| | | final SchemaBuilder builder = new SchemaBuilder(); |
| | | return asFutureResult(builder.addSchemaForEntryAsync(connection, name, true).then( |
| | | new Function<SchemaBuilder, Schema, ErrorResultException>() { |
| | | new Function<SchemaBuilder, Schema, LdapException>() { |
| | | |
| | | @Override |
| | | public Schema apply(SchemaBuilder builder) throws ErrorResultException { |
| | | public Schema apply(SchemaBuilder builder) throws LdapException { |
| | | return builder.toSchema(); |
| | | } |
| | | })); |
| | |
| | | try { |
| | | parentEntry = |
| | | policy.checkDITStructureRulesEntryResolver().getEntry(entry.getName().parent()); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | if (ruleWarnings != null) { |
| | | final LocalizableMessage message = |
| | | ERR_ENTRY_SCHEMA_DSR_PARENT_NOT_FOUND.get(entry.getName().toString(), e |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2014 Manuel Gaupp |
| | | */ |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.EntryNotFoundException; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.Filter; |
| | | import org.forgerock.opendj.ldap.FutureResult; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | import com.forgerock.opendj.util.SubstringReader; |
| | | |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.*; |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.forgerock.opendj.ldap.FutureResultWrapper.*; |
| | | import static org.forgerock.opendj.ldap.schema.Schema.*; |
| | | import static org.forgerock.opendj.ldap.schema.SchemaConstants.*; |
| | |
| | | SUBSCHEMA_ATTRS); |
| | | } |
| | | |
| | | private static DN getSubschemaSubentryDN(final DN name, final Entry entry) |
| | | throws ErrorResultException { |
| | | private static DN getSubschemaSubentryDN(final DN name, final Entry entry) throws LdapException { |
| | | final Attribute subentryAttr = entry.getAttribute(ATTR_SUBSCHEMA_SUBENTRY); |
| | | |
| | | if (subentryAttr == null || subentryAttr.isEmpty()) { |
| | |
| | | * {@code true} if existing schema elements with the same |
| | | * conflicting OIDs should be overwritten. |
| | | * @return A reference to this schema builder. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws UnsupportedOperationException |
| | |
| | | * If the {@code connection} or {@code name} was {@code null}. |
| | | */ |
| | | public SchemaBuilder addSchema(final Connection connection, final DN name, |
| | | final boolean overwrite) throws ErrorResultException { |
| | | final boolean overwrite) throws LdapException { |
| | | // The call to addSchema will perform copyOnWrite. |
| | | final SearchRequest request = getReadSchemaSearchRequest(name); |
| | | final Entry entry = connection.searchSingleEntry(request); |
| | |
| | | final SearchRequest request = getReadSchemaSearchRequest(name); |
| | | |
| | | return asFutureResult(connection.searchSingleEntryAsync(request).then( |
| | | new Function<SearchResultEntry, SchemaBuilder, ErrorResultException>() { |
| | | new Function<SearchResultEntry, SchemaBuilder, LdapException>() { |
| | | @Override |
| | | public SchemaBuilder apply(SearchResultEntry result) throws ErrorResultException { |
| | | public SchemaBuilder apply(SearchResultEntry result) throws LdapException { |
| | | addSchema(result, overwrite); |
| | | return SchemaBuilder.this; |
| | | } |
| | |
| | | * {@code true} if existing schema elements with the same |
| | | * conflicting OIDs should be overwritten. |
| | | * @return A reference to this schema builder. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws UnsupportedOperationException |
| | |
| | | * If the {@code connection} or {@code name} was {@code null}. |
| | | */ |
| | | public SchemaBuilder addSchemaForEntry(final Connection connection, final DN name, |
| | | final boolean overwrite) throws ErrorResultException { |
| | | final boolean overwrite) throws LdapException { |
| | | // The call to addSchema will perform copyOnWrite. |
| | | final SearchRequest request = getReadSchemaForEntrySearchRequest(name); |
| | | final Entry entry = connection.searchSingleEntry(request); |
| | |
| | | final SearchRequest request = getReadSchemaForEntrySearchRequest(name); |
| | | |
| | | return asFutureResult(connection.searchSingleEntryAsync(request).thenAsync( |
| | | new AsyncFunction<SearchResultEntry, SchemaBuilder, ErrorResultException>() { |
| | | new AsyncFunction<SearchResultEntry, SchemaBuilder, LdapException>() { |
| | | @Override |
| | | public Promise<SchemaBuilder, ErrorResultException> apply(SearchResultEntry result) |
| | | throws ErrorResultException { |
| | | public Promise<SchemaBuilder, LdapException> apply(SearchResultEntry result) |
| | | throws LdapException { |
| | | final DN subschemaDN = getSubschemaSubentryDN(name, result); |
| | | return addSchemaAsync(connection, subschemaDN, overwrite); |
| | | } |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2011-2013 ForgeRock AS |
| | | * Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | |
| | | /** |
| | | * This class provides various schema validation policy options for controlling |
| | |
| | | * @param dn |
| | | * The name of the entry to be returned. |
| | | * @return The named entry. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If the entry could not be retrieved. |
| | | */ |
| | | Entry getEntry(DN dn) throws ErrorResultException; |
| | | Entry getEntry(DN dn) throws LdapException; |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS. |
| | | * Portions Copyright 2011-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.spi; |
| | | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.FutureResultImpl; |
| | | import org.forgerock.opendj.ldap.IntermediateResponseHandler; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | protected final ErrorResultException tryCancel(final boolean mayInterruptIfRunning) { |
| | | protected final LdapException tryCancel(final boolean mayInterruptIfRunning) { |
| | | /* |
| | | * No other operations can be performed while a bind or startTLS |
| | | * operations is active. Therefore it is not possible to cancel bind or |
| | |
| | | * this future has already been changed. |
| | | */ |
| | | connection.abandonAsync(Requests.newAbandonRequest(getRequestID())); |
| | | return ErrorResultException.newErrorResult(ResultCode.CLIENT_SIDE_USER_CANCELLED); |
| | | return LdapException.newErrorResult(ResultCode.CLIENT_SIDE_USER_CANCELLED); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public final void setResultOrError(final S result) { |
| | | if (result.getResultCode().isExceptional()) { |
| | | handleError(ErrorResultException.newErrorResult(result)); |
| | | handleError(LdapException.newErrorResult(result)); |
| | | } else { |
| | | handleResult(result); |
| | | } |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2013 ForgeRock AS. |
| | | * Copyright 2013-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.spi; |
| | | |
| | |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.opendj.ldap.ConnectionEventListener; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.responses.ExtendedResult; |
| | | |
| | | /** |
| | |
| | | * All methods are synchronized and container classes may also synchronize on |
| | | * the state where needed. The state transition methods, |
| | | * {@link #notifyConnectionClosed()} and |
| | | * {@link #notifyConnectionError(boolean, ErrorResultException)}, correspond to |
| | | * {@link #notifyConnectionError(boolean, LdapException)}, correspond to |
| | | * methods in the {@link ConnectionEventListener} interface except that they |
| | | * return a boolean indicating whether the transition was successful or not. |
| | | */ |
| | |
| | | |
| | | @Override |
| | | boolean notifyConnectionError(final ConnectionState cs, |
| | | final boolean isDisconnectNotification, final ErrorResultException error) { |
| | | final boolean isDisconnectNotification, final LdapException error) { |
| | | // Transition from valid to error state. |
| | | cs.failedDueToDisconnect = isDisconnectNotification; |
| | | cs.connectionError = error; |
| | |
| | | } |
| | | |
| | | boolean notifyConnectionError(final ConnectionState cs, |
| | | final boolean isDisconnectNotification, final ErrorResultException error) { |
| | | final boolean isDisconnectNotification, final LdapException error) { |
| | | return false; |
| | | } |
| | | |
| | |
| | | * Non-{@code null} once the connection has failed due to a connection |
| | | * error. Volatile so that it can be read without synchronization. |
| | | */ |
| | | private volatile ErrorResultException connectionError = null; |
| | | private volatile LdapException connectionError; |
| | | |
| | | /** |
| | | * {@code true} if the connection has failed due to a disconnect |
| | |
| | | * @return The error that caused the connection to fail, or {@code null} if |
| | | * the connection has not failed. |
| | | */ |
| | | public ErrorResultException getConnectionError() { |
| | | public LdapException getConnectionError() { |
| | | return connectionError; |
| | | } |
| | | |
| | |
| | | * @return {@code true} if the state changed to error, or {@code false} if |
| | | * the state was already error or closed. |
| | | * @see ConnectionEventListener#handleConnectionError(boolean, |
| | | * ErrorResultException) |
| | | * LdapException) |
| | | */ |
| | | public synchronized boolean notifyConnectionError(final boolean isDisconnectNotification, |
| | | final ErrorResultException error) { |
| | | final LdapException error) { |
| | | return state.notifyConnectionError(this, isDisconnectNotification, error); |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions Copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldif; |
| | |
| | | import java.io.IOException; |
| | | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.ErrorResultIOException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.requests.AddRequest; |
| | | import org.forgerock.opendj.ldap.requests.DeleteRequest; |
| | | import org.forgerock.opendj.ldap.requests.ModifyDNRequest; |
| | |
| | | * All update requests are performed synchronously, blocking until an update |
| | | * result is received. If an update result indicates that an update request has |
| | | * failed for some reason then the error result is propagated to the caller |
| | | * using an {@code ErrorResultIOException}. |
| | | * using an {@code LdapException}. |
| | | * <p> |
| | | * <b>Note:</b> comments are not supported by connection change record writers. |
| | | * Attempts to write comments will be ignored. |
| | |
| | | * @param change |
| | | * The {@code AddRequest} to be written. |
| | | * @return A reference to this connection change record writer. |
| | | * @throws ErrorResultIOException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws NullPointerException |
| | | * If {@code change} was {@code null}. |
| | | */ |
| | | public ConnectionChangeRecordWriter writeChangeRecord(final AddRequest change) |
| | | throws ErrorResultIOException { |
| | | public ConnectionChangeRecordWriter writeChangeRecord(final AddRequest change) throws LdapException { |
| | | Reject.ifNull(change); |
| | | try { |
| | | connection.add(change); |
| | | } catch (final ErrorResultException e) { |
| | | throw new ErrorResultIOException(e); |
| | | } |
| | | return this; |
| | | } |
| | | |
| | |
| | | * @param change |
| | | * The change record to be written. |
| | | * @return A reference to this connection change record writer. |
| | | * @throws ErrorResultIOException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws NullPointerException |
| | | * If {@code change} was {@code null}. |
| | | */ |
| | | public ConnectionChangeRecordWriter writeChangeRecord(final ChangeRecord change) |
| | | throws ErrorResultIOException { |
| | | public ConnectionChangeRecordWriter writeChangeRecord(final ChangeRecord change) throws LdapException { |
| | | Reject.ifNull(change); |
| | | |
| | | final IOException e = change.accept(ChangeRecordVisitorWriter.getInstance(), this); |
| | |
| | | if (e != null) { |
| | | throw e; |
| | | } |
| | | } catch (final ErrorResultIOException e1) { |
| | | } catch (final LdapException e1) { |
| | | throw e1; |
| | | } catch (final IOException e1) { |
| | | // Should not happen. |
| | |
| | | * @param change |
| | | * The {@code DeleteRequest} to be written. |
| | | * @return A reference to this connection change record writer. |
| | | * @throws ErrorResultIOException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws NullPointerException |
| | | * If {@code change} was {@code null}. |
| | | */ |
| | | public ConnectionChangeRecordWriter writeChangeRecord(final DeleteRequest change) |
| | | throws ErrorResultIOException { |
| | | public ConnectionChangeRecordWriter writeChangeRecord(final DeleteRequest change) throws LdapException { |
| | | Reject.ifNull(change); |
| | | try { |
| | | connection.delete(change); |
| | | } catch (final ErrorResultException e) { |
| | | throw new ErrorResultIOException(e); |
| | | } |
| | | return this; |
| | | } |
| | | |
| | |
| | | * @param change |
| | | * The {@code ModifyDNRequest} to be written. |
| | | * @return A reference to this connection change record writer. |
| | | * @throws ErrorResultIOException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws NullPointerException |
| | | * If {@code change} was {@code null}. |
| | | */ |
| | | public ConnectionChangeRecordWriter writeChangeRecord(final ModifyDNRequest change) |
| | | throws ErrorResultIOException { |
| | | public ConnectionChangeRecordWriter writeChangeRecord(final ModifyDNRequest change) throws LdapException { |
| | | Reject.ifNull(change); |
| | | try { |
| | | connection.modifyDN(change); |
| | | } catch (final ErrorResultException e) { |
| | | throw new ErrorResultIOException(e); |
| | | } |
| | | return this; |
| | | } |
| | | |
| | |
| | | * @param change |
| | | * The {@code ModifyRequest} to be written. |
| | | * @return A reference to this connection change record writer. |
| | | * @throws ErrorResultIOException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws NullPointerException |
| | | * If {@code change} was {@code null}. |
| | | */ |
| | | public ConnectionChangeRecordWriter writeChangeRecord(final ModifyRequest change) |
| | | throws ErrorResultIOException { |
| | | public ConnectionChangeRecordWriter writeChangeRecord(final ModifyRequest change) throws LdapException { |
| | | Reject.ifNull(change); |
| | | try { |
| | | connection.modify(change); |
| | | } catch (final ErrorResultException e) { |
| | | throw new ErrorResultIOException(e); |
| | | } |
| | | return this; |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS. |
| | | * Portions Copyright 2011-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldif; |
| | |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.ErrorResultIOException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.FutureResult; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | |
| | | import org.forgerock.opendj.ldap.responses.SearchResultReference; |
| | | import org.forgerock.util.Reject; |
| | | |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.*; |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | |
| | | /** |
| | | * A {@code ConnectionEntryReader} is a bridge from {@code Connection}s to |
| | |
| | | * The Search operation is performed synchronously, blocking until a search |
| | | * result entry is received. If a search result indicates that the search |
| | | * operation has failed for some reason then the error result is propagated to |
| | | * the caller using an {@code ErrorResultIOException}. If a search result |
| | | * the caller using an {@code LdapException}. If a search result |
| | | * reference is returned then it is propagated to the caller using a |
| | | * {@code SearchResultReferenceIOException}. |
| | | * <p> |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | try { |
| | | responses.put(error.getResult()); |
| | | } catch (final InterruptedException e) { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public boolean hasNext() throws ErrorResultIOException { |
| | | public boolean hasNext() throws LdapException { |
| | | // Poll for the next response if needed. |
| | | final Response r = getNextResponse(); |
| | | if (!(r instanceof Result)) { |
| | |
| | | return false; |
| | | } |
| | | |
| | | throw new ErrorResultIOException(newErrorResult(result)); |
| | | throw newErrorResult(result); |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @return {@code true} if the next search result is an entry, or |
| | | * {@code false} if it is a reference. |
| | | * @throws ErrorResultIOException |
| | | * @throws LdapException |
| | | * If there are no more search result entries or references and |
| | | * the search result code indicates that the search operation |
| | | * failed for some reason. |
| | |
| | | * the search result code indicates that the search operation |
| | | * succeeded. |
| | | */ |
| | | public boolean isEntry() throws ErrorResultIOException { |
| | | // Throws ErrorResultIOException if search returned error. |
| | | public boolean isEntry() throws LdapException { |
| | | // Throws LdapException if search returned error. |
| | | if (!hasNext()) { |
| | | // Search has completed successfully. |
| | | throw new NoSuchElementException(); |
| | |
| | | * |
| | | * @return {@code true} if the next search result is a reference, or |
| | | * {@code false} if it is an entry. |
| | | * @throws ErrorResultIOException |
| | | * @throws LdapException |
| | | * If there are no more search result entries or references and |
| | | * the search result code indicates that the search operation |
| | | * failed for some reason. |
| | |
| | | * the search result code indicates that the search operation |
| | | * succeeded. |
| | | */ |
| | | public boolean isReference() throws ErrorResultIOException { |
| | | public boolean isReference() throws LdapException { |
| | | return !isEntry(); |
| | | } |
| | | |
| | |
| | | * This connection entry reader may still contain remaining |
| | | * search results and references which can be retrieved using |
| | | * additional calls to this method. |
| | | * @throws ErrorResultIOException |
| | | * @throws LdapException |
| | | * If there are no more search result entries or references and |
| | | * the search result code indicates that the search operation |
| | | * failed for some reason. |
| | |
| | | * succeeded. |
| | | */ |
| | | @Override |
| | | public SearchResultEntry readEntry() throws SearchResultReferenceIOException, |
| | | ErrorResultIOException { |
| | | public SearchResultEntry readEntry() throws SearchResultReferenceIOException, LdapException { |
| | | if (isEntry()) { |
| | | final SearchResultEntry entry = (SearchResultEntry) nextResponse; |
| | | nextResponse = null; |
| | |
| | | * |
| | | * @return The next search result reference, or {@code null} if the next |
| | | * response was a search result entry. |
| | | * @throws ErrorResultIOException |
| | | * @throws LdapException |
| | | * If there are no more search result entries or references and |
| | | * the search result code indicates that the search operation |
| | | * failed for some reason. |
| | |
| | | * the search result code indicates that the search operation |
| | | * succeeded. |
| | | */ |
| | | public SearchResultReference readReference() throws ErrorResultIOException { |
| | | public SearchResultReference readReference() throws LdapException { |
| | | if (isReference()) { |
| | | final SearchResultReference reference = (SearchResultReference) nextResponse; |
| | | nextResponse = null; |
| | |
| | | * Waits for the next search response to become available and returns it if |
| | | * it is a search result indicating that the search completed successfully. |
| | | * If the search result indicates that the search failed then an |
| | | * {@link ErrorResultIOException} is thrown. Otherwise, if the search |
| | | * {@link LdapException} is thrown. Otherwise, if the search |
| | | * response represents an entry or reference then an |
| | | * {@code IllegalStateException} is thrown. |
| | | * <p> |
| | |
| | | * once the current page of results has been processed. |
| | | * |
| | | * @return The search result indicating success. |
| | | * @throws ErrorResultIOException |
| | | * @throws LdapException |
| | | * If the search result indicates that the search operation |
| | | * failed for some reason. |
| | | * @throws IllegalStateException |
| | |
| | | * be processed. In other words, if {@link #hasNext()} would |
| | | * return {@code true}. |
| | | */ |
| | | public Result readResult() throws ErrorResultIOException { |
| | | public Result readResult() throws LdapException { |
| | | if (hasNext()) { |
| | | throw new IllegalStateException(); |
| | | } else { |
| | |
| | | } |
| | | } |
| | | |
| | | private Response getNextResponse() throws ErrorResultIOException { |
| | | private Response getNextResponse() throws LdapException { |
| | | while (nextResponse == null) { |
| | | try { |
| | | nextResponse = buffer.responses.poll(50, TimeUnit.MILLISECONDS); |
| | | } catch (final InterruptedException e) { |
| | | final ErrorResultException ere = |
| | | newErrorResult(ResultCode.CLIENT_SIDE_USER_CANCELLED, e); |
| | | throw new ErrorResultIOException(ere); |
| | | throw newErrorResult(ResultCode.CLIENT_SIDE_USER_CANCELLED, e); |
| | | } |
| | | |
| | | if (nextResponse == null && buffer.isInterrupted) { |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions Copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldif; |
| | | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.ErrorResultIOException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | |
| | | import org.forgerock.util.Reject; |
| | | |
| | |
| | | * All Add requests are performed synchronously, blocking until an Add result is |
| | | * received. If an Add result indicates that an Add request has failed for some |
| | | * reason then the error result is propagated to the caller using an |
| | | * {@code ErrorResultIOException}. |
| | | * {@code LdapException}. |
| | | * <p> |
| | | * <b>Note:</b> comments are not supported by connection change record writers. |
| | | * Attempts to write comments will be ignored. |
| | |
| | | * @param entry |
| | | * The {@code Entry} to be written. |
| | | * @return A reference to this connection entry writer. |
| | | * @throws ErrorResultIOException |
| | | * @throws LdapException |
| | | * If the result code indicates that the request failed for some |
| | | * reason. |
| | | * @throws NullPointerException |
| | | * If {@code entry} was {@code null}. |
| | | */ |
| | | public ConnectionEntryWriter writeEntry(final Entry entry) throws ErrorResultIOException { |
| | | public ConnectionEntryWriter writeEntry(final Entry entry) throws LdapException { |
| | | Reject.ifNull(entry); |
| | | try { |
| | | connection.add(entry); |
| | | } catch (final ErrorResultException e) { |
| | | throw new ErrorResultIOException(e); |
| | | } |
| | | return this; |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS. |
| | | * Portions Copyright 2011-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | |
| | | import static org.fest.assertions.Assertions.*; |
| | | import static org.fest.assertions.Fail.*; |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.*; |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.forgerock.opendj.ldap.FutureResultWrapper.*; |
| | | import static org.forgerock.opendj.ldap.TestCaseUtils.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | |
| | | try { |
| | | mockConnection.add(addRequest); |
| | | fail(); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.UNWILLING_TO_PERFORM); |
| | | } |
| | | } |
| | |
| | | try { |
| | | mockConnection.bind(bindRequest); |
| | | fail(); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.UNWILLING_TO_PERFORM); |
| | | } |
| | | } |
| | |
| | | try { |
| | | mockConnection.compare(compareRequest); |
| | | fail(); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.UNWILLING_TO_PERFORM); |
| | | } |
| | | } |
| | |
| | | try { |
| | | mockConnection.delete(deleteRequest); |
| | | fail(); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.UNWILLING_TO_PERFORM); |
| | | } |
| | | } |
| | |
| | | try { |
| | | mockConnection.extendedRequest(extendedRequest); |
| | | fail(); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.UNWILLING_TO_PERFORM); |
| | | } |
| | | } |
| | |
| | | try { |
| | | mockConnection.modify(modifyRequest); |
| | | fail(); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.UNWILLING_TO_PERFORM); |
| | | } |
| | | } |
| | |
| | | try { |
| | | mockConnection.modifyDN(modifyDNRequest); |
| | | fail(); |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.UNWILLING_TO_PERFORM); |
| | | } |
| | | } |
| | |
| | | List<SearchResultEntry> entries = new LinkedList<SearchResultEntry>(); |
| | | try { |
| | | mockConnection.search(searchRequest, entries); |
| | | failWasExpected(ErrorResultException.class); |
| | | } catch (ErrorResultException e) { |
| | | failWasExpected(LdapException.class); |
| | | } catch (LdapException e) { |
| | | assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.UNWILLING_TO_PERFORM); |
| | | assertThat(entries.isEmpty()); |
| | | } |
| | |
| | | newSearchResultEntry("cn=test")); |
| | | final SearchRequest request = |
| | | newSingleEntrySearchRequest("cn=test", SearchScope.BASE_OBJECT, "(objectClass=*)"); |
| | | FailureHandler<ErrorResultException> failureHandler = mock(FailureHandler.class); |
| | | FailureHandler<LdapException> failureHandler = mock(FailureHandler.class); |
| | | |
| | | try { |
| | | mockConnection.searchSingleEntryAsync(request).onFailure(failureHandler).getOrThrow(); |
| | | failWasExpected(MultipleEntriesFoundException.class); |
| | | } catch (MultipleEntriesFoundException e) { |
| | | assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.CLIENT_SIDE_UNEXPECTED_RESULTS_RETURNED); |
| | | verify(failureHandler).handleError(any(ErrorResultException.class)); |
| | | verify(failureHandler).handleError(any(LdapException.class)); |
| | | } |
| | | } |
| | | |
| | |
| | | final SearchRequest request = newSingleEntrySearchRequest("cn=test", SearchScope.BASE_OBJECT, |
| | | "(objectClass=*)"); |
| | | @SuppressWarnings("unchecked") |
| | | FailureHandler<ErrorResultException> failureHandler = mock(FailureHandler.class); |
| | | FailureHandler<LdapException> failureHandler = mock(FailureHandler.class); |
| | | try { |
| | | mockConnection.searchSingleEntryAsync(request).onFailure(failureHandler).getOrThrow(); |
| | | failWasExpected(MultipleEntriesFoundException.class); |
| | | } catch (MultipleEntriesFoundException e) { |
| | | assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.CLIENT_SIDE_UNEXPECTED_RESULTS_RETURNED); |
| | | verify(failureHandler).handleError(any(ErrorResultException.class)); |
| | | verify(failureHandler).handleError(any(LdapException.class)); |
| | | } |
| | | } |
| | | |
| | |
| | | newSingleEntrySearchRequest("cn=test", SearchScope.BASE_OBJECT, "(objectClass=*)"); |
| | | try { |
| | | mockConnection.searchSingleEntry(request); |
| | | failWasExpected(ErrorResultException.class); |
| | | } catch (ErrorResultException e) { |
| | | failWasExpected(LdapException.class); |
| | | } catch (LdapException e) { |
| | | assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.UNWILLING_TO_PERFORM); |
| | | } |
| | | } |
| | |
| | | final SearchRequest request = |
| | | newSingleEntrySearchRequest("cn=test", SearchScope.BASE_OBJECT, "(objectClass=*)"); |
| | | @SuppressWarnings("unchecked") |
| | | FailureHandler<ErrorResultException> failureHandler = mock(FailureHandler.class); |
| | | FailureHandler<LdapException> failureHandler = mock(FailureHandler.class); |
| | | try { |
| | | mockConnection.searchSingleEntryAsync(request).onFailure(failureHandler).getOrThrow(); |
| | | failWasExpected(ErrorResultException.class); |
| | | } catch (ErrorResultException e) { |
| | | failWasExpected(LdapException.class); |
| | | } catch (LdapException e) { |
| | | assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.UNWILLING_TO_PERFORM); |
| | | verify(failureHandler).handleError(any(ErrorResultException.class)); |
| | | verify(failureHandler).handleError(any(LdapException.class)); |
| | | } |
| | | } |
| | | |
| | |
| | | import static org.fest.assertions.Assertions.*; |
| | | import static org.fest.assertions.Fail.*; |
| | | import static org.forgerock.opendj.ldap.Connections.*; |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.*; |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.forgerock.util.promise.Promises.*; |
| | | import static org.mockito.Mockito.*; |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Connection getConnection() throws ErrorResultException { |
| | | public Connection getConnection() throws LdapException { |
| | | return mock.getConnection(); |
| | | } |
| | | |
| | | @Override |
| | | public Promise<Connection, ErrorResultException> getConnectionAsync() { |
| | | public Promise<Connection, LdapException> getConnectionAsync() { |
| | | try { |
| | | return newSuccessfulPromise(mock.getConnection()); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | return newFailedPromise(e); |
| | | } |
| | | } |
| | |
| | | * Create load-balancer with two failed connection factories. |
| | | */ |
| | | final ConnectionFactory first = mock(ConnectionFactory.class, "first"); |
| | | final ErrorResultException firstError = newErrorResult(ResultCode.CLIENT_SIDE_SERVER_DOWN); |
| | | final LdapException firstError = newErrorResult(ResultCode.CLIENT_SIDE_SERVER_DOWN); |
| | | when(first.getConnection()).thenThrow(firstError); |
| | | |
| | | final ConnectionFactory second = mock(ConnectionFactory.class, "second"); |
| | | final ErrorResultException secondError = newErrorResult(ResultCode.CLIENT_SIDE_SERVER_DOWN); |
| | | final LdapException secondError = newErrorResult(ResultCode.CLIENT_SIDE_SERVER_DOWN); |
| | | when(second.getConnection()).thenThrow(secondError); |
| | | |
| | | final ConnectionFactory loadBalancer = |
| | |
| | | try { |
| | | loadBalancer.getConnection().close(); |
| | | fail("Unexpectedly obtained a connection"); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | assertThat(e.getCause()).isSameAs(secondError); |
| | | } finally { |
| | | loadBalancer.close(); |
| | |
| | | */ |
| | | final ConnectionFactory first = mock(ConnectionFactory.class, "first"); |
| | | final ConnectionFactory firstAsync = mockAsync(first); |
| | | final ErrorResultException firstError = newErrorResult(ResultCode.CLIENT_SIDE_SERVER_DOWN); |
| | | final LdapException firstError = newErrorResult(ResultCode.CLIENT_SIDE_SERVER_DOWN); |
| | | when(first.getConnection()).thenThrow(firstError).thenReturn(mock(Connection.class)); |
| | | |
| | | final ConnectionFactory second = mock(ConnectionFactory.class, "second"); |
| | | final ConnectionFactory secondAsync = mockAsync(second); |
| | | final ErrorResultException secondError = newErrorResult(ResultCode.CLIENT_SIDE_SERVER_DOWN); |
| | | final LdapException secondError = newErrorResult(ResultCode.CLIENT_SIDE_SERVER_DOWN); |
| | | when(second.getConnection()).thenThrow(secondError); |
| | | |
| | | final LoadBalancerEventListener listener = mock(LoadBalancerEventListener.class); |
| | |
| | | try { |
| | | loadBalancer.getConnection().close(); |
| | | fail("Unexpectedly obtained a connection"); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | // Check that the event listener has been fired for both factories. |
| | | verify(listener).handleConnectionFactoryOffline(firstAsync, firstError); |
| | | verify(listener).handleConnectionFactoryOffline(secondAsync, secondError); |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS. |
| | | * Portions Copyright 2011-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | |
| | | import static org.fest.assertions.Assertions.*; |
| | | import static org.forgerock.opendj.ldap.Connections.*; |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.*; |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.forgerock.opendj.ldap.TestCaseUtils.*; |
| | | import static org.mockito.Matchers.*; |
| | | import static org.mockito.Mockito.*; |
| | |
| | | connection.close(); |
| | | |
| | | verify(listener).handleConnectionClosed(); |
| | | verify(listener, times(0)).handleConnectionError(anyBoolean(), |
| | | any(ErrorResultException.class)); |
| | | verify(listener, times(0)).handleConnectionError(anyBoolean(), any(LdapException.class)); |
| | | verify(listener, times(0)).handleUnsolicitedNotification(any(ExtendedResult.class)); |
| | | |
| | | // Get a connection again and make sure that the listener is no longer invoked. |
| | |
| | | listeners.get(0).handleUnsolicitedNotification( |
| | | Responses.newGenericExtendedResult(ResultCode.OTHER)); |
| | | verify(listener, times(0)).handleConnectionClosed(); |
| | | verify(listener, times(0)).handleConnectionError(anyBoolean(), |
| | | any(ErrorResultException.class)); |
| | | verify(listener, times(0)).handleConnectionError(anyBoolean(), any(LdapException.class)); |
| | | verify(listener).handleUnsolicitedNotification(any(ExtendedResult.class)); |
| | | connection.close(); |
| | | assertThat(listeners).hasSize(0); |
| | |
| | | * is a connection available immediately then the future will be |
| | | * completed immediately). |
| | | */ |
| | | final Promise<? extends Connection, ErrorResultException> future = pool.getConnectionAsync(); |
| | | final Promise<? extends Connection, LdapException> future = pool.getConnectionAsync(); |
| | | assertThat(future.isDone()).isFalse(); |
| | | |
| | | // Release a connection and verify that it is immediately redeemed by |
| | |
| | | final ConnectionFactory factory = mock(ConnectionFactory.class); |
| | | final int poolSize = 2; |
| | | final ConnectionPool pool = Connections.newFixedConnectionPool(factory, poolSize); |
| | | doAnswer(new Answer<Promise<Connection, ErrorResultException>>() { |
| | | doAnswer(new Answer<Promise<Connection, LdapException>>() { |
| | | @Override |
| | | public Promise<Connection, ErrorResultException> answer(final InvocationOnMock invocation) |
| | | public Promise<Connection, LdapException> answer(final InvocationOnMock invocation) |
| | | throws Throwable { |
| | | return PromiseImpl.create(); |
| | | } |
| | | }).when(factory).getConnectionAsync(); |
| | | |
| | | List<Promise<? extends Connection, ErrorResultException>> futures = |
| | | new ArrayList<Promise<? extends Connection, ErrorResultException>>(); |
| | | List<Promise<? extends Connection, LdapException>> futures = |
| | | new ArrayList<Promise<? extends Connection, LdapException>>(); |
| | | for (int i = 0; i < poolSize + 1; i++) { |
| | | futures.add(pool.getConnectionAsync()); |
| | | } |
| | | // factory.getConnectionAsync() has been called by the pool poolSize times |
| | | verify(factory, times(poolSize)).getConnectionAsync(); |
| | | final ErrorResultException connectError = ErrorResultException |
| | | .newErrorResult(ResultCode.CLIENT_SIDE_CONNECT_ERROR); |
| | | for (Promise<? extends Connection, ErrorResultException> future : futures) { |
| | | final LdapException connectError = LdapException.newErrorResult(ResultCode.CLIENT_SIDE_CONNECT_ERROR); |
| | | for (Promise<? extends Connection, LdapException> future : futures) { |
| | | // Simulate that an error happened with the created connections |
| | | ((FutureResultImpl) future).handleError(connectError); |
| | | |
| | | try { |
| | | // Before the fix for OPENDJ-1348 the third future.get() would hang. |
| | | future.getOrThrow(); |
| | | Assert.fail("ErrorResultException should have been called"); |
| | | } catch (ErrorResultException e) { |
| | | Assert.fail("Expected an exception to be thrown"); |
| | | } catch (LdapException e) { |
| | | assertThat(e).isSameAs(connectError); |
| | | } |
| | | } |
| | |
| | | |
| | | import static org.fest.assertions.Assertions.*; |
| | | import static org.fest.assertions.Fail.*; |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.*; |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.forgerock.opendj.ldap.FutureResultWrapper.*; |
| | | import static org.forgerock.opendj.ldap.SearchScope.*; |
| | | import static org.forgerock.opendj.ldap.TestCaseUtils.*; |
| | |
| | | public void testGetConnectionAsyncWithInitialHeartBeatError() throws Exception { |
| | | @SuppressWarnings("unchecked") |
| | | final SuccessHandler<Connection> mockSuccessHandler = mock(SuccessHandler.class); |
| | | final PromiseImpl<ErrorResultException, NeverThrowsException> promisedError = PromiseImpl.create(); |
| | | final PromiseImpl<LdapException, NeverThrowsException> promisedError = PromiseImpl.create(); |
| | | |
| | | mockConnectionWithInitialHeartbeatResult(ResultCode.BUSY); |
| | | Promise<? extends Connection, ErrorResultException> promise = hbcf.getConnectionAsync(); |
| | | promise.onSuccess(mockSuccessHandler).onFailure(new FailureHandler<ErrorResultException>() { |
| | | Promise<? extends Connection, LdapException> promise = hbcf.getConnectionAsync(); |
| | | promise.onSuccess(mockSuccessHandler).onFailure(new FailureHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(ErrorResultException error) { |
| | | public void handleError(LdapException error) { |
| | | promisedError.handleResult(error); |
| | | } |
| | | }); |
| | |
| | | try { |
| | | promise.getOrThrow(); |
| | | fail("Unexpectedly obtained a connection"); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | checkInitialHeartBeatFailure(e); |
| | | } |
| | | |
| | |
| | | try { |
| | | hbcf.getConnection(); |
| | | fail("Unexpectedly obtained a connection"); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | checkInitialHeartBeatFailure(e); |
| | | } |
| | | } |
| | |
| | | |
| | | // Attempt to send a new request: it should fail immediately. |
| | | @SuppressWarnings("unchecked") |
| | | final FailureHandler<ErrorResultException> mockHandler = mock(FailureHandler.class); |
| | | final FailureHandler<LdapException> mockHandler = mock(FailureHandler.class); |
| | | hbc.modifyAsync(newModifyRequest(DN.rootDN())).onFailure(mockHandler); |
| | | final ArgumentCaptor<ErrorResultException> arg = |
| | | ArgumentCaptor.forClass(ErrorResultException.class); |
| | | final ArgumentCaptor<LdapException> arg = ArgumentCaptor.forClass(LdapException.class); |
| | | verify(mockHandler).handleError(arg.capture()); |
| | | assertThat(arg.getValue().getResult().getResultCode()).isEqualTo( |
| | | ResultCode.CLIENT_SIDE_SERVER_DOWN); |
| | |
| | | assertThat(hbcf.toString()).isNotNull(); |
| | | } |
| | | |
| | | private void checkInitialHeartBeatFailure(final ErrorResultException e) { |
| | | private void checkInitialHeartBeatFailure(final LdapException e) { |
| | | /* |
| | | * Initial heartbeat failure should trigger connection exception with |
| | | * heartbeat cause. |
| | | */ |
| | | assertThat(e).isInstanceOf(ConnectionException.class); |
| | | assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.CLIENT_SIDE_SERVER_DOWN); |
| | | assertThat(e.getCause()).isInstanceOf(ErrorResultException.class); |
| | | assertThat(((ErrorResultException) e.getCause()).getResult().getResultCode()).isEqualTo( |
| | | ResultCode.BUSY); |
| | | assertThat(e.getCause()).isInstanceOf(LdapException.class); |
| | | assertThat(((LdapException) e.getCause()).getResult().getResultCode()).isEqualTo(ResultCode.BUSY); |
| | | } |
| | | |
| | | private void mockConnectionWithInitialHeartbeatResult(final ResultCode initialHeartBeatResult) { |
| | |
| | | } |
| | | |
| | | if (resultCode.isExceptional()) { |
| | | final ErrorResultException error = newErrorResult(resultCode); |
| | | final LdapException error = newErrorResult(resultCode); |
| | | if (error instanceof ConnectionException) { |
| | | for (final ConnectionEventListener listener : listeners) { |
| | | listener.handleConnectionError(false, error); |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | if (entryMap.containsKey(dn)) { |
| | | // duplicate entry. |
| | | result = Responses.newResult(ResultCode.ENTRY_ALREADY_EXISTS); |
| | | final ErrorResultException ere = ErrorResultException.newErrorResult(result); |
| | | handler.handleError(ere); |
| | | handler.handleError(LdapException.newErrorResult(result)); |
| | | // doesn't matter if it was canceled. |
| | | requestsInProgress.remove(context); |
| | | return; |
| | |
| | | |
| | | if (abReq.isCanceled()) { |
| | | result = Responses.newResult(ResultCode.CANCELLED); |
| | | final ErrorResultException ere = ErrorResultException.newErrorResult(result); |
| | | handler.handleError(ere); |
| | | handler.handleError(LdapException.newErrorResult(result)); |
| | | requestsInProgress.remove(context); |
| | | return; |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public byte[] unwrap(byte[] incoming, int offset, int len) |
| | | throws ErrorResultException { |
| | | public byte[] unwrap(byte[] incoming, int offset, int len) throws LdapException { |
| | | try { |
| | | return saslServer.unwrap(incoming, offset, len); |
| | | } catch (SaslException e) { |
| | | throw ErrorResultException |
| | | .newErrorResult(Responses.newResult( |
| | | ResultCode.OPERATIONS_ERROR).setCause(e)); |
| | | throw LdapException.newErrorResult( |
| | | Responses.newResult(ResultCode.OPERATIONS_ERROR).setCause(e)); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public byte[] wrap(byte[] outgoing, int offset, int len) |
| | | throws ErrorResultException { |
| | | public byte[] wrap(byte[] outgoing, int offset, int len) throws LdapException { |
| | | try { |
| | | return saslServer.wrap(outgoing, offset, len); |
| | | } catch (SaslException e) { |
| | | throw ErrorResultException |
| | | .newErrorResult(Responses.newResult( |
| | | ResultCode.OPERATIONS_ERROR).setCause(e)); |
| | | throw LdapException.newErrorResult( |
| | | Responses.newResult(ResultCode.OPERATIONS_ERROR).setCause(e)); |
| | | } |
| | | } |
| | | }; |
| | |
| | | ByteString.wrap(challenge))); |
| | | } |
| | | } catch (Exception e) { |
| | | resultHandler.handleError(ErrorResultException.newErrorResult(Responses |
| | | resultHandler.handleError(LdapException.newErrorResult(Responses |
| | | .newBindResult(ResultCode.OPERATIONS_ERROR).setCause(e) |
| | | .setDiagnosticMessage(e.toString()))); |
| | | } |
| | |
| | | if (!entryMap.containsKey(dn)) { |
| | | // entry not found. |
| | | result = Responses.newCompareResult(ResultCode.NO_SUCH_ATTRIBUTE); |
| | | final ErrorResultException ere = ErrorResultException.newErrorResult(result); |
| | | resultHandler.handleError(ere); |
| | | resultHandler.handleError(LdapException.newErrorResult(result)); |
| | | // doesn't matter if it was canceled. |
| | | requestsInProgress.remove(context); |
| | | return; |
| | |
| | | final ByteString s = it.next(); |
| | | if (abReq.isCanceled()) { |
| | | final Result r = Responses.newResult(ResultCode.CANCELLED); |
| | | final ErrorResultException ere = ErrorResultException.newErrorResult(r); |
| | | resultHandler.handleError(ere); |
| | | resultHandler.handleError(LdapException.newErrorResult(r)); |
| | | requestsInProgress.remove(context); |
| | | return; |
| | | } |
| | |
| | | if (!entryMap.containsKey(dn)) { |
| | | // entry is not found. |
| | | result = Responses.newResult(ResultCode.NO_SUCH_OBJECT); |
| | | final ErrorResultException ere = ErrorResultException.newErrorResult(result); |
| | | handler.handleError(ere); |
| | | handler.handleError(LdapException.newErrorResult(result)); |
| | | // doesn't matter if it was canceled. |
| | | requestsInProgress.remove(context); |
| | | return; |
| | |
| | | |
| | | if (abReq.isCanceled()) { |
| | | result = Responses.newResult(ResultCode.CANCELLED); |
| | | final ErrorResultException ere = ErrorResultException.newErrorResult(result); |
| | | handler.handleError(ere); |
| | | handler.handleError(LdapException.newErrorResult(result)); |
| | | requestsInProgress.remove(context); |
| | | return; |
| | | } |
| | |
| | | if (!entryMap.containsKey(dn)) { |
| | | // Entry not found. |
| | | result = Responses.newResult(ResultCode.NO_SUCH_OBJECT); |
| | | final ErrorResultException ere = ErrorResultException.newErrorResult(result); |
| | | resultHandler.handleError(ere); |
| | | resultHandler.handleError(LdapException.newErrorResult(result)); |
| | | // Should searchResultHandler handle anything? |
| | | |
| | | // doesn't matter if it was canceled. |
| | |
| | | |
| | | if (abReq.isCanceled()) { |
| | | result = Responses.newResult(ResultCode.CANCELLED); |
| | | final ErrorResultException ere = ErrorResultException.newErrorResult(result); |
| | | resultHandler.handleError(ere); |
| | | resultHandler.handleError(LdapException.newErrorResult(result)); |
| | | requestsInProgress.remove(context); |
| | | return; |
| | | } |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2013 ForgeRock AS. |
| | | * Copyright 2013-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | |
| | | .isEqualTo(newDomain); |
| | | } |
| | | |
| | | @Test(expectedExceptions = ErrorResultException.class) |
| | | @Test(expectedExceptions = LdapException.class) |
| | | public void testAddPreRead() throws Exception { |
| | | final Connection connection = getConnection(); |
| | | final Entry newDomain = |
| | |
| | | } |
| | | } |
| | | |
| | | @Test(expectedExceptions = ErrorResultException.class) |
| | | @Test(expectedExceptions = LdapException.class) |
| | | public void testDeletePostRead() throws Exception { |
| | | final Connection connection = getConnection(); |
| | | connection.delete(newDeleteRequest("dc=xxx,dc=com").addControl( |
| | |
| | | "objectClass: top", "dc: example")); |
| | | try { |
| | | reader.hasNext(); |
| | | TestCaseUtils.failWasExpected(ErrorResultIOException.class); |
| | | } catch (ErrorResultIOException e) { |
| | | assertThat(e.getCause().getResult().getResultCode()).isEqualTo(ResultCode.SIZE_LIMIT_EXCEEDED); |
| | | TestCaseUtils.failWasExpected(LdapException.class); |
| | | } catch (LdapException e) { |
| | | assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.SIZE_LIMIT_EXCEEDED); |
| | | } |
| | | } |
| | | |
| | |
| | | connection.search( |
| | | Requests.newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=*)"). |
| | | setSizeLimit(2), entries); |
| | | TestCaseUtils.failWasExpected(ErrorResultException.class); |
| | | } catch (ErrorResultException e) { |
| | | TestCaseUtils.failWasExpected(LdapException.class); |
| | | } catch (LdapException e) { |
| | | assertThat(e.getResult().getResultCode()).isEqualTo(ResultCode.SIZE_LIMIT_EXCEEDED); |
| | | assertThat(entries).hasSize(2); |
| | | } |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2012-2013 ForgeRock AS. |
| | | * Copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | |
| | | private final CountDownLatch errorLatch = new CountDownLatch(1); |
| | | private final CountDownLatch notificationLatch = new CountDownLatch(1); |
| | | private Boolean isDisconnectNotification = null; |
| | | private ErrorResultException error = null; |
| | | private LdapException error; |
| | | private ExtendedResult notification = null; |
| | | private final AtomicInteger invocationCount = new AtomicInteger(); |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void handleConnectionError(boolean isDisconnectNotification, ErrorResultException error) { |
| | | public void handleConnectionError(boolean isDisconnectNotification, LdapException error) { |
| | | this.isDisconnectNotification = isDisconnectNotification; |
| | | this.error = error; |
| | | invocationCount.incrementAndGet(); |
| | |
| | | return isDisconnectNotification; |
| | | } |
| | | |
| | | public ErrorResultException getError() { |
| | | public LdapException getError() { |
| | | return error; |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012-2014 ForgeRock AS. |
| | | * Portions Copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | |
| | | final ConnectionFactory factory = mock(ConnectionFactory.class); |
| | | try { |
| | | when(factory.getConnection()).thenReturn(first, remaining); |
| | | } catch (ErrorResultException ignored) { |
| | | } catch (LdapException ignored) { |
| | | // Cannot happen. |
| | | } |
| | | when(factory.getConnectionAsync()).thenAnswer(new Answer<Promise<Connection, ErrorResultException>>() { |
| | | when(factory.getConnectionAsync()).thenAnswer(new Answer<Promise<Connection, LdapException>>() { |
| | | @Override |
| | | public Promise<Connection, ErrorResultException> answer(final InvocationOnMock invocation) |
| | | public Promise<Connection, LdapException> answer(final InvocationOnMock invocation) |
| | | throws Throwable { |
| | | return newSuccessfulFutureResult(factory.getConnection()); |
| | | } |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2011 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.schema.SchemaValidationPolicy.EntryResolver; |
| | | import org.forgerock.opendj.ldap.schema.SchemaValidationPolicy.Action; |
| | |
| | | private EntryResolver newResolver(final Entry e) { |
| | | return new EntryResolver() { |
| | | |
| | | public Entry getEntry(final DN dn) throws ErrorResultException { |
| | | public Entry getEntry(final DN dn) throws LdapException { |
| | | if (e == null) { |
| | | throw ErrorResultException.newErrorResult(ResultCode.NO_SUCH_OBJECT, |
| | | throw LdapException.newErrorResult(ResultCode.NO_SUCH_OBJECT, |
| | | "no such entry " + dn.toString()); |
| | | } |
| | | |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | * Portions Copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.EntryNotFoundException; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.FutureResult; |
| | | import org.forgerock.opendj.ldap.FutureResultWrapper; |
| | | import org.forgerock.opendj.ldap.LinkedHashMapEntry; |
| | |
| | | }; |
| | | |
| | | // Send a search entry result promise : |
| | | Promise<SearchResultEntry, ErrorResultException> promise = |
| | | Promise<SearchResultEntry, LdapException> promise = |
| | | newSuccessfulPromise(Responses.newSearchResultEntry(entry)); |
| | | FutureResult<SearchResultEntry> result = FutureResultWrapper.asFutureResult(promise); |
| | | when(connection.searchSingleEntryAsync((SearchRequest) any())).thenReturn(result); |
| | |
| | | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.FutureResult; |
| | | import org.forgerock.opendj.ldap.FutureResultWrapper; |
| | | import org.forgerock.opendj.ldap.requests.SearchRequest; |
| | |
| | | }; |
| | | |
| | | // Send a search entry result promise : |
| | | Promise<SearchResultEntry, ErrorResultException> promise = |
| | | Promise<SearchResultEntry, LdapException> promise = |
| | | newSuccessfulPromise(Responses.newSearchResultEntry(entry)); |
| | | FutureResult<SearchResultEntry> result = FutureResultWrapper.asFutureResult(promise); |
| | | when(connection.searchSingleEntryAsync((SearchRequest) any())).thenReturn(result); |
| | |
| | | import java.net.InetSocketAddress; |
| | | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.util.promise.Promise; |
| | | |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.*; |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.forgerock.util.promise.Promises.*; |
| | | import static org.mockito.Mockito.*; |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Connection getConnection() throws ErrorResultException { |
| | | public Connection getConnection() throws LdapException { |
| | | try { |
| | | return getConnectionAsync().getOrThrow(); |
| | | } catch (final InterruptedException e) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Promise<Connection, ErrorResultException> getConnectionAsync() { |
| | | public Promise<Connection, LdapException> getConnectionAsync() { |
| | | return newSuccessfulPromise(mock(Connection.class)); |
| | | } |
| | | |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2013 ForgeRock AS. |
| | | * Copyright 2013-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.spi; |
| | | |
| | | import static org.fest.assertions.Assertions.assertThat; |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.newErrorResult; |
| | | import static org.forgerock.opendj.ldap.LdapException.newErrorResult; |
| | | import static org.forgerock.opendj.ldap.responses.Responses.newGenericExtendedResult; |
| | | import static org.mockito.Matchers.same; |
| | | import static org.mockito.Mockito.doAnswer; |
| | |
| | | import static org.mockito.Mockito.verifyNoMoreInteractions; |
| | | |
| | | import org.forgerock.opendj.ldap.ConnectionEventListener; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.responses.ExtendedResult; |
| | | import org.mockito.invocation.InvocationOnMock; |
| | |
| | | */ |
| | | @SuppressWarnings("javadoc") |
| | | public class ConnectionStateTest extends LDAPTestCase { |
| | | private static final ErrorResultException ERROR = newErrorResult(ResultCode.OTHER); |
| | | private static final ErrorResultException LATE_ERROR = newErrorResult(ResultCode.BUSY); |
| | | private static final LdapException ERROR = newErrorResult(ResultCode.OTHER); |
| | | private static final LdapException LATE_ERROR = newErrorResult(ResultCode.BUSY); |
| | | private static final ExtendedResult UNSOLICITED = |
| | | newGenericExtendedResult(ResultCode.OPERATIONS_ERROR); |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions Copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldif; |
| | | |
| | | import static org.mockito.Matchers.any; |
| | | import static org.mockito.Mockito.mock; |
| | | import static org.mockito.Mockito.times; |
| | | import static org.mockito.Mockito.verify; |
| | | import static org.mockito.Mockito.when; |
| | | |
| | | import java.io.IOException; |
| | | |
| | | import org.forgerock.i18n.LocalizedIllegalArgumentException; |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.ErrorResultIOException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.requests.AddRequest; |
| | | import org.forgerock.opendj.ldap.requests.DeleteRequest; |
| | |
| | | import org.testng.Assert; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.mockito.Matchers.*; |
| | | import static org.mockito.Mockito.*; |
| | | |
| | | /** |
| | | * This class tests the ConnectionChangeRecordWriter functionality. |
| | | */ |
| | |
| | | |
| | | /** |
| | | * ConnectionChangeRecordWriter writes a ChangeRecord and an |
| | | * ErrorResultIOException occurs on the ChangeAccept call. |
| | | * LdapException occurs on the ChangeAccept call. |
| | | * |
| | | * @throws Exception |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | @Test(expectedExceptions = ErrorResultIOException.class) |
| | | public final void testWriteChangeRecordChangeAcceptSendErrorResultIOException() |
| | | throws Exception { |
| | | @Test(expectedExceptions = LdapException.class) |
| | | public final void testWriteChangeRecordChangeAcceptSendLdapException() throws Exception { |
| | | Connection connection = mock(Connection.class); |
| | | ConnectionChangeRecordWriter writer = null; |
| | | ChangeRecord cr = mock(ChangeRecord.class); |
| | | |
| | | when(cr.accept(any(ChangeRecordVisitor.class), any(ConnectionChangeRecordWriter.class))) |
| | | .thenAnswer(new Answer<ErrorResultIOException>() { |
| | | .thenAnswer(new Answer<LdapException>() { |
| | | @Override |
| | | public ErrorResultIOException answer(final InvocationOnMock invocation) |
| | | throws Throwable { |
| | | public LdapException answer(final InvocationOnMock invocation) throws Throwable { |
| | | // Execute handler and return future. |
| | | final ChangeRecordVisitor<?, ?> handler = |
| | | (ChangeRecordVisitor<?, ?>) invocation.getArguments()[0]; |
| | | if (handler != null) { |
| | | // Data here if needed. |
| | | } |
| | | return new ErrorResultIOException(ErrorResultException |
| | | .newErrorResult(ResultCode.UNAVAILABLE_CRITICAL_EXTENSION)); |
| | | return newErrorResult(ResultCode.UNAVAILABLE_CRITICAL_EXTENSION); |
| | | } |
| | | }); |
| | | |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2011 ForgeRock AS |
| | | * Portions copyright 2012-2014 ForgeRock AS. |
| | | * Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldif; |
| | | |
| | | import static org.fest.assertions.Assertions.assertThat; |
| | | import static org.fest.assertions.Fail.fail; |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.newErrorResult; |
| | | import static org.forgerock.opendj.ldap.LdapException.newErrorResult; |
| | | import static org.forgerock.opendj.ldap.responses.Responses.newResult; |
| | | import static org.forgerock.opendj.ldap.responses.Responses.newSearchResultEntry; |
| | | import static org.forgerock.opendj.ldap.responses.Responses.newSearchResultReference; |
| | |
| | | import java.util.NoSuchElementException; |
| | | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ErrorResultIOException; |
| | | import org.forgerock.opendj.ldap.FutureResult; |
| | | import org.forgerock.opendj.ldap.FutureResultWrapper; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchResultHandler; |
| | | import org.forgerock.opendj.ldap.SearchResultReferenceIOException; |
| | |
| | | try { |
| | | reader.hasNext(); |
| | | fail(); |
| | | } catch (final ErrorResultIOException e) { |
| | | assertThat(e.getCause().getResult()).isSameAs(ERROR); |
| | | } catch (final LdapException e) { |
| | | assertThat(e.getResult()).isSameAs(ERROR); |
| | | } finally { |
| | | reader.close(); |
| | | } |
| | |
| | | try { |
| | | reader.readEntry(); |
| | | fail(); |
| | | } catch (final ErrorResultIOException e) { |
| | | assertThat(e.getCause().getResult()).isSameAs(ERROR); |
| | | } catch (final LdapException e) { |
| | | assertThat(e.getResult()).isSameAs(ERROR); |
| | | } finally { |
| | | reader.close(); |
| | | } |
| | |
| | | try { |
| | | reader.readReference(); |
| | | fail(); |
| | | } catch (final ErrorResultIOException e) { |
| | | assertThat(e.getCause().getResult()).isSameAs(ERROR); |
| | | } catch (final LdapException e) { |
| | | assertThat(e.getResult()).isSameAs(ERROR); |
| | | } finally { |
| | | reader.close(); |
| | | } |
| | |
| | | try { |
| | | reader.readResult(); |
| | | fail(); |
| | | } catch (final ErrorResultIOException e) { |
| | | assertThat(e.getCause().getResult()).isSameAs(ERROR); |
| | | } catch (final LdapException e) { |
| | | assertThat(e.getResult()).isSameAs(ERROR); |
| | | } finally { |
| | | reader.close(); |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions Copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.grizzly; |
| | | |
| | | import org.forgerock.opendj.ldap.ConnectionSecurityLayer; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.glassfish.grizzly.AbstractTransformer; |
| | | import org.glassfish.grizzly.Buffer; |
| | | import org.glassfish.grizzly.TransformationResult; |
| | |
| | | try { |
| | | final Buffer output = Buffers.wrap(memoryManager, layer.unwrap(buffer, 0, len)); |
| | | return TransformationResult.createCompletedResult(output, input); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | return TransformationResult.createErrorResult(e.getResult().getResultCode() |
| | | .intValue(), e.getMessage()); |
| | | } |
| | |
| | | try { |
| | | final Buffer output = Buffers.wrap(memoryManager, layer.wrap(buffer, 0, len)); |
| | | return TransformationResult.createCompletedResult(output, input); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | return TransformationResult.createErrorResult(e.getResult().getResultCode() |
| | | .intValue(), e.getMessage()); |
| | | } |
| | |
| | | import org.forgerock.opendj.ldap.AbstractAsynchronousConnection; |
| | | import org.forgerock.opendj.ldap.ConnectionEventListener; |
| | | import org.forgerock.opendj.ldap.Connections; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.FutureResult; |
| | | import org.forgerock.opendj.ldap.IntermediateResponseHandler; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | |
| | | import org.glassfish.grizzly.ssl.SSLEngineConfigurator; |
| | | import org.glassfish.grizzly.ssl.SSLFilter; |
| | | |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.newErrorResult; |
| | | import static org.forgerock.opendj.ldap.LdapException.newErrorResult; |
| | | import static org.forgerock.opendj.ldap.FutureResultWrapper.*; |
| | | |
| | | import static com.forgerock.opendj.grizzly.GrizzlyMessages.*; |
| | |
| | | */ |
| | | checkBindOrStartTLSInProgress(); |
| | | } |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | return newFailedFutureResult(e); |
| | | } |
| | | |
| | |
| | | pendingRequests.remove(messageID); |
| | | throw adaptRequestIOException(e); |
| | | } |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | future.adaptErrorResult(e.getResult()); |
| | | } |
| | | return future; |
| | |
| | | // FIXME: Is this the best result code? |
| | | final Result errorResult = Responses.newResult(ResultCode.CLIENT_SIDE_LOCAL_ERROR) |
| | | .setDiagnosticMessage("An error occurred while creating a bind context").setCause(e); |
| | | final ErrorResultException error = ErrorResultException.newErrorResult(errorResult); |
| | | final LdapException error = LdapException.newErrorResult(errorResult); |
| | | |
| | | return newFailedFutureResult(error, messageID); |
| | | } |
| | |
| | | bindOrStartTLSInProgress.set(false); |
| | | throw adaptRequestIOException(e); |
| | | } |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | future.adaptErrorResult(e.getResult()); |
| | | } |
| | | |
| | |
| | | pendingRequests.remove(messageID); |
| | | throw adaptRequestIOException(e); |
| | | } |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | future.adaptErrorResult(e.getResult()); |
| | | } |
| | | return future; |
| | |
| | | pendingRequests.remove(messageID); |
| | | throw adaptRequestIOException(e); |
| | | } |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | future.adaptErrorResult(e.getResult()); |
| | | } |
| | | return future; |
| | |
| | | bindOrStartTLSInProgress.set(false); |
| | | throw adaptRequestIOException(e); |
| | | } |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | future.adaptErrorResult(e.getResult()); |
| | | } |
| | | return future; |
| | |
| | | pendingRequests.remove(messageID); |
| | | throw adaptRequestIOException(e); |
| | | } |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | future.adaptErrorResult(e.getResult()); |
| | | } |
| | | return future; |
| | |
| | | pendingRequests.remove(messageID); |
| | | throw adaptRequestIOException(e); |
| | | } |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | future.adaptErrorResult(e.getResult()); |
| | | } |
| | | return future; |
| | |
| | | pendingRequests.remove(messageID); |
| | | throw adaptRequestIOException(e); |
| | | } |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | future.adaptErrorResult(e.getResult()); |
| | | } |
| | | return future; |
| | |
| | | } |
| | | } |
| | | |
| | | int continuePendingBindRequest(final LDAPBindFutureResultImpl future) |
| | | throws ErrorResultException { |
| | | int continuePendingBindRequest(final LDAPBindFutureResultImpl future) throws LdapException { |
| | | final int newMsgID = nextMsgID.getAndIncrement(); |
| | | synchronized (stateLock) { |
| | | checkConnectionIsValid(); |
| | |
| | | } |
| | | } |
| | | |
| | | private ErrorResultException adaptRequestIOException(final IOException e) { |
| | | private LdapException adaptRequestIOException(final IOException e) { |
| | | // FIXME: what other sort of IOExceptions can be thrown? |
| | | // FIXME: Is this the best result code? |
| | | final Result errorResult = Responses.newResult(ResultCode.CLIENT_SIDE_ENCODING_ERROR).setCause(e); |
| | |
| | | return newErrorResult(errorResult); |
| | | } |
| | | |
| | | private void checkBindOrStartTLSInProgress() throws ErrorResultException { |
| | | private void checkBindOrStartTLSInProgress() throws LdapException { |
| | | if (bindOrStartTLSInProgress.get()) { |
| | | throw newErrorResult(ResultCode.OPERATIONS_ERROR, "Bind or Start TLS operation in progress"); |
| | | } |
| | | } |
| | | |
| | | private void checkConnectionIsValid() throws ErrorResultException { |
| | | private void checkConnectionIsValid() throws LdapException { |
| | | if (!isValid0()) { |
| | | if (failedDueToDisconnect) { |
| | | /* |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.grizzly; |
| | |
| | | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.FutureResultImpl; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | |
| | | |
| | | import static org.forgerock.opendj.grizzly.DefaultTCPNIOTransport.*; |
| | | import static org.forgerock.opendj.grizzly.GrizzlyUtils.*; |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.*; |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.forgerock.opendj.ldap.TimeoutChecker.*; |
| | | |
| | | import static com.forgerock.opendj.grizzly.GrizzlyMessages.*; |
| | |
| | | public void handleResult(final ExtendedResult result) { |
| | | onSuccess(connection); |
| | | } |
| | | }).onFailure(new FailureHandler<ErrorResultException>() { |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | onFailure(connection, error); |
| | | } |
| | | }); |
| | |
| | | return ldapConnection; |
| | | } |
| | | |
| | | private ErrorResultException adaptConnectionException(Throwable t) { |
| | | if (!(t instanceof ErrorResultException) && t instanceof ExecutionException) { |
| | | private LdapException adaptConnectionException(Throwable t) { |
| | | if (!(t instanceof LdapException) && t instanceof ExecutionException) { |
| | | t = t.getCause() != null ? t.getCause() : t; |
| | | } |
| | | |
| | | if (t instanceof ErrorResultException) { |
| | | return (ErrorResultException) t; |
| | | if (t instanceof LdapException) { |
| | | return (LdapException) t; |
| | | } else { |
| | | return newErrorResult(ResultCode.CLIENT_SIDE_CONNECT_ERROR, t.getMessage(), t); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Connection getConnection() throws ErrorResultException { |
| | | public Connection getConnection() throws LdapException { |
| | | try { |
| | | return getConnectionAsync().getOrThrow(); |
| | | } catch (final InterruptedException e) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Promise<Connection, ErrorResultException> getConnectionAsync() { |
| | | public Promise<Connection, LdapException> getConnectionAsync() { |
| | | acquireTransportAndTimeoutChecker(); // Protect resources. |
| | | final SocketConnectorHandler connectorHandler = |
| | | TCPNIOConnectorHandler.builder(transport.get()).processor(defaultFilterChain) |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | * Portions Copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.grizzly; |
| | |
| | | import org.forgerock.opendj.ldap.ConnectionSecurityLayer; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.requests.AddRequest; |
| | | import org.forgerock.opendj.ldap.requests.BindClient; |
| | |
| | | } |
| | | return; |
| | | } |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | ldapConnection.setBindOrStartTLSInProgress(false); |
| | | future.adaptErrorResult(e.getResult()); |
| | | return; |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012-2014 ForgeRock AS. |
| | | * Portions Copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.grizzly; |
| | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ConnectionSecurityLayer; |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.IntermediateResponseHandler; |
| | | import org.forgerock.opendj.ldap.LDAPClientContext; |
| | | import org.forgerock.opendj.ldap.LDAPListenerOptions; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | handleResult(error.getResult()); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | final Result result = error.getResult(); |
| | | if (result instanceof BindResult) { |
| | | handleResult((BindResult) result); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | final Result result = error.getResult(); |
| | | if (result instanceof CompareResult) { |
| | | handleResult((CompareResult) result); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | handleResult(error.getResult()); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | final Result result = error.getResult(); |
| | | if (result instanceof ExtendedResult) { |
| | | handleResult((ExtendedResult) result); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | handleResult(error.getResult()); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | handleResult(error.getResult()); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | handleResult(error.getResult()); |
| | | } |
| | | |
| | |
| | | listener.getConnectionFactory().handleAccept(clientContext); |
| | | clientContext.setServerConnection(serverConn); |
| | | LDAP_CONNECTION_ATTR.set(connection, clientContext); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | connection.close(); |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.grizzly; |
| | |
| | | import org.forgerock.opendj.ldap.ConnectionPool; |
| | | import org.forgerock.opendj.ldap.Connections; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.FailoverLoadBalancingAlgorithm; |
| | | import org.forgerock.opendj.ldap.FutureResult; |
| | | import org.forgerock.opendj.ldap.IntermediateResponseHandler; |
| | |
| | | |
| | | import static org.fest.assertions.Assertions.*; |
| | | import static org.forgerock.opendj.ldap.Connections.*; |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.*; |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.forgerock.opendj.ldap.FutureResultWrapper.*; |
| | | import static org.forgerock.opendj.ldap.TestCaseUtils.*; |
| | | import static org.mockito.Matchers.*; |
| | |
| | | */ |
| | | @Test(dataProvider = "connectionFactories", timeOut = TEST_TIMEOUT_MS) |
| | | public void testBlockingFutureNoHandler(ConnectionFactory factory) throws Exception { |
| | | final Promise<? extends Connection, ErrorResultException> promise = factory.getConnectionAsync(); |
| | | final Promise<? extends Connection, LdapException> promise = factory.getConnectionAsync(); |
| | | final Connection con = promise.get(); |
| | | // quickly check if it is a valid connection. |
| | | // Don't use a result handler. |
| | |
| | | @Test(dataProvider = "connectionFactories", timeOut = TEST_TIMEOUT_MS) |
| | | public void testNonBlockingFutureWithHandler(ConnectionFactory factory) throws Exception { |
| | | // Use the handler to get the result asynchronously. |
| | | final PromiseImpl<Connection, ErrorResultException> promise = PromiseImpl.create(); |
| | | final PromiseImpl<Connection, LdapException> promise = PromiseImpl.create(); |
| | | |
| | | factory.getConnectionAsync().onSuccess(new SuccessHandler<Connection>() { |
| | | @Override |
| | |
| | | con.close(); |
| | | promise.handleResult(con); |
| | | } |
| | | }).onFailure(new FailureHandler<ErrorResultException>() { |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | |
| | | @Override |
| | | public void handleError(ErrorResultException error) { |
| | | public void handleError(LdapException error) { |
| | | promise.handleError(error); |
| | | } |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.ConnectionFactory; |
| | | import org.forgerock.opendj.ldap.Connections; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.FutureResult; |
| | | import org.forgerock.opendj.ldap.IntermediateResponseHandler; |
| | | import org.forgerock.opendj.ldap.LDAPClientContext; |
| | |
| | | new LDAPOptions().setConnectTimeout(1, TimeUnit.MILLISECONDS)); |
| | | try { |
| | | for (int i = 0; i < ITERATIONS; i++) { |
| | | final PromiseImpl<ErrorResultException, NeverThrowsException> promise = PromiseImpl.create(); |
| | | final Promise<? extends Connection, ErrorResultException> future = factory.getConnectionAsync(); |
| | | final PromiseImpl<LdapException, NeverThrowsException> promise = PromiseImpl.create(); |
| | | final Promise<? extends Connection, LdapException> future = factory.getConnectionAsync(); |
| | | future.onFailure(getFailureHandler(promise)); |
| | | |
| | | ConnectionException e = (ConnectionException) promise.getOrThrow(TEST_TIMEOUT, TimeUnit.SECONDS); |
| | |
| | | waitForConnect(); |
| | | final MockConnectionEventListener listener = new MockConnectionEventListener(); |
| | | connection.addConnectionEventListener(listener); |
| | | final PromiseImpl<ErrorResultException, NeverThrowsException> promise = PromiseImpl.create(); |
| | | final PromiseImpl<LdapException, NeverThrowsException> promise = PromiseImpl.create(); |
| | | final FutureResult<BindResult> future = connection.bindAsync(newSimpleBindRequest()); |
| | | future.onFailure(getFailureHandler(promise)); |
| | | waitForBind(); |
| | |
| | | connection.addConnectionEventListener(listener); |
| | | |
| | | // Now bind with timeout. |
| | | final PromiseImpl<ErrorResultException, NeverThrowsException> promise = PromiseImpl.create(); |
| | | final PromiseImpl<LdapException, NeverThrowsException> promise = PromiseImpl.create(); |
| | | final FutureResult<BindResult> future = connection.bindAsync(newSimpleBindRequest()); |
| | | future.onFailure(getFailureHandler(promise)); |
| | | waitForBind(); |
| | |
| | | waitForConnect(); |
| | | final ConnectionEventListener listener = mock(ConnectionEventListener.class); |
| | | connection.addConnectionEventListener(listener); |
| | | final PromiseImpl<ErrorResultException, NeverThrowsException> promise = PromiseImpl.create(); |
| | | final PromiseImpl<LdapException, NeverThrowsException> promise = PromiseImpl.create(); |
| | | final FutureResult<SearchResultEntry> future = connection.readEntryAsync(DN.valueOf("cn=test"), null); |
| | | future.onFailure(getFailureHandler(promise)); |
| | | waitForSearch(); |
| | | |
| | | ErrorResultException e = promise.getOrThrow(TEST_TIMEOUT, TimeUnit.SECONDS); |
| | | LdapException e = promise.getOrThrow(TEST_TIMEOUT, TimeUnit.SECONDS); |
| | | verifyResultCodeIsClientSideTimeout(e); |
| | | // Wait for the request to timeout. |
| | | try { |
| | |
| | | new ServerConnectionFactory<LDAPClientContext, Integer>() { |
| | | @Override |
| | | public ServerConnection<Integer> handleAccept( |
| | | final LDAPClientContext clientContext) throws ErrorResultException { |
| | | final LDAPClientContext clientContext) throws LdapException { |
| | | context.set(clientContext); |
| | | connectLatch.release(); |
| | | return serverConnection; |
| | |
| | | } |
| | | } |
| | | |
| | | private FailureHandler<ErrorResultException> getFailureHandler( |
| | | final PromiseImpl<ErrorResultException, NeverThrowsException> promise) { |
| | | return new FailureHandler<ErrorResultException>() { |
| | | private FailureHandler<LdapException> getFailureHandler( |
| | | final PromiseImpl<LdapException, NeverThrowsException> promise) { |
| | | return new FailureHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(ErrorResultException error) { |
| | | public void handleError(LdapException error) { |
| | | promise.handleResult(error); |
| | | } |
| | | }; |
| | |
| | | any(AbandonRequest.class)); |
| | | } |
| | | |
| | | private void verifyResultCodeIsClientSideTimeout(ErrorResultException error) { |
| | | private void verifyResultCodeIsClientSideTimeout(LdapException error) { |
| | | assertThat(error.getResult().getResultCode()).isEqualTo(ResultCode.CLIENT_SIDE_TIMEOUT); |
| | | } |
| | | |
| | |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | import org.forgerock.opendj.ldap.Connections; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.LDAPListener; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | |
| | | } |
| | | SearchResultHandler searchHandler = mock(SearchResultHandler.class); |
| | | @SuppressWarnings("unchecked") |
| | | FailureHandler<ErrorResultException> failureHandler = mock(FailureHandler.class); |
| | | FailureHandler<LdapException> failureHandler = mock(FailureHandler.class); |
| | | connection.searchAsync(request, searchHandler).onFailure(failureHandler); |
| | | |
| | | // Pass in a time which is guaranteed to trigger expiration. |
| | |
| | | if (isPersistentSearch) { |
| | | verifyZeroInteractions(searchHandler); |
| | | } else { |
| | | ArgumentCaptor<ErrorResultException> arg = |
| | | ArgumentCaptor.forClass(ErrorResultException.class); |
| | | ArgumentCaptor<LdapException> arg = ArgumentCaptor.forClass(LdapException.class); |
| | | verify(failureHandler).handleError(arg.capture()); |
| | | assertThat(arg.getValue()).isInstanceOf(TimeoutResultException.class); |
| | | assertThat(arg.getValue().getResult().getResultCode()).isEqualTo( |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS. |
| | | * Portions Copyright 2011-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.grizzly; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.ConnectionFactory; |
| | | import org.forgerock.opendj.ldap.Connections; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.FutureResultImpl; |
| | | import org.forgerock.opendj.ldap.IntermediateResponseHandler; |
| | | import org.forgerock.opendj.ldap.LDAPClientContext; |
| | |
| | | final ExtendedRequest<R> request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final ResultHandler<R> resultHandler) throws UnsupportedOperationException { |
| | | resultHandler.handleError(ErrorResultException.newErrorResult(request |
| | | resultHandler.handleError(LdapException.newErrorResult(request |
| | | .getResultDecoder().newExtendedErrorResult(ResultCode.PROTOCOL_ERROR, "", |
| | | "Extended operation " + request.getOID() + " not supported"))); |
| | | } |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public ServerConnection<Integer> handleAccept(final LDAPClientContext clientContext) |
| | | throws ErrorResultException { |
| | | public ServerConnection<Integer> handleAccept(final LDAPClientContext clientContext) throws LdapException { |
| | | serverConnection.context.handleResult(clientContext); |
| | | return serverConnection; |
| | | } |
| | |
| | | |
| | | @Override |
| | | public ServerConnection<Integer> handleAccept( |
| | | final LDAPClientContext clientContext) throws ErrorResultException { |
| | | final LDAPClientContext clientContext) throws LdapException { |
| | | // Get connection from load balancer, this should |
| | | // fail over twice before getting connection to |
| | | // online server. |
| | |
| | | resultHandler.handleResult(Responses.newBindResult(ResultCode.SUCCESS)); |
| | | } catch (final Exception e) { |
| | | // Unexpected. |
| | | resultHandler.handleError(ErrorResultException.newErrorResult( |
| | | resultHandler.handleError(LdapException.newErrorResult( |
| | | ResultCode.OTHER, |
| | | "Unexpected exception when connecting to load balancer", e)); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public ServerConnection<Integer> handleAccept( |
| | | final LDAPClientContext clientContext) throws ErrorResultException { |
| | | final LDAPClientContext clientContext) throws LdapException { |
| | | // First attempt offline server. |
| | | InetSocketAddress offlineAddress = findFreeSocketAddress(); |
| | | LDAPConnectionFactory lcf = |
| | |
| | | try { |
| | | // This is expected to fail. |
| | | lcf.getConnection().close(); |
| | | throw ErrorResultException.newErrorResult(ResultCode.OTHER, |
| | | throw LdapException.newErrorResult(ResultCode.OTHER, |
| | | "Connection to offline server succeeded unexpectedly"); |
| | | } catch (final ConnectionException ce) { |
| | | // This is expected - so go to online server. |
| | |
| | | lcf.getConnection().close(); |
| | | } catch (final Exception e) { |
| | | // Unexpected. |
| | | throw ErrorResultException |
| | | .newErrorResult( |
| | | throw LdapException.newErrorResult( |
| | | ResultCode.OTHER, |
| | | "Unexpected exception when connecting to online server", |
| | | e); |
| | | } |
| | | } catch (final Exception e) { |
| | | // Unexpected. |
| | | throw ErrorResultException |
| | | .newErrorResult( |
| | | throw LdapException.newErrorResult( |
| | | ResultCode.OTHER, |
| | | "Unexpected exception when connecting to offline server", |
| | | e); |
| | |
| | | try { |
| | | // This is expected to fail. |
| | | lcf.getConnection().close(); |
| | | resultHandler.handleError(ErrorResultException.newErrorResult( |
| | | resultHandler.handleError(LdapException.newErrorResult( |
| | | ResultCode.OTHER, |
| | | "Connection to offline server succeeded unexpectedly")); |
| | | } catch (final ConnectionException ce) { |
| | |
| | | resultHandler.handleResult(Responses.newBindResult(ResultCode.SUCCESS)); |
| | | } catch (final Exception e) { |
| | | // Unexpected. |
| | | resultHandler.handleError(ErrorResultException.newErrorResult( |
| | | resultHandler.handleError(LdapException.newErrorResult( |
| | | ResultCode.OTHER, |
| | | "Unexpected exception when connecting to online server", e)); |
| | | } |
| | | } catch (final Exception e) { |
| | | // Unexpected. |
| | | resultHandler.handleError(ErrorResultException.newErrorResult( |
| | | resultHandler.handleError(LdapException.newErrorResult( |
| | | ResultCode.OTHER, |
| | | "Unexpected exception when connecting to offline server", e)); |
| | | } |
| | |
| | | try { |
| | | connection.bind("cn=test", password2); |
| | | fail("Big bind unexpectedly succeeded"); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | // Expected exception. |
| | | assertThat(e.getResult().getResultCode()).isEqualTo( |
| | | ResultCode.CLIENT_SIDE_SERVER_DOWN); |
| | |
| | | connection = new LDAPConnectionFactory(listener.getHostName(), listener.getPort()).getConnection(); |
| | | try { |
| | | connection.bind("cn=test", "password".toCharArray()); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | connection.close(); |
| | | throw e; |
| | | } |
| | |
| | | try { |
| | | connection.bind("cn=test", "password".toCharArray()); |
| | | fail("Bind attempt on closed connection succeeded unexpectedly"); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | // Expected. |
| | | assertThat(connection.isValid()).isFalse(); |
| | | assertThat(connection.isClosed()).isFalse(); |
| | |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.ErrorResultIOException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.Filter; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | |
| | | //useSubtreeDeleteRequestControl(connection); |
| | | //useVirtualListViewRequestControl(connection); |
| | | |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(e.getResult().getResultCode().intValue()); |
| | | return; |
| | |
| | | * and expects entries under {@code dc=example,dc=com}. |
| | | * |
| | | * @param connection Active connection to Active Directory server. |
| | | * @throws ErrorResultException Operation failed. |
| | | * @throws LdapException Operation failed. |
| | | */ |
| | | static void useADNotificationRequestControl(Connection connection) |
| | | throws ErrorResultException { |
| | | static void useADNotificationRequestControl(Connection connection) throws LdapException { |
| | | |
| | | // --- JCite ADNotification --- |
| | | final String user = "cn=Administrator,cn=users,dc=example,dc=com"; |
| | |
| | | reader.readReference(); // Read and ignore reference |
| | | } |
| | | } |
| | | } catch (final ErrorResultIOException e) { |
| | | } catch (final LdapException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(e.getCause().getResult().getResultCode().intValue()); |
| | | System.exit(e.getResult().getResultCode().intValue()); |
| | | } catch (final SearchResultReferenceIOException e) { |
| | | System.err.println("Got search reference(s): " + e.getReference() |
| | | .getURIs().toString()); |
| | |
| | | * Active connection to LDAP server containing <a |
| | | * href="http://opendj.forgerock.org/Example.ldif" |
| | | * >Example.ldif</a> content. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * Operation failed. |
| | | */ |
| | | static void useAssertionControl(Connection connection) throws ErrorResultException { |
| | | static void useAssertionControl(Connection connection) throws LdapException { |
| | | // --- JCite assertion --- |
| | | if (isSupported(AssertionRequestControl.OID)) { |
| | | final String dn = "uid=bjensen,ou=People,dc=example,dc=com"; |
| | |
| | | * Active connection to LDAP server containing <a |
| | | * href="http://opendj.forgerock.org/Example.ldif" |
| | | * >Example.ldif</a> content. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * Operation failed. |
| | | */ |
| | | static void useAuthorizationIdentityRequestControl(Connection connection) throws ErrorResultException { |
| | | static void useAuthorizationIdentityRequestControl(Connection connection) throws LdapException { |
| | | // --- JCite authzid --- |
| | | if (isSupported(AuthorizationIdentityRequestControl.OID)) { |
| | | final String dn = "uid=bjensen,ou=People,dc=example,dc=com"; |
| | |
| | | * Active connection to LDAP server containing <a |
| | | * href="http://opendj.forgerock.org/Example.ldif" |
| | | * >Example.ldif</a> content. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * Operation failed. |
| | | */ |
| | | static void useGetEffectiveRightsRequestControl(Connection connection) throws ErrorResultException { |
| | | static void useGetEffectiveRightsRequestControl(Connection connection) throws LdapException { |
| | | // --- JCite effective rights --- |
| | | if (isSupported(GetEffectiveRightsRequestControl.OID)) { |
| | | final String authDN = "uid=kvaughan,ou=People,dc=example,dc=com"; |
| | |
| | | } |
| | | } |
| | | writer.close(); |
| | | } catch (final ErrorResultIOException e) { |
| | | } catch (final LdapException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(e.getCause().getResult().getResultCode().intValue()); |
| | | System.exit(e.getResult().getResultCode().intValue()); |
| | | } catch (final SearchResultReferenceIOException e) { |
| | | System.err.println("Got search reference(s): " + e.getReference() |
| | | .getURIs().toString()); |
| | |
| | | * Active connection to LDAP server containing <a |
| | | * href="http://opendj.forgerock.org/Example.ldif" |
| | | * >Example.ldif</a> content. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * Operation failed. |
| | | */ |
| | | static void useManageDsaITRequestControl(Connection connection) throws ErrorResultException { |
| | | static void useManageDsaITRequestControl(Connection connection) throws LdapException { |
| | | // --- JCite manage DsaIT --- |
| | | if (isSupported(ManageDsaITRequestControl.OID)) { |
| | | final String dn = "dc=ref,dc=com"; |
| | |
| | | final SearchResultEntry entry = connection.searchSingleEntry(request); |
| | | writer.writeEntry(entry); |
| | | writer.close(); |
| | | } catch (final ErrorResultIOException e) { |
| | | } catch (final LdapException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(e.getCause().getResult().getResultCode().intValue()); |
| | | System.exit(e.getResult().getResultCode().intValue()); |
| | | } catch (final SearchResultReferenceIOException e) { |
| | | System.err.println("Got search reference(s): " + e.getReference() |
| | | .getURIs().toString()); |
| | |
| | | * Active connection to LDAP server containing <a |
| | | * href="http://opendj.forgerock.org/Example.ldif" |
| | | * >Example.ldif</a> content. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * Operation failed. |
| | | */ |
| | | static void useMatchedValuesRequestControl(Connection connection) throws ErrorResultException { |
| | | static void useMatchedValuesRequestControl(Connection connection) throws LdapException { |
| | | // --- JCite matched values --- |
| | | if (isSupported(MatchedValuesRequestControl.OID)) { |
| | | final String dn = "uid=bjensen,ou=People,dc=example,dc=com"; |
| | |
| | | |
| | | try { |
| | | connection.bind(dn, pwd); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | final Result result = e.getResult(); |
| | | try { |
| | | final PasswordExpiredResponseControl control = |
| | |
| | | * Active connection to LDAP server containing <a |
| | | * href="http://opendj.forgerock.org/Example.ldif" |
| | | * >Example.ldif</a> content. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * Operation failed. |
| | | */ |
| | | static void usePasswordExpiringResponseControl(Connection connection) throws ErrorResultException { |
| | | static void usePasswordExpiringResponseControl(Connection connection) throws LdapException { |
| | | // --- JCite password expiring --- |
| | | if (isSupported(PasswordExpiringResponseControl.OID)) { |
| | | final String dn = "uid=bjensen,ou=People,dc=example,dc=com"; |
| | |
| | | + control.getWarningType().toString() + ", value " |
| | | + control.getWarningValue() + " for " + dn); |
| | | } |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | final Result result = e.getResult(); |
| | | try { |
| | | final PasswordPolicyResponseControl control = |
| | |
| | | * Active connection to LDAP server containing <a |
| | | * href="http://opendj.forgerock.org/Example.ldif" |
| | | * >Example.ldif</a> content. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * Operation failed. |
| | | */ |
| | | static void usePermissiveModifyRequestControl(Connection connection) throws ErrorResultException { |
| | | static void usePermissiveModifyRequestControl(Connection connection) throws LdapException { |
| | | // --- JCite permissive modify --- |
| | | if (isSupported(PermissiveModifyRequestControl.OID)) { |
| | | final String dn = "uid=bjensen,ou=People,dc=example,dc=com"; |
| | |
| | | * Active connection to LDAP server containing <a |
| | | * href="http://opendj.forgerock.org/Example.ldif" |
| | | * >Example.ldif</a> content. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * Operation failed. |
| | | */ |
| | | static void usePersistentSearchRequestControl(Connection connection) throws ErrorResultException { |
| | | static void usePersistentSearchRequestControl(Connection connection) throws LdapException { |
| | | // --- JCite psearch --- |
| | | if (isSupported(PersistentSearchRequestControl.OID)) { |
| | | final SearchRequest request = |
| | |
| | | } catch (final DecodeException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(ResultCode.CLIENT_SIDE_DECODING_ERROR.intValue()); |
| | | } catch (final ErrorResultIOException e) { |
| | | } catch (final LdapException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(e.getCause().getResult().getResultCode().intValue()); |
| | | System.exit(e.getResult().getResultCode().intValue()); |
| | | } catch (final SearchResultReferenceIOException e) { |
| | | System.err.println("Got search reference(s): " + e.getReference() |
| | | .getURIs().toString()); |
| | |
| | | * Active connection to LDAP server containing <a |
| | | * href="http://opendj.forgerock.org/Example.ldif" |
| | | * >Example.ldif</a> content. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * Operation failed. |
| | | */ |
| | | static void usePostReadRequestControl(Connection connection) throws ErrorResultException { |
| | | static void usePostReadRequestControl(Connection connection) throws LdapException { |
| | | // --- JCite post read --- |
| | | if (isSupported(PostReadRequestControl.OID)) { |
| | | final String dn = "uid=bjensen,ou=People,dc=example,dc=com"; |
| | |
| | | * Active connection to LDAP server containing <a |
| | | * href="http://opendj.forgerock.org/Example.ldif" |
| | | * >Example.ldif</a> content. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * Operation failed. |
| | | */ |
| | | static void usePreReadRequestControl(Connection connection) throws ErrorResultException { |
| | | static void usePreReadRequestControl(Connection connection) throws LdapException { |
| | | // --- JCite pre read --- |
| | | if (isSupported(PreReadRequestControl.OID)) { |
| | | final String dn = "uid=bjensen,ou=People,dc=example,dc=com"; |
| | |
| | | * Active connection to LDAP server containing <a |
| | | * href="http://opendj.forgerock.org/Example.ldif" |
| | | * >Example.ldif</a> content. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * Operation failed. |
| | | */ |
| | | static void useProxiedAuthV2RequestControl(Connection connection) throws ErrorResultException { |
| | | static void useProxiedAuthV2RequestControl(Connection connection) throws LdapException { |
| | | // --- JCite proxied authzv2 --- |
| | | if (isSupported(ProxiedAuthV2RequestControl.OID)) { |
| | | final String bindDN = "cn=My App,ou=Apps,dc=example,dc=com"; |
| | |
| | | * Active connection to LDAP server containing <a |
| | | * href="http://opendj.forgerock.org/Example.ldif" |
| | | * >Example.ldif</a> content. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * Operation failed. |
| | | */ |
| | | // --- JCite server-side sort --- |
| | | static void useServerSideSortRequestControl(Connection connection) |
| | | throws ErrorResultException { |
| | | static void useServerSideSortRequestControl(Connection connection) throws LdapException { |
| | | if (isSupported(ServerSideSortRequestControl.OID)) { |
| | | final SearchRequest request = |
| | | Requests.newSearchRequest("ou=People,dc=example,dc=com", |
| | |
| | | * Active connection to LDAP server containing <a |
| | | * href="http://opendj.forgerock.org/Example.ldif" |
| | | * >Example.ldif</a> content. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * Operation failed. |
| | | */ |
| | | static void useSimplePagedResultsControl(Connection connection) throws ErrorResultException { |
| | | static void useSimplePagedResultsControl(Connection connection) throws LdapException { |
| | | // --- JCite simple paged results --- |
| | | if (isSupported(SimplePagedResultsControl.OID)) { |
| | | ByteString cookie = ByteString.empty(); |
| | |
| | | * Active connection to LDAP server containing <a |
| | | * href="http://opendj.forgerock.org/Example.ldif" |
| | | * >Example.ldif</a> content. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * Operation failed. |
| | | */ |
| | | static void useSubentriesRequestControl(Connection connection) throws ErrorResultException { |
| | | static void useSubentriesRequestControl(Connection connection) throws LdapException { |
| | | // --- JCite subentries --- |
| | | if (isSupported(SubentriesRequestControl.OID)) { |
| | | final SearchRequest request = |
| | |
| | | } |
| | | } |
| | | writer.close(); |
| | | } catch (final ErrorResultIOException e) { |
| | | } catch (final LdapException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(e.getCause().getResult().getResultCode().intValue()); |
| | | System.exit(e.getResult().getResultCode().intValue()); |
| | | } catch (final SearchResultReferenceIOException e) { |
| | | System.err.println("Got search reference(s): " + e.getReference() |
| | | .getURIs().toString()); |
| | |
| | | * Active connection to LDAP server containing <a |
| | | * href="http://opendj.forgerock.org/Example.ldif" |
| | | * >Example.ldif</a> content. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * Operation failed. |
| | | */ |
| | | static void useSubtreeDeleteRequestControl(Connection connection) throws ErrorResultException { |
| | | static void useSubtreeDeleteRequestControl(Connection connection) throws LdapException { |
| | | // --- JCite tree delete --- |
| | | if (isSupported(SubtreeDeleteRequestControl.OID)) { |
| | | |
| | |
| | | * Active connection to LDAP server containing <a |
| | | * href="http://opendj.forgerock.org/Example.ldif" |
| | | * >Example.ldif</a> content. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * Operation failed. |
| | | */ |
| | | static void useVirtualListViewRequestControl(Connection connection) throws ErrorResultException { |
| | | static void useVirtualListViewRequestControl(Connection connection) throws LdapException { |
| | | // --- JCite vlv --- |
| | | if (isSupported(VirtualListViewRequestControl.OID)) { |
| | | ByteString contextID = ByteString.empty(); |
| | |
| | | * |
| | | * @param connection |
| | | * Active connection to the LDAP server. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * Failed to get list of controls. |
| | | */ |
| | | static void checkSupportedControls(Connection connection) |
| | | throws ErrorResultException { |
| | | static void checkSupportedControls(Connection connection) throws LdapException { |
| | | controls = RootDSE.readRootDSE(connection).getSupportedControls(); |
| | | } |
| | | |
| | |
| | | * |
| | | * CDDL HEADER END |
| | | * |
| | | * Copyright 2012 ForgeRock AS |
| | | * Copyright 2012-2014 ForgeRock AS |
| | | * |
| | | */ |
| | | |
| | |
| | | import java.util.Collection; |
| | | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.RootDSE; |
| | | import org.forgerock.opendj.ldap.requests.PasswordModifyExtendedRequest; |
| | |
| | | // For StartTLS, see the authentication examples. |
| | | useWhoAmIExtendedRequest(connection); |
| | | |
| | | } catch (ErrorResultException e) { |
| | | } catch (LdapException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(e.getResult().getResultCode().intValue()); |
| | | return; |
| | |
| | | * Active connection to LDAP server containing <a |
| | | * href="http://opendj.forgerock.org/Example.ldif" |
| | | * >Example.ldif</a> content. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * Operation failed. |
| | | */ |
| | | static void usePasswordModifyExtendedRequest(Connection connection) throws ErrorResultException { |
| | | static void usePasswordModifyExtendedRequest(Connection connection) throws LdapException { |
| | | // --- JCite password modify --- |
| | | if (isSupported(PasswordModifyExtendedRequest.OID)) { |
| | | final String userIdentity = "u:scarter"; |
| | |
| | | * @param connection Active connection to LDAP server containing <a |
| | | * href="http://opendj.forgerock.org/Example.ldif" |
| | | * >Example.ldif</a> content. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * Operation failed. |
| | | */ |
| | | static void useWhoAmIExtendedRequest(Connection connection) throws ErrorResultException { |
| | | static void useWhoAmIExtendedRequest(Connection connection) throws LdapException { |
| | | // --- JCite who am I --- |
| | | if (isSupported(WhoAmIExtendedRequest.OID)) { |
| | | |
| | |
| | | * |
| | | * @param connection |
| | | * Active connection to the LDAP server. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * Failed to get list of extended operations. |
| | | */ |
| | | static void checkSupportedExtendedOperations(Connection connection) |
| | | throws ErrorResultException { |
| | | static void checkSupportedExtendedOperations(Connection connection) throws LdapException { |
| | | extendedOperations = RootDSE.readRootDSE(connection) |
| | | .getSupportedExtendedOperations(); |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.examples; |
| | |
| | | import java.io.IOException; |
| | | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.ErrorResultIOException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | |
| | | + ref.getURIs().toString()); |
| | | } |
| | | } |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(e.getResult().getResultCode().intValue()); |
| | | } catch (final ErrorResultIOException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(e.getCause().getResult().getResultCode().intValue()); |
| | | } catch (final IOException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(ResultCode.CLIENT_SIDE_LOCAL_ERROR.intValue()); |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2012-2013 ForgeRock AS |
| | | * Copyright 2012-2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.examples; |
| | | |
| | | import java.io.IOException; |
| | | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | |
| | | writer.writeEntry(entry); |
| | | } |
| | | writer.flush(); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(e.getResult().getResultCode().intValue()); |
| | | return; |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.examples; |
| | |
| | | import java.io.InputStream; |
| | | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldif.ChangeRecord; |
| | |
| | | System.err.println("Successfully modified entry " |
| | | + changeRecord.getName().toString()); |
| | | } |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(e.getResult().getResultCode().intValue()); |
| | | return; |
| | |
| | | * |
| | | * CDDL HEADER END |
| | | * |
| | | * Copyright 2012-2013 ForgeRock AS |
| | | * Copyright 2012-2014 ForgeRock AS |
| | | * |
| | | */ |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.LinkedHashMapEntry; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | |
| | | final LDIFEntryWriter writer = new LDIFEntryWriter(System.out); |
| | | writer.writeEntry(newEntry); |
| | | writer.close(); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(e.getResult().getResultCode().intValue()); |
| | | return; |
| | |
| | | * DN of the entry to modify. |
| | | * @param attributeDescription |
| | | * Attribute to modify. Must take a String value. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * Modify failed. |
| | | */ |
| | | private static void updateEntry(final Connection connection, final String name, |
| | | final String attributeDescription) throws ErrorResultException { |
| | | final String attributeDescription) throws LdapException { |
| | | ModifyRequest request = Requests.newModifyRequest(name) |
| | | .addModification(ModificationType.REPLACE, attributeDescription, "This is a String."); |
| | | connection.modify(request); |
| | |
| | | * |
| | | * CDDL HEADER END |
| | | * |
| | | * Copyright 2013 ForgeRock AS |
| | | * Copyright 2013-2014 ForgeRock AS |
| | | * |
| | | */ |
| | | |
| | |
| | | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | |
| | | |
| | | System.out.println("Successfully changed password for " |
| | | + targetDN + " to " + newPassword + "."); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(e.getResult().getResultCode().intValue()); |
| | | } catch (final GeneralSecurityException e) { |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.examples; |
| | |
| | | |
| | | import org.forgerock.opendj.ldap.ConnectionFactory; |
| | | import org.forgerock.opendj.ldap.Connections; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LDAPClientContext; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.LDAPListener; |
| | |
| | | final RequestHandlerFactory<LDAPClientContext, RequestContext> proxyFactory = |
| | | new RequestHandlerFactory<LDAPClientContext, RequestContext>() { |
| | | @Override |
| | | public ProxyBackend handleAccept(LDAPClientContext clientContext) |
| | | throws ErrorResultException { |
| | | public ProxyBackend handleAccept(LDAPClientContext clientContext) throws LdapException { |
| | | return new ProxyBackend(factory, bindFactory); |
| | | } |
| | | }; |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.examples; |
| | |
| | | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ConnectionFactory; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.IntermediateResponseHandler; |
| | | import org.forgerock.opendj.ldap.RequestContext; |
| | | import org.forgerock.opendj.ldap.RequestHandler; |
| | |
| | | import org.forgerock.util.promise.Promise; |
| | | import org.forgerock.util.promise.SuccessHandler; |
| | | |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.*; |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.forgerock.util.Utils.*; |
| | | |
| | | /** |
| | |
| | | * final RequestHandlerFactory<LDAPClientContext, RequestContext> proxyFactory = |
| | | * new RequestHandlerFactory<LDAPClientContext, RequestContext>() { |
| | | * @Override |
| | | * public ProxyBackend handleAccept(LDAPClientContext clientContext) throws ErrorResultException { |
| | | * public ProxyBackend handleAccept(LDAPClientContext clientContext) throws LdapException { |
| | | * return new ProxyBackend(factory, bindFactory); |
| | | * } |
| | | * }; |
| | |
| | | final AtomicReference<Connection> connectionHolder = new AtomicReference<Connection>(); |
| | | addProxiedAuthControl(request); |
| | | |
| | | factory.getConnectionAsync().thenAsync(new AsyncFunction<Connection, Result, ErrorResultException>() { |
| | | factory.getConnectionAsync().thenAsync(new AsyncFunction<Connection, Result, LdapException>() { |
| | | @Override |
| | | public Promise<Result, ErrorResultException> apply(Connection connection) throws ErrorResultException { |
| | | public Promise<Result, LdapException> apply(Connection connection) throws LdapException { |
| | | connectionHolder.set(connection); |
| | | return connection.addAsync(request, intermediateResponseHandler); |
| | | } |
| | |
| | | final AtomicReference<Connection> connectionHolder = new AtomicReference<Connection>(); |
| | | proxiedAuthControl = null; |
| | | bindFactory.getConnectionAsync() |
| | | .thenAsync(new AsyncFunction<Connection, BindResult, ErrorResultException>() { |
| | | .thenAsync(new AsyncFunction<Connection, BindResult, LdapException>() { |
| | | @Override |
| | | public Promise<BindResult, ErrorResultException> apply(Connection connection) |
| | | throws ErrorResultException { |
| | | public Promise<BindResult, LdapException> apply(Connection connection) throws LdapException { |
| | | connectionHolder.set(connection); |
| | | return connection.bindAsync(request, intermediateResponseHandler); |
| | | } |
| | |
| | | addProxiedAuthControl(request); |
| | | |
| | | final AtomicReference<Connection> connectionHolder = new AtomicReference<Connection>(); |
| | | factory.getConnectionAsync().thenAsync(new AsyncFunction<Connection, CompareResult, ErrorResultException>() { |
| | | factory.getConnectionAsync().thenAsync(new AsyncFunction<Connection, CompareResult, LdapException>() { |
| | | @Override |
| | | public Promise<CompareResult, ErrorResultException> apply(Connection connection) |
| | | throws ErrorResultException { |
| | | public Promise<CompareResult, LdapException> apply(Connection connection) throws LdapException { |
| | | connectionHolder.set(connection); |
| | | return connection.compareAsync(request, intermediateResponseHandler); |
| | | } |
| | |
| | | addProxiedAuthControl(request); |
| | | |
| | | final AtomicReference<Connection> connectionHolder = new AtomicReference<Connection>(); |
| | | factory.getConnectionAsync().thenAsync(new AsyncFunction<Connection, Result, ErrorResultException>() { |
| | | factory.getConnectionAsync().thenAsync(new AsyncFunction<Connection, Result, LdapException>() { |
| | | @Override |
| | | public Promise<Result, ErrorResultException> apply(Connection connection) throws ErrorResultException { |
| | | public Promise<Result, LdapException> apply(Connection connection) throws LdapException { |
| | | connectionHolder.set(connection); |
| | | return connection.deleteAsync(request, intermediateResponseHandler); |
| | | } |
| | |
| | | addProxiedAuthControl(request); |
| | | |
| | | final AtomicReference<Connection> connectionHolder = new AtomicReference<Connection>(); |
| | | factory.getConnectionAsync().thenAsync(new AsyncFunction<Connection, R, ErrorResultException>() { |
| | | factory.getConnectionAsync().thenAsync(new AsyncFunction<Connection, R, LdapException>() { |
| | | @Override |
| | | public Promise<R, ErrorResultException> apply(Connection connection) throws ErrorResultException { |
| | | public Promise<R, LdapException> apply(Connection connection) throws LdapException { |
| | | connectionHolder.set(connection); |
| | | return connection.extendedRequestAsync(request, intermediateResponseHandler); |
| | | } |
| | |
| | | addProxiedAuthControl(request); |
| | | |
| | | final AtomicReference<Connection> connectionHolder = new AtomicReference<Connection>(); |
| | | factory.getConnectionAsync().thenAsync(new AsyncFunction<Connection, Result, ErrorResultException>() { |
| | | factory.getConnectionAsync().thenAsync(new AsyncFunction<Connection, Result, LdapException>() { |
| | | @Override |
| | | public Promise<Result, ErrorResultException> apply(Connection connection) throws ErrorResultException { |
| | | public Promise<Result, LdapException> apply(Connection connection) throws LdapException { |
| | | connectionHolder.set(connection); |
| | | return connection.modifyAsync(request, intermediateResponseHandler); |
| | | } |
| | |
| | | addProxiedAuthControl(request); |
| | | |
| | | final AtomicReference<Connection> connectionHolder = new AtomicReference<Connection>(); |
| | | factory.getConnectionAsync().thenAsync(new AsyncFunction<Connection, Result, ErrorResultException>() { |
| | | factory.getConnectionAsync().thenAsync(new AsyncFunction<Connection, Result, LdapException>() { |
| | | @Override |
| | | public Promise<Result, ErrorResultException> apply(Connection connection) throws ErrorResultException { |
| | | public Promise<Result, LdapException> apply(Connection connection) throws LdapException { |
| | | connectionHolder.set(connection); |
| | | return connection.modifyDNAsync(request, intermediateResponseHandler); |
| | | } |
| | |
| | | addProxiedAuthControl(request); |
| | | |
| | | final AtomicReference<Connection> connectionHolder = new AtomicReference<Connection>(); |
| | | factory.getConnectionAsync().thenAsync(new AsyncFunction<Connection, Result, ErrorResultException>() { |
| | | factory.getConnectionAsync().thenAsync(new AsyncFunction<Connection, Result, LdapException>() { |
| | | @Override |
| | | public Promise<Result, ErrorResultException> apply(Connection connection) throws ErrorResultException { |
| | | public Promise<Result, LdapException> apply(Connection connection) throws LdapException { |
| | | connectionHolder.set(connection); |
| | | return connection.searchAsync(request, intermediateResponseHandler, entryHandler); |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.examples; |
| | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.opendj.ldap.schema.MatchingRule; |
| | |
| | | System.out.println(" " + m.toString()); |
| | | } |
| | | System.out.println(); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(e.getResult().getResultCode().intValue()); |
| | | return; |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.examples; |
| | |
| | | import org.forgerock.opendj.ldap.ConnectionFactory; |
| | | import org.forgerock.opendj.ldap.Connections; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.Filter; |
| | | import org.forgerock.opendj.ldap.IntermediateResponseHandler; |
| | | import org.forgerock.opendj.ldap.LDAPClientContext; |
| | |
| | | final RequestHandlerFactory<LDAPClientContext, RequestContext> proxyFactory = |
| | | new RequestHandlerFactory<LDAPClientContext, RequestContext>() { |
| | | @Override |
| | | public Rewriter handleAccept(final LDAPClientContext clientContext) |
| | | throws ErrorResultException { |
| | | public Rewriter handleAccept(final LDAPClientContext clientContext) throws LdapException { |
| | | return new Rewriter(new ProxyBackend(factory, bindFactory)); |
| | | } |
| | | }; |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2011-2013 ForgeRock AS |
| | | * Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | /** |
| | |
| | | import javax.net.ssl.SSLContext; |
| | | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | |
| | | .setAuthorizationID(authzid); |
| | | connection.bind(request); |
| | | System.out.println("Authenticated as " + authcid + "."); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(e.getResult().getResultCode().intValue()); |
| | | return; |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.examples; |
| | |
| | | import java.util.Arrays; |
| | | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.ErrorResultIOException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | |
| | | } |
| | | } |
| | | writer.flush(); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(e.getResult().getResultCode().intValue()); |
| | | return; |
| | | } catch (final ErrorResultIOException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(e.getCause().getResult().getResultCode().intValue()); |
| | | return; |
| | | } catch (final IOException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(ResultCode.CLIENT_SIDE_LOCAL_ERROR.intValue()); |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.examples; |
| | |
| | | import java.util.concurrent.CountDownLatch; |
| | | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.FutureResult; |
| | | import org.forgerock.opendj.ldap.FutureResultWrapper; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | |
| | | System.err.println("Cancel request succeeded"); |
| | | CANCEL_LATCH.countDown(); |
| | | } |
| | | }).onFailure(new FailureHandler<ErrorResultException>() { |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(ErrorResultException error) { |
| | | public void handleError(LdapException error) { |
| | | System.err.println("Cancel request failed with result code: " |
| | | + error.getResult().getResultCode().intValue()); |
| | | CANCEL_LATCH.countDown(); |
| | |
| | | // Initiate the asynchronous connect, bind, and search. |
| | | final LDAPConnectionFactory factory = new LDAPConnectionFactory(hostName, port); |
| | | |
| | | factory.getConnectionAsync().thenAsync(new AsyncFunction<Connection, BindResult, ErrorResultException>() { |
| | | factory.getConnectionAsync().thenAsync(new AsyncFunction<Connection, BindResult, LdapException>() { |
| | | @Override |
| | | public Promise<BindResult, ErrorResultException> apply(Connection connection) throws ErrorResultException { |
| | | public Promise<BindResult, LdapException> apply(Connection connection) throws LdapException { |
| | | SearchAsync.connection = connection; |
| | | return connection.bindAsync(Requests.newSimpleBindRequest(userName, password.toCharArray())); |
| | | } |
| | | }).thenAsync(new AsyncFunction<BindResult, Result, ErrorResultException>() { |
| | | }).thenAsync(new AsyncFunction<BindResult, Result, LdapException>() { |
| | | @Override |
| | | public Promise<Result, ErrorResultException> apply(BindResult result) throws ErrorResultException { |
| | | public Promise<Result, LdapException> apply(BindResult result) throws LdapException { |
| | | FutureResult<Result> future = FutureResultWrapper.asFutureResult(connection.searchAsync( |
| | | Requests.newSearchRequest(baseDN, scope, filter, attributes), new SearchResultHandlerImpl())); |
| | | requestID = future.getRequestID(); |
| | |
| | | resultCode = result.getResultCode().intValue(); |
| | | COMPLETION_LATCH.countDown(); |
| | | } |
| | | }).onFailure(new FailureHandler<ErrorResultException>() { |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(ErrorResultException error) { |
| | | public void handleError(LdapException error) { |
| | | System.err.println(error.getMessage()); |
| | | resultCode = error.getResult().getResultCode().intValue(); |
| | | COMPLETION_LATCH.countDown(); |
| | |
| | | * |
| | | * CDDL HEADER END |
| | | * |
| | | * Copyright 2012-2013 ForgeRock AS |
| | | * Copyright 2012-2014 ForgeRock AS |
| | | * |
| | | */ |
| | | |
| | |
| | | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | |
| | | |
| | | String cn = entry.getAttribute("cn").firstValueAsString(); |
| | | System.out.println("Hello, " + cn + "!"); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | System.err.println("Failed to bind."); |
| | | System.exit(e.getResult().getResultCode().intValue()); |
| | | return; |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.examples; |
| | |
| | | import javax.net.ssl.SSLContext; |
| | | |
| | | import org.forgerock.opendj.ldap.Connections; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.KeyManagers; |
| | | import org.forgerock.opendj.ldap.LDAPClientContext; |
| | | import org.forgerock.opendj.ldap.LDAPListener; |
| | |
| | | new ServerConnectionFactory<LDAPClientContext, Integer>() { |
| | | |
| | | @Override |
| | | public ServerConnection<Integer> handleAccept( |
| | | final LDAPClientContext clientContext) |
| | | throws ErrorResultException { |
| | | public ServerConnection<Integer> handleAccept(final LDAPClientContext clientContext) |
| | | throws LdapException { |
| | | clientContext.enableTLS(sslContext, null, null, false, false); |
| | | return connectionHandler.handleAccept(clientContext); |
| | | } |
| | |
| | | * |
| | | * CDDL HEADER END |
| | | * |
| | | * Copyright 2012-2013 ForgeRock AS |
| | | * Copyright 2012-2014 ForgeRock AS |
| | | * |
| | | */ |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.Entries; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.LinkedHashMapEntry; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | |
| | | connection.delete(newDN); |
| | | System.out.println("...done."); |
| | | // --- JCite delete --- |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(e.getResult().getResultCode().intValue()); |
| | | return; |
| | |
| | | import javax.net.ssl.TrustManager; |
| | | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | |
| | | connection = factory.getConnection(); |
| | | connection.bind(bindDN, bindPassword.toCharArray()); |
| | | System.out.println("Authenticated as " + bindDN + "."); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(e.getResult().getResultCode().intValue()); |
| | | return; |
| | |
| | | |
| | | System.out.println("Authenticated as " + bindDN + "."); |
| | | |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(e.getResult().getResultCode().intValue()); |
| | | return; |
| | |
| | | connection = factory.getConnection(); |
| | | connection.bind(bindDN, bindPassword.toCharArray()); |
| | | System.out.println("Authenticated as " + bindDN + "."); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(e.getResult().getResultCode().intValue()); |
| | | return; |
| | |
| | | * |
| | | * CDDL HEADER END |
| | | * |
| | | * Copyright 2012-2013 ForgeRock AS |
| | | * Copyright 2012-2014 ForgeRock AS |
| | | * |
| | | */ |
| | | |
| | |
| | | import java.util.Collection; |
| | | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | |
| | | System.out.println("The entry with DN " + memberDN + " has been " |
| | | + op + " the group with DN " + groupDN + "."); |
| | | |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(e.getResult().getResultCode().intValue()); |
| | | return; |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.examples; |
| | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.ErrorResultIOException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | |
| | | writer.flush(); |
| | | } |
| | | |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(e.getResult().getResultCode().intValue()); |
| | | } catch (final ErrorResultIOException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(e.getCause().getResult().getResultCode().intValue()); |
| | | } catch (final IOException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(ResultCode.CLIENT_SIDE_LOCAL_ERROR.intValue()); |
| | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ConnectionFactory; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | | import org.forgerock.opendj.ldap.requests.AddRequest; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Promise<?, ErrorResultException> performOperation(Connection connection, DataSource[] dataSources, |
| | | public Promise<?, LdapException> performOperation(Connection connection, DataSource[] dataSources, |
| | | long currentTime) { |
| | | if (needsDelete(currentTime)) { |
| | | DeleteRequest dr = Requests.newDeleteRequest(getDNEntryToRemove()); |
| | |
| | | } |
| | | } |
| | | |
| | | private Promise<Result, ErrorResultException> performAddOperation(Connection connection, long currentTime) { |
| | | private Promise<Result, LdapException> performAddOperation(Connection connection, long currentTime) { |
| | | try { |
| | | Entry entry; |
| | | synchronized (generator) { |
| | |
| | | } catch (IOException e) { |
| | | // faking an error result by notifying the Handler |
| | | UpdateStatsResultHandler<Result> resHandler = new UpdateStatsResultHandler<Result>(currentTime); |
| | | resHandler.handleError(ErrorResultException.newErrorResult(ResultCode.OTHER, e)); |
| | | resHandler.handleError(LdapException.newErrorResult(ResultCode.OTHER, e)); |
| | | return null; |
| | | } |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | package com.forgerock.opendj.ldap.tools; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ConnectionFactory; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.requests.BindRequest; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | super.handleError(error); |
| | | |
| | | if (error.getResult().getResultCode() == ResultCode.INVALID_CREDENTIALS) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Promise<?, ErrorResultException> performOperation(final Connection connection, |
| | | public Promise<?, LdapException> performOperation(final Connection connection, |
| | | final DataSource[] dataSources, final long startTime) { |
| | | if (dataSources != null) { |
| | | data = DataSource.generateData(dataSources, data); |
| | |
| | | } |
| | | } |
| | | |
| | | Promise<BindResult, ErrorResultException> returnedPromise; |
| | | Promise<BindResult, LdapException> returnedPromise; |
| | | if (filter != null && baseDN != null) { |
| | | if (sr == null) { |
| | | if (dataSources == null) { |
| | |
| | | } |
| | | |
| | | returnedPromise = connection.searchSingleEntryAsync(sr).thenAsync( |
| | | new AsyncFunction<SearchResultEntry, BindResult, ErrorResultException>() { |
| | | new AsyncFunction<SearchResultEntry, BindResult, LdapException>() { |
| | | @Override |
| | | public Promise<BindResult, ErrorResultException> apply(SearchResultEntry result) |
| | | throws ErrorResultException { |
| | | public Promise<BindResult, LdapException> apply(SearchResultEntry result) |
| | | throws LdapException { |
| | | searchWaitRecentTime.getAndAdd(System.nanoTime() - startTime); |
| | | if (data == null) { |
| | | data = new Object[1]; |
| | |
| | | new BindUpdateStatsResultHandler(startTime)); |
| | | } |
| | | |
| | | private Promise<BindResult, ErrorResultException> performBind(final Connection connection, |
| | | private Promise<BindResult, LdapException> performBind(final Connection connection, |
| | | final Object[] data) { |
| | | final boolean useInvalidPassword; |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | package com.forgerock.opendj.ldap.tools; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ConnectionFactory; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.Filter; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.controls.AssertionRequestControl; |
| | |
| | | |
| | | println(INFO_COMPARE_OPERATION_RESULT_TRUE.get(request.getName().toString())); |
| | | } |
| | | } catch (final ErrorResultException ere) { |
| | | } catch (final LdapException ere) { |
| | | final LocalizableMessage msg = INFO_OPERATION_FAILED.get("COMPARE"); |
| | | errPrintln(msg); |
| | | final Result r = ere.getResult(); |
| | |
| | | if (!noop.isPresent()) { |
| | | try { |
| | | connection = connectionFactory.getConnection(); |
| | | } catch (final ErrorResultException ere) { |
| | | } catch (final LdapException ere) { |
| | | errPrintln(LocalizableMessage.raw(ere.getMessage())); |
| | | return ere.getResult().getResultCode().intValue(); |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | package com.forgerock.opendj.ldap.tools; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.ConnectionFactory; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.Filter; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.controls.AssertionRequestControl; |
| | |
| | | Result r = connection.add(change); |
| | | printResult(opType, change.getName().toString(), r); |
| | | return r.getResultCode().intValue(); |
| | | } catch (final ErrorResultException ere) { |
| | | } catch (final LdapException ere) { |
| | | return Utils.printErrorMessage(LDAPModify.this, ere); |
| | | } |
| | | } |
| | |
| | | Result r = connection.delete(change); |
| | | printResult(opType, change.getName().toString(), r); |
| | | return r.getResultCode().intValue(); |
| | | } catch (final ErrorResultException ere) { |
| | | } catch (final LdapException ere) { |
| | | return printErrorMessage(LDAPModify.this, ere); |
| | | } |
| | | } |
| | |
| | | Result r = connection.modifyDN(change); |
| | | printResult(opType, change.getName().toString(), r); |
| | | return r.getResultCode().intValue(); |
| | | } catch (final ErrorResultException ere) { |
| | | } catch (final LdapException ere) { |
| | | return Utils.printErrorMessage(LDAPModify.this, ere); |
| | | } |
| | | } |
| | |
| | | Result r = connection.modify(change); |
| | | printResult(opType, change.getName().toString(), r); |
| | | return r.getResultCode().intValue(); |
| | | } catch (final ErrorResultException ere) { |
| | | } catch (final LdapException ere) { |
| | | return Utils.printErrorMessage(LDAPModify.this, ere); |
| | | } |
| | | } |
| | |
| | | if (!noop.isPresent()) { |
| | | try { |
| | | connection = connectionFactory.getConnection(); |
| | | } catch (final ErrorResultException ere) { |
| | | } catch (final LdapException ere) { |
| | | return Utils.printErrorMessage(this, ere); |
| | | } |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | package com.forgerock.opendj.ldap.tools; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ConnectionFactory; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.controls.Control; |
| | | import org.forgerock.opendj.ldap.requests.PasswordModifyExtendedRequest; |
| | |
| | | Connection connection; |
| | | try { |
| | | connection = connectionFactory.getConnection(); |
| | | } catch (final ErrorResultException ere) { |
| | | } catch (final LdapException ere) { |
| | | return Utils.printErrorMessage(this, ere); |
| | | } |
| | | |
| | |
| | | PasswordModifyExtendedResult result; |
| | | try { |
| | | result = connection.extendedRequest(request); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | LocalizableMessage message = |
| | | ERR_LDAPPWMOD_FAILED.get(e.getResult().getResultCode().intValue(), e |
| | | .getResult().getResultCode().toString()); |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | package com.forgerock.opendj.ldap.tools; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.Filter; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchResultHandler; |
| | |
| | | Connection connection; |
| | | try { |
| | | connection = connectionFactory.getConnection(); |
| | | } catch (final ErrorResultException ere) { |
| | | } catch (final LdapException ere) { |
| | | return Utils.printErrorMessage(this, ere); |
| | | } |
| | | |
| | |
| | | println(message); |
| | | println(); |
| | | } |
| | | } catch (final ErrorResultException ere) { |
| | | } catch (final LdapException ere) { |
| | | return Utils.printErrorMessage(this, ere); |
| | | } finally { |
| | | closeSilently(ldifWriter, connection); |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | package com.forgerock.opendj.ldap.tools; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ConnectionFactory; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Promise<?, ErrorResultException> performOperation(final Connection connection, |
| | | public Promise<?, LdapException> performOperation(final Connection connection, |
| | | final DataSource[] dataSources, final long startTime) { |
| | | if (dataSources != null) { |
| | | data = DataSource.generateData(dataSources, data); |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS. |
| | | * Portions Copyright 2011-2014 ForgeRock AS. |
| | | */ |
| | | package com.forgerock.opendj.ldap.tools; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ConnectionEventListener; |
| | | import org.forgerock.opendj.ldap.ConnectionFactory; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | | import org.forgerock.opendj.ldap.responses.ExtendedResult; |
| | | import org.forgerock.opendj.ldap.responses.Result; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | failedRecentCount.getAndIncrement(); |
| | | updateStats(); |
| | | app.errPrintVerboseMessage(LocalizableMessage.raw(error.getResult().toString())); |
| | |
| | | this.connectionFactory = connectionFactory; |
| | | } |
| | | |
| | | public abstract Promise<?, ErrorResultException> performOperation(Connection connection, |
| | | public abstract Promise<?, LdapException> performOperation(Connection connection, |
| | | DataSource[] dataSources, long startTime); |
| | | |
| | | @Override |
| | | public void run() { |
| | | Promise<?, ErrorResultException> promise; |
| | | Promise<?, LdapException> promise; |
| | | Connection connection; |
| | | |
| | | final double targetTimeInMS = 1000.0 / (targetThroughput / (double) (numThreads * numConnections)); |
| | |
| | | } catch (final InterruptedException e) { |
| | | // Ignore and check stop requested |
| | | continue; |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | app.errPrintln(LocalizableMessage.raw(e.getResult().getDiagnosticMessage())); |
| | | if (e.getCause() != null && app.isVerbose()) { |
| | | e.getCause().printStackTrace(app.getErrorStream()); |
| | |
| | | } catch (final InterruptedException e) { |
| | | // Ignore and check stop requested |
| | | continue; |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | app.errPrintln(LocalizableMessage.raw(e.getResult().toString())); |
| | | if (e.getCause() != null && app.isVerbose()) { |
| | | e.getCause().printStackTrace(app.getErrorStream()); |
| | |
| | | } catch (final InterruptedException e) { |
| | | // Ignore and check stop requested |
| | | continue; |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | if (e.getCause() instanceof IOException) { |
| | | e.getCause().printStackTrace(app.getErrorStream()); |
| | | stopRequested = true; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public synchronized void handleConnectionError(final boolean isDisconnectNotification, |
| | | final ErrorResultException error) { |
| | | public synchronized void handleConnectionError(final boolean isDisconnectNotification, final LdapException error) { |
| | | if (!stopRequested) { |
| | | app.errPrintln(LocalizableMessage.raw("Error occurred on one or more connections: " |
| | | + error.getResult())); |
| | |
| | | statsThread.join(); |
| | | } catch (final InterruptedException e) { |
| | | stopRequested = true; |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | stopRequested = true; |
| | | app.println(LocalizableMessage.raw(e.getResult().getDiagnosticMessage())); |
| | | } finally { |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | package com.forgerock.opendj.ldap.tools; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ConnectionFactory; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchResultHandler; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Promise<?, ErrorResultException> performOperation(final Connection connection, |
| | | public Promise<?, LdapException> performOperation(final Connection connection, |
| | | final DataSource[] dataSources, final long startTime) { |
| | | if (sr == null) { |
| | | if (dataSources == null) { |
| | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.controls.AuthorizationIdentityRequestControl; |
| | | import org.forgerock.opendj.ldap.controls.AuthorizationIdentityResponseControl; |
| | | import org.forgerock.opendj.ldap.controls.GenericControl; |
| | |
| | | * The error result. |
| | | * @return The error code. |
| | | */ |
| | | static int printErrorMessage(final ConsoleApplication app, final ErrorResultException ere) { |
| | | static int printErrorMessage(final ConsoleApplication app, final LdapException ere) { |
| | | /* if ((ere.getMessage() != null) && (ere.getMessage().length() > 0)) { |
| | | app.println(LocalizableMessage.raw(ere.getMessage())); |
| | | }*/ |
| | |
| | | import org.forgerock.opendj.ldap.Connections; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.EntryNotFoundException; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.MultipleEntriesFoundException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | |
| | | |
| | | import static org.forgerock.json.resource.SecurityContext.*; |
| | | import static org.forgerock.json.resource.servlet.SecurityContextFactory.*; |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.*; |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.forgerock.opendj.rest2ldap.Rest2LDAP.*; |
| | | import static org.forgerock.opendj.rest2ldap.servlet.Rest2LDAPContextFactory.*; |
| | |
| | | searchFilterTemplate, username); |
| | | final SearchRequest searchRequest = newSearchRequest(searchBaseDN, searchScope, filter, "1.1"); |
| | | searchLDAPConnectionFactory.getConnectionAsync() |
| | | .thenAsync(new AsyncFunction<Connection, SearchResultEntry, ErrorResultException>() { |
| | | .thenAsync(new AsyncFunction<Connection, SearchResultEntry, LdapException>() { |
| | | @Override |
| | | public Promise<SearchResultEntry, ErrorResultException> apply(Connection connection) |
| | | throws ErrorResultException { |
| | | public Promise<SearchResultEntry, LdapException> apply(Connection connection) |
| | | throws LdapException { |
| | | savedConnection.set(connection); |
| | | // Do the search. |
| | | return connection.searchSingleEntryAsync(searchRequest); |
| | |
| | | doBind(req, res, newSimpleBindRequest(bindDN, password), chain, savedConnection, sync, |
| | | username, authzid); |
| | | } |
| | | }).onFailure(new FailureHandler<ErrorResultException>() { |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | ErrorResultException normalizedError = error; |
| | | public void handleError(final LdapException error) { |
| | | LdapException normalizedError = error; |
| | | if (savedConnection.get() != null) { |
| | | savedConnection.get().close(); |
| | | /* |
| | |
| | | final BindRequest bindRequest, final FilterChain chain, final AtomicReference<Connection> savedConnection, |
| | | final ServletSynchronizer sync, final String authcid, final Map<String, Object> authzid) { |
| | | bindLDAPConnectionFactory.getConnectionAsync() |
| | | .thenAsync(new AsyncFunction<Connection, BindResult, ErrorResultException>() { |
| | | .thenAsync(new AsyncFunction<Connection, BindResult, LdapException>() { |
| | | @Override |
| | | public Promise<BindResult, ErrorResultException> apply(Connection connection) |
| | | throws ErrorResultException { |
| | | public Promise<BindResult, LdapException> apply(Connection connection) |
| | | throws LdapException { |
| | | savedConnection.set(connection); |
| | | return connection.bindAsync(bindRequest); |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | }).onFailure(new FailureHandler<ErrorResultException>() { |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | sync.signalAndComplete(asResourceException(error)); |
| | | } |
| | | }); |
| | |
| | | * Header, with the fields enclosed by brackets [] replaced by your own identifying |
| | | * information: "Portions copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2012 ForgeRock AS. |
| | | * Copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.rest2ldap.servlet; |
| | | |
| | |
| | | * try { |
| | | * connection.bind(username, password.toCharArray()); |
| | | * request.setAttribute(ATTRIBUTE_AUTHN_CONNECTION, connection); |
| | | * } catch (ErrorResultException e) { |
| | | * } catch (LdapException e) { |
| | | * // Fail the HTTP request. |
| | | * response.setStatus(...); |
| | | * return; |
| | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.ConnectionEventListener; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.FutureResult; |
| | | import org.forgerock.opendj.ldap.IntermediateResponseHandler; |
| | | import org.forgerock.opendj.ldap.ResultHandler; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | handleResult(error.getResult()); |
| | | } |
| | | |
| | |
| | | connection = wrap(result); |
| | | runnable.run(); |
| | | } |
| | | }).onFailure(new FailureHandler<ErrorResultException>() { |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | @Override |
| | | public final void handleError(final ErrorResultException error) { |
| | | public final void handleError(final LdapException error) { |
| | | handler.handleError(asResourceException(error)); |
| | | } |
| | | }); |
| | |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.Filter; |
| | | import org.forgerock.opendj.ldap.Function; |
| | | import org.forgerock.opendj.ldap.Modification; |
| | |
| | | completeIfNecessary(SUCCESS); |
| | | } |
| | | } |
| | | }).onFailure(new FailureHandler<ErrorResultException>() { |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(ErrorResultException error) { |
| | | public void handleError(LdapException error) { |
| | | synchronized (sequenceLock) { |
| | | completeIfNecessary(asResourceException(error)); |
| | | } |
| | |
| | | public void handleResult(final SearchResultEntry entry) { |
| | | adaptEntry(c, entry, h); |
| | | } |
| | | }).onFailure(new FailureHandler<ErrorResultException>() { |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | h.handleError(asResourceException(error)); |
| | | } |
| | | }); |
| | |
| | | h.handleError(asResourceException(e)); |
| | | } |
| | | } |
| | | }).onFailure(new FailureHandler<ErrorResultException>() { |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | h.handleError(asResourceException(error)); |
| | | } |
| | | }); |
| | |
| | | updateHandler.handleError(asResourceException(e)); |
| | | } |
| | | } |
| | | }).onFailure(new FailureHandler<ErrorResultException>() { |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | updateHandler.handleError(asResourceException(error)); |
| | | } |
| | | }); |
| | |
| | | }; |
| | | } |
| | | |
| | | private FailureHandler<ErrorResultException> postEmptyPatchFailureHandler(final ResultHandler<Resource> h) { |
| | | return new FailureHandler<ErrorResultException>() { |
| | | private FailureHandler<LdapException> postEmptyPatchFailureHandler(final ResultHandler<Resource> h) { |
| | | return new FailureHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | h.handleError(asResourceException(error)); |
| | | } |
| | | }; |
| | |
| | | }; |
| | | } |
| | | |
| | | private FailureHandler<ErrorResultException> postUpdateFailureHandler(final ResultHandler<Resource> handler) { |
| | | private FailureHandler<LdapException> postUpdateFailureHandler(final ResultHandler<Resource> handler) { |
| | | // The handler which will be invoked for the LDAP add result. |
| | | return new FailureHandler<ErrorResultException>() { |
| | | return new FailureHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | handler.handleError(asResourceException(error)); |
| | | } |
| | | }; |
| | |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.EntryNotFoundException; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.Filter; |
| | | import org.forgerock.opendj.ldap.Function; |
| | | import org.forgerock.opendj.ldap.LinkedAttribute; |
| | |
| | | import org.forgerock.util.promise.FailureHandler; |
| | | import org.forgerock.util.promise.SuccessHandler; |
| | | |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.*; |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.forgerock.opendj.rest2ldap.Rest2LDAP.*; |
| | | import static org.forgerock.opendj.rest2ldap.Utils.*; |
| | |
| | | final SearchRequest request = createSearchRequest(result); |
| | | final List<Filter> subFilters = new LinkedList<Filter>(); |
| | | |
| | | final FailureHandler<ErrorResultException> failureHandler = |
| | | new FailureHandler<ErrorResultException>() { |
| | | final FailureHandler<LdapException> failureHandler = new FailureHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(ErrorResultException error) { |
| | | public void handleError(LdapException error) { |
| | | h.handleError(asResourceException(error)); // Propagate. |
| | | } |
| | | }; |
| | |
| | | } |
| | | completeIfNecessary(); |
| | | } |
| | | }).onFailure(new FailureHandler<ErrorResultException>() { |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | ResourceException re; |
| | | try { |
| | | throw error; |
| | |
| | | "The request cannot be processed " + "because the resource '%s' " |
| | | + "referenced in field '%s' is " + "ambiguous", |
| | | primaryKeyValue.toString(), path)); |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | re = asResourceException(e); |
| | | } |
| | | exception.compareAndSet(null, re); |
| | |
| | | public void handleResult(final SearchResultEntry result) { |
| | | mapper.read(c, path, result, handler); |
| | | } |
| | | }).onFailure(new FailureHandler<ErrorResultException>() { |
| | | }).onFailure(new FailureHandler<LdapException>() { |
| | | @Override |
| | | public void handleError(final ErrorResultException error) { |
| | | public void handleError(final LdapException error) { |
| | | if (!(error instanceof EntryNotFoundException)) { |
| | | handler.handleError(asResourceException(error)); |
| | | } else { |
| | |
| | | * Header, with the fields enclosed by brackets [] replaced by your own identifying |
| | | * information: "Portions copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2013 ForgeRock AS. |
| | | * Copyright 2013-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.rest2ldap; |
| | |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.EntryNotFoundException; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.FailoverLoadBalancingAlgorithm; |
| | | import org.forgerock.opendj.ldap.Filter; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | |
| | | |
| | | /** |
| | | * Adapts a {@code Throwable} to a {@code ResourceException}. If the |
| | | * {@code Throwable} is an LDAP {@code ErrorResultException} then an |
| | | * {@code Throwable} is an LDAP {@link LdapException} then an |
| | | * appropriate {@code ResourceException} is returned, otherwise an |
| | | * {@code InternalServerErrorException} is returned. |
| | | * |
| | |
| | | resourceResultCode = ResourceException.INTERNAL_ERROR; |
| | | } catch (final TimeoutResultException e) { |
| | | resourceResultCode = 408; |
| | | } catch (final ErrorResultException e) { |
| | | } catch (final LdapException e) { |
| | | final ResultCode rc = e.getResult().getResultCode(); |
| | | if (rc.equals(ResultCode.ADMIN_LIMIT_EXCEEDED)) { |
| | | resourceResultCode = 413; // Request Entity Too Large |
| | |
| | | * |
| | | * |
| | | * Copyright 2008-2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2013 ForgeRock AS. |
| | | * Portions Copyright 2013-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.server.core; |
| | | |
| | |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | |
| | | * {@code true} if the entry was successfully retrieved. |
| | | */ |
| | | @Override |
| | | public boolean containsEntry(final DN dn) throws ErrorResultException { |
| | | public boolean containsEntry(final DN dn) throws LdapException { |
| | | return getEntry(dn) != null; |
| | | } |
| | | |
| | |
| | | * that change notification is not supported. |
| | | */ |
| | | @Override |
| | | public boolean supportsChangeNotification(final DN baseDN) throws ErrorResultException { |
| | | public boolean supportsChangeNotification(final DN baseDN) throws LdapException { |
| | | return false; |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions copyright 2013 ForgeRock AS. |
| | | * Portions Copyright 2013-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.server.core; |
| | | |
| | |
| | | * implementation simpler? E.g. initialization, crypto. |
| | | * <p> |
| | | * FIXME: the async APIs used below are a bad fit. We do not want to return an |
| | | * ErrorResultException. We really need a more generic promises API. |
| | | * {@link LdapException}. We really need a more generic promises API. |
| | | */ |
| | | public interface ArchivableDataProvider { |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2008-2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2013 ForgeRock AS. |
| | | * Portions Copyright 2013-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.server.core; |
| | | |
| | |
| | | |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.RequestHandler; |
| | | |
| | | /** |
| | |
| | | * The DN of the entry. |
| | | * @return {@code true} if this data provider contains the specified entry, |
| | | * or {@code false} if it does not. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If a problem occurs while trying to make the determination, |
| | | * or if {@code dn} is not a DN equal to or subordinate to one |
| | | * of the base DNs managed by this data provider. |
| | | */ |
| | | boolean containsEntry(DN dn) throws ErrorResultException; |
| | | boolean containsEntry(DN dn) throws LdapException; |
| | | |
| | | /** |
| | | * Deregisters an event listener from this data provider. |
| | |
| | | * The DN of the entry. |
| | | * @return The requested entry, or {@code null} if this data provider does |
| | | * not contain the specified entry. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If a problem occurs while trying to retrieve the entry, or if |
| | | * {@code dn} is not a DN equal to or subordinate to one of the |
| | | * base DNs managed by this data provider. |
| | | */ |
| | | Entry getEntry(DN dn) throws ErrorResultException; |
| | | Entry getEntry(DN dn) throws LdapException; |
| | | |
| | | /** |
| | | * Returns the current status of the provided base DN in this data provider. |
| | |
| | | * @param baseDN |
| | | * The base DN in this data provider. |
| | | * @return The current status of the provided base DN in this data provider. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If {@code baseDN} is not one of the base DNs managed by this |
| | | * data provider. |
| | | */ |
| | | DataProviderStatus getStatus(DN baseDN) throws ErrorResultException; |
| | | DataProviderStatus getStatus(DN baseDN) throws LdapException; |
| | | |
| | | /** |
| | | * Returns an unmodifiable set containing the OIDs of the controls that may |
| | |
| | | * The base DN in this data provider. |
| | | * @return An unmodifiable set containing the OIDs of the controls that may |
| | | * be supported by the provided base DN in this data provider. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If {@code baseDN} is not one of the base DNs managed by this |
| | | * data provider. |
| | | */ |
| | | Set<String> getSupportedControls(DN baseDN) throws ErrorResultException; |
| | | Set<String> getSupportedControls(DN baseDN) throws LdapException; |
| | | |
| | | /** |
| | | * Returns an unmodifiable set containing the OIDs of the features that may |
| | |
| | | * The base DN in this data provider. |
| | | * @return An unmodifiable set containing the OIDs of the features that may |
| | | * be supported by the provided base DN in this data provider. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If {@code baseDN} is not one of the base DNs managed by this |
| | | * data provider. |
| | | */ |
| | | Set<String> getSupportedFeatures(DN baseDN) throws ErrorResultException; |
| | | Set<String> getSupportedFeatures(DN baseDN) throws LdapException; |
| | | |
| | | /** |
| | | * Registers an event listener with this data provider. |
| | |
| | | * The base DN in this data provider. |
| | | * @return {@code true} if the provided base DN in this data provider |
| | | * supports change notification. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If {@code baseDN} is not one of the base DNs managed by this |
| | | * data provider. |
| | | */ |
| | | boolean supportsChangeNotification(DN baseDN) throws ErrorResultException; |
| | | boolean supportsChangeNotification(DN baseDN) throws LdapException; |
| | | |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2008-2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2013 ForgeRock AS. |
| | | * Portions Copyright 2013-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.server.core; |
| | | |
| | |
| | | |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.RequestHandler; |
| | | |
| | | /** |
| | |
| | | * The DN of the entry. |
| | | * @return {@code true} if the underlying data provider contains the |
| | | * specified entry, or {@code false} if it does not. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If a problem occurs while trying to make the determination, |
| | | * or if {@code dn} is not a DN equal to or subordinate to one |
| | | * of the base DNs managed by the underlying data provider. |
| | | */ |
| | | boolean containsEntry(DN dn) throws ErrorResultException; |
| | | boolean containsEntry(DN dn) throws LdapException; |
| | | |
| | | /** |
| | | * Deregisters an event listener from the underlying data provider. |
| | |
| | | * The DN of the entry. |
| | | * @return The requested entry, or {@code null} if the underlying data |
| | | * provider does not contain the specified entry. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If a problem occurs while trying to retrieve the entry, or if |
| | | * {@code dn} is not a DN equal to or subordinate to one of the |
| | | * base DNs managed by the underlying data provider. |
| | | */ |
| | | Entry getEntry(DN dn) throws ErrorResultException; |
| | | Entry getEntry(DN dn) throws LdapException; |
| | | |
| | | /** |
| | | * Returns the current status of the provided base DN in the underlying data |
| | |
| | | * The base DN in the underlying data provider. |
| | | * @return The current status of the provided base DN in the underlying data |
| | | * provider. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If {@code baseDN} is not one of the base DNs managed by the |
| | | * underlying data provider. |
| | | */ |
| | | DataProviderStatus getStatus(DN baseDN) throws ErrorResultException; |
| | | DataProviderStatus getStatus(DN baseDN) throws LdapException; |
| | | |
| | | /** |
| | | * Returns an unmodifiable set containing the OIDs of the controls that may |
| | |
| | | * @return An unmodifiable set containing the OIDs of the controls that may |
| | | * be supported by the provided base DN in the underlying data |
| | | * provider. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If {@code baseDN} is not one of the base DNs managed by the |
| | | * underlying data provider. |
| | | */ |
| | | Set<String> getSupportedControls(DN baseDN) throws ErrorResultException; |
| | | Set<String> getSupportedControls(DN baseDN) throws LdapException; |
| | | |
| | | /** |
| | | * Returns an unmodifiable set containing the OIDs of the features that may |
| | |
| | | * @return An unmodifiable set containing the OIDs of the features that may |
| | | * be supported by the provided base DN in the underlying data |
| | | * provider. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If {@code baseDN} is not one of the base DNs managed by the |
| | | * underlying data provider. |
| | | */ |
| | | Set<String> getSupportedFeatures(DN baseDN) throws ErrorResultException; |
| | | Set<String> getSupportedFeatures(DN baseDN) throws LdapException; |
| | | |
| | | /** |
| | | * Registers an event listener with the underlying data provider. |
| | |
| | | * The base DN in the underlying data provider. |
| | | * @return {@code true} if the provided base DN in the underlying data |
| | | * provider supports change notification. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If {@code baseDN} is not one of the base DNs managed by the |
| | | * underlying data provider. |
| | | */ |
| | | boolean supportsChangeNotification(DN baseDN) throws ErrorResultException; |
| | | boolean supportsChangeNotification(DN baseDN) throws LdapException; |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions copyright 2013 ForgeRock AS. |
| | | * Portions Copyright 2013-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.server.core; |
| | | |
| | |
| | | * A data provider which supports LDIF export functionality. |
| | | * <p> |
| | | * FIXME: the async APIs used below are a bad fit. We do not want to return an |
| | | * ErrorResultException. We really need a more generic promises API. |
| | | * {@link LdapException}. We really need a more generic promises API. |
| | | */ |
| | | public interface ExportableDataProvider { |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions copyright 2013 ForgeRock AS. |
| | | * Portions Copyright 2013-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.server.core; |
| | | |
| | |
| | | * A data provider which supports LDIF import functionality. |
| | | * <p> |
| | | * FIXME: the async APIs used below are a bad fit. We do not want to return an |
| | | * ErrorResultException. We really need a more generic promises API. |
| | | * {@link LdapException}. We really need a more generic promises API. |
| | | * <p> |
| | | * FIXME: it would be nice if we can use EntryReader, however we may need to |
| | | * provide an optimized implementation for use in multi-threaded imports. E.g. |
| | |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.IntermediateResponseHandler; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchResultHandler; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Promise<Connection, ErrorResultException> getConnectionAsync() { |
| | | public Promise<Connection, LdapException> getConnectionAsync() { |
| | | // TODO change the path... |
| | | return newSuccessfulPromise(newConnection(icc)); |
| | | } |
| | | |
| | | @Override |
| | | public Connection getConnection() throws ErrorResultException { |
| | | public Connection getConnection() throws LdapException { |
| | | return newConnection(icc); |
| | | } |
| | | }; |
| | |
| | | * @param dn |
| | | * The DN of the user. |
| | | * @return A new connection for a specified user. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If no such object. |
| | | */ |
| | | public static Connection newConnectionForUser(final DN dn) throws ErrorResultException { |
| | | public static Connection newConnectionForUser(final DN dn) throws LdapException { |
| | | try { |
| | | return newConnection(new InternalClientConnection(to(dn))); |
| | | } catch (DirectoryException e) { |
| | | throw ErrorResultException.newErrorResult(Responses |
| | | .newResult(ResultCode.NO_SUCH_OBJECT)); |
| | | throw LdapException.newErrorResult(Responses.newResult(ResultCode.NO_SUCH_OBJECT)); |
| | | } |
| | | } |
| | | |
| | |
| | | return new AbstractSynchronousConnection() { |
| | | |
| | | @Override |
| | | public Result search(final SearchRequest request, final SearchResultHandler handler) |
| | | throws ErrorResultException { |
| | | public Result search(final SearchRequest request, final SearchResultHandler handler) throws LdapException { |
| | | InternalSearchListener internalSearchListener = new InternalSearchListener() { |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result modifyDN(final ModifyDNRequest request) throws ErrorResultException { |
| | | public Result modifyDN(final ModifyDNRequest request) throws LdapException { |
| | | final ModifyDNOperation modifyDNOperation = |
| | | icc.processModifyDN(to(valueOf(request.getName())), to(valueOf(request |
| | | .getNewRDN())), request.isDeleteOldRDN(), |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result modify(final ModifyRequest request) throws ErrorResultException { |
| | | public Result modify(final ModifyRequest request) throws LdapException { |
| | | final ModifyOperation modifyOperation = |
| | | icc.processModify(to(valueOf(request.getName())), toRawModifications(request |
| | | .getModifications()), to(request.getControls())); |
| | |
| | | |
| | | @Override |
| | | public <R extends ExtendedResult> R extendedRequest(final ExtendedRequest<R> request, |
| | | final IntermediateResponseHandler handler) throws ErrorResultException { |
| | | final IntermediateResponseHandler handler) throws LdapException { |
| | | |
| | | final ExtendedOperation extendedOperation = |
| | | icc.processExtendedOperation(request.getOID(), to(request.getValue()), |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result delete(final DeleteRequest request) throws ErrorResultException { |
| | | public Result delete(final DeleteRequest request) throws LdapException { |
| | | final DeleteOperation deleteOperation = |
| | | icc.processDelete(to(valueOf(request.getName())), to(request.getControls())); |
| | | return getResponseResult(deleteOperation); |
| | | } |
| | | |
| | | @Override |
| | | public CompareResult compare(final CompareRequest request) throws ErrorResultException { |
| | | public CompareResult compare(final CompareRequest request) throws LdapException { |
| | | final CompareOperation compareOperation = |
| | | icc.processCompare(to(valueOf(request.getName())), request |
| | | .getAttributeDescription().toString(), to(request |
| | |
| | | } |
| | | |
| | | @Override |
| | | public BindResult bind(final BindRequest request) throws ErrorResultException { |
| | | public BindResult bind(final BindRequest request) throws LdapException { |
| | | BindOperation bindOperation = null; |
| | | if (request instanceof SimpleBindRequest) { |
| | | bindOperation = |
| | |
| | | bindClient.dispose(); |
| | | |
| | | } else { // not supported |
| | | throw ErrorResultException.newErrorResult(Responses |
| | | throw LdapException.newErrorResult(Responses |
| | | .newResult(ResultCode.AUTH_METHOD_NOT_SUPPORTED)); |
| | | } |
| | | BindResult result = |
| | |
| | | if (result.isSuccess()) { |
| | | return result; |
| | | } else { |
| | | throw ErrorResultException.newErrorResult(result); |
| | | throw LdapException.newErrorResult(result); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result add(final AddRequest request) throws ErrorResultException { |
| | | public Result add(final AddRequest request) throws LdapException { |
| | | final AddOperation addOperation = |
| | | icc.processAdd(to(valueOf(request.getName())), to(request |
| | | .getAllAttributes()), to(request.getControls())); |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2013 ForgeRock AS. |
| | | * Copyright 2013-2014 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.adapter.server2x; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LinkedAttribute; |
| | | import org.forgerock.opendj.ldap.RDN; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | |
| | | /** |
| | | * Populates the result object with the operation details and return the |
| | | * result object if it was successful. Otherwise, it throws an |
| | | * {@link ErrorResultException}. |
| | | * {@link LdapException}. |
| | | * |
| | | * @param <T> |
| | | * the type of the result object |
| | |
| | | * used to populate the result |
| | | * @param result |
| | | * the result object to populate from the Operation |
| | | * @return the result if successful, an {@link ErrorResultException} is thrown |
| | | * @return the result if successful, an {@link LdapException} is thrown |
| | | * otherwise |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * when an error occurs |
| | | */ |
| | | public static <T extends Result> T getResponseResult(final Operation operation, final T result) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | if (operation.getReferralURLs() != null) { |
| | | for (String ref : operation.getReferralURLs()) { |
| | | result.addReferralURI(ref); |
| | |
| | | if (result.isSuccess()) { |
| | | return result; |
| | | } else { |
| | | throw ErrorResultException.newErrorResult(result); |
| | | throw LdapException.newErrorResult(result); |
| | | } |
| | | } |
| | | |
| | |
| | | * @param operation |
| | | * value to convert |
| | | * @return the converted value |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * when an error occurs |
| | | */ |
| | | public static Result getResponseResult(final Operation operation) throws ErrorResultException { |
| | | public static Result getResponseResult(final Operation operation) throws LdapException { |
| | | return getResponseResult(operation, newSDKResult(operation)); |
| | | } |
| | | |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Portions copyright 2013 ForgeRock AS |
| | | * Copyright 2013-2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.adapter.server2x; |
| | | |
| | | import static org.fest.assertions.Assertions.assertThat; |
| | | import static org.fest.assertions.Fail.fail; |
| | | |
| | | import java.security.GeneralSecurityException; |
| | | import java.util.NoSuchElementException; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.Entries; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.EntryNotFoundException; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.ErrorResultIOException; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LinkedHashMapEntry; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.forgerock.opendj.adapter.server2x.EmbeddedServerTestCaseUtils.CONFIG_PROPERTIES; |
| | | import static org.fest.assertions.Assertions.*; |
| | | import static org.fest.assertions.Fail.*; |
| | | import static org.forgerock.opendj.adapter.server2x.EmbeddedServerTestCaseUtils.*; |
| | | |
| | | /** |
| | | * This class defines a set of tests for the Adapters.class. |
| | |
| | | /** |
| | | * A simple LDAP connection. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test() |
| | | public void testSimpleLDAPConnectionFactorySimpleBind() throws ErrorResultException { |
| | | public void testSimpleLDAPConnectionFactorySimpleBind() throws LdapException { |
| | | final LDAPConnectionFactory factory = |
| | | new LDAPConnectionFactory("localhost", |
| | | Integer.valueOf(CONFIG_PROPERTIES.getProperty("listen-port"))); |
| | |
| | | * |
| | | * @throws NumberFormatException |
| | | * @throws GeneralSecurityException |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test() |
| | | public void testLDAPSASLBind() throws NumberFormatException, GeneralSecurityException, |
| | | ErrorResultException { |
| | | public void testLDAPSASLBind() throws NumberFormatException, GeneralSecurityException, LdapException { |
| | | LDAPConnectionFactory factory = |
| | | new LDAPConnectionFactory("localhost", |
| | | Integer.valueOf(CONFIG_PROPERTIES.getProperty("listen-port"))); |
| | |
| | | /** |
| | | * Tests an SASL connection with the adapter. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test() |
| | | public void testAdapterConnectionSASLBindRequest() throws ErrorResultException, |
| | | public void testAdapterConnectionSASLBindRequest() throws LdapException, |
| | | GeneralSecurityException { |
| | | final Connection connection = Adapters.newRootConnection(); |
| | | |
| | |
| | | * This type of connection is not supported. Anonymous SASL Mechanisms is |
| | | * disabled in the config.ldif file. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "anonymousConnectionFactories", |
| | | expectedExceptions = ErrorResultException.class) |
| | | public void testConnectionAnonymousSASLBindRequest(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | @Test(dataProvider = "anonymousConnectionFactories", expectedExceptions = LdapException.class) |
| | | public void testConnectionAnonymousSASLBindRequest(final ConnectionFactory factory) throws LdapException { |
| | | final Connection connection = factory.getConnection(); |
| | | try { |
| | | connection.bind(Requests.newAnonymousSASLBindRequest("anonymousSASLBindRequest")); |
| | |
| | | * Performs a search with a sub entries request control. Sub-entries are |
| | | * included and the normal entries are excluded. No result expected. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws ErrorResultIOException |
| | | * @throws LdapException |
| | | * @throws SearchResultReferenceIOException |
| | | */ |
| | | @Test(dataProvider = "rootConnectionFactories", |
| | | expectedExceptions = NoSuchElementException.class) |
| | | public void testAdapterSearchRequestSubEntriesWithNoResult(final ConnectionFactory factory) |
| | | throws ErrorResultException, ErrorResultIOException, SearchResultReferenceIOException { |
| | | throws LdapException, SearchResultReferenceIOException { |
| | | final Connection connection = factory.getConnection(); |
| | | try { |
| | | final SearchRequest request = |
| | |
| | | * Performs a search with a sub entries request control. Sub-entries are |
| | | * excluded this time and the normal entries are included. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws ErrorResultIOException |
| | | * @throws LdapException |
| | | * @throws SearchResultReferenceIOException |
| | | */ |
| | | @Test(dataProvider = "rootConnectionFactories") |
| | | public void testAdapterSearchRequestSubEntries(final ConnectionFactory factory) |
| | | throws ErrorResultException, ErrorResultIOException, SearchResultReferenceIOException { |
| | | throws LdapException, SearchResultReferenceIOException { |
| | | final Connection connection = factory.getConnection(); |
| | | |
| | | final SearchRequest request = |
| | |
| | | /** |
| | | * Deletes an inexistent entry. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "rootConnectionFactories", |
| | | expectedExceptions = EntryNotFoundException.class) |
| | | public void testAdapterDeleteRequestNoSuchEntry(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | public void testAdapterDeleteRequestNoSuchEntry(final ConnectionFactory factory) throws LdapException { |
| | | final DeleteRequest deleteRequest = Requests.newDeleteRequest("cn=test"); |
| | | final Connection connection = factory.getConnection(); |
| | | try { |
| | |
| | | /** |
| | | * Deletes an existing entry with the 'no-op' control. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "rootConnectionFactories") |
| | | public void testAdapterDeleteRequestNoOpControl(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | public void testAdapterDeleteRequestNoOpControl(final ConnectionFactory factory) throws LdapException { |
| | | final DeleteRequest deleteRequest = |
| | | Requests.newDeleteRequest("uid=user.1, dc=example,dc=org") |
| | | // The no-op control is specified with his OID. |
| | |
| | | /** |
| | | * Deletes an existing entry. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test() |
| | | public void testAdapterDeleteRequest() throws ErrorResultException { |
| | | public void testAdapterDeleteRequest() throws LdapException { |
| | | |
| | | final Connection connection = Adapters.newRootConnection(); |
| | | // Checks if the entry exists. |
| | |
| | | /** |
| | | * Modifies an existing entry. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * @throws DecodeException |
| | | */ |
| | | @Test() |
| | | public void testAdapterModifyRequest() throws ErrorResultException, DecodeException { |
| | | public void testAdapterModifyRequest() throws LdapException, DecodeException { |
| | | |
| | | final ModifyRequest changeRequest = |
| | | Requests.newModifyRequest("uid=user.2, dc=example,dc=org").addControl( |
| | |
| | | * Tries to modify the existing entry with the same values but using the |
| | | * permissive modify control. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "rootConnectionFactories") |
| | | public void testAdapterUsePermissiveModifyRequest(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | public void testAdapterUsePermissiveModifyRequest(final ConnectionFactory factory) throws LdapException { |
| | | |
| | | final ModifyRequest changeRequest = |
| | | Requests.newModifyRequest("uid=user.2, dc=example,dc=org").addControl( |
| | |
| | | /** |
| | | * Tries to modify the existing entry with the same values. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "rootConnectionFactories", |
| | | expectedExceptions = ConstraintViolationException.class) |
| | | public void testAdapterModifyRequestFails(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | |
| | | public void testAdapterModifyRequestFails(final ConnectionFactory factory) throws LdapException { |
| | | final ModifyRequest changeRequest = |
| | | Requests.newModifyRequest("uid=user.2, dc=example,dc=org").addModification( |
| | | ModificationType.ADD, "uid", "user.2"); |
| | |
| | | /** |
| | | * Modifies the DN. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "rootConnectionFactories") |
| | | public void testAdapterModifyDNRequest(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | public void testAdapterModifyDNRequest(final ConnectionFactory factory) throws LdapException { |
| | | final Connection connection = factory.getConnection(); |
| | | |
| | | // Verifies that entry has been correctly modified. |
| | |
| | | /** |
| | | * Compare request. The comparison returns true. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "rootConnectionFactories") |
| | | public void testAdapterCompareRequestTrue(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | |
| | | public void testAdapterCompareRequestTrue(final ConnectionFactory factory) throws LdapException { |
| | | final CompareRequest compareRequest = |
| | | Requests.newCompareRequest("uid=user.0,dc=example,dc=org", "uid", "user.0"); |
| | | |
| | |
| | | /** |
| | | * Compare request. The comparison returns false. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "rootConnectionFactories") |
| | | public void testAdapterCompareRequestFalse(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | |
| | | public void testAdapterCompareRequestFalse(final ConnectionFactory factory) throws LdapException { |
| | | final CompareRequest compareRequest = |
| | | Requests.newCompareRequest("uid=user.0,dc=example,dc=org", "uid", "scarter"); |
| | | |
| | |
| | | /** |
| | | * Use the Who Am I? extended request. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "rootConnectionFactories") |
| | | public void testAdapterExtendedOperation(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | public void testAdapterExtendedOperation(final ConnectionFactory factory) throws LdapException { |
| | | final WhoAmIExtendedRequest request = Requests.newWhoAmIExtendedRequest(); |
| | | final Connection connection = factory.getConnection(); |
| | | try { |
| | |
| | | * If an anonymous tries to delete, sends a result code : insufficient |
| | | * access rights. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "anonymousConnectionFactories", |
| | | expectedExceptions = AuthorizationException.class) |
| | | public void testAdapterAsAnonymousCannotPerformDeleteRequest(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | |
| | | final DeleteRequest deleteRequest = |
| | | Requests.newDeleteRequest("uid=user.2,dc=example,dc=org"); |
| | |
| | | * If an anonymous tries to do an add request, sends a result code : |
| | | * insufficient access rights. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "anonymousConnectionFactories", |
| | | expectedExceptions = AuthorizationException.class) |
| | | public void testAdapterAsAnonymousCannotPerformAddRequest(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | |
| | | // @formatter:off |
| | | final AddRequest addRequest = Requests.newAddRequest( |
| | |
| | | * If an anonymous tries to do a modify DN request, sends a result code : |
| | | * insufficient access rights. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "anonymousConnectionFactories", |
| | | expectedExceptions = AuthorizationException.class) |
| | | public void testAdapterAsAnonymousCannotPerformModifyDNRequest(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | |
| | | final Connection connection = factory.getConnection(); |
| | | |
| | |
| | | * If an anonymous tries to do a modify request, sends a result code : |
| | | * insufficient access rights. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "anonymousConnectionFactories", |
| | | expectedExceptions = ErrorResultException.class) |
| | | expectedExceptions = LdapException.class) |
| | | public void testAdapterAsAnonymousCannotPerformModifyRequest(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | |
| | | final ModifyRequest changeRequest = |
| | | Requests.newModifyRequest("uid=user.2,dc=example,dc=org").addControl( |
| | |
| | | /** |
| | | * The anonymous connection is allowed to perform compare request. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "anonymousConnectionFactories") |
| | | public void testAdapterAsAnonymousPerformsCompareRequest(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | |
| | | final CompareRequest compareRequest = |
| | | Requests.newCompareRequest("uid=user.0,dc=example,dc=org", "uid", "user.0"); |
| | |
| | | * |
| | | * @throws Exception |
| | | */ |
| | | @Test(dataProvider = "anonymousConnectionFactories", |
| | | expectedExceptions = ErrorResultIOException.class) |
| | | @Test(dataProvider = "anonymousConnectionFactories", expectedExceptions = LdapException.class) |
| | | public void testAdapterAsAnonymousCannotPerformSearchRequestWithControl( |
| | | final ConnectionFactory factory) throws Exception { |
| | | final Connection connection = factory.getConnection(); |
| | |
| | | * add/delete/search and compare results with an SDK adapter connection |
| | | * doing the same. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws ErrorResultIOException |
| | | * @throws LdapException |
| | | * @throws SearchResultReferenceIOException |
| | | */ |
| | | @Test() |
| | | public void testLDAPConnectionAndAdapterComparison() throws ErrorResultException, |
| | | ErrorResultIOException, SearchResultReferenceIOException { |
| | | |
| | | public void testLDAPConnectionAndAdapterComparison() throws LdapException, SearchResultReferenceIOException { |
| | | // @formatter:off |
| | | final AddRequest addRequest = Requests.newAddRequest( |
| | | "dn: sn=babs,dc=example,dc=org", |
| | |
| | | assertThat(entry.getName().toString()).isEqualTo(sdkEntry.getName().toString()); |
| | | assertThat(entry.getAttributeCount()).isEqualTo(sdkEntry.getAttributeCount()); |
| | | assertThat(entry.getAllAttributes().iterator().next().getAttributeDescription()) |
| | | .isEqualTo( |
| | | sdkEntry.getAllAttributes().iterator().next().getAttributeDescription()); |
| | | .isEqualTo(sdkEntry.getAllAttributes().iterator().next().getAttributeDescription()); |
| | | assertThat(entry.getControls().size()).isEqualTo(sdkEntry.getControls().size()); |
| | | } |
| | | } |
| | |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.IntermediateResponseHandler; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchResultHandler; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Promise<Connection, ErrorResultException> getConnectionAsync() { |
| | | public Promise<Connection, LdapException> getConnectionAsync() { |
| | | // TODO change the path... |
| | | return newSuccessfulPromise(newConnection(icc)); |
| | | } |
| | | |
| | | @Override |
| | | public Connection getConnection() throws ErrorResultException { |
| | | public Connection getConnection() throws LdapException { |
| | | return newConnection(icc); |
| | | } |
| | | }; |
| | |
| | | * @param dn |
| | | * The DN of the user. |
| | | * @return A new connection for a specified user. |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * If no such object. |
| | | */ |
| | | public static Connection newConnectionForUser(final DN dn) throws ErrorResultException { |
| | | public static Connection newConnectionForUser(final DN dn) throws LdapException { |
| | | try { |
| | | return newConnection(new InternalClientConnection(to(dn))); |
| | | } catch (DirectoryException e) { |
| | | throw ErrorResultException.newErrorResult(Responses |
| | | .newResult(ResultCode.NO_SUCH_OBJECT)); |
| | | throw LdapException.newErrorResult(Responses.newResult(ResultCode.NO_SUCH_OBJECT)); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public Result search(final SearchRequest request, final SearchResultHandler handler) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | InternalSearchListener internalSearchListener = new InternalSearchListener() { |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result modifyDN(final ModifyDNRequest request) throws ErrorResultException { |
| | | public Result modifyDN(final ModifyDNRequest request) throws LdapException { |
| | | final ModifyDNOperation modifyDNOperation = |
| | | icc.processModifyDN(valueOf(request.getName()), valueOf(request.getNewRDN()), |
| | | request.isDeleteOldRDN(), |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result modify(final ModifyRequest request) throws ErrorResultException { |
| | | public Result modify(final ModifyRequest request) throws LdapException { |
| | | final ModifyOperation modifyOperation = |
| | | icc.processModify(valueOf(request.getName()), toRawModifications(request |
| | | .getModifications()), to(request.getControls())); |
| | |
| | | |
| | | @Override |
| | | public <R extends ExtendedResult> R extendedRequest(final ExtendedRequest<R> request, |
| | | final IntermediateResponseHandler handler) throws ErrorResultException { |
| | | final IntermediateResponseHandler handler) throws LdapException { |
| | | |
| | | final ExtendedOperation extendedOperation = |
| | | icc.processExtendedOperation(request.getOID(), request.getValue(), |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result delete(final DeleteRequest request) throws ErrorResultException { |
| | | public Result delete(final DeleteRequest request) throws LdapException { |
| | | final DeleteOperation deleteOperation = |
| | | icc.processDelete(valueOf(request.getName()), to(request.getControls())); |
| | | return getResponseResult(deleteOperation); |
| | | } |
| | | |
| | | @Override |
| | | public CompareResult compare(final CompareRequest request) throws ErrorResultException { |
| | | public CompareResult compare(final CompareRequest request) throws LdapException { |
| | | final CompareOperation compareOperation = |
| | | icc.processCompare(valueOf(request.getName()), |
| | | request.getAttributeDescription().toString(), |
| | |
| | | } |
| | | |
| | | @Override |
| | | public BindResult bind(final BindRequest request) throws ErrorResultException { |
| | | public BindResult bind(final BindRequest request) throws LdapException { |
| | | BindOperation bindOperation = null; |
| | | if (request instanceof SimpleBindRequest) { |
| | | bindOperation = |
| | |
| | | bindClient.dispose(); |
| | | |
| | | } else { // not supported |
| | | throw ErrorResultException.newErrorResult(Responses |
| | | throw LdapException.newErrorResult(Responses |
| | | .newResult(ResultCode.AUTH_METHOD_NOT_SUPPORTED)); |
| | | } |
| | | BindResult result = Responses.newBindResult(bindOperation.getResultCode()); |
| | |
| | | if (result.isSuccess()) { |
| | | return result; |
| | | } else { |
| | | throw ErrorResultException.newErrorResult(result); |
| | | throw LdapException.newErrorResult(result); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result add(final AddRequest request) throws ErrorResultException { |
| | | public Result add(final AddRequest request) throws LdapException { |
| | | final AddOperation addOperation = |
| | | icc.processAdd(valueOf(request.getName()), to(request |
| | | .getAllAttributes()), to(request.getControls())); |
| | |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LinkedAttribute; |
| | | import org.forgerock.opendj.ldap.LinkedHashMapEntry; |
| | | import org.forgerock.opendj.ldap.RDN; |
| | |
| | | /** |
| | | * Populates the result object with the operation details and return the |
| | | * result object if it was successful. Otherwise, it throws an |
| | | * {@link ErrorResultException}. |
| | | * {@link LdapException}. |
| | | * |
| | | * @param <T> |
| | | * the type of the result object |
| | |
| | | * used to populate the result |
| | | * @param result |
| | | * the result object to populate from the Operation |
| | | * @return the result if successful, an {@link ErrorResultException} is thrown |
| | | * @return the result if successful, an {@link LdapException} is thrown |
| | | * otherwise |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * when an error occurs |
| | | */ |
| | | public static <T extends Result> T getResponseResult(final Operation operation, final T result) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | if (operation.getReferralURLs() != null) { |
| | | for (String ref : operation.getReferralURLs()) { |
| | | result.addReferralURI(ref); |
| | |
| | | if (result.isSuccess()) { |
| | | return result; |
| | | } else { |
| | | throw ErrorResultException.newErrorResult(result); |
| | | throw LdapException.newErrorResult(result); |
| | | } |
| | | } |
| | | |
| | |
| | | * @param operation |
| | | * value to convert |
| | | * @return the converted value |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * when an error occurs |
| | | */ |
| | | public static Result getResponseResult(final Operation operation) throws ErrorResultException { |
| | | public static Result getResponseResult(final Operation operation) throws LdapException { |
| | | return getResponseResult(operation, newSDKResult(operation)); |
| | | } |
| | | |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Portions copyright 2013-2014 ForgeRock AS |
| | | * Copyright 2013-2014 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.adapter.server3x; |
| | | |
| | | import static org.fest.assertions.Assertions.assertThat; |
| | | import static org.fest.assertions.Fail.fail; |
| | | |
| | | import java.security.GeneralSecurityException; |
| | | import java.util.NoSuchElementException; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.Entries; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.EntryNotFoundException; |
| | | import org.forgerock.opendj.ldap.ErrorResultException; |
| | | import org.forgerock.opendj.ldap.ErrorResultIOException; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LinkedHashMapEntry; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.forgerock.opendj.adapter.server3x.EmbeddedServerTestCaseUtils.CONFIG_PROPERTIES; |
| | | import static org.fest.assertions.Assertions.*; |
| | | import static org.fest.assertions.Fail.*; |
| | | import static org.forgerock.opendj.adapter.server3x.EmbeddedServerTestCaseUtils.*; |
| | | |
| | | /** |
| | | * This class defines a set of tests for the Adapters.class. |
| | |
| | | /** |
| | | * A simple LDAP connection. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test() |
| | | public void testSimpleLDAPConnectionFactorySimpleBind() throws ErrorResultException { |
| | | public void testSimpleLDAPConnectionFactorySimpleBind() throws LdapException { |
| | | final LDAPConnectionFactory factory = |
| | | new LDAPConnectionFactory("localhost", |
| | | Integer.valueOf(CONFIG_PROPERTIES.getProperty("listen-port"))); |
| | |
| | | * |
| | | * @throws NumberFormatException |
| | | * @throws GeneralSecurityException |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test() |
| | | public void testLDAPSASLBind() throws NumberFormatException, GeneralSecurityException, |
| | | ErrorResultException { |
| | | public void testLDAPSASLBind() throws NumberFormatException, GeneralSecurityException, LdapException { |
| | | LDAPConnectionFactory factory = |
| | | new LDAPConnectionFactory("localhost", |
| | | Integer.valueOf(CONFIG_PROPERTIES.getProperty("listen-port"))); |
| | |
| | | /** |
| | | * Tests an SASL connection with the adapter. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test() |
| | | public void testAdapterConnectionSASLBindRequest() throws ErrorResultException, |
| | | public void testAdapterConnectionSASLBindRequest() throws LdapException, |
| | | GeneralSecurityException { |
| | | final Connection connection = Adapters.newRootConnection(); |
| | | |
| | |
| | | * This type of connection is not supported. Anonymous SASL Mechanisms is |
| | | * disabled in the config.ldif file. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "anonymousConnectionFactories", |
| | | expectedExceptions = ErrorResultException.class) |
| | | public void testConnectionAnonymousSASLBindRequest(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | @Test(dataProvider = "anonymousConnectionFactories", expectedExceptions = LdapException.class) |
| | | public void testConnectionAnonymousSASLBindRequest(final ConnectionFactory factory) throws LdapException { |
| | | final Connection connection = factory.getConnection(); |
| | | try { |
| | | connection.bind(Requests.newAnonymousSASLBindRequest("anonymousSASLBindRequest")); |
| | |
| | | * Performs a search with a sub entries request control. Sub-entries are |
| | | * included and the normal entries are excluded. No result expected. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws ErrorResultIOException |
| | | * @throws LdapException |
| | | * @throws SearchResultReferenceIOException |
| | | */ |
| | | @Test(dataProvider = "rootConnectionFactories", |
| | | expectedExceptions = NoSuchElementException.class) |
| | | public void testAdapterSearchRequestSubEntriesWithNoResult(final ConnectionFactory factory) |
| | | throws ErrorResultException, ErrorResultIOException, SearchResultReferenceIOException { |
| | | throws LdapException, SearchResultReferenceIOException { |
| | | final Connection connection = factory.getConnection(); |
| | | try { |
| | | final SearchRequest request = |
| | |
| | | * Performs a search with a sub entries request control. Sub-entries are |
| | | * excluded this time and the normal entries are included. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws ErrorResultIOException |
| | | * @throws LdapException |
| | | * @throws SearchResultReferenceIOException |
| | | */ |
| | | @Test(dataProvider = "rootConnectionFactories") |
| | | public void testAdapterSearchRequestSubEntries(final ConnectionFactory factory) |
| | | throws ErrorResultException, ErrorResultIOException, SearchResultReferenceIOException { |
| | | throws LdapException, SearchResultReferenceIOException { |
| | | final Connection connection = factory.getConnection(); |
| | | |
| | | final SearchRequest request = |
| | |
| | | /** |
| | | * Deletes an inexistent entry. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "rootConnectionFactories", |
| | | expectedExceptions = EntryNotFoundException.class) |
| | | public void testAdapterDeleteRequestNoSuchEntry(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | public void testAdapterDeleteRequestNoSuchEntry(final ConnectionFactory factory) throws LdapException { |
| | | final DeleteRequest deleteRequest = Requests.newDeleteRequest("cn=test"); |
| | | final Connection connection = factory.getConnection(); |
| | | try { |
| | |
| | | /** |
| | | * Deletes an existing entry with the 'no-op' control. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "rootConnectionFactories") |
| | | public void testAdapterDeleteRequestNoOpControl(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | public void testAdapterDeleteRequestNoOpControl(final ConnectionFactory factory) throws LdapException { |
| | | final DeleteRequest deleteRequest = |
| | | Requests.newDeleteRequest("uid=user.1, dc=example,dc=org") |
| | | // The no-op control is specified with his OID. |
| | |
| | | /** |
| | | * Deletes an existing entry. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test() |
| | | public void testAdapterDeleteRequest() throws ErrorResultException { |
| | | public void testAdapterDeleteRequest() throws LdapException { |
| | | |
| | | final Connection connection = Adapters.newRootConnection(); |
| | | // Checks if the entry exists. |
| | |
| | | /** |
| | | * Modifies an existing entry. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | * @throws DecodeException |
| | | */ |
| | | @Test() |
| | | public void testAdapterModifyRequest() throws ErrorResultException, DecodeException { |
| | | public void testAdapterModifyRequest() throws LdapException, DecodeException { |
| | | |
| | | final ModifyRequest changeRequest = |
| | | Requests.newModifyRequest("uid=user.2, dc=example,dc=org").addControl( |
| | |
| | | * Tries to modify the existing entry with the same values but using the |
| | | * permissive modify control. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "rootConnectionFactories") |
| | | public void testAdapterUsePermissiveModifyRequest(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | public void testAdapterUsePermissiveModifyRequest(final ConnectionFactory factory) throws LdapException { |
| | | |
| | | final ModifyRequest changeRequest = |
| | | Requests.newModifyRequest("uid=user.2, dc=example,dc=org").addControl( |
| | |
| | | /** |
| | | * Tries to modify the existing entry with the same values. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "rootConnectionFactories", |
| | | expectedExceptions = ConstraintViolationException.class) |
| | | public void testAdapterModifyRequestFails(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | |
| | | public void testAdapterModifyRequestFails(final ConnectionFactory factory) throws LdapException { |
| | | final ModifyRequest changeRequest = |
| | | Requests.newModifyRequest("uid=user.2, dc=example,dc=org").addModification( |
| | | ModificationType.ADD, "uid", "user.2"); |
| | |
| | | /** |
| | | * Modifies the DN. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "rootConnectionFactories") |
| | | public void testAdapterModifyDNRequest(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | public void testAdapterModifyDNRequest(final ConnectionFactory factory) throws LdapException { |
| | | final Connection connection = factory.getConnection(); |
| | | |
| | | // Verifies that entry has been correctly modified. |
| | |
| | | /** |
| | | * Compare request. The comparison returns true. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "rootConnectionFactories") |
| | | public void testAdapterCompareRequestTrue(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | |
| | | public void testAdapterCompareRequestTrue(final ConnectionFactory factory) throws LdapException { |
| | | final CompareRequest compareRequest = |
| | | Requests.newCompareRequest("uid=user.0,dc=example,dc=org", "uid", "user.0"); |
| | | |
| | |
| | | /** |
| | | * Compare request. The comparison returns false. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "rootConnectionFactories") |
| | | public void testAdapterCompareRequestFalse(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | |
| | | public void testAdapterCompareRequestFalse(final ConnectionFactory factory) throws LdapException { |
| | | final CompareRequest compareRequest = |
| | | Requests.newCompareRequest("uid=user.0,dc=example,dc=org", "uid", "scarter"); |
| | | |
| | |
| | | /** |
| | | * Use the Who Am I? extended request. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "rootConnectionFactories") |
| | | public void testAdapterExtendedOperation(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | public void testAdapterExtendedOperation(final ConnectionFactory factory) throws LdapException { |
| | | final WhoAmIExtendedRequest request = Requests.newWhoAmIExtendedRequest(); |
| | | final Connection connection = factory.getConnection(); |
| | | try { |
| | |
| | | * If an anonymous tries to delete, sends a result code : insufficient |
| | | * access rights. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "anonymousConnectionFactories", |
| | | expectedExceptions = AuthorizationException.class) |
| | | public void testAdapterAsAnonymousCannotPerformDeleteRequest(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | |
| | | final DeleteRequest deleteRequest = |
| | | Requests.newDeleteRequest("uid=user.2,dc=example,dc=org"); |
| | |
| | | * If an anonymous tries to do an add request, sends a result code : |
| | | * insufficient access rights. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "anonymousConnectionFactories", |
| | | expectedExceptions = AuthorizationException.class) |
| | | public void testAdapterAsAnonymousCannotPerformAddRequest(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | |
| | | // @formatter:off |
| | | final AddRequest addRequest = Requests.newAddRequest( |
| | |
| | | * If an anonymous tries to do a modify DN request, sends a result code : |
| | | * insufficient access rights. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "anonymousConnectionFactories", |
| | | expectedExceptions = AuthorizationException.class) |
| | | public void testAdapterAsAnonymousCannotPerformModifyDNRequest(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | |
| | | final Connection connection = factory.getConnection(); |
| | | |
| | |
| | | * If an anonymous tries to do a modify request, sends a result code : |
| | | * insufficient access rights. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "anonymousConnectionFactories", |
| | | expectedExceptions = ErrorResultException.class) |
| | | expectedExceptions = LdapException.class) |
| | | public void testAdapterAsAnonymousCannotPerformModifyRequest(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | |
| | | final ModifyRequest changeRequest = |
| | | Requests.newModifyRequest("uid=user.2,dc=example,dc=org").addControl( |
| | |
| | | /** |
| | | * The anonymous connection is allowed to perform compare request. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws LdapException |
| | | */ |
| | | @Test(dataProvider = "anonymousConnectionFactories") |
| | | public void testAdapterAsAnonymousPerformsCompareRequest(final ConnectionFactory factory) |
| | | throws ErrorResultException { |
| | | throws LdapException { |
| | | |
| | | final CompareRequest compareRequest = |
| | | Requests.newCompareRequest("uid=user.0,dc=example,dc=org", "uid", "user.0"); |
| | |
| | | * |
| | | * @throws Exception |
| | | */ |
| | | @Test(dataProvider = "anonymousConnectionFactories", |
| | | expectedExceptions = ErrorResultIOException.class) |
| | | @Test(dataProvider = "anonymousConnectionFactories", expectedExceptions = LdapException.class) |
| | | public void testAdapterAsAnonymousCannotPerformSearchRequestWithControl( |
| | | final ConnectionFactory factory) throws Exception { |
| | | final Connection connection = factory.getConnection(); |
| | |
| | | * add/delete/search and compare results with an SDK adapter connection |
| | | * doing the same. |
| | | * |
| | | * @throws ErrorResultException |
| | | * @throws ErrorResultIOException |
| | | * @throws LdapException |
| | | * @throws SearchResultReferenceIOException |
| | | */ |
| | | @Test() |
| | | public void testLDAPConnectionAndAdapterComparison() throws ErrorResultException, |
| | | ErrorResultIOException, SearchResultReferenceIOException { |
| | | |
| | | public void testLDAPConnectionAndAdapterComparison() throws LdapException, SearchResultReferenceIOException { |
| | | // @formatter:off |
| | | final AddRequest addRequest = Requests.newAddRequest( |
| | | "dn: sn=babs,dc=example,dc=org", |
| | |
| | | assertThat(entry.getName().toString()).isEqualTo(sdkEntry.getName().toString()); |
| | | assertThat(entry.getAttributeCount()).isEqualTo(sdkEntry.getAttributeCount()); |
| | | assertThat(entry.getAllAttributes().iterator().next().getAttributeDescription()) |
| | | .isEqualTo( |
| | | sdkEntry.getAllAttributes().iterator().next().getAttributeDescription()); |
| | | .isEqualTo(sdkEntry.getAllAttributes().iterator().next().getAttributeDescription()); |
| | | assertThat(entry.getControls().size()).isEqualTo(sdkEntry.getControls().size()); |
| | | } |
| | | } |