Search in sources :

Example 6 with Extension

use of org.parosproxy.paros.extension.Extension in project zaproxy by zaproxy.

the class AddOnLoader method unloadDependentExtensions.

private void unloadDependentExtensions(AddOn ao) {
    boolean changed = true;
    for (Entry<String, AddOnClassLoader> entry : new HashMap<>(addOnLoaders).entrySet()) {
        AddOn runningAddOn = aoc.getAddOn(entry.getKey());
        for (Extension ext : runningAddOn.getLoadedExtensionsWithDeps()) {
            if (runningAddOn.dependsOn(ext, ao)) {
                String classname = ext.getClass().getCanonicalName();
                AddOnInstaller.uninstallAddOnExtension(runningAddOn, ext, NULL_CALLBACK);
                try (AddOnClassLoader extensionClassLoader = (AddOnClassLoader) ext.getClass().getClassLoader()) {
                    ext = null;
                    entry.getValue().removeChildClassLoader(extensionClassLoader);
                    extensionClassLoader.clearDependencies();
                    ResourceBundle.clearCache(extensionClassLoader);
                } catch (Exception e) {
                    logger.error("Failure while closing class loader of extension '" + classname + "':", e);
                }
                runnableAddOns.get(runningAddOn).remove(classname);
                changed = true;
            }
        }
    }
    if (changed) {
        saveAddOnsRunState(runnableAddOns);
    }
}
Also used : Extension(org.parosproxy.paros.extension.Extension) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) ConfigurationException(org.apache.commons.configuration.ConfigurationException)

Example 7 with Extension

use of org.parosproxy.paros.extension.Extension 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 8 with Extension

use of org.parosproxy.paros.extension.Extension in project zaproxy by zaproxy.

the class AddOn method getLoadedExtensionsWithDeps.

/**
	 * Gets the extensions of this add-on that have dependencies and were loaded.
	 *
	 * @return an unmodifiable {@code List} with the extensions of this add-on that have dependencies and were loaded
	 * @since 2.4.0
	 */
public List<Extension> getLoadedExtensionsWithDeps() {
    List<String> classnames = getExtensionsWithDeps();
    ArrayList<Extension> loadedExtensions = new ArrayList<>(extensionsWithDeps.size());
    for (Extension extension : getLoadedExtensions()) {
        if (classnames.contains(extension.getClass().getCanonicalName())) {
            loadedExtensions.add(extension);
        }
    }
    loadedExtensions.trimToSize();
    return loadedExtensions;
}
Also used : Extension(org.parosproxy.paros.extension.Extension) ArrayList(java.util.ArrayList)

Example 9 with Extension

use of org.parosproxy.paros.extension.Extension in project zaproxy by zaproxy.

the class OptionsExtensionPanel method saveParam.

@Override
public void saveParam(Object obj) throws Exception {
    OptionsParam optionsParam = (OptionsParam) obj;
    Map<String, Boolean> extensionsState = new HashMap<>();
    List<Extension> exts = extensionModel.getExtensions();
    for (Extension ext : exts) {
        extensionsState.put(ext.getName(), ext.isEnabled());
    }
    optionsParam.getExtensionParam().setExtensionsState(extensionsState);
}
Also used : Extension(org.parosproxy.paros.extension.Extension) OptionsParam(org.parosproxy.paros.model.OptionsParam) HashMap(java.util.HashMap)

Example 10 with Extension

use of org.parosproxy.paros.extension.Extension in project zaproxy by zaproxy.

the class OptionsExtensionPanel method getTableExtension.

/**
	 * This method initializes tableAuth	
	 * 	
	 * @return javax.swing.JTable	
	 */
private JTable getTableExtension() {
    if (tableExt == null) {
        tableExt = new JTable();
        tableExt.setModel(getExtensionModel());
        tableExt.setRowHeight(DisplayUtils.getScaledSize(18));
        tableExt.getColumnModel().getColumn(0).setPreferredWidth(DisplayUtils.getScaledSize(70));
        tableExt.getColumnModel().getColumn(1).setPreferredWidth(DisplayUtils.getScaledSize(70));
        tableExt.getColumnModel().getColumn(2).setPreferredWidth(DisplayUtils.getScaledSize(120));
        tableExt.getColumnModel().getColumn(3).setPreferredWidth(DisplayUtils.getScaledSize(220));
        ListSelectionListener sl = new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent arg0) {
                if (tableExt.getSelectedRow() > -1) {
                    Extension ext = ((OptionsExtensionTableModel) tableExt.getModel()).getExtension(tableExt.getSelectedRow());
                    if (ext != null) {
                        try {
                            extName.setText(ext.getUIName());
                            extDescription.setText(ext.getDescription());
                            if (ext.getAuthor() != null) {
                                extAuthor.setText(ext.getAuthor());
                            } else {
                                extAuthor.setText("");
                            }
                            if (ext.getURL() != null) {
                                extURL.setText(ext.getURL().toString());
                                getUrlLaunchButton().setEnabled(true);
                            } else {
                                extURL.setText("");
                                getUrlLaunchButton().setEnabled(false);
                            }
                        } catch (Exception e) {
                            // Just to be safe
                            log.error(e.getMessage(), e);
                        }
                    }
                }
            }
        };
        tableExt.getSelectionModel().addListSelectionListener(sl);
        tableExt.getColumnModel().getSelectionModel().addListSelectionListener(sl);
    }
    return tableExt;
}
Also used : Extension(org.parosproxy.paros.extension.Extension) JTable(javax.swing.JTable) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener)

Aggregations

Extension (org.parosproxy.paros.extension.Extension)17 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)3 AddOn (org.zaproxy.zap.control.AddOn)3 ExtensionLoader (org.parosproxy.paros.extension.ExtensionLoader)2 OptionsParam (org.parosproxy.paros.model.OptionsParam)2 AddOnRunRequirements (org.zaproxy.zap.control.AddOn.AddOnRunRequirements)2 ExtensionRunRequirements (org.zaproxy.zap.control.AddOn.ExtensionRunRequirements)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 JTable (javax.swing.JTable)1 ListSelectionEvent (javax.swing.event.ListSelectionEvent)1 ListSelectionListener (javax.swing.event.ListSelectionListener)1 ConfigurationException (org.apache.commons.configuration.ConfigurationException)1 XmlReporterExtension (org.zaproxy.zap.extension.XmlReporterExtension)1 ExtensionParam (org.zaproxy.zap.extension.ext.ExtensionParam)1