use of com.zimbra.cs.ldap.IAttributes in project zm-mailbox by Zimbra.
the class LdapProvisioning method searchDynamicGroupInternalMemberDeliveryAddresses.
private void searchDynamicGroupInternalMemberDeliveryAddresses(ZLdapContext initZlc, String dynGroupId, final Collection<String> result) {
SearchLdapVisitor visitor = new SearchLdapVisitor(false) {
@Override
public void visit(String dn, IAttributes ldapAttrs) throws StopIteratingException {
String addr = null;
try {
addr = ldapAttrs.getAttrString(Provisioning.A_zimbraMailDeliveryAddress);
} catch (ServiceException e) {
ZimbraLog.account.warn("unable to get attr", e);
}
if (addr != null) {
result.add(addr);
}
}
};
ZLdapContext zlc = initZlc;
try {
if (zlc == null) {
// always use master to search for dynamic group members
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.SEARCH);
}
searchDynamicGroupInternalMembers(zlc, dynGroupId, visitor);
} catch (ServiceException e) {
ZimbraLog.account.warn("unable to search dynamic group members", e);
} finally {
if (initZlc == null) {
LdapClient.closeContext(zlc);
}
}
}
use of com.zimbra.cs.ldap.IAttributes in project zm-mailbox by Zimbra.
the class BUG_57866 method upgradeGalSyncAccounts.
private void upgradeGalSyncAccounts(ZLdapContext zlc) throws ServiceException {
LdapDIT dit = prov.getDIT();
String[] returnAttrs = new String[] { Provisioning.A_zimbraGalAccountId };
String base = dit.mailBranchBaseDN();
String query = "(&(objectclass=zimbraDomain)(zimbraGalAccountId=*))";
final Set<String> galAcctIds = new HashSet<String>();
SearchLdapVisitor visitor = new SearchLdapVisitor(false) {
@Override
public void visit(String dn, IAttributes ldapAttrs) throws StopIteratingException {
try {
String acctId;
acctId = ldapAttrs.getAttrString(Provisioning.A_zimbraGalAccountId);
if (acctId != null) {
galAcctIds.add(acctId);
}
} catch (ServiceException e) {
printer.printStackTrace("unsble to search domains for GAL sync accounts", e);
}
}
};
SearchLdapOptions searchOpts = new SearchLdapOptions(base, getFilter(query), returnAttrs, SearchLdapOptions.SIZE_UNLIMITED, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
zlc.searchPaged(searchOpts);
for (String galAcctId : galAcctIds) {
printer.format("Checking GAL sync account %s\n", galAcctId);
Account acct = prov.get(AccountBy.id, galAcctId);
setIsSystemAccount(zlc, acct);
}
}
use of com.zimbra.cs.ldap.IAttributes in project zm-mailbox by Zimbra.
the class TestLdapZLdapContext method searchPaged.
@Test
public void searchPaged() throws Exception {
int SIZE_LIMIT = 5;
String base = LdapConstants.DN_ROOT_DSE;
ZLdapFilter filter = ZLdapFilterFactory.getInstance().anyEntry();
String[] returnAttrs = new String[] { "objectClass" };
final List<String> result = new ArrayList<String>();
SearchLdapOptions.SearchLdapVisitor visitor = new SearchLdapOptions.SearchLdapVisitor() {
@Override
public void visit(String dn, Map<String, Object> attrs, IAttributes ldapAttrs) {
result.add(dn);
}
};
SearchLdapOptions searchOptions = new SearchLdapOptions(base, filter, returnAttrs, SIZE_LIMIT, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
boolean caughtException = false;
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapUsage.UNITTEST);
zlc.searchPaged(searchOptions);
} catch (LdapSizeLimitExceededException e) {
caughtException = true;
} finally {
LdapClient.closeContext(zlc);
}
assertTrue(caughtException);
assertEquals(SIZE_LIMIT, result.size());
}
use of com.zimbra.cs.ldap.IAttributes in project zm-mailbox by Zimbra.
the class TestLdapProvDomain method verifyAllDomains.
private void verifyAllDomains(List<Domain> allDomains) throws Exception {
// domains created by r-t-w
// TODO: this verification is very fragile
Set<String> expectedDomains = new HashSet<String>();
String defaultDomainName = prov.getInstance().getConfig().getDefaultDomainName();
expectedDomains.add(defaultDomainName);
expectedDomains.add("example.com");
assertEquals(expectedDomains.size(), allDomains.size());
for (Domain domain : allDomains) {
assertTrue(expectedDomains.contains(domain.getName()));
}
//
// another verification
//
LdapHelper ldapHelper = ((LdapProv) prov).getHelper();
final List<String> /* zimbraId */
domainIds = new ArrayList<String>();
SearchLdapOptions.SearchLdapVisitor visitor = new SearchLdapOptions.SearchLdapVisitor() {
@Override
public void visit(String dn, Map<String, Object> attrs, IAttributes ldapAttrs) {
try {
domainIds.add(ldapAttrs.getAttrString(Provisioning.A_zimbraId));
} catch (ServiceException e) {
fail();
}
}
};
SearchLdapOptions searchOpts = new SearchLdapOptions(LdapConstants.DN_ROOT_DSE, ZLdapFilterFactory.getInstance().fromFilterString(FilterId.UNITTEST, "(objectclass=zimbraDomain)"), new String[] { Provisioning.A_zimbraId }, SearchLdapOptions.SIZE_UNLIMITED, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapUsage.UNITTEST);
ldapHelper.searchLdap(zlc, searchOpts);
} finally {
LdapClient.closeContext(zlc);
}
assertEquals(domainIds.size(), allDomains.size());
for (Domain domain : allDomains) {
assertTrue(domainIds.contains(domain.getId()));
}
}
use of com.zimbra.cs.ldap.IAttributes in project zm-mailbox by Zimbra.
the class LdapProvisioning method searchContainingDynamicGroupIdsForExternalAddress.
/*
* returns zimbraId of dynamic groups containing addr as an external member.
*/
private Set<String> searchContainingDynamicGroupIdsForExternalAddress(String addr, ZLdapContext initZlc) {
final Set<String> groupIds = Sets.newHashSet();
SearchLdapVisitor visitor = new SearchLdapVisitor(false) {
@Override
public void visit(String dn, IAttributes ldapAttrs) throws StopIteratingException {
String groupId = null;
try {
groupId = ldapAttrs.getAttrString(A_zimbraGroupId);
} catch (ServiceException e) {
ZimbraLog.account.warn("unable to get attr", e);
}
if (groupId != null) {
groupIds.add(groupId);
}
}
};
ZLdapContext zlc = initZlc;
try {
if (zlc == null) {
zlc = LdapClient.getContext(LdapServerType.REPLICA, LdapUsage.SEARCH);
}
String base = mDIT.mailBranchBaseDN();
ZLdapFilter filter = filterFactory.dynamicGroupsStaticUnitByMemberAddr(addr);
SearchLdapOptions searchOptions = new SearchLdapOptions(base, filter, new String[] { A_zimbraGroupId }, SearchLdapOptions.SIZE_UNLIMITED, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
zlc.searchPaged(searchOptions);
} catch (ServiceException e) {
ZimbraLog.account.warn("unable to search dynamic groups for guest acct", e);
} finally {
if (initZlc == null) {
LdapClient.closeContext(zlc);
}
}
return groupIds;
}
Aggregations