use of com.zimbra.cs.ldap.ZLdapFilter in project zm-mailbox by Zimbra.
the class LdapProvisioning method getAllServers.
@Override
public List<Server> getAllServers(String service) throws ServiceException {
List<Server> result = new ArrayList<Server>();
ZLdapFilter filter;
if (service != null) {
filter = filterFactory.serverByService(service);
} else {
filter = filterFactory.allServers();
}
try {
Map<String, Object> serverDefaults = getConfig().getServerDefaults();
ZSearchResultEnumeration ne = helper.searchDir(mDIT.serverBaseDN(), filter, ZSearchControls.SEARCH_CTLS_SUBTREE());
while (ne.hasMore()) {
ZSearchResultEntry sr = ne.next();
LdapServer s = new LdapServer(sr.getDN(), sr.getAttributes(), serverDefaults, this);
result.add(s);
}
ne.close();
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to list all servers", e);
}
if (result.size() > 0)
serverCache.put(result, true);
Collections.sort(result);
return result;
}
use of com.zimbra.cs.ldap.ZLdapFilter in project zm-mailbox by Zimbra.
the class LdapProvisioning method getAllAlwaysOnClusters.
@Override
public List<AlwaysOnCluster> getAllAlwaysOnClusters() throws ServiceException {
List<AlwaysOnCluster> result = new ArrayList<AlwaysOnCluster>();
ZLdapFilter filter = filterFactory.allAlwaysOnClusters();
try {
ZSearchResultEnumeration ne = helper.searchDir(mDIT.alwaysOnClusterBaseDN(), filter, ZSearchControls.SEARCH_CTLS_SUBTREE());
while (ne.hasMore()) {
ZSearchResultEntry sr = ne.next();
LdapAlwaysOnCluster c = new LdapAlwaysOnCluster(sr.getDN(), sr.getAttributes(), null, this);
result.add(c);
}
ne.close();
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to list all alwaysOnClusters", e);
}
if (result.size() > 0)
alwaysOnClusterCache.put(result, true);
Collections.sort(result);
return result;
}
use of com.zimbra.cs.ldap.ZLdapFilter in project zm-mailbox by Zimbra.
the class LdapProvisioning method isEmptyOu.
/**
* @param habOrgUnitName organizational unit name
* @param domainDn the domain distinguishedd name
* @return true if the ou has groups or false if empty
* @throws ServiceException
*/
private static boolean isEmptyOu(String habOrgUnitName, String domainDn) throws ServiceException {
ZLdapContext zlc = null;
boolean empty = false;
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.CREATE_OU);
String baseDN = createOuDn(habOrgUnitName, domainDn);
String filter = "(objectClass=zimbraDistributionList)";
String[] returnAttrs = new String[] { "cn" };
ZLdapFilter zFilter = ZLdapFilterFactory.getInstance().fromFilterString(FilterId.ALL_DISTRIBUTION_LISTS, filter);
ZSearchControls searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_SUBTREE, ZSearchControls.SIZE_UNLIMITED, returnAttrs);
ZSearchResultEnumeration ne = zlc.searchDir(baseDN, zFilter, searchControls);
empty = !ne.hasMore();
} catch (ServiceException e) {
throw ServiceException.FAILURE(String.format("Unable to delete HAB org unit: %s for domain=%s", habOrgUnitName, domainDn), e);
} finally {
LdapClient.closeContext(zlc);
}
return empty;
}
use of com.zimbra.cs.ldap.ZLdapFilter in project zm-mailbox by Zimbra.
the class LdapProvisioning method getAllXMPPComponents.
@Override
public List<XMPPComponent> getAllXMPPComponents() throws ServiceException {
List<XMPPComponent> result = new ArrayList<XMPPComponent>();
try {
String base = mDIT.xmppcomponentBaseDN();
ZLdapFilter filter = filterFactory.allXMPPComponents();
ZSearchResultEnumeration ne = helper.searchDir(base, filter, ZSearchControls.SEARCH_CTLS_SUBTREE());
while (ne.hasMore()) {
ZSearchResultEntry sr = ne.next();
LdapXMPPComponent x = new LdapXMPPComponent(sr.getDN(), sr.getAttributes(), this);
result.add(x);
}
ne.close();
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to list all XMPPComponents", e);
}
if (result.size() > 0) {
xmppComponentCache.put(result, true);
}
Collections.sort(result);
return result;
}
use of com.zimbra.cs.ldap.ZLdapFilter in project zm-mailbox by Zimbra.
the class LdapProvisioning method getDNforAccountById.
public String getDNforAccountById(String zimbraId, ZLdapContext zlc, boolean loadFromMaster) {
if (zimbraId == null) {
return null;
}
ZLdapFilter filter = filterFactory.accountById(zimbraId);
try {
String[] retAttrs = new String[] { Provisioning.A_zimbraId };
/* Just 1 attr to save bandwidth */
ZSearchResultEntry sr;
sr = getSearchResultForAccountByQuery(mDIT.mailBranchBaseDN(), filter, zlc, loadFromMaster, retAttrs);
// search again under the admin base if not found and admin base is not under mail base
if (sr == null && !mDIT.isUnder(mDIT.mailBranchBaseDN(), mDIT.adminBaseDN())) {
sr = getSearchResultForAccountByQuery(mDIT.adminBaseDN(), filter, zlc, loadFromMaster, retAttrs);
}
if (sr != null) {
return sr.getDN();
}
} catch (ServiceException e) {
ZimbraLog.search.debug("unable to lookup DN for account via query: %s", filter.toFilterString(), e);
}
return null;
}
Aggregations