Search in sources :

Example 11 with SearchGalResult

use of com.zimbra.cs.account.Provisioning.SearchGalResult in project zm-mailbox by Zimbra.

the class TestLdapProvGal method searchGalADGroupMember.

@Test
@Ignore
public void searchGalADGroupMember() throws Exception {
    String DOMAIN_NAME = genDomainSegmentName() + "." + baseDomainName();
    Map<String, Object> domainAttrs = new HashMap<String, Object>();
    domainAttrs.put(Provisioning.A_zimbraGalMode, ZAttrProvisioning.GalMode.ldap.name());
    // replace XXX to real VMware AD credentials before checking in.
    // NEVER check in the crdentials
    domainAttrs.put(Provisioning.A_zimbraGalLdapURL, "ldap://XXX.vmware.com:3268");
    domainAttrs.put(Provisioning.A_zimbraGalLdapBindDn, "XXX@vmware.com");
    domainAttrs.put(Provisioning.A_zimbraGalLdapBindPassword, "XXX");
    domainAttrs.put(Provisioning.A_zimbraGalLdapFilter, "ad");
    domainAttrs.put(Provisioning.A_zimbraGalLdapGroupHandlerClass, "com.zimbra.cs.gal.ADGalGroupHandler");
    Domain galDomain = provUtil.createDomain(DOMAIN_NAME, domainAttrs);
    String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart("searchGalADGroupMember");
    Account user = provUtil.createAccount(ACCT_NAME_LOCALPART, galDomain, null);
    GalSearchType type = GalSearchType.group;
    String query = "server-pm@vmware.com";
    GalSearchParams params = new GalSearchParams(user);
    SearchGalResult result = SearchGalResult.newSearchGalResult(null);
    params.setOp(GalOp.search);
    params.setType(type);
    // has to be set before calling createSearchConfig
    params.setFetchGroupMembers(true);
    params.createSearchConfig(GalSearchConfig.GalType.ldap);
    params.setQuery(query);
    params.setGalResult(result);
    prov.searchGal(params);
    assertEquals(1, result.getMatches().size());
    GalContact galContact = result.getMatches().get(0);
    assertTrue(galContact.isGroup());
    Map<String, Object> galEntryAttrs = galContact.getAttrs();
    Object members = galEntryAttrs.get(ContactConstants.A_member);
    assertTrue(members instanceof String[]);
    assertEquals(6, ((String[]) members).length);
}
Also used : Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) GalContact(com.zimbra.cs.account.GalContact) GalSearchParams(com.zimbra.cs.gal.GalSearchParams) SearchGalResult(com.zimbra.cs.account.Provisioning.SearchGalResult) Domain(com.zimbra.cs.account.Domain) GalSearchType(com.zimbra.soap.type.GalSearchType)

Example 12 with SearchGalResult

use of com.zimbra.cs.account.Provisioning.SearchGalResult in project zm-mailbox by Zimbra.

the class TestLdapProvGal method searchGal.

@Test
public void searchGal() throws Exception {
    SKIP_FOR_INMEM_LDAP_SERVER(SkipTestReason.DN_SUBTREE_MATCH_FILTER);
    int NUM_ACCTS = 10;
    int SIZE_LIMIT = 5;
    Account user = null;
    for (int i = 0; i < NUM_ACCTS; i++) {
        String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart(String.valueOf(i)));
        Account acct = createAccount(ACCT_NAME_LOCALPART);
        // use the first one as the user
        if (user == null) {
            user = acct;
        }
    }
    GalSearchType type = GalSearchType.account;
    String query = "searchGal";
    GalSearchParams params = new GalSearchParams(user);
    SearchGalResult result = SearchGalResult.newSearchGalResult(null);
    params.setOp(GalOp.search);
    params.setType(type);
    params.createSearchConfig(GalSearchConfig.GalType.zimbra);
    params.setQuery(query);
    params.setLimit(SIZE_LIMIT);
    params.setGalResult(result);
    prov.searchGal(params);
    assertEquals(SIZE_LIMIT, result.getMatches().size());
    assertTrue(result.getHadMore());
    result = prov.searchGal(domain, query, type, 0, null);
    assertEquals(NUM_ACCTS, result.getMatches().size());
    assertFalse(result.getHadMore());
}
Also used : Account(com.zimbra.cs.account.Account) GalSearchParams(com.zimbra.cs.gal.GalSearchParams) SearchGalResult(com.zimbra.cs.account.Provisioning.SearchGalResult) GalSearchType(com.zimbra.soap.type.GalSearchType)

Example 13 with SearchGalResult

use of com.zimbra.cs.account.Provisioning.SearchGalResult in project zm-mailbox by Zimbra.

the class ProvUtil method doAutoCompleteGal.

private void doAutoCompleteGal(String[] args) throws ServiceException {
    String domain = args[1];
    String query = args[2];
    int limit = 100;
    Domain d = lookupDomain(domain);
    GalContact.Visitor visitor = new GalContact.Visitor() {

        @Override
        public void visit(GalContact gc) throws ServiceException {
            dumpContact(gc);
        }
    };
    SearchGalResult result = prov.autoCompleteGal(d, query, GalSearchType.all, limit, visitor);
}
Also used : PublishedShareInfoVisitor(com.zimbra.cs.account.Provisioning.PublishedShareInfoVisitor) SearchGalResult(com.zimbra.cs.account.Provisioning.SearchGalResult)

Example 14 with SearchGalResult

use of com.zimbra.cs.account.Provisioning.SearchGalResult in project zm-mailbox by Zimbra.

the class AclReports method getMatchingPrincipals.

private ArrayList<DavResource> getMatchingPrincipals(DavContext ctxt, QName prop, String match, GalSearchType type) throws DavException, ServiceException {
    Provisioning prov = Provisioning.getInstance();
    ArrayList<DavResource> ret = new ArrayList<DavResource>();
    Account authAccount = ctxt.getAuthAccount();
    if (prop.equals(DavElements.E_DISPLAYNAME)) {
        if (!authAccount.isFeatureGalEnabled() || !authAccount.isFeatureGalAutoCompleteEnabled())
            return ret;
        SearchGalResult result = prov.searchGal(prov.getDomain(authAccount), match, type, Provisioning.GalMode.zimbra, null);
        for (GalContact ct : result.getMatches()) {
            String email = (String) ct.getAttrs().get(ContactConstants.A_email);
            if (email != null) {
                Account acct = prov.get(Key.AccountBy.name, email);
                if (acct != null)
                    ret.add(UrlNamespace.getPrincipal(ctxt, acct));
            }
        }
    } else if (prop.equals(DavElements.E_CALENDAR_HOME_SET)) {
        int index = match.lastIndexOf('/');
        if (index > 0)
            match = match.substring(index + 1);
        Account acct = prov.get(Key.AccountBy.name, match);
        if (acct != null)
            ret.add(UrlNamespace.getPrincipal(ctxt, acct));
    }
    return ret;
}
Also used : Account(com.zimbra.cs.account.Account) DavResource(com.zimbra.cs.dav.resource.DavResource) GalContact(com.zimbra.cs.account.GalContact) ArrayList(java.util.ArrayList) SearchGalResult(com.zimbra.cs.account.Provisioning.SearchGalResult) Provisioning(com.zimbra.cs.account.Provisioning)

Aggregations

SearchGalResult (com.zimbra.cs.account.Provisioning.SearchGalResult)14 Domain (com.zimbra.cs.account.Domain)5 Account (com.zimbra.cs.account.Account)3 GalContact (com.zimbra.cs.account.GalContact)3 PublishedShareInfoVisitor (com.zimbra.cs.account.Provisioning.PublishedShareInfoVisitor)3 LdapProv (com.zimbra.cs.account.ldap.LdapProv)2 GalSearchParams (com.zimbra.cs.gal.GalSearchParams)2 GalSearchType (com.zimbra.soap.type.GalSearchType)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)1 Control (com.unboundid.ldap.sdk.Control)1 LDAPException (com.unboundid.ldap.sdk.LDAPException)1 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)1 SearchRequest (com.unboundid.ldap.sdk.SearchRequest)1 SearchResult (com.unboundid.ldap.sdk.SearchResult)1 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)1 SearchScope (com.unboundid.ldap.sdk.SearchScope)1 AssertionRequestControl (com.unboundid.ldap.sdk.controls.AssertionRequestControl)1 ManageDsaITRequestControl (com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl)1