Search in sources :

Example 1 with Extension

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

the class OptionsExtensionTableModel method enableDependants.

private void enableDependants(Extension extension, Boolean enabled) {
    int row = 0;
    for (Extension ext : extensions) {
        if (ext.getDependencies().contains(extension.getClass())) {
            ext.setEnabled(enabled);
            this.fireTableCellUpdated(row, 0);
            enableDependants(ext, enabled);
        }
        row++;
    }
}
Also used : Extension(org.parosproxy.paros.extension.Extension)

Example 2 with Extension

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

the class ExtensionAutoUpdate method processAddOnChanges.

/**
     * Processes the given add-on changes.
     * 
     * @param caller the caller to set as parent of shown dialogues
     * @param changes the changes that will be processed
     */
void processAddOnChanges(Window caller, AddOnDependencyChecker.AddOnChangesResult changes) {
    if (addonsDialog != null) {
        addonsDialog.setDownloadingUpdates();
    }
    if (getView() != null) {
        Set<AddOn> addOns = new HashSet<>(changes.getUninstalls());
        addOns.addAll(changes.getOldVersions());
        Set<Extension> extensions = new HashSet<>();
        extensions.addAll(changes.getUnloadExtensions());
        extensions.addAll(changes.getSoftUnloadExtensions());
        if (!warnUnsavedResourcesOrActiveActions(caller, addOns, extensions, true)) {
            return;
        }
    }
    uninstallAddOns(caller, changes.getUninstalls(), false);
    Set<AddOn> allAddons = new HashSet<>(changes.getNewVersions());
    allAddons.addAll(changes.getInstalls());
    for (AddOn addOn : allAddons) {
        if (addonsDialog != null) {
            addonsDialog.notifyAddOnDownloading(addOn);
        }
        downloadAddOn(addOn);
    }
}
Also used : Extension(org.parosproxy.paros.extension.Extension) AddOn(org.zaproxy.zap.control.AddOn) HashSet(java.util.HashSet)

Example 3 with Extension

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

the class AddOnDependencyChecker method calculateChanges.

private AddOnChangesResult calculateChanges(Set<AddOn> selectedAddOns, boolean updating) {
    Set<AddOn> oldVersions = new HashSet<>();
    Set<AddOn> uninstalls = new HashSet<>();
    Set<AddOn> newVersions = new HashSet<>();
    Set<AddOn> installs = new HashSet<>();
    if (updating) {
        for (AddOn update : selectedAddOns) {
            AddOn oldVersion = installedAddOns.getAddOn(update.getId());
            oldVersions.add(oldVersion);
        }
    }
    boolean newerJavaVersion = false;
    for (AddOn addOn : selectedAddOns) {
        newerJavaVersion |= addDependencies(addOn, selectedAddOns, oldVersions, newVersions, installs);
    }
    Set<AddOn> remainingInstalledAddOns = new HashSet<>();
    for (AddOn addOn : installedAddOns.getAddOns()) {
        if (!contains(selectedAddOns, addOn) && !contains(newVersions, addOn)) {
            remainingInstalledAddOns.add(addOn);
        }
    }
    Set<AddOn> expectedInstalledAddOns = new HashSet<>(remainingInstalledAddOns);
    expectedInstalledAddOns.addAll(selectedAddOns);
    expectedInstalledAddOns.addAll(installs);
    expectedInstalledAddOns.addAll(newVersions);
    for (AddOn addOn : remainingInstalledAddOns) {
        if (addOn.calculateRunRequirements(expectedInstalledAddOns).hasDependencyIssue()) {
            uninstalls.add(addOn);
        }
    }
    for (Iterator<AddOn> it = uninstalls.iterator(); it.hasNext(); ) {
        AddOn addOn = it.next();
        AddOn addOnUpdate = availableAddOns.getAddOn(addOn.getId());
        if (addOnUpdate != null && !addOnUpdate.equals(addOn)) {
            it.remove();
            oldVersions.add(addOn);
            newVersions.add(addOnUpdate);
            newerJavaVersion |= addDependencies(addOnUpdate, selectedAddOns, oldVersions, newVersions, installs);
        }
    }
    for (Iterator<AddOn> it = uninstalls.iterator(); it.hasNext(); ) {
        AddOn addOn = it.next();
        if (contains(installs, addOn) || contains(newVersions, addOn) || (addOn.calculateRunRequirements(installedAddOns.getAddOns()).hasDependencyIssue() && !containsAny(addOn.getIdsAddOnDependencies(), uninstalls))) {
            it.remove();
        }
    }
    if (updating) {
        newVersions.addAll(selectedAddOns);
    } else {
        installs.addAll(selectedAddOns);
    }
    expectedInstalledAddOns = new HashSet<>(remainingInstalledAddOns);
    expectedInstalledAddOns.removeAll(uninstalls);
    expectedInstalledAddOns.removeAll(oldVersions);
    expectedInstalledAddOns.addAll(installs);
    expectedInstalledAddOns.addAll(newVersions);
    Set<Extension> unloadExtensions = new HashSet<>();
    Set<Extension> softUnloadExtensions = new HashSet<>();
    Set<AddOn> optionalAddOns = new HashSet<>();
    for (AddOn addOn : expectedInstalledAddOns) {
        List<String> extensionsWithDeps = addOn.getExtensionsWithDeps();
        for (Extension extension : addOn.getLoadedExtensionsWithDeps()) {
            AddOn.AddOnRunRequirements requirements = addOn.calculateExtensionRunRequirements(extension, expectedInstalledAddOns);
            AddOn.ExtensionRunRequirements extReqs = requirements.getExtensionRequirements().get(0);
            if (!extReqs.isRunnable()) {
                unloadExtensions.add(extension);
            } else if (CollectionUtils.containsAny(extReqs.getDependencies(), oldVersions)) {
                softUnloadExtensions.add(extension);
            }
            extensionsWithDeps.remove(extReqs.getClassname());
        }
        for (String classname : extensionsWithDeps) {
            AddOn.AddOnRunRequirements requirements = addOn.calculateExtensionRunRequirements(classname, availableAddOns.getAddOns());
            AddOn.ExtensionRunRequirements extReqs = requirements.getExtensionRequirements().get(0);
            if (extReqs.isRunnable()) {
                optionalAddOns.addAll(extReqs.getDependencies());
            }
        }
    }
    optionalAddOns.removeAll(installs);
    optionalAddOns.removeAll(newVersions);
    optionalAddOns.removeAll(remainingInstalledAddOns);
    return new AddOnChangesResult(selectedAddOns, oldVersions, uninstalls, newVersions, installs, newerJavaVersion, optionalAddOns, unloadExtensions, softUnloadExtensions);
}
Also used : AddOn(org.zaproxy.zap.control.AddOn) Extension(org.parosproxy.paros.extension.Extension) HashSet(java.util.HashSet)

Example 4 with Extension

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

the class AddOnDependencyChecker method calculateUninstallChanges.

/**
     * Calculates the changes required to uninstall the given add-ons.
     * <p>
     * It might require uninstalling other add-ons depending on the dependencies of the affected add-ons.
     *
     * @param selectedAddOns the add-ons that would be uninstalled
     * @return the resulting changes with the add-ons that need to be uninstalled
     */
public UninstallationResult calculateUninstallChanges(Set<AddOn> selectedAddOns) {
    List<AddOn> remainingAddOns = new ArrayList<>(installedAddOns.getAddOns());
    remainingAddOns.removeAll(selectedAddOns);
    Set<AddOn> uninstallations = new HashSet<>();
    List<AddOn> addOnsToCheck = new ArrayList<>(remainingAddOns);
    while (!addOnsToCheck.isEmpty()) {
        AddOn addOn = addOnsToCheck.remove(0);
        AddOn.AddOnRunRequirements requirements = addOn.calculateRunRequirements(remainingAddOns);
        if (!requirements.hasDependencyIssue()) {
            addOnsToCheck.removeAll(requirements.getDependencies());
        } else if (AddOn.InstallationStatus.UNINSTALLATION_FAILED != addOn.getInstallationStatus()) {
            uninstallations.add(addOn);
        }
    }
    for (Iterator<AddOn> it = uninstallations.iterator(); it.hasNext(); ) {
        AddOn addOn = it.next();
        if (addOn.calculateRunRequirements(installedAddOns.getAddOns()).hasDependencyIssue() && !containsAny(addOn.getIdsAddOnDependencies(), uninstallations)) {
            it.remove();
        }
    }
    remainingAddOns.removeAll(uninstallations);
    Set<Extension> extensions = new HashSet<>();
    for (AddOn addOn : remainingAddOns) {
        if (addOn.hasExtensionsWithDeps()) {
            for (Extension ext : addOn.getLoadedExtensions()) {
                AddOn.AddOnRunRequirements requirements = addOn.calculateExtensionRunRequirements(ext, remainingAddOns);
                if (!requirements.getExtensionRequirements().isEmpty()) {
                    AddOn.ExtensionRunRequirements extReqs = requirements.getExtensionRequirements().get(0);
                    if (!extReqs.isRunnable()) {
                        extensions.add(ext);
                    }
                }
            }
        }
    }
    uninstallations.addAll(selectedAddOns);
    return new UninstallationResult(selectedAddOns, uninstallations, extensions);
}
Also used : Extension(org.parosproxy.paros.extension.Extension) AddOn(org.zaproxy.zap.control.AddOn) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 5 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)

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