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());
}
}
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());
}
}
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());
}
}
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);
}
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);
}
Aggregations