Search in sources :

Example 1 with AttributeConstraint

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

the class GetDelegatedAdminConstraints method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    Entry entry = getEntry(request);
    AdminAccessControl.GetAttrsRight gar = new AdminAccessControl.GetAttrsRight();
    gar.addAttr(Provisioning.A_zimbraConstraint);
    checkRight(zsc, context, entry, gar);
    Map<String, AttributeConstraint> constraints = AttributeConstraint.getConstraint(entry);
    Element response = zsc.createElement(AdminConstants.GET_DELEGATED_ADMIN_CONSTRAINTS_RESPONSE);
    // return constraints for requested attrs
    boolean hasRequestedAttrs = false;
    for (Element a : request.listElements(AdminConstants.E_A)) {
        hasRequestedAttrs = true;
        String attrName = a.getAttribute(AdminConstants.A_NAME);
        AttributeConstraint ac = constraints.get(attrName);
        if (ac != null) {
            Element eAttr = response.addElement(AdminConstants.E_A).addAttribute(AdminConstants.A_NAME, attrName);
            ac.toXML(eAttr);
        }
    }
    // no attr is specifically requested, return all
    if (!hasRequestedAttrs) {
        for (Map.Entry<String, AttributeConstraint> cons : constraints.entrySet()) {
            String attrName = cons.getKey();
            AttributeConstraint ac = cons.getValue();
            Element eAttr = response.addElement(AdminConstants.E_A).addAttribute(AdminConstants.A_NAME, attrName);
            ac.toXML(eAttr);
        }
    }
    return response;
}
Also used : Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning) Entry(com.zimbra.cs.account.Entry) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) AttributeConstraint(com.zimbra.cs.account.accesscontrol.AttributeConstraint) Map(java.util.Map)

Example 2 with AttributeConstraint

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

the class ModifyDelegatedAdminConstraints method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    Entry entry = GetDelegatedAdminConstraints.getEntry(request);
    AdminAccessControl.SetAttrsRight sar = new AdminAccessControl.SetAttrsRight();
    sar.addAttr(Provisioning.A_zimbraConstraint);
    checkRight(zsc, context, entry, sar);
    AttributeManager am = AttributeManager.getInstance();
    List<AttributeConstraint> constraints = new ArrayList<AttributeConstraint>();
    for (Element a : request.listElements(AdminConstants.E_A)) {
        String attrName = a.getAttribute(AdminConstants.A_NAME);
        Element eConstraint = a.getElement(AdminConstants.E_CONSTRAINT);
        constraints.add(AttributeConstraint.fromXML(am, attrName, eConstraint));
    }
    AttributeConstraint.modifyConstraint(entry, constraints);
    // log it
    Map<String, Object> attrs = new HashMap<String, Object>();
    attrs.put(CONSTRAINT_ATTR, entry.getMultiAttr(CONSTRAINT_ATTR, false));
    ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "ModifyDelegatedAdminConstraints", "name", entry.getLabel() }, attrs));
    Element response = zsc.createElement(AdminConstants.MODIFY_DELEGATED_ADMIN_CONSTRAINTS_RESPONSE);
    return response;
}
Also used : HashMap(java.util.HashMap) Element(com.zimbra.common.soap.Element) ArrayList(java.util.ArrayList) Provisioning(com.zimbra.cs.account.Provisioning) Entry(com.zimbra.cs.account.Entry) AttributeManager(com.zimbra.cs.account.AttributeManager) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) AttributeConstraint(com.zimbra.cs.account.accesscontrol.AttributeConstraint)

Aggregations

Element (com.zimbra.common.soap.Element)2 Entry (com.zimbra.cs.account.Entry)2 Provisioning (com.zimbra.cs.account.Provisioning)2 AttributeConstraint (com.zimbra.cs.account.accesscontrol.AttributeConstraint)2 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)2 AttributeManager (com.zimbra.cs.account.AttributeManager)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1