Search in sources :

Example 6 with SearchResult

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

the class LdapAuthenticationTest method checkIfUsersConfContainsAllUsersFromSampleDataLdif.

@Test
public void checkIfUsersConfContainsAllUsersFromSampleDataLdif() throws Exception {
    SearchResult searchResult = getDS().search(ACCOUNT_BASE, SearchScope.SUB, "objectClass=person");
    assertEquals("Number of ldap users in gitblit user model", searchResult.getEntryCount(), countLdapUsersInUserManager());
}
Also used : SearchResult(com.unboundid.ldap.sdk.SearchResult) Test(org.junit.Test)

Example 7 with SearchResult

use of com.unboundid.ldap.sdk.SearchResult 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 8 with SearchResult

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

Example 9 with SearchResult

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

the class UBIDLdapContext method countEntries.

@Override
public long countEntries(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());
        NoopSearchControl noopSearchCtl = new NoopSearchControl();
        searchRequest.addControl(noopSearchCtl);
        // no point to request attributes
        if (sc.getReturnAttrs() != null) {
            throw LdapException.INVALID_REQUEST("return attributes are not allowed for countEntries", null);
        }
        SearchResult result = UBIDLdapOperation.SEARCH.execute(this, searchRequest, filter);
        NoopSearchControl control = NoopSearchControl.get(result);
        if (control == null) {
            throw LdapException.LDAP_ERROR("Noop search control is not present in response", null);
        }
        return control.getCount();
    } 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)

Example 10 with SearchResult

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

Aggregations

SearchResult (com.unboundid.ldap.sdk.SearchResult)22 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)14 LDAPException (com.unboundid.ldap.sdk.LDAPException)10 SearchRequest (com.unboundid.ldap.sdk.SearchRequest)10 LdapConnection (com.gitblit.ldap.LdapConnection)6 BindResult (com.unboundid.ldap.sdk.BindResult)5 TeamModel (com.gitblit.models.TeamModel)4 Test (org.junit.Test)4 ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)3 UserModel (com.gitblit.models.UserModel)2 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)2 Attribute (com.unboundid.ldap.sdk.Attribute)2 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Control (com.unboundid.ldap.sdk.Control)1 DN (com.unboundid.ldap.sdk.DN)1 Entry (com.unboundid.ldap.sdk.Entry)1 Filter (com.unboundid.ldap.sdk.Filter)1 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)1