Search in sources :

Example 11 with Extension

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

the class OptionsExtensionPanel method initParam.

@Override
public void initParam(Object obj) {
    OptionsParam optionsParam = (OptionsParam) obj;
    ExtensionParam extParam = optionsParam.getExtensionParam();
    List<Extension> exts = extensionModel.getExtensions();
    for (Extension ext : exts) {
        ext.setEnabled(extParam.isExtensionEnabled(ext.getName()));
    }
    extensionModel.fireTableRowsUpdated(0, extensionModel.getRowCount());
}
Also used : Extension(org.parosproxy.paros.extension.Extension) OptionsParam(org.parosproxy.paros.model.OptionsParam)

Example 12 with Extension

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

the class AddOn method isExtensionLoaded.

/**
     * Tells whether or not the extension with the given {@code classname} is loaded.
     *
     * @param classname the classname of the extension
     * @return {@code true} if the extension is loaded, {@code false} otherwise
     * @since 2.4.0
     */
public boolean isExtensionLoaded(String classname) {
    List<Extension> allExtensions = new ArrayList<>(getLoadedExtensions().size() + getLoadedExtensionsWithDeps().size());
    allExtensions.addAll(getLoadedExtensions());
    allExtensions.addAll(getLoadedExtensionsWithDeps());
    for (Extension extension : getLoadedExtensions()) {
        if (classname.equals(extension.getClass().getCanonicalName())) {
            return true;
        }
    }
    return false;
}
Also used : Extension(org.parosproxy.paros.extension.Extension) ArrayList(java.util.ArrayList)

Example 13 with Extension

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

the class AddOnLoader method getExtensions.

/**
     * Returns all {@code Extension}s of the given {@code addOn}.
     * <p>
     * The discovery of {@code Extension}s is done by resorting to {@link AddOn#MANIFEST_FILE_NAME manifest file} bundled in the
     * add-on.
     * <p>
     * Extensions with unfulfilled dependencies are not be returned.
     * <p>
     * <strong>Note:</strong> If the add-on is not installed the method returns an empty list.
     *
     * @param addOn the add-on whose extensions will be returned
     * @return a list containing the {@code Extension}s of the given {@code addOn}
     * @since 2.4.0
     * @see Extension
     * @see #getExtensions()
     */
public List<Extension> getExtensions(AddOn addOn) {
    AddOnClassLoader addOnClassLoader = this.addOnLoaders.get(addOn.getId());
    if (addOnClassLoader == null) {
        return Collections.emptyList();
    }
    List<Extension> extensions = new ArrayList<>();
    extensions.addAll(loadAddOnExtensions(addOn, addOn.getExtensions(), addOnClassLoader));
    if (addOn.hasExtensionsWithDeps()) {
        AddOn.AddOnRunRequirements reqs = addOn.calculateRunRequirements(aoc.getInstalledAddOns());
        for (ExtensionRunRequirements extReqs : reqs.getExtensionRequirements()) {
            if (extReqs.isRunnable()) {
                List<AddOnClassLoader> dependencies = new ArrayList<>(extReqs.getDependencies().size());
                for (AddOn addOnDep : extReqs.getDependencies()) {
                    dependencies.add(addOnLoaders.get(addOnDep.getId()));
                }
                AddOnClassLoader extAddOnClassLoader = new AddOnClassLoader(addOnClassLoader, dependencies, addOn.getExtensionAddOnClassnames(extReqs.getClassname()));
                Extension ext = loadAddOnExtension(addOn, extReqs.getClassname(), extAddOnClassLoader);
                if (ext != null) {
                    extensions.add(ext);
                }
            } else if (logger.isDebugEnabled()) {
                logger.debug("Can't run extension '" + extReqs.getClassname() + "' of add-on '" + addOn.getName() + "' because of missing requirements: " + AddOnRunIssuesUtils.getRunningIssues(extReqs));
            }
        }
    }
    return extensions;
}
Also used : Extension(org.parosproxy.paros.extension.Extension) ExtensionRunRequirements(org.zaproxy.zap.control.AddOn.ExtensionRunRequirements) ArrayList(java.util.ArrayList) AddOnRunRequirements(org.zaproxy.zap.control.AddOn.AddOnRunRequirements)

Example 14 with Extension

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

the class AddOnLoader method checkAndLoadDependentExtensions.

/**
     * Checks and loads all the extensions that have (now) all required dependencies fulfilled.
     * <p>
     * Should be called after an installation of an add-on.
     *
     * @see #addAddOnImpl(AddOn)
     * @since 2.4.0
     */
private void checkAndLoadDependentExtensions() {
    boolean changed = false;
    for (Entry<String, AddOnClassLoader> entry : new HashMap<>(addOnLoaders).entrySet()) {
        AddOn runningAddOn = aoc.getAddOn(entry.getKey());
        for (String extClassName : runningAddOn.getExtensionsWithDeps()) {
            if (!runningAddOn.isExtensionLoaded(extClassName)) {
                AddOn.AddOnRunRequirements reqs = runningAddOn.calculateExtensionRunRequirements(extClassName, aoc.getInstalledAddOns());
                ExtensionRunRequirements extReqs = reqs.getExtensionRequirements().get(0);
                if (extReqs.isRunnable()) {
                    List<AddOnClassLoader> dependencies = new ArrayList<>(extReqs.getDependencies().size());
                    for (AddOn addOnDep : extReqs.getDependencies()) {
                        dependencies.add(addOnLoaders.get(addOnDep.getId()));
                    }
                    AddOnClassLoader extAddOnClassLoader = new AddOnClassLoader(entry.getValue(), dependencies, runningAddOn.getExtensionAddOnClassnames(extClassName));
                    Extension ext = loadAddOnExtension(runningAddOn, extReqs.getClassname(), extAddOnClassLoader);
                    AddOnInstaller.installAddOnExtension(runningAddOn, ext);
                    runnableAddOns.get(runningAddOn).add(extReqs.getClassname());
                    changed = true;
                }
            }
        }
    }
    if (changed) {
        saveAddOnsRunState(runnableAddOns);
    }
}
Also used : Extension(org.parosproxy.paros.extension.Extension) ExtensionRunRequirements(org.zaproxy.zap.control.AddOn.ExtensionRunRequirements) ArrayList(java.util.ArrayList) AddOnRunRequirements(org.zaproxy.zap.control.AddOn.AddOnRunRequirements)

Example 15 with Extension

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

the class AddOnInstaller method installAddOnExtensions.

private static List<Extension> installAddOnExtensions(AddOn addOn) {
    ExtensionLoader extensionLoader = Control.getSingleton().getExtensionLoader();
    List<Extension> listExts = ExtensionFactory.loadAddOnExtensions(extensionLoader, Model.getSingleton().getOptionsParam().getConfig(), addOn);
    for (Extension ext : listExts) {
        installAddOnExtensionImpl(addOn, ext, extensionLoader);
    }
    return listExts;
}
Also used : Extension(org.parosproxy.paros.extension.Extension) ExtensionLoader(org.parosproxy.paros.extension.ExtensionLoader)

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