Search in sources :

Example 1 with LdapEntryNotFoundException

use of com.zimbra.cs.ldap.LdapException.LdapEntryNotFoundException in project zm-mailbox by Zimbra.

the class LdapProvisioning method getUCServiceByName.

private UCService getUCServiceByName(String name, boolean nocache) throws ServiceException {
    if (!nocache) {
        UCService s = ucServiceCache.getByName(name);
        if (s != null) {
            return s;
        }
    }
    try {
        String dn = mDIT.ucServiceNameToDN(name);
        ZAttributes attrs = helper.getAttributes(LdapUsage.GET_UCSERVICE, dn);
        LdapUCService s = new LdapUCService(dn, attrs, this);
        ucServiceCache.put(s);
        return s;
    } catch (LdapEntryNotFoundException e) {
        return null;
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to lookup ucservice by name: " + name + " message: " + e.getMessage(), e);
    }
}
Also used : LdapUCService(com.zimbra.cs.account.ldap.entry.LdapUCService) UCService(com.zimbra.cs.account.UCService) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) LdapEntryNotFoundException(com.zimbra.cs.ldap.LdapException.LdapEntryNotFoundException) ZAttributes(com.zimbra.cs.ldap.ZAttributes) LdapUCService(com.zimbra.cs.account.ldap.entry.LdapUCService)

Example 2 with LdapEntryNotFoundException

use of com.zimbra.cs.ldap.LdapException.LdapEntryNotFoundException 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);
    }
}
Also used : HashMap(java.util.HashMap) LdapDomain(com.zimbra.cs.account.ldap.entry.LdapDomain) SearchLdapOptions(com.zimbra.cs.ldap.SearchLdapOptions) LdapContextNotEmptyException(com.zimbra.cs.ldap.LdapException.LdapContextNotEmptyException) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ZimletException(com.zimbra.cs.zimlet.ZimletException) LdapEntryNotFoundException(com.zimbra.cs.ldap.LdapException.LdapEntryNotFoundException) IOException(java.io.IOException) LdapInvalidSearchFilterException(com.zimbra.cs.ldap.LdapException.LdapInvalidSearchFilterException) StopIteratingException(com.zimbra.cs.ldap.SearchLdapOptions.StopIteratingException) LdapInvalidAttrValueException(com.zimbra.cs.ldap.LdapException.LdapInvalidAttrValueException) LdapContextNotEmptyException(com.zimbra.cs.ldap.LdapException.LdapContextNotEmptyException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) LdapEntryAlreadyExistException(com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException) ServiceException(com.zimbra.common.service.ServiceException) LdapException(com.zimbra.cs.ldap.LdapException) LdapMultipleEntriesMatchedException(com.zimbra.cs.ldap.LdapException.LdapMultipleEntriesMatchedException) PatternSyntaxException(java.util.regex.PatternSyntaxException) LdapSizeLimitExceededException(com.zimbra.cs.ldap.LdapException.LdapSizeLimitExceededException) LdapInvalidAttrNameException(com.zimbra.cs.ldap.LdapException.LdapInvalidAttrNameException) SearchLdapVisitor(com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor) SearchLdapVisitor(com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) LdapEntryNotFoundException(com.zimbra.cs.ldap.LdapException.LdapEntryNotFoundException) IAttributes(com.zimbra.cs.ldap.IAttributes) LdapSizeLimitExceededException(com.zimbra.cs.ldap.LdapException.LdapSizeLimitExceededException) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap)

Example 3 with LdapEntryNotFoundException

use of com.zimbra.cs.ldap.LdapException.LdapEntryNotFoundException in project zm-mailbox by Zimbra.

the class TestLdapHelper method getAttributesEntryNotFound.

@Test
public void getAttributesEntryNotFound() throws Exception {
    String dn = prov.getDIT().configDN() + "-not";
    boolean caughtException = false;
    try {
        ZAttributes attrs = ldapHelper.getAttributes(LdapUsage.UNITTEST, dn);
    } catch (LdapEntryNotFoundException e) {
        caughtException = true;
    }
    assertTrue(caughtException);
}
Also used : LdapEntryNotFoundException(com.zimbra.cs.ldap.LdapException.LdapEntryNotFoundException) ZAttributes(com.zimbra.cs.ldap.ZAttributes)

Example 4 with LdapEntryNotFoundException

use of com.zimbra.cs.ldap.LdapException.LdapEntryNotFoundException in project zm-mailbox by Zimbra.

the class LdapGalSearch method getGalEntryByDn.

public static void getGalEntryByDn(ZLdapContext zlc, GalSearchConfig.GalType galType, String dn, LdapGalMapRules rules, SearchGalResult result) throws ServiceException {
    String[] reqAttrs = rules.getLdapAttrs();
    if (ZimbraLog.gal.isDebugEnabled()) {
        StringBuffer returnAttrs = new StringBuffer();
        for (String a : reqAttrs) {
            returnAttrs.append(a + ",");
        }
        zlc.debug();
        ZimbraLog.gal.debug("getGalEntryByDn: " + ", dn=" + dn + ", attrs=" + returnAttrs);
    }
    SearhcGalVisitor visitor = new SearhcGalVisitor(zlc, galType, null, rules, result);
    try {
        ZAttributes attrs = zlc.getAttributes(dn, reqAttrs);
        visitor.visit(dn, attrs);
    } catch (LdapEntryNotFoundException e) {
        ZimbraLog.gal.debug("getGalEntryByDn: no such dn: " + dn, e);
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to search gal", e);
    }
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) LdapEntryNotFoundException(com.zimbra.cs.ldap.LdapException.LdapEntryNotFoundException) ZAttributes(com.zimbra.cs.ldap.ZAttributes)

Example 5 with LdapEntryNotFoundException

use of com.zimbra.cs.ldap.LdapException.LdapEntryNotFoundException in project zm-mailbox by Zimbra.

the class LdapProvisioning method getServerByName.

private Server getServerByName(String name, boolean nocache) throws ServiceException {
    if (!nocache) {
        Server s = serverCache.getByName(name);
        if (s != null)
            return s;
    }
    try {
        String dn = mDIT.serverNameToDN(name);
        ZAttributes attrs = helper.getAttributes(LdapUsage.GET_SERVER, dn);
        LdapServer s = new LdapServer(dn, attrs, getConfig().getServerDefaults(), this);
        serverCache.put(s);
        return s;
    } catch (LdapEntryNotFoundException e) {
        return null;
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to lookup server by name: " + name + " message: " + e.getMessage(), e);
    }
}
Also used : InMemoryLdapServer(com.zimbra.cs.ldap.unboundid.InMemoryLdapServer) LdapServer(com.zimbra.cs.account.ldap.entry.LdapServer) InMemoryLdapServer(com.zimbra.cs.ldap.unboundid.InMemoryLdapServer) LdapServer(com.zimbra.cs.account.ldap.entry.LdapServer) Server(com.zimbra.cs.account.Server) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) LdapEntryNotFoundException(com.zimbra.cs.ldap.LdapException.LdapEntryNotFoundException) ZAttributes(com.zimbra.cs.ldap.ZAttributes)

Aggregations

LdapEntryNotFoundException (com.zimbra.cs.ldap.LdapException.LdapEntryNotFoundException)9 ServiceException (com.zimbra.common.service.ServiceException)8 ZAttributes (com.zimbra.cs.ldap.ZAttributes)8 AccountServiceException (com.zimbra.cs.account.AccountServiceException)7 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)7 ZimletException (com.zimbra.cs.zimlet.ZimletException)2 AlwaysOnCluster (com.zimbra.cs.account.AlwaysOnCluster)1 Server (com.zimbra.cs.account.Server)1 UCService (com.zimbra.cs.account.UCService)1 XMPPComponent (com.zimbra.cs.account.XMPPComponent)1 LdapAlwaysOnCluster (com.zimbra.cs.account.ldap.entry.LdapAlwaysOnCluster)1 LdapCos (com.zimbra.cs.account.ldap.entry.LdapCos)1 LdapDomain (com.zimbra.cs.account.ldap.entry.LdapDomain)1 LdapServer (com.zimbra.cs.account.ldap.entry.LdapServer)1 LdapUCService (com.zimbra.cs.account.ldap.entry.LdapUCService)1 LdapXMPPComponent (com.zimbra.cs.account.ldap.entry.LdapXMPPComponent)1 LdapZimlet (com.zimbra.cs.account.ldap.entry.LdapZimlet)1 IAttributes (com.zimbra.cs.ldap.IAttributes)1 LdapException (com.zimbra.cs.ldap.LdapException)1 LdapContextNotEmptyException (com.zimbra.cs.ldap.LdapException.LdapContextNotEmptyException)1