Search in sources :

Example 41 with ServiceException

use of com.zimbra.common.service.ServiceException 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;
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) LdapCos(com.zimbra.cs.account.ldap.entry.LdapCos) Cos(com.zimbra.cs.account.Cos) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) ArrayList(java.util.ArrayList) LdapCos(com.zimbra.cs.account.ldap.entry.LdapCos) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 42 with ServiceException

use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.

the class LdapProvisioning method getAllIdentities.

@Override
public List<Identity> getAllIdentities(Account account) throws ServiceException {
    LdapEntry ldapEntry = (LdapEntry) (account instanceof LdapEntry ? account : getAccountById(account.getId()));
    if (ldapEntry == null)
        throw AccountServiceException.NO_SUCH_ACCOUNT(account.getName());
    @SuppressWarnings("unchecked") List<Identity> result = (List<Identity>) account.getCachedData(IDENTITY_LIST_CACHE_KEY);
    if (result != null) {
        return result;
    }
    result = getIdentitiesByQuery(ldapEntry, filterFactory.allIdentities(), null);
    for (Identity identity : result) {
        // gross hack for 4.5beta. should be able to remove post 4.5
        if (identity.getId() == null) {
            String id = LdapUtil.generateUUID();
            identity.setId(id);
            Map<String, Object> newAttrs = new HashMap<String, Object>();
            newAttrs.put(Provisioning.A_zimbraPrefIdentityId, id);
            try {
                modifyIdentity(account, identity.getName(), newAttrs);
            } catch (ServiceException se) {
                ZimbraLog.account.warn("error updating identity: " + account.getName() + " " + identity.getName() + " " + se.getMessage(), se);
            }
        }
    }
    result.add(getDefaultIdentity(account));
    result = Collections.unmodifiableList(result);
    account.setCachedData(IDENTITY_LIST_CACHE_KEY, result);
    return result;
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) HashMap(java.util.HashMap) LdapEntry(com.zimbra.cs.account.ldap.entry.LdapEntry) LdapDistributionList(com.zimbra.cs.account.ldap.entry.LdapDistributionList) ArrayList(java.util.ArrayList) List(java.util.List) DistributionList(com.zimbra.cs.account.DistributionList) LdapIdentity(com.zimbra.cs.account.ldap.entry.LdapIdentity) Identity(com.zimbra.cs.account.Identity)

Example 43 with ServiceException

use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.

the class LdapProvisioning method createUCService.

@Override
public UCService createUCService(String name, Map<String, Object> attrs) throws ServiceException {
    name = name.toLowerCase().trim();
    CallbackContext callbackContext = new CallbackContext(CallbackContext.Op.CREATE);
    AttributeManager.getInstance().preModify(attrs, null, callbackContext, true);
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.CREATE_UCSERVICE);
        ZMutableEntry entry = LdapClient.createMutableEntry();
        entry.mapToAttrs(attrs);
        Set<String> ocs = LdapObjectClass.getUCServiceObjectClasses(this);
        entry.addAttr(A_objectClass, ocs);
        String zimbraIdStr = LdapUtil.generateUUID();
        entry.setAttr(A_zimbraId, zimbraIdStr);
        entry.setAttr(A_zimbraCreateTimestamp, LdapDateUtil.toGeneralizedTime(new Date()));
        entry.setAttr(A_cn, name);
        String dn = mDIT.ucServiceNameToDN(name);
        entry.setDN(dn);
        zlc.createEntry(entry);
        UCService ucService = getUCServiceById(zimbraIdStr, zlc, true);
        AttributeManager.getInstance().postModify(attrs, ucService, callbackContext);
        return ucService;
    } catch (LdapEntryAlreadyExistException nabe) {
        throw AccountServiceException.SERVER_EXISTS(name);
    } catch (LdapException e) {
        throw e;
    } catch (AccountServiceException e) {
        throw e;
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to create ucservice: " + name, e);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : ZMutableEntry(com.zimbra.cs.ldap.ZMutableEntry) LdapEntryAlreadyExistException(com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) 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) CallbackContext(com.zimbra.cs.account.callback.CallbackContext) LdapException(com.zimbra.cs.ldap.LdapException) Date(java.util.Date)

Example 44 with ServiceException

use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.

the class LdapProvisioning method refreshEntry.

void refreshEntry(Entry entry, ZLdapContext initZlc) throws ServiceException {
    try {
        String dn = ((LdapEntry) entry).getDN();
        ZAttributes attributes = helper.getAttributes(initZlc, dn);
        Map<String, Object> attrs = attributes.getAttrs();
        Map<String, Object> defaults = null;
        Map<String, Object> secondaryDefaults = null;
        Map<String, Object> overrideDefaults = null;
        if (entry instanceof Account) {
            //
            // We can get here from either modifyAttrsInternal or reload path.
            //
            // If we got here from modifyAttrsInternal, zimbraCOSId on account
            // might have been changed, added, removed, but entry now still contains
            // the old attrs.  Create a temp Account object from the new attrs, and then
            // use the same cos of the temp Account object for our entry object.
            //
            // If we got here from reload, attrs are likely not changed, the callsites
            // just want a refreshed object.  For this case it's best if we still
            // always resolve the COS correctly.  makeAccount is a cheap call and won't
            // add any overhead like loading cos/domain from LDAP: even if cos/domain
            // has to be loaded (because not in cache) in the getCOS(temp) call, it's
            // just the same as calling (buggy) getCOS(entry) before.
            //
            // We only need the temp object for the getCOS call, don't need to setup
            // primary/secondary defaults on the temp object because:
            //     zimbraCOSId is only on account(of course), and that's all needed
            //     for determining the COS for the account in the getCOS call: if
            //     zimbraCOSId is not set on account, it will fallback to the domain
            //     default COS, then fallback to the system default COS.
            //
            Account temp = makeAccountNoDefaults(dn, attributes);
            Cos cos = getCOS(temp);
            if (cos != null)
                defaults = cos.getAccountDefaults();
            Domain domain = getDomain((Account) entry);
            if (domain != null)
                secondaryDefaults = domain.getAccountDefaults();
        } else if (entry instanceof Domain) {
            defaults = getConfig().getDomainDefaults();
        } else if (entry instanceof Server) {
            defaults = getConfig().getServerDefaults();
            AlwaysOnCluster aoc = getAlwaysOnCluster((Server) entry);
            if (aoc != null) {
                overrideDefaults = aoc.getServerOverrides();
            }
        }
        if (defaults == null && secondaryDefaults == null)
            entry.setAttrs(attrs);
        else
            entry.setAttrs(attrs, defaults, secondaryDefaults, overrideDefaults);
        extendLifeInCacheOrFlush(entry);
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to refresh entry", e);
    }
}
Also used : Account(com.zimbra.cs.account.Account) GuestAccount(com.zimbra.cs.account.GuestAccount) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) InMemoryLdapServer(com.zimbra.cs.ldap.unboundid.InMemoryLdapServer) LdapServer(com.zimbra.cs.account.ldap.entry.LdapServer) Server(com.zimbra.cs.account.Server) LdapAlwaysOnCluster(com.zimbra.cs.account.ldap.entry.LdapAlwaysOnCluster) AlwaysOnCluster(com.zimbra.cs.account.AlwaysOnCluster) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) LdapCos(com.zimbra.cs.account.ldap.entry.LdapCos) Cos(com.zimbra.cs.account.Cos) ZAttributes(com.zimbra.cs.ldap.ZAttributes) LdapEntry(com.zimbra.cs.account.ldap.entry.LdapEntry) LdapDomain(com.zimbra.cs.account.ldap.entry.LdapDomain) Domain(com.zimbra.cs.account.Domain)

Example 45 with ServiceException

use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.

the class LdapProvisioning method renameXMPPComponent.

// Only called from renameDomain for now
void renameXMPPComponent(String zimbraId, String newName) throws ServiceException {
    LdapXMPPComponent comp = (LdapXMPPComponent) get(Key.XMPPComponentBy.id, zimbraId);
    if (comp == null)
        throw AccountServiceException.NO_SUCH_XMPP_COMPONENT(zimbraId);
    newName = newName.toLowerCase().trim();
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.RENAME_XMPPCOMPONENT);
        String newDn = mDIT.xmppcomponentNameToDN(newName);
        zlc.renameEntry(comp.getDN(), newDn);
        // remove old comp from cache
        xmppComponentCache.remove(comp);
    } catch (LdapEntryAlreadyExistException nabe) {
        throw AccountServiceException.IM_COMPONENT_EXISTS(newName);
    } catch (LdapException e) {
        throw e;
    } catch (AccountServiceException e) {
        throw e;
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to rename XMPPComponent: " + zimbraId, e);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : LdapEntryAlreadyExistException(com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) LdapXMPPComponent(com.zimbra.cs.account.ldap.entry.LdapXMPPComponent) LdapException(com.zimbra.cs.ldap.LdapException)

Aggregations

ServiceException (com.zimbra.common.service.ServiceException)772 AccountServiceException (com.zimbra.cs.account.AccountServiceException)220 Account (com.zimbra.cs.account.Account)193 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)149 IOException (java.io.IOException)127 Mailbox (com.zimbra.cs.mailbox.Mailbox)122 ArrayList (java.util.ArrayList)107 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)100 Element (com.zimbra.common.soap.Element)97 HashMap (java.util.HashMap)93 Test (org.junit.Test)89 Provisioning (com.zimbra.cs.account.Provisioning)86 Domain (com.zimbra.cs.account.Domain)60 Folder (com.zimbra.cs.mailbox.Folder)54 Server (com.zimbra.cs.account.Server)53 ItemId (com.zimbra.cs.service.util.ItemId)52 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)51 ZMailbox (com.zimbra.client.ZMailbox)50 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)46 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)44