use of com.unboundid.ldap.sdk.SearchResultEntry 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.SearchResultEntry 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.SearchResultEntry in project zm-mailbox by Zimbra.
the class UBIDLdapContext method getLastEntryCreationDate.
private String getLastEntryCreationDate(int limit, List<SearchResultEntry> entries) throws LdapException {
String leCreateDate = null;
int size = entries.size();
ZimbraLog.gal.debug("inside getLastEntryCreationDate()");
ZimbraLog.gal.debug("Liimit = %d, Size = %d", limit, size);
SearchResultEntry entry = null;
if (size != 0) {
if (limit <= size && limit > 0) {
entry = entries.get(limit - 1);
} else {
entry = entries.get(size - 1);
}
UBIDAttributes ubidAttrs = new UBIDAttributes(entry);
leCreateDate = ubidAttrs.getAttrString("whenCreated") != null ? ubidAttrs.getAttrString("whenCreated") : ubidAttrs.getAttrString("createTimeStamp");
}
return leCreateDate;
}
use of com.unboundid.ldap.sdk.SearchResultEntry in project zm-mailbox by Zimbra.
the class UBIDLdapContext method moveChildren.
@Override
public void moveChildren(String oldDn, String newDn) throws ServiceException {
try {
// use ZLdapFilter instead of just the native Filter so it's
// convenient for stating
ZLdapFilter filter = ZLdapFilterFactory.getInstance().anyEntry();
// Filter filter = Filter.createPresenceFilter(LdapConstants.ATTR_OBJECTCLASS);
SearchRequest searchRequest = new SearchRequest(oldDn, SearchScope.ONE, derefAliasPolicy, // size limit
0, // time limit
0, // getTypesOnly
false, ((UBIDLdapFilter) filter).getNative());
searchRequest.setAttributes("dn");
SearchResult result = UBIDLdapOperation.SEARCH.execute(this, searchRequest, filter);
List<SearchResultEntry> entries = result.getSearchEntries();
for (SearchResultEntry entry : entries) {
DN entryDN = entry.getParsedDN();
String childDn = entryDN.toNormalizedString();
String childRdn = entryDN.getRDNString();
UBIDLdapOperation.MODIFY_DN.execute(this, childDn, childRdn, true, newDn);
}
} catch (LDAPException e) {
throw mapToLdapException("unable to move children", e);
}
}
use of com.unboundid.ldap.sdk.SearchResultEntry in project oxCore by GluuFederation.
the class LdapEntryManager method removeSubtreeThroughIteration.
private void removeSubtreeThroughIteration(String dn) {
SearchResult searchResult = null;
try {
searchResult = this.ldapOperationService.search(dn, toLdapFilter(Filter.createPresenceFilter("objectClass")), 0, 0, null, "dn");
if (!ResultCode.SUCCESS.equals(searchResult.getResultCode())) {
throw new EntryPersistenceException(String.format("Failed to find sub-entries of entry '%s' for removal", dn));
}
} catch (SearchException ex) {
throw new EntryPersistenceException(String.format("Failed to find sub-entries of entry '%s' for removal", dn), ex);
}
List<String> removeEntriesDn = new ArrayList<String>(searchResult.getEntryCount());
for (SearchResultEntry searchResultEntry : searchResult.getSearchEntries()) {
removeEntriesDn.add(searchResultEntry.getDN());
}
Collections.sort(removeEntriesDn, LINE_LENGHT_COMPARATOR);
for (String removeEntryDn : removeEntriesDn) {
remove(removeEntryDn);
}
}
Aggregations