use of com.unboundid.ldap.sdk.LDAPException in project oxAuth by GluuFederation.
the class InumGenerator method contains.
public boolean contains(String inum, IdType type) {
final String baseDn = baseDn(type);
try {
final Filter filter = Filter.create(String.format("inum=%s", inum));
final List<LdapDummyEntry> entries = ldapEntryManager.findEntries(baseDn, LdapDummyEntry.class, filter);
return entries != null && !entries.isEmpty();
} catch (LDAPException e) {
log.error(e.getMessage(), e);
}
return false;
}
use of com.unboundid.ldap.sdk.LDAPException in project oxAuth by GluuFederation.
the class LdapUtils method createAnyFilterFromDnList.
/**
* Creates any filter to load all objects represented by this dn list.
*
* @param p_filterAttributeName filter attribute name
* @param p_dnList dn list
* @return filter
*/
public static Filter createAnyFilterFromDnList(String p_filterAttributeName, List<String> p_dnList) {
try {
if (p_dnList != null && !p_dnList.isEmpty()) {
final StringBuilder sb = new StringBuilder("(|");
for (String dn : p_dnList) {
final DN dnObj = new DN(dn);
final RDN rdn = dnObj.getRDN();
if (rdn.getAttributeNames()[0].equals(p_filterAttributeName)) {
final String[] values = rdn.getAttributeValues();
if (values != null && values.length == 1) {
sb.append("(");
sb.append(p_filterAttributeName).append("=");
sb.append(values[0]);
sb.append(")");
}
}
}
sb.append(")");
final String filterAsString = sb.toString();
log.trace("dnList: " + p_dnList + ", ldapFilter: " + filterAsString);
return Filter.create(filterAsString);
}
} catch (LDAPException e) {
log.trace(e.getMessage(), e);
}
return null;
}
use of com.unboundid.ldap.sdk.LDAPException in project oxTrust by GluuFederation.
the class LdifService method validateLdifFile.
public ResultCode validateLdifFile(InputStream is, String dn) throws LDAPException {
ResultCode result = ResultCode.UNAVAILABLE;
try {
LdifDataUtility ldifDataUtility = LdifDataUtility.instance();
LDIFReader validateLdifReader = new LDIFReader(is);
result = ldifDataUtility.validateLDIF(validateLdifReader, dn);
validateLdifReader.close();
} catch (Exception ex) {
log.error("Failed to validate ldif file: ", ex);
}
return result;
}
use of com.unboundid.ldap.sdk.LDAPException in project oxTrust by GluuFederation.
the class LdifService method importLdifFileInLdap.
public ResultCode importLdifFileInLdap(InputStream is) throws LDAPException {
ResultCode result = ResultCode.UNAVAILABLE;
LDAPConnection connection = ldapEntryManager.getOperationService().getConnection();
try {
LdifDataUtility ldifDataUtility = LdifDataUtility.instance();
LDIFReader importLdifReader = new LDIFReader(is);
result = ldifDataUtility.importLdifFile(connection, importLdifReader);
importLdifReader.close();
} catch (Exception ex) {
log.error("Failed to import ldif file: ", ex);
} finally {
ldapEntryManager.getOperationService().releaseConnection(connection);
}
return result;
}
use of com.unboundid.ldap.sdk.LDAPException 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;
}
Aggregations