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));
}
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);
}
Aggregations