Search in sources :

Example 71 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)

Example 72 with ServiceException

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

the class LdapProvisioning method getAttrsInOCs.

@Override
public void getAttrsInOCs(String[] ocs, Set<String> attrsInOCs) throws ServiceException {
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.GET_SCHEMA);
        ZLdapSchema schema = zlc.getSchema();
        for (String oc : ocs) {
            try {
                ZLdapSchema.ZObjectClassDefinition ocSchema = schema.getObjectClass(oc);
                if (ocSchema != null) {
                    List<String> optAttrs = ocSchema.getOptionalAttributes();
                    for (String attr : optAttrs) {
                        attrsInOCs.add(attr);
                    }
                    List<String> reqAttrs = ocSchema.getRequiredAttributes();
                    for (String attr : reqAttrs) {
                        attrsInOCs.add(attr);
                    }
                }
            } catch (ServiceException e) {
                ZimbraLog.account.debug("unable to lookup attributes for objectclass: " + oc, e);
            }
        }
    } catch (ServiceException e) {
        ZimbraLog.account.warn("unable to get LDAP schema", e);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : ZLdapSchema(com.zimbra.cs.ldap.ZLdapSchema) 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)

Example 73 with ServiceException

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

the class LdapProvisioning method createShareLocator.

@Override
public ShareLocator createShareLocator(String id, Map<String, Object> attrs) throws ServiceException {
    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_SHARELOCATOR);
        ZMutableEntry entry = LdapClient.createMutableEntry();
        entry.mapToAttrs(attrs);
        Set<String> ocs = LdapObjectClass.getShareLocatorObjectClasses(this);
        entry.addAttr(A_objectClass, ocs);
        entry.setAttr(A_cn, id);
        String dn = mDIT.shareLocatorIdToDN(id);
        entry.setDN(dn);
        zlc.createEntry(entry);
        ShareLocator shloc = getShareLocatorById(id, zlc, true);
        AttributeManager.getInstance().postModify(attrs, shloc, callbackContext);
        return shloc;
    } catch (LdapEntryAlreadyExistException nabe) {
        throw AccountServiceException.SHARE_LOCATOR_EXISTS(id);
    } catch (LdapException e) {
        throw e;
    } catch (AccountServiceException e) {
        throw e;
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to create share locator: " + id, 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) 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) LdapShareLocator(com.zimbra.cs.account.ldap.entry.LdapShareLocator) ShareLocator(com.zimbra.cs.account.ShareLocator)

Example 74 with ServiceException

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

the class LdapProvisioning method getGroupByQuery.

private Group getGroupByQuery(ZLdapFilter filter, ZLdapContext initZlc, boolean basicAttrsOnly, boolean loadFromMaster) throws ServiceException {
    try {
        String[] returnAttrs = basicAttrsOnly ? BASIC_GROUP_ATTRS : null;
        ZSearchResultEntry sr = helper.searchForEntry(mDIT.mailBranchBaseDN(), filter, initZlc, loadFromMaster, returnAttrs);
        if (sr != null) {
            ZAttributes attrs = sr.getAttributes();
            List<String> objectclass = attrs.getMultiAttrStringAsList(Provisioning.A_objectClass, CheckBinary.NOCHECK);
            if (objectclass.contains(AttributeClass.OC_zimbraDistributionList)) {
                return makeDistributionList(sr.getDN(), attrs, basicAttrsOnly);
            } else if (objectclass.contains(AttributeClass.OC_zimbraGroup)) {
                return makeDynamicGroup(initZlc, sr.getDN(), attrs);
            }
        }
    } catch (LdapMultipleEntriesMatchedException e) {
        throw AccountServiceException.MULTIPLE_ENTRIES_MATCHED("getGroupByQuery", e);
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to lookup group via query: " + filter.toFilterString() + " message:" + e.getMessage(), e);
    }
    return null;
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) LdapMultipleEntriesMatchedException(com.zimbra.cs.ldap.LdapException.LdapMultipleEntriesMatchedException) ZAttributes(com.zimbra.cs.ldap.ZAttributes) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 75 with ServiceException

use of com.zimbra.common.service.ServiceException 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)

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