use of com.zimbra.cs.ldap.ZSearchResultEntry 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.ZSearchResultEntry in project zm-mailbox by Zimbra.
the class LdapProvisioning method searchCOS.
private List<Cos> searchCOS(ZLdapFilter filter, ZLdapContext initZlc) throws ServiceException {
List<Cos> result = new ArrayList<Cos>();
try {
ZSearchResultEnumeration ne = helper.searchDir(mDIT.cosBaseDN(), filter, ZSearchControls.SEARCH_CTLS_SUBTREE(), initZlc, LdapServerType.REPLICA);
while (ne.hasMore()) {
ZSearchResultEntry sr = ne.next();
result.add(new LdapCos(sr.getDN(), sr.getAttributes(), this));
}
ne.close();
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to lookup cos via query: " + filter.toFilterString() + " message: " + e.getMessage(), e);
}
return result;
}
use of com.zimbra.cs.ldap.ZSearchResultEntry in project zm-mailbox by Zimbra.
the class LdapProvisioning method getDynamicGroupByQuery.
private DynamicGroup getDynamicGroupByQuery(ZLdapFilter filter, ZLdapContext initZlc, boolean basicAttrsOnly) throws ServiceException {
try {
String[] returnAttrs = basicAttrsOnly ? BASIC_DYNAMIC_GROUP_ATTRS : null;
ZSearchResultEntry sr = helper.searchForEntry(mDIT.mailBranchBaseDN(), filter, initZlc, false, returnAttrs);
if (sr != null) {
DynamicGroup grp = makeDynamicGroup(initZlc, sr.getDN(), sr.getAttributes());
List<String> objectclass = sr.getAttributes().getMultiAttrStringAsList(Provisioning.A_objectClass, CheckBinary.NOCHECK);
if (grp != null && objectclass != null && objectclass.contains(AttributeClass.OC_zimbraHabGroup)) {
grp.setHABGroup(Boolean.TRUE);
}
return grp;
}
} catch (LdapMultipleEntriesMatchedException e) {
throw AccountServiceException.MULTIPLE_ENTRIES_MATCHED("getDynamicGroupByQuery", e);
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to lookup group via query: " + filter.toFilterString() + " message:" + e.getMessage(), e);
}
return null;
}
use of com.zimbra.cs.ldap.ZSearchResultEntry 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;
}
use of com.zimbra.cs.ldap.ZSearchResultEntry in project zm-mailbox by Zimbra.
the class ZLdapHelper method searchForEntry.
@Override
@TODOEXCEPTIONMAPPING
public ZSearchResultEntry searchForEntry(String base, ZLdapFilter filter, ZLdapContext initZlc, boolean useMaster, String[] returnAttrs) throws LdapMultipleEntriesMatchedException, ServiceException {
ZLdapContext zlc = initZlc;
try {
if (zlc == null) {
zlc = LdapClient.getContext(LdapServerType.get(useMaster), LdapUsage.SEARCH);
}
ZSearchControls sc = (returnAttrs == null) ? ZSearchControls.SEARCH_CTLS_SUBTREE() : ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_SUBTREE, ZSearchControls.SIZE_UNLIMITED, returnAttrs);
ZSearchResultEnumeration ne = zlc.searchDir(base, filter, sc);
if (ne.hasMore()) {
ZSearchResultEntry sr = ne.next();
if (ne.hasMore()) {
String dups = LdapUtil.formatMultipleMatchedEntries(sr, ne);
throw LdapException.MULTIPLE_ENTRIES_MATCHED(base, filter.toFilterString(), dups);
}
ne.close();
return sr;
}
/* all callsites with the following @TODOEXCEPTIONMAPPING pattern can have ease of mind now and remove the
* TODOEXCEPTIONMAPPING annotation
*
} catch (NameNotFoundException e) {
return null;
} catch (InvalidNameException e) {
return null;
} catch (NamingException e) {
throw ServiceException.FAILURE("unable to lookup account via query: "+query+" message: "+e.getMessage(), e);
*/
} finally {
if (initZlc == null)
LdapClient.closeContext(zlc);
}
return null;
}
Aggregations