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;
}
use of com.unboundid.ldap.sdk.LDAPException in project oxCore by GluuFederation.
the class LdifDataUtility method deleteEntryWithAllSubs.
/**
* Remove base entry with all sub entries
*
* @param connection
* Connection to LDAP server
* @param baseDN
* Base DN entry
* @return The result code for the processing that was performed.
*/
public ResultCode deleteEntryWithAllSubs(LDAPConnection connection, String baseDN) {
ResultCode resultCode = ResultCode.SUCCESS;
SearchResult searchResult = null;
try {
searchResult = connection.search(baseDN, SearchScope.SUB, "objectClass=*");
if ((searchResult == null) || (searchResult.getEntryCount() == 0)) {
return ResultCode.LOCAL_ERROR;
}
} catch (LDAPSearchException le) {
log.error("Failed to search subordinate entries", le);
return ResultCode.LOCAL_ERROR;
}
LinkedList<String> dns = new LinkedList<String>();
for (SearchResultEntry entry : searchResult.getSearchEntries()) {
dns.add(entry.getDN());
}
ListIterator<String> listIterator = dns.listIterator(dns.size());
while (listIterator.hasPrevious()) {
try {
connection.delete(listIterator.previous());
} catch (LDAPException le) {
log.error("Failed to delete entry", le);
resultCode = ResultCode.LOCAL_ERROR;
break;
}
}
return resultCode;
}
use of com.unboundid.ldap.sdk.LDAPException in project oxCore by GluuFederation.
the class LdifDataUtility method getAttributeResultEntryLDIF.
public List<SearchResultEntry> getAttributeResultEntryLDIF(LDAPConnection connection, List<String> patterns, String baseDN) {
List<SearchResultEntry> searchResultEntryList = new ArrayList<SearchResultEntry>();
try {
for (String pattern : patterns) {
String[] targetArray = new String[] { pattern };
Filter inumFilter = Filter.createSubstringFilter("inum", null, targetArray, null);
Filter searchFilter = Filter.createORFilter(inumFilter);
SearchResultEntry sr = connection.searchForEntry(baseDN, SearchScope.SUB, searchFilter, null);
searchResultEntryList.add(sr);
}
return searchResultEntryList;
} catch (LDAPException le) {
if (le.getResultCode() != ResultCode.NO_SUCH_OBJECT) {
log.error("Failed to search ldif record", le);
return null;
}
}
return null;
}
use of com.unboundid.ldap.sdk.LDAPException in project oxCore by GluuFederation.
the class LDAPConnectionProvider method createSSLConnectionPoolWithPreviousProtocols.
private LDAPConnectionPool createSSLConnectionPoolWithPreviousProtocols(SSLUtil sslUtil, BindRequest bindRequest, LDAPConnectionOptions connectionOptions, int maxConnections) throws LDAPException {
for (int i = 1; i < SSL_PROTOCOLS.length; i++) {
String protocol = SSL_PROTOCOLS[i];
try {
FailoverServerSet failoverSet = new FailoverServerSet(this.addresses, this.ports, sslUtil.createSSLSocketFactory(protocol), connectionOptions);
LDAPConnectionPool connectionPool = new LDAPConnectionPool(failoverSet, bindRequest, maxConnections);
log.info("Server supports: '" + protocol + "'");
return connectionPool;
} catch (GeneralSecurityException ex) {
log.debug("Server not supports: '" + protocol + "'", ex);
} catch (LDAPException ex) {
// Error when LDAP server not supports specified encryption
if (ex.getResultCode() != ResultCode.SERVER_DOWN) {
throw ex;
}
log.debug("Server not supports: '" + protocol + "'", ex);
}
}
return null;
}
use of com.unboundid.ldap.sdk.LDAPException in project oxCore by GluuFederation.
the class LDAPConnectionProvider method createConnectionPoolWithWaitImpl.
private LDAPConnectionPool createConnectionPoolWithWaitImpl(Properties props, FailoverServerSet failoverSet, BindRequest bindRequest, LDAPConnectionOptions connectionOptions, int maxConnections, SSLUtil sslUtil) throws LDAPException {
String connectionPoolMaxWaitTime = props.getProperty("connection-pool-max-wait-time");
int connectionPoolMaxWaitTimeSeconds = 30;
if (StringHelper.isNotEmpty(connectionPoolMaxWaitTime)) {
connectionPoolMaxWaitTimeSeconds = Integer.parseInt(connectionPoolMaxWaitTime);
}
log.debug("Using LDAP connection pool timeout: '" + connectionPoolMaxWaitTimeSeconds + "'");
LDAPConnectionPool createdConnectionPool = null;
LDAPException lastException = null;
int attempt = 0;
long currentTime = System.currentTimeMillis();
long maxWaitTime = currentTime + connectionPoolMaxWaitTimeSeconds * 1000;
do {
attempt++;
if (attempt > 0) {
log.info("Attempting to create connection pool: " + attempt);
}
try {
createdConnectionPool = createConnectionPoolImpl(failoverSet, bindRequest, connectionOptions, maxConnections, sslUtil);
break;
} catch (LDAPException ex) {
if (ex.getResultCode().intValue() != ResultCode.CONNECT_ERROR_INT_VALUE) {
throw ex;
}
lastException = ex;
}
try {
Thread.sleep(5000);
} catch (InterruptedException ex) {
log.error("Exception happened in sleep", ex);
return null;
}
currentTime = System.currentTimeMillis();
} while (maxWaitTime > currentTime);
if ((createdConnectionPool == null) && (lastException != null)) {
throw lastException;
}
return createdConnectionPool;
}
Aggregations