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