Search in sources :

Example 1 with ExtensionParam

use of org.zaproxy.zap.extension.ext.ExtensionParam in project zaproxy by zaproxy.

the class ExtensionFactory method loadAllExtension.

public static synchronized void loadAllExtension(ExtensionLoader extensionLoader, OptionsParam optionsParam) {
    log.info("Loading extensions");
    List<Extension> listExts = new ArrayList<>(CoreFunctionality.getBuiltInExtensions());
    listExts.addAll(getAddOnLoader(optionsParam.getCheckForUpdatesParam().getAddonDirectories()).getExtensions());
    ExtensionParam extParam = optionsParam.getExtensionParam();
    synchronized (mapAllExtension) {
        mapAllExtension.clear();
        for (int i = 0; i < listExts.size(); i++) {
            Extension extension = listExts.get(i);
            if (mapAllExtension.containsKey(extension.getName())) {
                if (mapAllExtension.get(extension.getName()).getClass().equals(extension.getClass())) {
                    // Same name, same class so ignore
                    log.error("Duplicate extension: " + extension.getName() + " " + extension.getClass().getCanonicalName());
                    continue;
                } else {
                    // Same name but different class, log but still load it
                    log.error("Duplicate extension name: " + extension.getName() + " " + extension.getClass().getCanonicalName() + " " + mapAllExtension.get(extension.getName()).getClass().getCanonicalName());
                }
            }
            if (extension.isDepreciated()) {
                log.debug("Depreciated extension " + extension.getName());
                continue;
            }
            extension.setEnabled(extParam.isExtensionEnabled(extension.getName()));
            listAllExtension.add(extension);
            mapAllExtension.put(extension.getName(), extension);
            int order = extension.getOrder();
            if (order == 0) {
                unorderedExtensions.add(extension);
            } else if (mapOrderToExtension.containsKey(order)) {
                log.error("Duplicate order " + order + " " + mapOrderToExtension.get(order).getName() + "/" + mapOrderToExtension.get(order).getClass().getCanonicalName() + " already registered, " + extension.getName() + "/" + extension.getClass().getCanonicalName() + " will be added as an unordered extension");
                unorderedExtensions.add(extension);
            } else {
                mapOrderToExtension.put(order, extension);
            }
        }
        // Add the ordered extensions
        Iterator<Integer> iter = mapOrderToExtension.keySet().iterator();
        while (iter.hasNext()) {
            Integer order = iter.next();
            Extension ext = mapOrderToExtension.get(order);
            if (ext.isEnabled()) {
                log.debug("Ordered extension " + order + " " + ext.getName());
            }
            loadMessagesAndAddExtension(extensionLoader, ext);
        }
        // And then the unordered ones
        for (Extension ext : unorderedExtensions) {
            if (ext.isEnabled()) {
                log.debug("Unordered extension " + ext.getName());
            }
            loadMessagesAndAddExtension(extensionLoader, ext);
        }
    }
    log.info("Extensions loaded");
}
Also used : Extension(org.parosproxy.paros.extension.Extension) ArrayList(java.util.ArrayList) ExtensionParam(org.zaproxy.zap.extension.ext.ExtensionParam)

Example 2 with ExtensionParam

use of org.zaproxy.zap.extension.ext.ExtensionParam in project zaproxy by zaproxy.

the class ExtensionFactory method addExtensionImpl.

private static void addExtensionImpl(Extension extension) {
    if (mapAllExtension.containsKey(extension.getName())) {
        if (mapAllExtension.get(extension.getName()).getClass().equals(extension.getClass())) {
            // Same name, same class cant currently replace exts already loaded
            log.debug("Duplicate extension: " + extension.getName() + " " + extension.getClass().getCanonicalName());
            extension.setEnabled(false);
            return;
        }
        // Same name but different class, log but still load it
        log.error("Duplicate extension name: " + extension.getName() + " " + extension.getClass().getCanonicalName() + " " + mapAllExtension.get(extension.getName()).getClass().getCanonicalName());
    }
    if (extension.isDepreciated()) {
        log.debug("Depreciated extension " + extension.getName());
        return;
    }
    ExtensionParam extensionParam = Model.getSingleton().getOptionsParam().getExtensionParam();
    extension.setEnabled(extensionParam.isExtensionEnabled(extension.getName()));
    listAllExtension.add(extension);
    mapAllExtension.put(extension.getName(), extension);
    // Order actually irrelevant when adding an addon;)
    int order = extension.getOrder();
    if (order == 0) {
        unorderedExtensions.add(extension);
    } else if (mapOrderToExtension.containsKey(order)) {
        log.error("Duplicate order " + order + " " + mapOrderToExtension.get(order).getName() + "/" + mapOrderToExtension.get(order).getClass().getCanonicalName() + " already registered, " + extension.getName() + "/" + extension.getClass().getCanonicalName() + " will be added as an unordered extension");
        unorderedExtensions.add(extension);
    } else {
        mapOrderToExtension.put(order, extension);
    }
}
Also used : ExtensionParam(org.zaproxy.zap.extension.ext.ExtensionParam)

Aggregations

ExtensionParam (org.zaproxy.zap.extension.ext.ExtensionParam)2 ArrayList (java.util.ArrayList)1 Extension (org.parosproxy.paros.extension.Extension)1