Search in sources :

Example 1 with DocumentHandler

use of com.zimbra.soap.DocumentHandler 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)

Example 2 with DocumentHandler

use of com.zimbra.soap.DocumentHandler in project zm-mailbox by Zimbra.

the class GetRightsDoc method genDomainAdminRights.

// handle dynamic group
@ACLTODO
private void genDomainAdminRights(Map<String, Object> context, Element response) throws ServiceException {
    Element eDomainAdmin = response.addElement("domainAdmin-copypaste-to-zimbra-rights-domainadmin-xml-template");
    SoapEngine engine = (SoapEngine) context.get(SoapEngine.ZIMBRA_ENGINE);
    DocumentDispatcher dispatcher = engine.getDocumentDispatcher();
    Map<QName, DocumentHandler> handlers = dispatcher.getHandlers();
    // keys are sorted by targetType
    // values are sets sorted by attr name
    Map<TargetType, TreeSet<String>> rights = new TreeMap<TargetType, TreeSet<String>>();
    for (TargetType tt : TargetType.values()) rights.put(tt, new TreeSet<String>());
    // add our domain admin attr rights, which are generated by RightManager
    rights.get(TargetType.account).add(Admin.R_setDomainAdminAccountAndCalendarResourceAttrs.getName());
    rights.get(TargetType.calresource).add(Admin.R_setDomainAdminAccountAndCalendarResourceAttrs.getName());
    rights.get(TargetType.calresource).add(Admin.R_setDomainAdminCalendarResourceAttrs.getName());
    rights.get(TargetType.dl).add(Admin.R_setDomainAdminDistributionListAttrs.getName());
    rights.get(TargetType.domain).add(Admin.R_setDomainAdminDomainAttrs.getName());
    for (Map.Entry<QName, DocumentHandler> handler : handlers.entrySet()) {
        DocumentHandler soapHandler = handler.getValue();
        // only works for AdminDocumentHandler
        if (soapHandler instanceof AdminRightCheckPoint && soapHandler instanceof AdminDocumentHandler) {
            AdminDocumentHandler adminHandler = (AdminDocumentHandler) soapHandler;
            if (adminHandler.domainAuthSufficient(context)) {
                List<AdminRight> relatedRights = new ArrayList<AdminRight>();
                List<String> notes = new ArrayList<String>();
                adminHandler.docRights(relatedRights, notes);
                for (AdminRight r : relatedRights) {
                    if (r.isPresetRight()) {
                        TargetType tt = r.getTargetType();
                        rights.get(tt).add(r.getName());
                    } else if (r.isAttrRight()) {
                        Set<TargetType> tts = ((AttrRight) r).getTargetTypes();
                        for (TargetType tt : tts) rights.get(tt).add(r.getName());
                    }
                }
            }
        }
    }
    for (Map.Entry<TargetType, TreeSet<String>> entry : rights.entrySet()) {
        TargetType tt = entry.getKey();
        if (entry.getValue().size() > 0) {
            Element eRight = eDomainAdmin.addElement("right").addAttribute("name", "domainAdmin" + tt.getPrettyName() + "Rights").addAttribute("type", "combo");
            eRight.addElement("desc").setText("domain admin " + tt.getCode() + " right");
            Element eRights = eRight.addElement("rights");
            for (String r : entry.getValue()) {
                eRights.addElement("r").addAttribute("n", r);
            }
        }
    }
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) 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) TreeSet(java.util.TreeSet) DocumentDispatcher(com.zimbra.soap.DocumentDispatcher) TargetType(com.zimbra.cs.account.accesscontrol.TargetType) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Aggregations

Element (com.zimbra.common.soap.Element)2 AdminRight (com.zimbra.cs.account.accesscontrol.AdminRight)2 DocumentDispatcher (com.zimbra.soap.DocumentDispatcher)2 DocumentHandler (com.zimbra.soap.DocumentHandler)2 SoapEngine (com.zimbra.soap.SoapEngine)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 QName (org.dom4j.QName)2 TargetType (com.zimbra.cs.account.accesscontrol.TargetType)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1