Search in sources :

Example 1 with SearchResultEntry

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;
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) LDAPSearchException(com.unboundid.ldap.sdk.LDAPSearchException) SearchResult(com.unboundid.ldap.sdk.SearchResult) ResultCode(com.unboundid.ldap.sdk.ResultCode) LinkedList(java.util.LinkedList) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Example 2 with SearchResultEntry

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;
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) Filter(com.unboundid.ldap.sdk.Filter) ArrayList(java.util.ArrayList) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Example 3 with SearchResultEntry

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;
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Example 4 with SearchResultEntry

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);
    }
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) SearchRequest(com.unboundid.ldap.sdk.SearchRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) SearchResult(com.unboundid.ldap.sdk.SearchResult) DN(com.unboundid.ldap.sdk.DN) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Example 5 with SearchResultEntry

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);
    }
}
Also used : ArrayList(java.util.ArrayList) EntryPersistenceException(org.gluu.persist.exception.mapping.EntryPersistenceException) SearchException(org.gluu.persist.exception.operation.SearchException) SearchResult(com.unboundid.ldap.sdk.SearchResult) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Aggregations

SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)31 SearchResult (com.unboundid.ldap.sdk.SearchResult)23 ArrayList (java.util.ArrayList)13 LDAPException (com.unboundid.ldap.sdk.LDAPException)11 SearchException (org.gluu.persist.exception.operation.SearchException)10 MappingException (org.gluu.persist.exception.mapping.MappingException)9 ConnectionException (org.gluu.persist.exception.operation.ConnectionException)9 SearchRequest (com.unboundid.ldap.sdk.SearchRequest)8 LdapConnection (com.gitblit.ldap.LdapConnection)6 ParseException (java.text.ParseException)6 EntryPersistenceException (org.gluu.persist.exception.mapping.EntryPersistenceException)6 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)5 BindResult (com.unboundid.ldap.sdk.BindResult)5 LDAPSearchException (com.unboundid.ldap.sdk.LDAPSearchException)5 AuthenticationException (org.gluu.persist.exception.operation.AuthenticationException)5 SearchScopeException (org.gluu.persist.exception.operation.SearchScopeException)5 TeamModel (com.gitblit.models.TeamModel)4 Attribute (com.unboundid.ldap.sdk.Attribute)4 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)4 LinkedList (java.util.LinkedList)4