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