Search in sources :

Example 1 with LDIFException

use of com.unboundid.ldif.LDIFException in project oxCore by GluuFederation.

the class LdifDataUtility method checkIfSerrverHasEntryFromLDIFFile.

/**
	 * Check if DS has at least one DN simular to specified in ldif file.
	 * 
	 * @param connection
	 *            Connection to LDAP server
	 * @param ldifFileName
	 *            LDIF file
	 * @return true if server contains at least one DN simular to specified in
	 *         ldif file.
	 */
public boolean checkIfSerrverHasEntryFromLDIFFile(LDAPConnection connection, String ldifFileName) {
    // Set up the LDIF reader that will be used to read the changes to apply
    LDIFReader ldifReader = createLdifReader(ldifFileName);
    if (ldifReader == null) {
        return true;
    }
    // Check all ldif entries
    while (true) {
        // Read the next change to process.
        Entry entry = null;
        try {
            entry = ldifReader.readEntry();
        } catch (LDIFException le) {
            log.error("Malformed ldif record", le);
            if (!le.mayContinueReading()) {
                return true;
            }
        } catch (IOException ioe) {
            log.error("I/O error encountered while reading a change record", ioe);
            return true;
        }
        // changes to be processed.
        if (entry == null) {
            break;
        }
        // Search entry in the server.
        try {
            SearchResult sr = connection.search(entry.getDN(), SearchScope.BASE, "objectClass=*");
            if ((sr != null) && (sr.getEntryCount() > 0)) {
                return true;
            }
        } catch (LDAPException le) {
            if (le.getResultCode() != ResultCode.NO_SUCH_OBJECT) {
                log.error("Failed to search ldif record", le);
                return true;
            }
        }
    }
    disposeLdifReader(ldifReader);
    return false;
}
Also used : Entry(com.unboundid.ldap.sdk.Entry) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry) LDAPException(com.unboundid.ldap.sdk.LDAPException) LDIFReader(com.unboundid.ldif.LDIFReader) LDIFException(com.unboundid.ldif.LDIFException) SearchResult(com.unboundid.ldap.sdk.SearchResult) IOException(java.io.IOException)

Example 2 with LDIFException

use of com.unboundid.ldif.LDIFException 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)

Aggregations

LDIFException (com.unboundid.ldif.LDIFException)2 IOException (java.io.IOException)2 Entry (com.unboundid.ldap.sdk.Entry)1 LDAPException (com.unboundid.ldap.sdk.LDAPException)1 ResultCode (com.unboundid.ldap.sdk.ResultCode)1 SearchResult (com.unboundid.ldap.sdk.SearchResult)1 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)1 LDIFChangeRecord (com.unboundid.ldif.LDIFChangeRecord)1 LDIFReader (com.unboundid.ldif.LDIFReader)1