Search in sources :

Example 11 with GalContact

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

the class TestSearchGal method searchByFilter.

private void searchByFilter(boolean ldap, String domainName) throws Exception {
    SoapTransport transport = authUser(TestUtil.getAddress(AUTHED_USER, domainName));
    Element request = Element.create(transport.getRequestProtocol(), AccountConstants.SEARCH_GAL_REQUEST);
    request.addElement(AccountConstants.E_NAME).setText(".");
    Element eSearchFilter = request.addElement(AccountConstants.E_ENTRY_SEARCH_FILTER);
    Element eConds = eSearchFilter.addElement(AccountConstants.E_ENTRY_SEARCH_FILTER_MULTICOND);
    int acctToMatch = 8;
    Element eCondResType = eConds.addElement(AccountConstants.E_ENTRY_SEARCH_FILTER_SINGLECOND);
    eCondResType.addAttribute(AccountConstants.A_ENTRY_SEARCH_FILTER_ATTR, ContactConstants.A_email);
    eCondResType.addAttribute(AccountConstants.A_ENTRY_SEARCH_FILTER_OP, Operator.has.name());
    eCondResType.addAttribute(AccountConstants.A_ENTRY_SEARCH_FILTER_VALUE, acctToMatch);
    String matchDepartment = getDepartment(acctToMatch, domainName);
    Element eCondResSite = eConds.addElement(AccountConstants.E_ENTRY_SEARCH_FILTER_SINGLECOND);
    eCondResSite.addAttribute(AccountConstants.A_ENTRY_SEARCH_FILTER_ATTR, ContactConstants.A_department);
    eCondResSite.addAttribute(AccountConstants.A_ENTRY_SEARCH_FILTER_OP, Operator.has.name());
    eCondResSite.addAttribute(AccountConstants.A_ENTRY_SEARCH_FILTER_VALUE, matchDepartment);
    Element response = transport.invoke(request);
    List<GalContact> result = new ArrayList<GalContact>();
    for (Element e : response.listElements(AdminConstants.E_CN)) {
        result.add(new GalContact(AdminConstants.A_ID, SoapProvisioning.getAttrs(e)));
    }
    assertEquals(1, result.size());
    assertEquals(getAcctEmail(acctToMatch, domainName), result.get(0).getSingleAttr(ContactConstants.A_email));
}
Also used : GalContact(com.zimbra.cs.account.GalContact) Element(com.zimbra.common.soap.Element) ArrayList(java.util.ArrayList) SoapTransport(com.zimbra.common.soap.SoapTransport)

Example 12 with GalContact

use of com.zimbra.cs.account.GalContact 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)

Aggregations

GalContact (com.zimbra.cs.account.GalContact)12 Element (com.zimbra.common.soap.Element)9 ArrayList (java.util.ArrayList)6 SoapTransport (com.zimbra.common.soap.SoapTransport)5 SearchGalResult (com.zimbra.cs.account.Provisioning.SearchGalResult)3 XMLElement (com.zimbra.common.soap.Element.XMLElement)2 Account (com.zimbra.cs.account.Account)2 Domain (com.zimbra.cs.account.Domain)2 Provisioning (com.zimbra.cs.account.Provisioning)2 GalOp (com.zimbra.cs.account.gal.GalOp)1 DavResource (com.zimbra.cs.dav.resource.DavResource)1 GalSearchParams (com.zimbra.cs.gal.GalSearchParams)1 Contact (com.zimbra.cs.mailbox.Contact)1 ContactGroup (com.zimbra.cs.mailbox.ContactGroup)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 GalSearchType (com.zimbra.soap.type.GalSearchType)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1