use of com.zimbra.cs.ldap.ZSearchResultEntry in project zm-mailbox by Zimbra.
the class LdapProvisioning method getAllCos.
@Override
public List<Cos> getAllCos() throws ServiceException {
List<Cos> result = new ArrayList<Cos>();
try {
ZSearchResultEnumeration ne = helper.searchDir(mDIT.cosBaseDN(), filterFactory.allCoses(), ZSearchControls.SEARCH_CTLS_SUBTREE());
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 list all COS", e);
}
Collections.sort(result);
return result;
}
use of com.zimbra.cs.ldap.ZSearchResultEntry in project zm-mailbox by Zimbra.
the class ExternalGroup method searchGroup.
private static ExternalGroup searchGroup(DomainBy domainBy, String extGroupGrantee, boolean asAdmin) throws ServiceException {
LdapProv prov = LdapProv.getInst();
ExternalGroupInfo extGrpInfo = ExternalGroupInfo.parse(extGroupGrantee);
String zimbraDomain = extGrpInfo.getZimbraDmain();
String extGroupName = extGrpInfo.getExternalGroupName();
Domain domain = prov.get(domainBy, zimbraDomain);
if (domain == null) {
throw AccountServiceException.NO_SUCH_DOMAIN(zimbraDomain);
}
String searchBase = domain.getExternalGroupLdapSearchBase();
String filterTemplate = domain.getExternalGroupLdapSearchFilter();
if (searchBase == null) {
searchBase = LdapConstants.DN_ROOT_DSE;
}
String searchFilter = LdapUtil.computeDn(extGroupName, filterTemplate);
GroupHandler groupHandler = getGroupHandler(domain);
ZLdapContext zlc = null;
try {
zlc = groupHandler.getExternalDelegatedAdminGroupsLdapContext(domain, asAdmin);
ZSearchResultEntry entry = prov.getHelper().searchForEntry(searchBase, FilterId.EXTERNAL_GROUP, searchFilter, zlc, new String[] { "mail" });
if (entry != null) {
return makeExternalGroup(domain, groupHandler, extGroupName, entry.getDN(), entry.getAttributes());
} else {
return null;
}
} finally {
LdapClient.closeContext(zlc);
}
}
use of com.zimbra.cs.ldap.ZSearchResultEntry in project zm-mailbox by Zimbra.
the class LdapProvisioning method getAddressList.
/**
* @param id id of the address list
* @return AddressList object
* @throws ServiceException if an error occurs while querying LDAP.
*/
@Override
public AddressList getAddressList(String zimbraId) throws ServiceException {
AddressList list = null;
try {
ZimbraLog.ldap.info("Called addresslist");
String[] returnAttrs = { "objectClass", Provisioning.A_uid, Provisioning.A_zimbraId, Provisioning.A_zimbraAddressListGalFilter, Provisioning.A_description, Provisioning.A_zimbraIsAddressListActive, Provisioning.A_zimbraAddressListLdapFilter };
ZSearchControls searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_SUBTREE, ZSearchControls.SIZE_UNLIMITED, returnAttrs);
ZSearchResultEnumeration ne = helper.searchDir(mDIT.mailBranchBaseDN(), filterFactory.addressListById(zimbraId), searchControls, null, LdapServerType.MASTER);
if (ne.hasMore()) {
ZSearchResultEntry sr = ne.next();
String dn = sr.getDN();
ZimbraLog.ldap.debug("Got address list: %s with attributes : %s", dn, sr.getAttributes());
Map<String, Object> attrs = sr.getAttributes().getAttrs();
String name = (String) attrs.get(Provisioning.A_displayName);
list = new AddressList(dn, name, zimbraId, attrs, null, this);
}
ne.close();
} catch (ServiceException e) {
throw ServiceException.FAILURE(String.format("Unable to fetch address list '%s'", zimbraId), e);
}
return list;
}
use of com.zimbra.cs.ldap.ZSearchResultEntry in project zm-mailbox by Zimbra.
the class LdapProvisioning method getAllMimeTypesByQuery.
@Override
public List<MimeTypeInfo> getAllMimeTypesByQuery() throws ServiceException {
List<MimeTypeInfo> mimeTypes = new ArrayList<MimeTypeInfo>();
try {
ZSearchResultEnumeration ne = helper.searchDir(mDIT.mimeBaseDN(), filterFactory.allMimeEntries(), ZSearchControls.SEARCH_CTLS_SUBTREE());
while (ne.hasMore()) {
ZSearchResultEntry sr = ne.next();
mimeTypes.add(new LdapMimeType(sr, this));
}
ne.close();
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to get mime types", e);
}
return mimeTypes;
}
use of com.zimbra.cs.ldap.ZSearchResultEntry in project zm-mailbox by Zimbra.
the class LdapProvisioning method getEmptyAliasDomainIds.
public List<String> getEmptyAliasDomainIds(ZLdapContext zlc, Domain targetDomain, boolean subordinateCheck) throws ServiceException {
List<String> aliasDomainIds = new ArrayList<String>();
ZSearchResultEnumeration ne = null;
try {
ZSearchControls searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_SUBTREE, ZSearchControls.SIZE_UNLIMITED, new String[] { Provisioning.A_zimbraId, Provisioning.A_zimbraDomainName });
ne = helper.searchDir(mDIT.domainBaseDN(), filterFactory.domainAliases(targetDomain.getId()), searchControls, zlc, LdapServerType.MASTER);
while (ne.hasMore()) {
ZSearchResultEntry sr = ne.next();
String aliasDomainId = sr.getAttributes().getAttrString(Provisioning.A_zimbraId);
String aliasDomainName = sr.getAttributes().getAttrString(Provisioning.A_zimbraDomainName);
// make sure the alias domain is ready to be deleted
String aliasDomainDn = sr.getDN();
String acctBaseDn = mDIT.domainDNToAccountBaseDN(aliasDomainDn);
String dynGroupsBaseDn = mDIT.domainDNToDynamicGroupsBaseDN(aliasDomainDn);
if (subordinateCheck && (hasSubordinates(zlc, acctBaseDn) || hasSubordinates(zlc, dynGroupsBaseDn))) {
throw ServiceException.FAILURE("alias domain " + aliasDomainName + " of domain " + targetDomain.getName() + " is not empty", null);
}
if (aliasDomainId != null) {
aliasDomainIds.add(aliasDomainId);
}
}
} finally {
ne.close();
}
return aliasDomainIds;
}
Aggregations