Search in sources :

Example 46 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 47 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 48 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)

Example 49 with LdapException

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

the class LdapNetworkConnection method bindAsync.

/**
 * Do an asynchronous bind, based on a GssApiRequest.
 *
 * @param request The GssApiRequest POJO containing all the needed parameters
 * @return The bind operation's future
 * @throws LdapException if some error occurred
 */
public BindFuture bindAsync(SaslGssApiRequest request) throws LdapException {
    // Krb5.conf file
    if (request.getKrb5ConfFilePath() != null) {
        // Using the krb5.conf file provided by the user
        System.setProperty(KRB5_CONF, request.getKrb5ConfFilePath());
    } else if ((request.getRealmName() != null) && (request.getKdcHost() != null) && (request.getKdcPort() != 0)) {
        try {
            // Using a custom krb5.conf we create from the settings provided by the user
            String krb5ConfPath = createKrb5ConfFile(request.getRealmName(), request.getKdcHost(), request.getKdcPort());
            System.setProperty(KRB5_CONF, krb5ConfPath);
        } catch (IOException ioe) {
            throw new LdapException(ioe);
        }
    } else {
        // Using the system Kerberos configuration
        System.clearProperty(KRB5_CONF);
    }
    // Login Module configuration
    if (request.getLoginModuleConfiguration() != null) {
        // Using the configuration provided by the user
        Configuration.setConfiguration(request.getLoginModuleConfiguration());
    } else {
        // Using the default configuration
        Configuration.setConfiguration(new Krb5LoginConfiguration());
    }
    try {
        System.setProperty("javax.security.auth.useSubjectCredsOnly", "true");
        LoginContext loginContext = new LoginContext(request.getLoginContextName(), new SaslCallbackHandler(request));
        loginContext.login();
        final SaslGssApiRequest requetFinal = request;
        return (BindFuture) Subject.doAs(loginContext.getSubject(), new PrivilegedExceptionAction<Object>() {

            @Override
            public Object run() throws Exception {
                return bindSasl(requetFinal);
            }
        });
    } catch (Exception e) {
        throw new LdapException(e);
    }
}
Also used : LoginContext(javax.security.auth.login.LoginContext) SaslCallbackHandler(org.apache.directory.ldap.client.api.callback.SaslCallbackHandler) IOException(java.io.IOException) BindFuture(org.apache.directory.ldap.client.api.future.BindFuture) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) 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 50 with LdapException

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

the class LdapNetworkConnection method add.

/**
 * {@inheritDoc}
 */
@Override
public AddResponse add(AddRequest addRequest) throws LdapException {
    if (addRequest == null) {
        String msg = "Cannot process a null addRequest";
        LOG.debug(msg);
        throw new IllegalArgumentException(msg);
    }
    if (addRequest.getEntry() == null) {
        String msg = "Cannot add a null entry";
        LOG.debug(msg);
        throw new IllegalArgumentException(msg);
    }
    AddFuture addFuture = addAsync(addRequest);
    // Get the result from the future
    try {
        // Read the response, waiting for it if not available immediately
        // Get the response, blocking
        AddResponse addResponse = addFuture.get(timeout, TimeUnit.MILLISECONDS);
        if (addResponse == null) {
            // We didn't received anything : this is an error
            if (LOG.isErrorEnabled()) {
                LOG.error(I18n.err(I18n.ERR_03203_OP_FAILED_TIMEOUT, "Add"));
            }
            throw new LdapException(TIME_OUT_ERROR);
        }
        if (addResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS) {
            // Everything is fine, return the response
            if (LOG.isDebugEnabled()) {
                LOG.debug(I18n.msg(I18n.MSG_03209_ADD_SUCCESSFUL, addResponse));
            }
        } else {
            // We have had an error
            if (LOG.isDebugEnabled()) {
                LOG.debug(I18n.msg(I18n.MSG_03208_ADD_FAILED, addResponse));
            }
        }
        return addResponse;
    } catch (Exception ie) {
        // Catch all other exceptions
        LOG.error(NO_RESPONSE_ERROR, ie);
        // Send an abandon request
        if (!addFuture.isCancelled()) {
            abandon(addRequest.getMessageId());
        }
        throw new LdapException(NO_RESPONSE_ERROR, ie);
    }
}
Also used : AddFuture(org.apache.directory.ldap.client.api.future.AddFuture) AddResponse(org.apache.directory.api.ldap.model.message.AddResponse) 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)361 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)161 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)111 ArrayList (java.util.ArrayList)94 FinderException (org.apache.directory.fortress.core.FinderException)73 Modification (org.apache.directory.api.ldap.model.entry.Modification)70 Entry (org.apache.directory.api.ldap.model.entry.Entry)68 IOException (java.io.IOException)57 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)57 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)53 SearchCursor (org.apache.directory.api.ldap.model.cursor.SearchCursor)51 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 SEPASecurityException (it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException)29 LdapAuthenticationException (org.apache.directory.api.ldap.model.exception.LdapAuthenticationException)25 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)25 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)23 DecoderException (org.apache.directory.api.asn1.DecoderException)22 LdapNoPermissionException (org.apache.directory.api.ldap.model.exception.LdapNoPermissionException)22