Search in sources :

Example 1 with ModifyAccountRequest

use of com.zimbra.soap.admin.message.ModifyAccountRequest in project zm-mailbox by Zimbra.

the class TestServerEnumeration method testModifyAccountAsGlobalAdmin.

@Test
public void testModifyAccountAsGlobalAdmin() throws Exception {
    ModifyAccountRequest req = new ModifyAccountRequest(myUser.getId());
    req.addAttr(new Attr(Provisioning.A_zimbraMailHost, NON_EXISTING_SERVER));
    req.addAttr(new Attr(Provisioning.A_description, "test description"));
    try {
        adminSoapProv.invokeJaxb(req);
        fail("should have caught an exception");
    } catch (SoapFaultException e) {
        assertEquals("should be getting 'no such server' response", AccountServiceException.NO_SUCH_SERVER, e.getCode());
    }
}
Also used : ModifyAccountRequest(com.zimbra.soap.admin.message.ModifyAccountRequest) Attr(com.zimbra.soap.admin.type.Attr) SoapFaultException(com.zimbra.common.soap.SoapFaultException) Test(org.junit.Test)

Example 2 with ModifyAccountRequest

use of com.zimbra.soap.admin.message.ModifyAccountRequest in project zm-mailbox by Zimbra.

the class TestServerEnumeration method testModifyAccount.

@Test
public void testModifyAccount() throws Exception {
    List<AdminRight> relatedRights = new ArrayList<AdminRight>();
    List<String> notes = new ArrayList<String>();
    AdminDocumentHandler handler = new ModifyAccount();
    handler.docRights(relatedRights, notes);
    createDelegatedAdmin(relatedRights);
    grantRightToAdmin(adminSoapProv, com.zimbra.soap.type.TargetType.fromString(com.zimbra.cs.account.accesscontrol.TargetType.account.toString()), MY_USER, DELEGATED_ADMIN_NAME, Admin.R_modifyAccount.getName());
    adminSoapProv.flushCache(CacheEntryType.acl, null);
    ModifyAccountRequest req = new ModifyAccountRequest(myUser.getId());
    req.addAttr(new Attr(Provisioning.A_zimbraMailHost, NON_EXISTING_SERVER));
    req.addAttr(new Attr(Provisioning.A_description, "test description"));
    try {
        delegatedSoapProv.invokeJaxb(req);
        fail("should have caught an exception");
    } catch (SoapFaultException e) {
        assertEquals("should be getting 'Permission Denied' response", ServiceException.PERM_DENIED, e.getCode());
    }
}
Also used : ModifyAccount(com.zimbra.cs.service.admin.ModifyAccount) AdminRight(com.zimbra.cs.account.accesscontrol.AdminRight) ModifyAccountRequest(com.zimbra.soap.admin.message.ModifyAccountRequest) ArrayList(java.util.ArrayList) AdminDocumentHandler(com.zimbra.cs.service.admin.AdminDocumentHandler) Attr(com.zimbra.soap.admin.type.Attr) SoapFaultException(com.zimbra.common.soap.SoapFaultException) Test(org.junit.Test)

Example 3 with ModifyAccountRequest

use of com.zimbra.soap.admin.message.ModifyAccountRequest in project zm-mailbox by Zimbra.

the class TestServerEnumeration method testModifyAccountSufficientPermissions.

@Test
public void testModifyAccountSufficientPermissions() throws Exception {
    List<AdminRight> relatedRights = new ArrayList<AdminRight>();
    List<String> notes = new ArrayList<String>();
    AdminDocumentHandler handler = new ModifyAccount();
    handler.docRights(relatedRights, notes);
    createDelegatedAdmin(relatedRights);
    grantRightToAdmin(adminSoapProv, com.zimbra.soap.type.TargetType.fromString(com.zimbra.cs.account.accesscontrol.TargetType.account.toString()), MY_USER, DELEGATED_ADMIN_NAME, Admin.R_modifyAccount.getName());
    grantRightToAdmin(adminSoapProv, com.zimbra.soap.type.TargetType.fromString(com.zimbra.cs.account.accesscontrol.TargetType.global.toString()), null, DELEGATED_ADMIN_NAME, Admin.R_listServer.getName());
    adminSoapProv.flushCache(CacheEntryType.acl, null);
    ModifyAccountRequest req = new ModifyAccountRequest(myUser.getId());
    req.addAttr(new Attr(Provisioning.A_zimbraMailHost, NON_EXISTING_SERVER));
    req.addAttr(new Attr(Provisioning.A_description, "test description"));
    try {
        delegatedSoapProv.invokeJaxb(req);
        fail("should have caught an exception");
    } catch (SoapFaultException e) {
        assertEquals("should be getting 'no such server' response", AccountServiceException.NO_SUCH_SERVER, e.getCode());
    }
}
Also used : ModifyAccount(com.zimbra.cs.service.admin.ModifyAccount) AdminRight(com.zimbra.cs.account.accesscontrol.AdminRight) ModifyAccountRequest(com.zimbra.soap.admin.message.ModifyAccountRequest) ArrayList(java.util.ArrayList) AdminDocumentHandler(com.zimbra.cs.service.admin.AdminDocumentHandler) Attr(com.zimbra.soap.admin.type.Attr) SoapFaultException(com.zimbra.common.soap.SoapFaultException) Test(org.junit.Test)

Example 4 with ModifyAccountRequest

use of com.zimbra.soap.admin.message.ModifyAccountRequest in project zm-mailbox by Zimbra.

the class ModifyAccount method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    ModifyAccountRequest req = JaxbUtil.elementToJaxb(request);
    AuthToken authToken = zsc.getAuthToken();
    String id = req.getId();
    if (null == id) {
        throw ServiceException.INVALID_REQUEST("missing required attribute: " + AdminConstants.E_ID, null);
    }
    Account account = prov.get(AccountBy.id, id, authToken);
    Map<String, Object> attrs = req.getAttrsAsOldMultimap();
    defendAgainstAccountHarvesting(account, AccountBy.id, id, zsc, attrs);
    // check to see if quota is being changed
    long curQuota = account.getLongAttr(Provisioning.A_zimbraMailQuota, 0);
    /*
         * // Note: isDomainAdminOnly *always* returns false for pure ACL based AccessManager // checkQuota is called
         * only for domain based access manager, remove when we // can totally deprecate domain based access manager if
         * (isDomainAdminOnly(zsc)) checkQuota(zsc, account, attrs);
         */
    /*
         * for bug 42896, the above is no longer true.
         * 
         * For quota, we have to support the per admin limitation zimbraDomainAdminMaxMailQuota, until we come up with a
         * framework to support constraints on a per admin basis.
         * 
         * for now, always call checkQuota, which will check zimbraDomainAdminMaxMailQuota.
         * 
         * If the access manager, and if we have come here, it has already passed the constraint checking, in the
         * checkAccountRight call. If it had violated any constraint, it would have errored out. i.e. for
         * zimbraMailQuota, both zimbraConstraint and zimbraDomainAdminMaxMailQuota are enforced.
         */
    checkQuota(zsc, account, attrs);
    // check to see if cos is being changed, need right on new cos
    checkCos(zsc, account, attrs);
    Server newServer = null;
    String newServerName = getStringAttrNewValue(Provisioning.A_zimbraMailHost, attrs);
    if (newServerName != null) {
        newServer = Provisioning.getInstance().getServerByName(newServerName);
        defendAgainstServerNameHarvesting(newServer, Key.ServerBy.name, newServerName, zsc, Admin.R_listServer);
    }
    // pass in true to checkImmutable
    prov.modifyAttrs(account, attrs, true);
    // get account again, in the case when zimbraCOSId or zimbraForeignPrincipal
    // is changed, the cache object(he one we are holding on to) would'd been
    // flushed out from cache. Get the account again to get the fresh one.
    account = prov.get(AccountBy.id, id, zsc.getAuthToken());
    ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "ModifyAccount", "name", account.getName() }, attrs));
    if (newServer != null) {
        checkNewServer(zsc, context, account, newServer);
    }
    long newQuota = account.getLongAttr(Provisioning.A_zimbraMailQuota, 0);
    if (newQuota != curQuota) {
        // clear the quota cache
        AdminSession session = (AdminSession) getSession(zsc, Session.Type.ADMIN);
        if (session != null) {
            GetQuotaUsage.clearCachedQuotaUsage(session);
        }
    }
    Element response = zsc.createElement(AdminConstants.MODIFY_ACCOUNT_RESPONSE);
    ToXML.encodeAccount(response, account);
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) Server(com.zimbra.cs.account.Server) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) ModifyAccountRequest(com.zimbra.soap.admin.message.ModifyAccountRequest) AdminSession(com.zimbra.cs.session.AdminSession) Element(com.zimbra.common.soap.Element) AuthToken(com.zimbra.cs.account.AuthToken) Provisioning(com.zimbra.cs.account.Provisioning) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning)

Example 5 with ModifyAccountRequest

use of com.zimbra.soap.admin.message.ModifyAccountRequest in project zm-mailbox by Zimbra.

the class TestPurgeDataSource method setThreadingAlgorithm.

private void setThreadingAlgorithm(String algorithm) throws ServiceException, IOException {
    Map<String, Object> attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_zimbraMailThreadingAlgorithm, algorithm);
    ModifyAccountRequest modifyRequest = new ModifyAccountRequest(account.getId());
    modifyRequest.setAttrs(attrs);
    SoapTest.invokeJaxb(transport, modifyRequest);
}
Also used : HashMap(java.util.HashMap) ModifyAccountRequest(com.zimbra.soap.admin.message.ModifyAccountRequest)

Aggregations

ModifyAccountRequest (com.zimbra.soap.admin.message.ModifyAccountRequest)8 SoapFaultException (com.zimbra.common.soap.SoapFaultException)5 Attr (com.zimbra.soap.admin.type.Attr)5 Test (org.junit.Test)5 Account (com.zimbra.cs.account.Account)3 SoapProvisioning (com.zimbra.cs.account.soap.SoapProvisioning)3 AdminRight (com.zimbra.cs.account.accesscontrol.AdminRight)2 AdminDocumentHandler (com.zimbra.cs.service.admin.AdminDocumentHandler)2 ModifyAccount (com.zimbra.cs.service.admin.ModifyAccount)2 DeleteAccountRequest (com.zimbra.soap.admin.message.DeleteAccountRequest)2 DeleteAccountResponse (com.zimbra.soap.admin.message.DeleteAccountResponse)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Element (com.zimbra.common.soap.Element)1 AuthToken (com.zimbra.cs.account.AuthToken)1 Provisioning (com.zimbra.cs.account.Provisioning)1 Server (com.zimbra.cs.account.Server)1 AdminSession (com.zimbra.cs.session.AdminSession)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 ModifyAccountResponse (com.zimbra.soap.admin.message.ModifyAccountResponse)1