use of com.zimbra.cs.ldap.LdapException.LdapContextNotEmptyException in project zm-mailbox by Zimbra.
the class LdapProvisioning method deleteDomainInternal.
public void deleteDomainInternal(ZLdapContext zlc, String zimbraId) throws ServiceException {
// TODO: should only allow a domain delete to succeed if there are no people
// if there aren't, we need to delete the people trees first, then delete the domain.
LdapDomain domain = null;
String acctBaseDn = null;
String dynGroupsBaseDn = null;
try {
domain = (LdapDomain) getDomainById(zimbraId, zlc);
if (domain == null) {
throw AccountServiceException.NO_SUCH_DOMAIN(zimbraId);
}
String name = domain.getName();
// delete account base DN
acctBaseDn = mDIT.domainDNToAccountBaseDN(domain.getDN());
if (!acctBaseDn.equals(domain.getDN())) {
try {
zlc.deleteEntry(acctBaseDn);
} catch (LdapEntryNotFoundException e) {
ZimbraLog.account.info("entry %s not found", acctBaseDn);
}
}
// delete dynamic groups base DN
dynGroupsBaseDn = mDIT.domainDNToDynamicGroupsBaseDN(domain.getDN());
if (!dynGroupsBaseDn.equals(domain.getDN())) {
try {
zlc.deleteEntry(dynGroupsBaseDn);
} catch (LdapEntryNotFoundException e) {
ZimbraLog.account.info("entry %s not found", dynGroupsBaseDn);
}
}
try {
zlc.deleteEntry(domain.getDN());
domainCache.remove(domain);
} catch (LdapContextNotEmptyException e) {
// remove from cache before nuking all attrs
domainCache.remove(domain);
// assume subdomains exist and turn into plain dc object
Map<String, String> attrs = new HashMap<String, String>();
attrs.put("-" + A_objectClass, "zimbraDomain");
// remove all zimbra attrs
for (String key : domain.getAttrs(false).keySet()) {
if (key.startsWith("zimbra"))
attrs.put(key, "");
}
// cannot invoke callback here. If another domain attr is added in a callback,
// e.g. zimbraDomainStatus would add zimbraMailStatus, then we will get a LDAP
// schema violation naming error(zimbraDomain is removed, thus there cannot be
// any zimbraAttrs left) and the modify will fail.
modifyAttrs(domain, attrs, false, false);
}
String defaultDomain = getConfig().getAttr(A_zimbraDefaultDomainName, null);
if (name.equalsIgnoreCase(defaultDomain)) {
try {
Map<String, String> attrs = new HashMap<String, String>();
attrs.put(A_zimbraDefaultDomainName, "");
modifyAttrs(getConfig(), attrs);
} catch (Exception e) {
ZimbraLog.account.warn("unable to remove config attr:" + A_zimbraDefaultDomainName, e);
}
}
} catch (LdapContextNotEmptyException e) {
// get a few entries to include in the error message
int maxEntriesToGet = 5;
final String doNotReportThisDN = acctBaseDn;
final StringBuilder sb = new StringBuilder();
sb.append(" (remaining entries: ");
SearchLdapOptions.SearchLdapVisitor visitor = new SearchLdapOptions.SearchLdapVisitor() {
@Override
public void visit(String dn, Map<String, Object> attrs, IAttributes ldapAttrs) {
if (!dn.equals(doNotReportThisDN)) {
sb.append("[" + dn + "] ");
}
}
};
SearchLdapOptions searchOptions = new SearchLdapOptions(acctBaseDn, filterFactory.anyEntry(), new String[] { Provisioning.A_objectClass }, maxEntriesToGet, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
try {
zlc.searchPaged(searchOptions);
} catch (LdapSizeLimitExceededException lslee) {
// quietly ignore
} catch (ServiceException se) {
ZimbraLog.account.warn("unable to get sample entries in non-empty domain " + domain.getName() + " for reporting", se);
}
sb.append("...)");
throw AccountServiceException.DOMAIN_NOT_EMPTY(domain.getName() + sb.toString(), e);
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to purge domain: " + zimbraId, e);
}
}
Aggregations