Search in sources :

Example 1 with AccessControl

use of org.directwebremoting.extend.AccessControl in project ma-core-public by infiniteautomation.

the class AnnotationsConfigurator method processCreate.

/**
 * Process the @RemoteProxy annotaion on a given class
 * @param clazz The class annotated with @RemoteProxy
 * @param createAnn The annotation
 * @param container The IoC container to configure
 */
private void processCreate(Class<?> clazz, RemoteProxy createAnn, Container container) {
    Class<? extends Creator> creator = createAnn.creator();
    String creatorClass = creator.getName();
    Map<String, String> creatorParams = getParamsMap(createAnn.creatorParams());
    ScriptScope scope = createAnn.scope();
    CreatorManager creatorManager = (CreatorManager) container.getBean(CreatorManager.class.getName());
    String creatorName = LocalUtil.replace(creatorClass, ".", "_");
    creatorManager.addCreatorType(creatorName, creatorClass);
    Map<String, String> params = new HashMap<String, String>();
    if (NewCreator.class.isAssignableFrom(creator)) {
        params.put("class", clazz.getName());
    }
    params.putAll(creatorParams);
    params.put("scope", scope.getValue());
    String name = createAnn.name();
    if (name == null || name.length() == 0) {
        name = LocalUtil.getShortClassName(clazz);
    }
    try {
        log.info("Adding class " + clazz.getName() + " as " + name);
        creatorManager.addCreator(name, creatorName, params);
    } catch (Exception ex) {
        log.error("Failed to add class as Creator: " + clazz.getName(), ex);
    }
    AccessControl accessControl = (AccessControl) container.getBean(AccessControl.class.getName());
    Method[] methods = clazz.getMethods();
    for (int i = 0; i < methods.length; i++) {
        if (methods[i].getAnnotation(RemoteMethod.class) != null) {
            accessControl.addIncludeRule(name, methods[i].getName());
            Auth authAnn = methods[i].getAnnotation(Auth.class);
            if (authAnn != null) {
                accessControl.addRoleRestriction(name, methods[i].getName(), authAnn.role());
            }
        }
    }
    Filters filtersAnn = clazz.getAnnotation(Filters.class);
    if (filtersAnn != null) {
        Filter[] fs = filtersAnn.value();
        for (int i = 0; i < fs.length; i++) {
            processFilter(fs[i], name, container);
        }
    } else // process single filter for convenience
    {
        Filter filterAnn = clazz.getAnnotation(Filter.class);
        if (filterAnn != null) {
            processFilter(filterAnn, name, container);
        }
    }
}
Also used : HashMap(java.util.HashMap) Method(java.lang.reflect.Method) AccessControl(org.directwebremoting.extend.AccessControl) AjaxFilter(org.directwebremoting.AjaxFilter) CreatorManager(org.directwebremoting.extend.CreatorManager)

Example 2 with AccessControl

use of org.directwebremoting.extend.AccessControl in project ma-core-public by infiniteautomation.

the class SpringConfigurator method configure.

/* (non-Javadoc)
     * @see org.directwebremoting.Configurator#configure(org.directwebremoting.Container)
     */
public void configure(Container container) {
    AccessControl accessControl = (AccessControl) container.getBean(AccessControl.class.getName());
    AjaxFilterManager ajaxFilterManager = (AjaxFilterManager) container.getBean(AjaxFilterManager.class.getName());
    ConverterManager converterManager = (ConverterManager) container.getBean(ConverterManager.class.getName());
    CreatorManager creatorManager = (CreatorManager) container.getBean(CreatorManager.class.getName());
    // Configure the creator types
    if (creatorTypes != null) {
        for (Iterator it = creatorTypes.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry entry = (Map.Entry) it.next();
            String typeName = (String) entry.getKey();
            String className = (String) entry.getValue();
            creatorManager.addCreatorType(typeName, className);
        }
    }
    // Configure the converter types
    if (converterTypes != null) {
        for (Iterator it = converterTypes.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry entry = (Map.Entry) it.next();
            String typeName = (String) entry.getKey();
            String className = (String) entry.getValue();
            converterManager.addConverterType(typeName, className);
        }
    }
    // Configure the creators
    if (creators != null) {
        try {
            for (Iterator it = creators.entrySet().iterator(); it.hasNext(); ) {
                Map.Entry entry = (Map.Entry) it.next();
                String scriptName = (String) entry.getKey();
                CreatorConfig creatorConfig = (CreatorConfig) entry.getValue();
                if (creatorConfig.getCreator() != null) {
                    Creator creator = creatorConfig.getCreator();
                    creatorManager.addCreator(scriptName, creator);
                } else {
                    String creatorName = creatorConfig.getCreatorType();
                    Map params = creatorConfig.getParams();
                    creatorManager.addCreator(scriptName, creatorName, params);
                }
                List excludes = creatorConfig.getExcludes();
                for (Iterator eit = excludes.iterator(); eit.hasNext(); ) {
                    String exclude = (String) eit.next();
                    accessControl.addExcludeRule(scriptName, exclude);
                }
                List includes = creatorConfig.getIncludes();
                for (Iterator iit = includes.iterator(); iit.hasNext(); ) {
                    String include = (String) iit.next();
                    accessControl.addIncludeRule(scriptName, include);
                }
                Properties auth = creatorConfig.getAuth();
                for (Iterator ait = auth.entrySet().iterator(); ait.hasNext(); ) {
                    Map.Entry aentry = (Map.Entry) ait.next();
                    String methodName = (String) aentry.getKey();
                    String role = (String) aentry.getValue();
                    accessControl.addRoleRestriction(scriptName, methodName, role);
                }
                List filters = creatorConfig.getFilters();
                for (Iterator fit = filters.iterator(); fit.hasNext(); ) {
                    Object obj = fit.next();
                    if (obj instanceof String) {
                        String filterName = (String) obj;
                        AjaxFilter filter = (AjaxFilter) LocalUtil.classNewInstance(filterName, filterName, AjaxFilter.class);
                        if (filter != null) {
                            ajaxFilterManager.addAjaxFilter(filter, scriptName);
                        }
                    } else if (obj instanceof AjaxFilter) {
                        AjaxFilter filter = (AjaxFilter) obj;
                        ajaxFilterManager.addAjaxFilter(filter, scriptName);
                    } else {
                        throw new IllegalArgumentException(Messages.getString("SpringConfigurator.InvalidFilter", scriptName, obj));
                    }
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new IllegalArgumentException(ex.toString());
        }
    }
    // Configure the converters
    if (converters != null) {
        try {
            for (Iterator it = converters.entrySet().iterator(); it.hasNext(); ) {
                Map.Entry entry = (Map.Entry) it.next();
                String match = (String) entry.getKey();
                ConverterConfig converterConfig = (ConverterConfig) entry.getValue();
                Map params = converterConfig.getParams();
                if (converterConfig.getIncludes().size() > 0) {
                    params.put("include", StringUtils.collectionToCommaDelimitedString(converterConfig.getIncludes()));
                }
                if (converterConfig.getExcludes().size() > 0) {
                    params.put("exclude", StringUtils.collectionToCommaDelimitedString(converterConfig.getExcludes()));
                }
                // params.put("force", Boolean.valueOf(converterConfig.isForce()));
                if (StringUtils.hasText(converterConfig.getJavascriptClassName())) {
                    params.put("javascript", converterConfig.getJavascriptClassName());
                }
                converterManager.addConverter(match, converterConfig.getType(), params);
            }
        } catch (Exception ex) {
            throw new IllegalArgumentException(Messages.getString("SpringConfigurator.ConfigureConverterError"));
        }
    }
    // Configure the signatures
    if (StringUtils.hasText(signatures)) {
        SignatureParser sigp = new SignatureParser(converterManager, creatorManager);
        sigp.parse(signatures);
    }
}
Also used : Creator(org.directwebremoting.extend.Creator) Properties(java.util.Properties) AccessControl(org.directwebremoting.extend.AccessControl) AjaxFilterManager(org.directwebremoting.extend.AjaxFilterManager) ConverterManager(org.directwebremoting.extend.ConverterManager) Iterator(java.util.Iterator) List(java.util.List) CreatorManager(org.directwebremoting.extend.CreatorManager) Map(java.util.Map) SignatureParser(org.directwebremoting.impl.SignatureParser) AjaxFilter(org.directwebremoting.AjaxFilter)

Example 3 with AccessControl

use of org.directwebremoting.extend.AccessControl in project ma-core-public by infiniteautomation.

the class DwrXmlConfigurator method configure.

/* (non-Javadoc)
     * @see org.directwebremoting.Configurator#configure(org.directwebremoting.Container)
     */
public void configure(Container container) {
    accessControl = (AccessControl) container.getBean(AccessControl.class.getName());
    ajaxFilterManager = (AjaxFilterManager) container.getBean(AjaxFilterManager.class.getName());
    converterManager = (ConverterManager) container.getBean(ConverterManager.class.getName());
    creatorManager = (CreatorManager) container.getBean(CreatorManager.class.getName());
    Element root = document.getDocumentElement();
    NodeList rootChildren = root.getChildNodes();
    for (int i = 0; i < rootChildren.getLength(); i++) {
        Node node = rootChildren.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element child = (Element) node;
            if (child.getNodeName().equals(ELEMENT_INIT)) {
                loadInits(child);
            } else if (child.getNodeName().equals(ELEMENT_ALLOW)) {
                loadAllows(child);
            } else if (child.getNodeName().equals(ELEMENT_SIGNATURES)) {
                loadSignature(child);
            }
        }
    }
}
Also used : ConverterManager(org.directwebremoting.extend.ConverterManager) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) CreatorManager(org.directwebremoting.extend.CreatorManager) AccessControl(org.directwebremoting.extend.AccessControl) AjaxFilterManager(org.directwebremoting.extend.AjaxFilterManager)

Example 4 with AccessControl

use of org.directwebremoting.extend.AccessControl in project ma-core-public by infiniteautomation.

the class ContainerUtil method debugConfig.

/**
 * Create a bunch of debug information about a container
 * @param container The container to print debug information about
 */
public static void debugConfig(Container container) {
    if (log.isDebugEnabled()) {
        // Container level debug
        log.debug("Container");
        log.debug("  Type: " + container.getClass().getName());
        Collection beanNames = container.getBeanNames();
        for (Iterator it = beanNames.iterator(); it.hasNext(); ) {
            String name = (String) it.next();
            Object object = container.getBean(name);
            if (object instanceof String) {
                log.debug("  Param: " + name + " = " + object + " (" + object.getClass().getName() + ")");
            } else {
                log.debug("  Bean: " + name + " = " + object + " (" + object.getClass().getName() + ")");
            }
        }
        // AccessControl debugging
        AccessControl accessControl = (AccessControl) container.getBean(AccessControl.class.getName());
        log.debug("AccessControl");
        log.debug("  Type: " + accessControl.getClass().getName());
        // AjaxFilterManager debugging
        AjaxFilterManager ajaxFilterManager = (AjaxFilterManager) container.getBean(AjaxFilterManager.class.getName());
        log.debug("AjaxFilterManager");
        log.debug("  Type: " + ajaxFilterManager.getClass().getName());
        // ConverterManager debugging
        ConverterManager converterManager = (ConverterManager) container.getBean(ConverterManager.class.getName());
        log.debug("ConverterManager");
        log.debug("  Type: " + converterManager.getClass().getName());
        // CreatorManager debugging
        CreatorManager creatorManager = (CreatorManager) container.getBean(CreatorManager.class.getName());
        log.debug("CreatorManager");
        log.debug("  Type: " + creatorManager.getClass().getName());
        Collection creatorNames = creatorManager.getCreatorNames();
        for (Iterator it = creatorNames.iterator(); it.hasNext(); ) {
            String creatorName = (String) it.next();
            Creator creator = creatorManager.getCreator(creatorName);
            log.debug("  Creator: " + creatorName + " = " + creator + " (" + creator.getClass().getName() + ")");
        }
    }
}
Also used : ConverterManager(org.directwebremoting.extend.ConverterManager) DefaultConverterManager(org.directwebremoting.dwrp.DefaultConverterManager) Iterator(java.util.Iterator) Collection(java.util.Collection) Creator(org.directwebremoting.extend.Creator) CreatorManager(org.directwebremoting.extend.CreatorManager) AccessControl(org.directwebremoting.extend.AccessControl) AjaxFilterManager(org.directwebremoting.extend.AjaxFilterManager)

Aggregations

AccessControl (org.directwebremoting.extend.AccessControl)4 CreatorManager (org.directwebremoting.extend.CreatorManager)4 AjaxFilterManager (org.directwebremoting.extend.AjaxFilterManager)3 ConverterManager (org.directwebremoting.extend.ConverterManager)3 Iterator (java.util.Iterator)2 AjaxFilter (org.directwebremoting.AjaxFilter)2 Creator (org.directwebremoting.extend.Creator)2 Method (java.lang.reflect.Method)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1 DefaultConverterManager (org.directwebremoting.dwrp.DefaultConverterManager)1 SignatureParser (org.directwebremoting.impl.SignatureParser)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1