Search in sources :

Example 96 with ServiceException

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

the class LdapProvisioning method getDynamicGroupByQuery.

private DynamicGroup getDynamicGroupByQuery(ZLdapFilter filter, ZLdapContext initZlc, boolean basicAttrsOnly) throws ServiceException {
    try {
        String[] returnAttrs = basicAttrsOnly ? BASIC_DYNAMIC_GROUP_ATTRS : null;
        ZSearchResultEntry sr = helper.searchForEntry(mDIT.mailBranchBaseDN(), filter, initZlc, false, returnAttrs);
        if (sr != null) {
            return makeDynamicGroup(initZlc, sr.getDN(), sr.getAttributes());
        }
    } catch (LdapMultipleEntriesMatchedException e) {
        throw AccountServiceException.MULTIPLE_ENTRIES_MATCHED("getDynamicGroupByQuery", 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) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 97 with ServiceException

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

the class LdapProvisioning method getDNforAccountById.

public String getDNforAccountById(String zimbraId, ZLdapContext zlc, boolean loadFromMaster) {
    if (zimbraId == null) {
        return null;
    }
    ZLdapFilter filter = filterFactory.accountById(zimbraId);
    try {
        String[] retAttrs = new String[] { Provisioning.A_zimbraId };
        /* Just 1 attr to save bandwidth */
        ZSearchResultEntry sr;
        sr = getSearchResultForAccountByQuery(mDIT.mailBranchBaseDN(), filter, zlc, loadFromMaster, retAttrs);
        // search again under the admin base if not found and admin base is not under mail base
        if (sr == null && !mDIT.isUnder(mDIT.mailBranchBaseDN(), mDIT.adminBaseDN())) {
            sr = getSearchResultForAccountByQuery(mDIT.adminBaseDN(), filter, zlc, loadFromMaster, retAttrs);
        }
        if (sr != null) {
            return sr.getDN();
        }
    } catch (ServiceException e) {
        ZimbraLog.search.debug("unable to lookup DN for account via query: %s", filter.toFilterString(), e);
    }
    return null;
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 98 with ServiceException

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

the class LdapProvisioning method renameUCService.

@Override
public void renameUCService(String zimbraId, String newName) throws ServiceException {
    LdapUCService ucService = (LdapUCService) getUCServiceById(zimbraId, null, false);
    if (ucService == null) {
        throw AccountServiceException.NO_SUCH_UC_SERVICE(zimbraId);
    }
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.RENAME_UCSERVICE);
        String newDn = mDIT.ucServiceNameToDN(newName);
        zlc.renameEntry(ucService.getDN(), newDn);
        ucServiceCache.remove(ucService);
    } catch (LdapEntryAlreadyExistException nabe) {
        throw AccountServiceException.UC_SERVICE_EXISTS(newName);
    } catch (LdapException e) {
        throw e;
    } catch (AccountServiceException e) {
        throw e;
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to rename ucservice: " + 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) LdapUCService(com.zimbra.cs.account.ldap.entry.LdapUCService) LdapException(com.zimbra.cs.ldap.LdapException)

Example 99 with ServiceException

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

the class LdapProvisioning method createZimlet.

@Override
public Zimlet createZimlet(String name, Map<String, Object> zimletAttrs) throws ServiceException {
    name = name.toLowerCase().trim();
    CallbackContext callbackContext = new CallbackContext(CallbackContext.Op.CREATE);
    AttributeManager.getInstance().preModify(zimletAttrs, null, callbackContext, true);
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.CREATE_ZIMLET);
        String hasKeyword = LdapConstants.LDAP_FALSE;
        if (zimletAttrs.containsKey(A_zimbraZimletKeyword)) {
            hasKeyword = ProvisioningConstants.TRUE;
        }
        ZMutableEntry entry = LdapClient.createMutableEntry();
        entry.mapToAttrs(zimletAttrs);
        entry.setAttr(A_objectClass, "zimbraZimletEntry");
        entry.setAttr(A_zimbraZimletEnabled, ProvisioningConstants.FALSE);
        entry.setAttr(A_zimbraZimletIndexingEnabled, hasKeyword);
        entry.setAttr(A_zimbraCreateTimestamp, LdapDateUtil.toGeneralizedTime(new Date()));
        String dn = mDIT.zimletNameToDN(name);
        entry.setDN(dn);
        zlc.createEntry(entry);
        Zimlet zimlet = lookupZimlet(name, zlc);
        AttributeManager.getInstance().postModify(zimletAttrs, zimlet, callbackContext);
        return zimlet;
    } catch (LdapEntryAlreadyExistException nabe) {
        throw AccountServiceException.ZIMLET_EXISTS(name);
    } catch (LdapException e) {
        throw e;
    } catch (AccountServiceException e) {
        throw e;
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to create zimlet: " + 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) Zimlet(com.zimbra.cs.account.Zimlet) LdapZimlet(com.zimbra.cs.account.ldap.entry.LdapZimlet) 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) Date(java.util.Date)

Example 100 with ServiceException

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

the class BUG_18277 method getAllDomainOrGlobalAdmins.

private void getAllDomainOrGlobalAdmins(Set<String> domainAdminIds, Set<String> globalAdminIds) throws ServiceException {
    LdapDIT dit = prov.getDIT();
    String[] returnAttrs = new String[] { Provisioning.A_objectClass, Provisioning.A_zimbraId, Provisioning.A_zimbraIsAdminAccount, Provisioning.A_zimbraIsDomainAdminAccount, Provisioning.A_zimbraIsDelegatedAdminAccount };
    String configBranchBaseDn = dit.configBranchBaseDN();
    String base = dit.mailBranchBaseDN();
    String query = "(&(objectclass=zimbraAccount)(|(zimbraIsDomainAdminAccount=TRUE)(zimbraIsAdminAccount=TRUE)))";
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.UPGRADE);
        Bug18277Visitor visitor = new Bug18277Visitor(this, configBranchBaseDn, domainAdminIds, globalAdminIds);
        SearchLdapOptions searchOpts = new SearchLdapOptions(base, getFilter(query), returnAttrs, SearchLdapOptions.SIZE_UNLIMITED, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
        zlc.searchPaged(searchOpts);
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to list all objects", e);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : LdapDIT(com.zimbra.cs.account.ldap.LdapDIT) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) ServiceException(com.zimbra.common.service.ServiceException) SearchLdapOptions(com.zimbra.cs.ldap.SearchLdapOptions)

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