use of com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor in project zm-mailbox by Zimbra.
the class AutoProvision method searchAutoProvDirectory.
/*
* entries are returned in DirectoryEntryVisitor interface.
*/
static void searchAutoProvDirectory(LdapProv prov, Domain domain, String filter, String name, String createTimestampLaterThan, String[] returnAttrs, int maxResults, final DirectoryEntryVisitor visitor) throws ServiceException {
SearchLdapVisitor ldapVisitor = new SearchLdapVisitor() {
@Override
public void visit(String dn, Map<String, Object> attrs, IAttributes ldapAttrs) throws StopIteratingException {
visitor.visit(dn, attrs);
}
};
searchAutoProvDirectory(prov, domain, filter, name, createTimestampLaterThan, returnAttrs, maxResults, ldapVisitor, false);
}
use of com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor in project zm-mailbox by Zimbra.
the class AutoProvisionEager method searchAccounts.
private boolean searchAccounts(final List<ExternalEntry> entries, int batchSize) throws ServiceException {
String lastPolledAt = domain.getAutoProvLastPolledTimestampAsString();
String[] returnAttrs = getAttrsToFetch();
SearchLdapVisitor visitor = new SearchLdapVisitor(false) {
@Override
public void visit(String dn, IAttributes ldapAttrs) throws StopIteratingException {
entries.add(new ExternalEntry(dn, (ZAttributes) ldapAttrs));
}
};
boolean hitSizeLimitExceededException = AutoProvision.searchAutoProvDirectory(prov, domain, null, null, lastPolledAt, returnAttrs, batchSize, visitor, true);
ZimbraLog.autoprov.debug("searched external LDAP source, hit size limit ? %s", hitSizeLimitExceededException);
return hitSizeLimitExceededException;
}
use of com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor 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.SearchLdapOptions.SearchLdapVisitor in project zm-mailbox by Zimbra.
the class LdapProvisioning method deleteMemberOfOnAccounts.
// TODO: change to ldif and do in background
private void deleteMemberOfOnAccounts(ZLdapContext zlc, String dynGroupId) throws ServiceException {
final List<Account> accts = new ArrayList<Account>();
SearchLdapVisitor visitor = new SearchLdapVisitor(false) {
@Override
public void visit(String dn, IAttributes ldapAttrs) throws StopIteratingException {
Account acct;
try {
acct = makeAccountNoDefaults(dn, (ZAttributes) ldapAttrs);
accts.add(acct);
} catch (ServiceException e) {
ZimbraLog.account.warn("unable to make account " + dn, e);
}
}
};
searchDynamicGroupInternalMembers(zlc, dynGroupId, visitor);
// do in background?
for (Account acct : accts) {
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put("-" + Provisioning.A_zimbraMemberOf, dynGroupId);
modifyLdapAttrs(acct, zlc, attrs);
// remove the account from cache
// note: cannnot just removeFromCache(acct) because acct only
// contains the name, so id/alias/foreignPrincipal cached in NamedCache
// won't be cleared.
Account cached = getFromCache(AccountBy.name, acct.getName());
if (cached != null) {
removeFromCache(cached);
}
}
}
use of com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor 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);
}
}
}
Aggregations