Search in sources :

Example 6 with AdminRight

use of com.zimbra.cs.account.accesscontrol.AdminRight 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 7 with AdminRight

use of com.zimbra.cs.account.accesscontrol.AdminRight 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 8 with AdminRight

use of com.zimbra.cs.account.accesscontrol.AdminRight in project zm-mailbox by Zimbra.

the class TestServerEnumeration method testModifyCalresSufficientPermissions.

@Test
public void testModifyCalresSufficientPermissions() throws Exception {
    List<AdminRight> relatedRights = new ArrayList<AdminRight>();
    List<String> notes = new ArrayList<String>();
    AdminDocumentHandler handler = new ModifyCalendarResource();
    handler.docRights(relatedRights, notes);
    createDelegatedAdmin(relatedRights);
    grantRightToAdmin(adminSoapProv, com.zimbra.soap.type.TargetType.fromString(com.zimbra.cs.account.accesscontrol.TargetType.calresource.toString()), MY_CALRES, DELEGATED_ADMIN_NAME, Admin.R_modifyCalendarResource.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);
    ModifyCalendarResourceRequest req = new ModifyCalendarResourceRequest(myCalRes.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 : ModifyCalendarResourceRequest(com.zimbra.soap.admin.message.ModifyCalendarResourceRequest) AdminRight(com.zimbra.cs.account.accesscontrol.AdminRight) ModifyCalendarResource(com.zimbra.cs.service.admin.ModifyCalendarResource) 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 9 with AdminRight

use of com.zimbra.cs.account.accesscontrol.AdminRight in project zm-mailbox by Zimbra.

the class TestServerEnumeration method createDelegatedAdmin.

public void createDelegatedAdmin(List<AdminRight> relatedRights) throws ServiceException {
    Map<String, Object> attrs = new HashMap<String, Object>();
    StringUtil.addToMultiMap(attrs, Provisioning.A_zimbraIsDelegatedAdminAccount, LdapConstants.LDAP_TRUE);
    domainAdmin = adminSoapProv.createAccount(DELEGATED_ADMIN_NAME, TestUtil.DEFAULT_PASSWORD, attrs);
    assertNotNull("failed to create domin admin account", domainAdmin);
    for (AdminRight r : relatedRights) {
        String target = null;
        com.zimbra.cs.account.accesscontrol.TargetType targetType = null;
        if (r.getTargetType() == com.zimbra.cs.account.accesscontrol.TargetType.domain) {
            targetType = com.zimbra.cs.account.accesscontrol.TargetType.domain;
            target = MY_DOMAIN;
        } else if (r.getTargetType() == com.zimbra.cs.account.accesscontrol.TargetType.account) {
            targetType = com.zimbra.cs.account.accesscontrol.TargetType.account;
            target = MY_USER;
        } else if (r.getTargetType() == com.zimbra.cs.account.accesscontrol.TargetType.calresource) {
            targetType = com.zimbra.cs.account.accesscontrol.TargetType.calresource;
            target = MY_CALRES;
        } else if (r.getTargetType() == com.zimbra.cs.account.accesscontrol.TargetType.server) {
            targetType = com.zimbra.cs.account.accesscontrol.TargetType.server;
            target = Provisioning.getInstance().getLocalServer().getName();
        } else if (r.getTargetType() == com.zimbra.cs.account.accesscontrol.TargetType.cos) {
            targetType = com.zimbra.cs.account.accesscontrol.TargetType.cos;
            target = Provisioning.getInstance().getDefaultCOS(myDomain).getName();
        }
        if (targetType != null) {
            grantRightToAdmin(adminSoapProv, com.zimbra.soap.type.TargetType.fromString(targetType.toString()), target, DELEGATED_ADMIN_NAME, r.getName());
        }
    }
    adminSoapProv.flushCache(CacheEntryType.acl, null);
    delegatedSoapProv = TestUtil.newDelegatedSoapProvisioning(DELEGATED_ADMIN_NAME, TestUtil.DEFAULT_PASSWORD);
}
Also used : AdminRight(com.zimbra.cs.account.accesscontrol.AdminRight) HashMap(java.util.HashMap)

Example 10 with AdminRight

use of com.zimbra.cs.account.accesscontrol.AdminRight in project zm-mailbox by Zimbra.

the class GetRightsDoc method doGetRightsDoc.

private void doGetRightsDoc(Map<String, Object> context, HashSet<String> specificPackages, Element response) throws ServiceException {
    SoapEngine engine = (SoapEngine) context.get(SoapEngine.ZIMBRA_ENGINE);
    DocumentDispatcher dispatcher = engine.getDocumentDispatcher();
    Map<QName, DocumentHandler> handlers = dispatcher.getHandlers();
    Map<String, TreeMap<String, AdminRightCheckPoint>> handlersWithRightsDoc = new TreeMap<String, TreeMap<String, AdminRightCheckPoint>>();
    for (Map.Entry<QName, DocumentHandler> handler : handlers.entrySet()) {
        // String soapName = handler.getKey().getQualifiedName();
        DocumentHandler soapHandler = handler.getValue();
        if (soapHandler instanceof AdminRightCheckPoint) {
            QName qname = handler.getKey();
            String pkg = soapHandler.getClass().getPackage().getName();
            if (specificPackages != null && !specificPackages.contains(pkg))
                continue;
            TreeMap<String, AdminRightCheckPoint> handlersInPkg = handlersWithRightsDoc.get(pkg);
            if (handlersInPkg == null) {
                handlersInPkg = new TreeMap<String, AdminRightCheckPoint>();
                handlersWithRightsDoc.put(pkg, handlersInPkg);
            }
            handlersInPkg.put(qname.getQualifiedName(), (AdminRightCheckPoint) soapHandler);
        }
    }
    Set<AdminRight> usedRights = new HashSet<AdminRight>();
    List<AdminRight> relatedRights = new ArrayList<AdminRight>();
    List<String> notes = new ArrayList<String>();
    for (Map.Entry<String, TreeMap<String, AdminRightCheckPoint>> entry : handlersWithRightsDoc.entrySet()) {
        String pkg = entry.getKey();
        Map<String, AdminRightCheckPoint> handlersInPkg = entry.getValue();
        Element ePackage = response.addElement(AdminConstants.E_PACKAGE);
        ePackage.addAttribute(AdminConstants.A_NAME, pkg);
        for (Map.Entry<String, AdminRightCheckPoint> handler : handlersInPkg.entrySet()) {
            String soapName = handler.getKey();
            AdminRightCheckPoint soapHandler = handler.getValue();
            relatedRights.clear();
            notes.clear();
            soapHandler.docRights(relatedRights, notes);
            Element eCommand = ePackage.addElement(AdminConstants.E_CMD);
            eCommand.addAttribute(AdminConstants.A_NAME, soapName);
            Element eRights = eCommand.addElement(AdminConstants.E_RIGHTS);
            for (AdminRight adminRight : relatedRights) {
                Element eRight = eRights.addElement(AdminConstants.E_RIGHT);
                eRight.addAttribute(AdminConstants.A_NAME, adminRight.getName());
                usedRights.add(adminRight);
            }
            Element eNotes = eCommand.addElement(AdminConstants.E_DESC);
            for (String note : notes) eNotes.addElement(AdminConstants.E_NOTE).setText(note);
        }
    }
    genNotUsed(usedRights, response);
    genDomainAdminRights(context, response);
}
Also used : QName(org.dom4j.QName) Element(com.zimbra.common.soap.Element) ArrayList(java.util.ArrayList) SoapEngine(com.zimbra.soap.SoapEngine) TreeMap(java.util.TreeMap) DocumentHandler(com.zimbra.soap.DocumentHandler) AdminRight(com.zimbra.cs.account.accesscontrol.AdminRight) DocumentDispatcher(com.zimbra.soap.DocumentDispatcher) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

AdminRight (com.zimbra.cs.account.accesscontrol.AdminRight)12 ArrayList (java.util.ArrayList)8 SoapFaultException (com.zimbra.common.soap.SoapFaultException)6 AdminDocumentHandler (com.zimbra.cs.service.admin.AdminDocumentHandler)6 Test (org.junit.Test)6 Attr (com.zimbra.soap.admin.type.Attr)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Element (com.zimbra.common.soap.Element)2 Mailbox (com.zimbra.cs.mailbox.Mailbox)2 LockoutMailbox (com.zimbra.cs.service.admin.LockoutMailbox)2 ModifyAccount (com.zimbra.cs.service.admin.ModifyAccount)2 ModifyCalendarResource (com.zimbra.cs.service.admin.ModifyCalendarResource)2 DocumentDispatcher (com.zimbra.soap.DocumentDispatcher)2 DocumentHandler (com.zimbra.soap.DocumentHandler)2 SoapEngine (com.zimbra.soap.SoapEngine)2 LockoutMailboxRequest (com.zimbra.soap.admin.message.LockoutMailboxRequest)2 ModifyAccountRequest (com.zimbra.soap.admin.message.ModifyAccountRequest)2 ModifyCalendarResourceRequest (com.zimbra.soap.admin.message.ModifyCalendarResourceRequest)2 Map (java.util.Map)2