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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations