use of com.unboundid.ldap.sdk.ResultCode in project oxCore by GluuFederation.
the class LdifDataUtility method validateLDIF.
public ResultCode validateLDIF(LDIFReader ldifReader, String dn) {
String baseDn = dn.toLowerCase();
ResultCode resultCode = ResultCode.SUCCESS;
while (true) {
// Read the next change to process
LDIFChangeRecord ldifRecord = null;
try {
ldifRecord = ldifReader.readChangeRecord(true);
if (ldifRecord != null) {
if (StringHelper.isNotEmpty(baseDn)) {
if (!ldifRecord.getDN().toLowerCase().endsWith(baseDn)) {
resultCode = ResultCode.NOT_SUPPORTED;
break;
}
}
}
} catch (LDIFException le) {
log.info("Malformed ldif record " + ldifRecord);
log.error("Malformed ldif record", le);
resultCode = ResultCode.DECODING_ERROR;
break;
} catch (IOException ioe) {
log.error("I/O error encountered while reading a change record", ioe);
resultCode = ResultCode.LOCAL_ERROR;
break;
}
// changes to be processed.
if (ldifRecord == null) {
break;
}
}
return resultCode;
}
use of com.unboundid.ldap.sdk.ResultCode in project zm-mailbox by Zimbra.
the class UBIDLdapException method mapToExternalLdapException.
// need more precise mapping for external LDAP exceptions so we
// can report config error better
static LdapException mapToExternalLdapException(String message, LDAPException e) {
Throwable cause = e.getCause();
ResultCode rc = e.getResultCode();
// the LdapException instance to return
LdapException ldapException = mapToLdapException(message, e);
if (cause instanceof IOException) {
// Unboundid hides the original IOException and throws a
// generic IOException. This doesn't work with check.toResult(IOException).
// Do our best to figure out the original IOException and set it
// in the detail field. Very hacky!
//
// Seems the root exception can be found in the message of the IOException
// thrown by Unboundi.
//
// e.g. An error occurred while attempting to establish a connection to server bogus:389: java.net.UnknownHostException: bogus
IOException ioException = (IOException) cause;
String causeMsg = ioException.getMessage();
IOException rootException = null;
if (causeMsg != null) {
//
if (causeMsg.contains("java.net.UnknownHostException")) {
rootException = new java.net.UnknownHostException(causeMsg);
} else if (causeMsg.contains("java.net.ConnectException")) {
rootException = new java.net.ConnectException(causeMsg);
} else if (causeMsg.contains("javax.net.ssl.SSLHandshakeException")) {
rootException = new javax.net.ssl.SSLHandshakeException(causeMsg);
}
}
if (rootException != null) {
ldapException.setDetail(rootException);
} else {
ldapException.setDetail(cause);
}
} else {
String causeMsg = e.getMessage();
Throwable rootException = null;
if (causeMsg.contains("unsupported extended operation")) {
// most likely startTLS failed, for backward compatibility with check.toResult,
// return a generic IOException
rootException = new IOException(causeMsg);
} else {
// just map using the regular mapping
rootException = mapToLdapException(message, e);
}
ldapException.setDetail(rootException);
}
return ldapException;
}
Aggregations