Search in sources :

Example 1 with SearchRequest

use of com.unboundid.ldap.sdk.SearchRequest in project oxCore by GluuFederation.

the class LdapOperationsServiceImpl method scrollSimplePagedResultsControl.

private ASN1OctetString scrollSimplePagedResultsControl(LDAPConnection ldapConnection, String dn, Filter filter, SearchScope scope, Control[] controls, int startIndex) throws LDAPException, InvalidSimplePageControlException {
    SearchRequest searchRequest = new SearchRequest(dn, scope, filter, "dn");
    int currentStartIndex = startIndex;
    ASN1OctetString cookie = null;
    do {
        int pageSize = Math.min(currentStartIndex, 100);
        searchRequest.setControls(new Control[] { new SimplePagedResultsControl(pageSize, cookie, true) });
        setControls(searchRequest, controls);
        SearchResult searchResult = ldapConnection.search(searchRequest);
        currentStartIndex -= searchResult.getEntryCount();
        try {
            SimplePagedResultsControl c = SimplePagedResultsControl.get(searchResult);
            if (c != null) {
                cookie = c.getCookie();
            }
        } catch (LDAPException ex) {
            LOG.error("Error while accessing cookie", ex);
            throw new InvalidSimplePageControlException(ex.getResultCode(), "Error while accessing cookie");
        }
    } while ((cookie != null) && (cookie.getValueLength() > 0) && (currentStartIndex > 0));
    return cookie;
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) SearchRequest(com.unboundid.ldap.sdk.SearchRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) SearchResult(com.unboundid.ldap.sdk.SearchResult) SimplePagedResultsControl(com.unboundid.ldap.sdk.controls.SimplePagedResultsControl) InvalidSimplePageControlException(org.gluu.persist.ldap.exception.InvalidSimplePageControlException)

Example 2 with SearchRequest

use of com.unboundid.ldap.sdk.SearchRequest in project gitblit by gitblit.

the class LdapAuthProvider method doSearch.

private SearchResult doSearch(LdapConnection ldapConnection, String base, String filter) {
    try {
        SearchRequest searchRequest = new SearchRequest(base, SearchScope.SUB, filter);
        SearchResult result = ldapConnection.search(searchRequest);
        if (result.getResultCode() != ResultCode.SUCCESS) {
            return null;
        }
        return result;
    } catch (LDAPException e) {
        logger.error("Problem creating LDAP search", e);
        return null;
    }
}
Also used : SearchRequest(com.unboundid.ldap.sdk.SearchRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) SearchResult(com.unboundid.ldap.sdk.SearchResult)

Example 3 with SearchRequest

use of com.unboundid.ldap.sdk.SearchRequest in project gitblit by gitblit.

the class LdapConnection method search.

public SearchResult search(String base, boolean dereferenceAliases, String filter, List<String> attributes) {
    try {
        SearchRequest searchRequest = new SearchRequest(base, SearchScope.SUB, filter);
        if (dereferenceAliases) {
            searchRequest.setDerefPolicy(DereferencePolicy.SEARCHING);
        }
        if (attributes != null) {
            searchRequest.setAttributes(attributes);
        }
        SearchResult result = search(searchRequest);
        return result;
    } catch (LDAPException e) {
        logger.error("Problem creating LDAP search", e);
        return null;
    }
}
Also used : SearchRequest(com.unboundid.ldap.sdk.SearchRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) SearchResult(com.unboundid.ldap.sdk.SearchResult)

Example 4 with SearchRequest

use of com.unboundid.ldap.sdk.SearchRequest 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 SearchRequest

use of com.unboundid.ldap.sdk.SearchRequest in project zm-mailbox by Zimbra.

the class UBIDLdapContext method searchDir.

@Override
public ZSearchResultEnumeration searchDir(String baseDN, ZLdapFilter filter, ZSearchControls searchControls) throws LdapException {
    UBIDSearchControls sc = (UBIDSearchControls) searchControls;
    try {
        SearchRequest searchRequest = new SearchRequest(baseDN, sc.getSearchScope(), derefAliasPolicy, sc.getSizeLimit(), sc.getTimeLimit(), sc.getTypesOnly(), ((UBIDLdapFilter) filter).getNative());
        searchRequest.setAttributes(sc.getReturnAttrs());
        SearchResult result = UBIDLdapOperation.SEARCH.execute(this, searchRequest, filter);
        return new UBIDSearchResultEnumeration(result);
    } catch (LDAPException e) {
        throw mapToLdapException("unable to search ldap", e);
    }
}
Also used : SearchRequest(com.unboundid.ldap.sdk.SearchRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) SearchResult(com.unboundid.ldap.sdk.SearchResult)

Aggregations

SearchRequest (com.unboundid.ldap.sdk.SearchRequest)16 SearchResult (com.unboundid.ldap.sdk.SearchResult)16 LDAPException (com.unboundid.ldap.sdk.LDAPException)13 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)8 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)5 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)4 SimplePagedResultsControl (com.unboundid.ldap.sdk.controls.SimplePagedResultsControl)4 InvalidSimplePageControlException (org.gluu.persist.ldap.exception.InvalidSimplePageControlException)4 LDAPSearchException (com.unboundid.ldap.sdk.LDAPSearchException)3 ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)3 MappingException (org.gluu.persist.exception.mapping.MappingException)3 ConnectionException (org.gluu.persist.exception.operation.ConnectionException)3 DuplicateEntryException (org.gluu.persist.exception.operation.DuplicateEntryException)3 SearchException (org.gluu.persist.exception.operation.SearchException)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Attribute (com.unboundid.ldap.sdk.Attribute)2 BindResult (com.unboundid.ldap.sdk.BindResult)2 SearchResultReference (com.unboundid.ldap.sdk.SearchResultReference)2 SearchScope (com.unboundid.ldap.sdk.SearchScope)2 ArrayList (java.util.ArrayList)2