Search in sources :

Example 26 with LdapException

use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.

the class ModifyRequestTest method testRequestWithModificationWithEmptyValue.

/**
 * Test parsing of a request with a Modification element with an empty value
 * @throws NamingException
 */
@Test
public void testRequestWithModificationWithEmptyValue() throws LdapException {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(ModifyRequestTest.class.getResource("request_with_modification_with_empty_value.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    ModifyRequest modifyRequest = (ModifyRequest) parser.getBatchRequest().getCurrentRequest();
    Collection<Modification> modifications = modifyRequest.getModifications();
    assertEquals(1, modifications.size());
    Modification modification = modifications.iterator().next();
    assertEquals(ModificationOperation.ADD_ATTRIBUTE, modification.getOperation());
    Attribute attribute = modification.getAttribute();
    assertEquals("directreport", attribute.getId());
    assertEquals(1, attribute.size());
    assertEquals("", attribute.get().getValue());
}
Also used : Modification(org.apache.directory.api.ldap.model.entry.Modification) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 27 with LdapException

use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.

the class LdapNetworkConnection method bind.

/**
 * Bind to the server using a CramMd5Request object.
 *
 * @param request The CramMd5Request POJO containing all the needed parameters
 * @return A LdapResponse containing the result
 * @throws LdapException if some error occurred
 */
public BindResponse bind(SaslCramMd5Request request) throws LdapException {
    if (request == null) {
        String msg = I18n.msg(I18n.MSG_03204_NULL_REQUEST);
        LOG.debug(msg);
        throw new IllegalArgumentException(msg);
    }
    BindFuture bindFuture = bindAsync(request);
    // Get the result from the future
    try {
        // Read the response, waiting for it if not available immediately
        // Get the response, blocking
        BindResponse bindResponse = bindFuture.get(timeout, TimeUnit.MILLISECONDS);
        if (bindResponse == null) {
            // We didn't received anything : this is an error
            if (LOG.isErrorEnabled()) {
                LOG.error(I18n.err(I18n.ERR_03203_OP_FAILED_TIMEOUT, "Bind"));
            }
            throw new LdapException(TIME_OUT_ERROR);
        }
        if (bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS) {
            authenticated.set(true);
            // Everything is fine, return the response
            if (LOG.isDebugEnabled()) {
                LOG.debug(I18n.msg(I18n.MSG_03202_BIND_SUCCESSFUL, bindResponse));
            }
        } else {
            // We have had an error
            if (LOG.isDebugEnabled()) {
                LOG.debug(I18n.msg(I18n.MSG_03201_BIND_FAIL, bindResponse));
            }
        }
        return bindResponse;
    } catch (Exception ie) {
        // Catch all other exceptions
        LOG.error(NO_RESPONSE_ERROR, ie);
        throw new LdapException(NO_RESPONSE_ERROR, ie);
    }
}
Also used : BindFuture(org.apache.directory.ldap.client.api.future.BindFuture) BindResponse(org.apache.directory.api.ldap.model.message.BindResponse) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException) InvalidConnectionException(org.apache.directory.ldap.client.api.exception.InvalidConnectionException) LdapOperationException(org.apache.directory.api.ldap.model.exception.LdapOperationException) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) MessageEncoderException(org.apache.directory.api.ldap.codec.api.MessageEncoderException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) DecoderException(org.apache.directory.api.asn1.DecoderException) LdapNoPermissionException(org.apache.directory.api.ldap.model.exception.LdapNoPermissionException) LdapOtherException(org.apache.directory.api.ldap.model.exception.LdapOtherException) ProtocolEncoderException(org.apache.mina.filter.codec.ProtocolEncoderException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 28 with LdapException

use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.

the class LdapNetworkConnection method extended.

/**
 * {@inheritDoc}
 */
@Override
public ExtendedResponse extended(ExtendedRequest extendedRequest) throws LdapException {
    if (extendedRequest == null) {
        String msg = "Cannot process a null extendedRequest";
        LOG.debug(msg);
        throw new IllegalArgumentException(msg);
    }
    ExtendedFuture extendedFuture = extendedAsync(extendedRequest);
    // Get the result from the future
    try {
        // Read the response, waiting for it if not available immediately
        // Get the response, blocking
        ExtendedResponse response = (ExtendedResponse) extendedFuture.get(timeout, TimeUnit.MILLISECONDS);
        if (response == null) {
            // We didn't received anything : this is an error
            if (LOG.isErrorEnabled()) {
                LOG.error(I18n.err(I18n.ERR_03203_OP_FAILED_TIMEOUT, "Extended"));
            }
            throw new LdapException(TIME_OUT_ERROR);
        }
        if (response.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS) {
            // Everything is fine, return the response
            if (LOG.isDebugEnabled()) {
                LOG.debug(I18n.msg(I18n.MSG_03219_EXTENDED_SUCCESSFUL, response));
            }
        } else {
            // We have had an error
            if (LOG.isDebugEnabled()) {
                LOG.debug(I18n.msg(I18n.MSG_03218_EXTENDED_FAILED, response));
            }
        }
        // Get back the response. It's still an opaque response
        if (Strings.isEmpty(response.getResponseName())) {
            response.setResponseName(extendedRequest.getRequestName());
        }
        // Decode the payload now
        return codec.decorate(response);
    } catch (Exception ie) {
        // Catch all other exceptions
        LOG.error(NO_RESPONSE_ERROR, ie);
        // Send an abandon request
        if (!extendedFuture.isCancelled()) {
            abandon(extendedRequest.getMessageId());
        }
        throw new LdapException(NO_RESPONSE_ERROR, ie);
    }
}
Also used : ExtendedResponse(org.apache.directory.api.ldap.model.message.ExtendedResponse) ExtendedFuture(org.apache.directory.ldap.client.api.future.ExtendedFuture) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException) InvalidConnectionException(org.apache.directory.ldap.client.api.exception.InvalidConnectionException) LdapOperationException(org.apache.directory.api.ldap.model.exception.LdapOperationException) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) MessageEncoderException(org.apache.directory.api.ldap.codec.api.MessageEncoderException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) DecoderException(org.apache.directory.api.asn1.DecoderException) LdapNoPermissionException(org.apache.directory.api.ldap.model.exception.LdapNoPermissionException) LdapOtherException(org.apache.directory.api.ldap.model.exception.LdapOtherException) ProtocolEncoderException(org.apache.mina.filter.codec.ProtocolEncoderException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 29 with LdapException

use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.

the class LdapNetworkConnection method delete.

/**
 * {@inheritDoc}
 */
@Override
public DeleteResponse delete(DeleteRequest deleteRequest) throws LdapException {
    if (deleteRequest == null) {
        String msg = "Cannot process a null deleteRequest";
        LOG.debug(msg);
        throw new IllegalArgumentException(msg);
    }
    DeleteFuture deleteFuture = deleteAsync(deleteRequest);
    // Get the result from the future
    try {
        // Read the response, waiting for it if not available immediately
        // Get the response, blocking
        DeleteResponse delResponse = deleteFuture.get(timeout, TimeUnit.MILLISECONDS);
        if (delResponse == null) {
            // We didn't received anything : this is an error
            if (LOG.isErrorEnabled()) {
                LOG.error(I18n.err(I18n.ERR_03203_OP_FAILED_TIMEOUT, "Delete"));
            }
            throw new LdapException(TIME_OUT_ERROR);
        }
        if (delResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS) {
            // Everything is fine, return the response
            if (LOG.isDebugEnabled()) {
                LOG.debug(I18n.msg(I18n.MSG_03217_DELETE_SUCCESSFUL, delResponse));
            }
        } else {
            // We have had an error
            if (LOG.isDebugEnabled()) {
                LOG.debug(I18n.msg(I18n.MSG_03216_DELETE_FAILED, delResponse));
            }
        }
        return delResponse;
    } catch (Exception ie) {
        // Catch all other exceptions
        LOG.error(NO_RESPONSE_ERROR, ie);
        // Send an abandon request
        if (!deleteFuture.isCancelled()) {
            abandon(deleteRequest.getMessageId());
        }
        throw new LdapException(NO_RESPONSE_ERROR, ie);
    }
}
Also used : DeleteFuture(org.apache.directory.ldap.client.api.future.DeleteFuture) DeleteResponse(org.apache.directory.api.ldap.model.message.DeleteResponse) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException) InvalidConnectionException(org.apache.directory.ldap.client.api.exception.InvalidConnectionException) LdapOperationException(org.apache.directory.api.ldap.model.exception.LdapOperationException) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) MessageEncoderException(org.apache.directory.api.ldap.codec.api.MessageEncoderException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) DecoderException(org.apache.directory.api.asn1.DecoderException) LdapNoPermissionException(org.apache.directory.api.ldap.model.exception.LdapNoPermissionException) LdapOtherException(org.apache.directory.api.ldap.model.exception.LdapOtherException) ProtocolEncoderException(org.apache.mina.filter.codec.ProtocolEncoderException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 30 with LdapException

use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.

the class LdapNetworkConnection method modifyDn.

/**
 * {@inheritDoc}
 */
@Override
public ModifyDnResponse modifyDn(ModifyDnRequest modDnRequest) throws LdapException {
    if (modDnRequest == null) {
        String msg = "Cannot process a null modDnRequest";
        LOG.debug(msg);
        throw new IllegalArgumentException(msg);
    }
    ModifyDnFuture modifyDnFuture = modifyDnAsync(modDnRequest);
    // Get the result from the future
    try {
        // Read the response, waiting for it if not available immediately
        // Get the response, blocking
        ModifyDnResponse modifyDnResponse = modifyDnFuture.get(timeout, TimeUnit.MILLISECONDS);
        if (modifyDnResponse == null) {
            // We didn't received anything : this is an error
            if (LOG.isErrorEnabled()) {
                LOG.error(I18n.err(I18n.ERR_03203_OP_FAILED_TIMEOUT, "ModifyDn"));
            }
            throw new LdapException(TIME_OUT_ERROR);
        }
        if (modifyDnResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS) {
            // Everything is fine, return the response
            if (LOG.isDebugEnabled()) {
                LOG.debug(I18n.msg(I18n.MSG_03226_MODIFYDN_SUCCESSFUL, modifyDnResponse));
            }
        } else {
            // We have had an error
            if (LOG.isDebugEnabled()) {
                LOG.debug(I18n.msg(I18n.MSG_03225_MODIFYDN_FAILED, modifyDnResponse));
            }
        }
        return modifyDnResponse;
    } catch (Exception ie) {
        // Catch all other exceptions
        LOG.error(NO_RESPONSE_ERROR, ie);
        // Send an abandon request
        if (!modifyDnFuture.isCancelled()) {
            abandon(modDnRequest.getMessageId());
        }
        throw new LdapException(NO_RESPONSE_ERROR, ie);
    }
}
Also used : ModifyDnResponse(org.apache.directory.api.ldap.model.message.ModifyDnResponse) ModifyDnFuture(org.apache.directory.ldap.client.api.future.ModifyDnFuture) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException) InvalidConnectionException(org.apache.directory.ldap.client.api.exception.InvalidConnectionException) LdapOperationException(org.apache.directory.api.ldap.model.exception.LdapOperationException) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) MessageEncoderException(org.apache.directory.api.ldap.codec.api.MessageEncoderException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) DecoderException(org.apache.directory.api.asn1.DecoderException) LdapNoPermissionException(org.apache.directory.api.ldap.model.exception.LdapNoPermissionException) LdapOtherException(org.apache.directory.api.ldap.model.exception.LdapOtherException) ProtocolEncoderException(org.apache.mina.filter.codec.ProtocolEncoderException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Aggregations

LdapException (org.apache.directory.api.ldap.model.exception.LdapException)329 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)159 ArrayList (java.util.ArrayList)93 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)91 FinderException (org.apache.directory.fortress.core.FinderException)73 Entry (org.apache.directory.api.ldap.model.entry.Entry)63 Modification (org.apache.directory.api.ldap.model.entry.Modification)63 IOException (java.io.IOException)54 SearchCursor (org.apache.directory.api.ldap.model.cursor.SearchCursor)51 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)50 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)49 UpdateException (org.apache.directory.fortress.core.UpdateException)41 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)35 Dn (org.apache.directory.api.ldap.model.name.Dn)34 LdapAuthenticationException (org.apache.directory.api.ldap.model.exception.LdapAuthenticationException)25 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)25 DecoderException (org.apache.directory.api.asn1.DecoderException)22 LdapNoPermissionException (org.apache.directory.api.ldap.model.exception.LdapNoPermissionException)22 LdapOtherException (org.apache.directory.api.ldap.model.exception.LdapOtherException)22 ConnectException (java.net.ConnectException)21