Search in sources :

Example 6 with ResultCode

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;
}
Also used : LDIFChangeRecord(com.unboundid.ldif.LDIFChangeRecord) LDIFException(com.unboundid.ldif.LDIFException) IOException(java.io.IOException) ResultCode(com.unboundid.ldap.sdk.ResultCode)

Example 7 with 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;
}
Also used : IOException(java.io.IOException) LdapException(com.zimbra.cs.ldap.LdapException) ResultCode(com.unboundid.ldap.sdk.ResultCode)

Aggregations

ResultCode (com.unboundid.ldap.sdk.ResultCode)7 LDAPException (com.unboundid.ldap.sdk.LDAPException)5 IOException (java.io.IOException)4 LDIFReader (com.unboundid.ldif.LDIFReader)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 LdifDataUtility (org.gluu.site.ldap.persistence.LdifDataUtility)2 LdapMappingException (org.gluu.site.ldap.persistence.exception.LdapMappingException)2 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)1 LDAPSearchException (com.unboundid.ldap.sdk.LDAPSearchException)1 SearchResult (com.unboundid.ldap.sdk.SearchResult)1 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)1 LDIFChangeRecord (com.unboundid.ldif.LDIFChangeRecord)1 LDIFException (com.unboundid.ldif.LDIFException)1 LdapException (com.zimbra.cs.ldap.LdapException)1 LinkedList (java.util.LinkedList)1