Search in sources :

Example 1 with AddOnRunRequirements

use of org.zaproxy.zap.control.AddOn.AddOnRunRequirements in project zaproxy by zaproxy.

the class AddOnLoader method addAddOnImpl.

private void addAddOnImpl(AddOn ao) {
    if (AddOn.InstallationStatus.INSTALLED == ao.getInstallationStatus()) {
        return;
    }
    if (this.blockList.contains(ao.getId())) {
        // Explicitly being added back, so remove from the block list
        this.blockList.remove(ao.getId());
        this.saveBlockList();
    }
    if (!isDynamicallyInstallable(ao)) {
        return;
    }
    AddOnRunRequirements reqs = calculateRunRequirements(ao, aoc.getInstalledAddOns());
    if (!reqs.isRunnable()) {
        ao.setInstallationStatus(AddOn.InstallationStatus.NOT_INSTALLED);
        return;
    }
    AddOnInstaller.install(createAndAddAddOnClassLoader(ao), ao);
    ao.setInstallationStatus(AddOn.InstallationStatus.INSTALLED);
    Control.getSingleton().getExtensionLoader().addOnInstalled(ao);
    if (runnableAddOns.get(ao) == null) {
        runnableAddOns.put(ao, getRunnableExtensionsWithDeps(reqs));
        saveAddOnsRunState(runnableAddOns);
    }
    checkAndLoadDependentExtensions();
    checkAndInstallAddOnsNotInstalled();
    if (View.isInitialised()) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                View.getSingleton().refreshTabViewMenus();
            }
        });
    }
}
Also used : AddOnRunRequirements(org.zaproxy.zap.control.AddOn.AddOnRunRequirements)

Example 2 with AddOnRunRequirements

use of org.zaproxy.zap.control.AddOn.AddOnRunRequirements in project zaproxy by zaproxy.

the class AddOnLoader method loadAllAddOns.

private void loadAllAddOns() {
    runnableAddOns = new HashMap<>();
    idsAddOnsWithRunningIssuesSinceLastRun = new ArrayList<>();
    Map<AddOn, List<String>> oldRunnableAddOns = loadAddOnsRunState(aoc);
    List<AddOn> runAddons = new ArrayList<>();
    for (Iterator<AddOn> iterator = aoc.getAddOns().iterator(); iterator.hasNext(); ) {
        AddOn addOn = iterator.next();
        if (canLoadAddOn(addOn)) {
            AddOnRunRequirements reqs = calculateRunRequirements(addOn, aoc.getAddOns());
            if (reqs.isRunnable()) {
                List<String> runnableExtensions;
                if (addOn.hasExtensionsWithDeps()) {
                    runnableExtensions = getRunnableExtensionsWithDeps(reqs);
                    List<String> oldRunnableExtensions = oldRunnableAddOns.get(addOn);
                    if (oldRunnableExtensions != null && !oldRunnableExtensions.isEmpty()) {
                        oldRunnableExtensions.removeAll(runnableExtensions);
                        if (!oldRunnableExtensions.isEmpty()) {
                            idsAddOnsWithRunningIssuesSinceLastRun.add(addOn.getId());
                        }
                    }
                } else {
                    runnableExtensions = Collections.emptyList();
                }
                runnableAddOns.put(addOn, runnableExtensions);
                runAddons.add(addOn);
            } else if (oldRunnableAddOns.get(addOn) != null) {
                idsAddOnsWithRunningIssuesSinceLastRun.add(addOn.getId());
            }
        } else {
            iterator.remove();
        }
    }
    saveAddOnsRunState(runnableAddOns);
    for (AddOn addOn : runAddons) {
        addOn.setInstallationStatus(AddOn.InstallationStatus.INSTALLED);
        createAndAddAddOnClassLoader(addOn);
    }
}
Also used : AddOnRunRequirements(org.zaproxy.zap.control.AddOn.AddOnRunRequirements) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with AddOnRunRequirements

use of org.zaproxy.zap.control.AddOn.AddOnRunRequirements in project zaproxy by zaproxy.

the class InstalledAddOnsTableModel method refreshUpdateIssues.

private boolean refreshUpdateIssues(AddOnWrapper aow) {
    AddOnRunRequirements reqs = aow.getAddOnUpdate().calculateRunRequirements(availableAddOns.getAddOns());
    String issues = getAddOnRunningIssues(reqs);
    aow.setUpdateIssues(issues, !reqs.hasExtensionsWithRunningIssues());
    return !issues.isEmpty();
}
Also used : AddOnRunRequirements(org.zaproxy.zap.control.AddOn.AddOnRunRequirements)

Example 4 with AddOnRunRequirements

use of org.zaproxy.zap.control.AddOn.AddOnRunRequirements in project zaproxy by zaproxy.

the class AddOnsTableModel method refreshRunningIssues.

protected boolean refreshRunningIssues(AddOnWrapper aow, int row) {
    AddOnRunRequirements reqs = aow.getAddOn().calculateRunRequirements(addOnCollection.getAddOns());
    String issues = getAddOnRunningIssues(reqs);
    aow.setRunningIssues(issues, !reqs.hasExtensionsWithRunningIssues());
    return !issues.isEmpty();
}
Also used : AddOnRunRequirements(org.zaproxy.zap.control.AddOn.AddOnRunRequirements)

Example 5 with AddOnRunRequirements

use of org.zaproxy.zap.control.AddOn.AddOnRunRequirements in project zaproxy by zaproxy.

the class ExtensionAutoUpdate method installLocalAddOn.

private void installLocalAddOn(Path file) throws Exception {
    if (!AddOn.isAddOn(file)) {
        showWarningMessageInvalidAddOnFile();
        return;
    }
    AddOn ao;
    try {
        ao = new AddOn(file);
    } catch (Exception e) {
        showWarningMessageInvalidAddOnFile();
        return;
    }
    if (!ao.canLoadInCurrentVersion()) {
        showWarningMessageCantLoadAddOn(ao);
        return;
    }
    AddOnDependencyChecker dependencyChecker = new AddOnDependencyChecker(getLocalVersionInfo(), latestVersionInfo == null ? getLocalVersionInfo() : latestVersionInfo);
    boolean update = false;
    AddOnChangesResult result;
    AddOn installedAddOn = getLocalVersionInfo().getAddOn(ao.getId());
    if (installedAddOn != null) {
        if (!ao.isUpdateTo(installedAddOn)) {
            View.getSingleton().showWarningDialog(MessageFormat.format(Constant.messages.getString("cfu.warn.addOnOlderVersion"), installedAddOn.getFileVersion(), View.getSingleton().getStatusUI(installedAddOn.getStatus()).toString(), ao.getFileVersion(), View.getSingleton().getStatusUI(ao.getStatus()).toString()));
            return;
        }
        result = dependencyChecker.calculateUpdateChanges(ao);
        update = true;
    } else {
        result = dependencyChecker.calculateInstallChanges(ao);
    }
    if (result.getOldVersions().isEmpty() && result.getUninstalls().isEmpty()) {
        AddOnRunRequirements reqs = ao.calculateRunRequirements(getLocalVersionInfo().getAddOns());
        if (!reqs.isRunnable()) {
            if (!AddOnRunIssuesUtils.askConfirmationAddOnNotRunnable(Constant.messages.getString("cfu.warn.addOnNotRunnable.message"), Constant.messages.getString("cfu.warn.addOnNotRunnable.question"), getLocalVersionInfo(), ao)) {
                return;
            }
        }
        installLocalAddOn(ao);
        return;
    }
    if (update) {
        if (!dependencyChecker.confirmUpdateChanges(getView().getMainFrame(), result)) {
            return;
        }
        // The new version of the add-on is installed manually
        result.getNewVersions().remove(ao);
    } else {
        if (!dependencyChecker.confirmInstallChanges(getView().getMainFrame(), result)) {
            return;
        }
        // The add-on is installed manually
        result.getInstalls().remove(ao);
    }
    processAddOnChanges(getView().getMainFrame(), result);
    installLocalAddOn(ao);
}
Also used : AddOnRunRequirements(org.zaproxy.zap.control.AddOn.AddOnRunRequirements) AddOn(org.zaproxy.zap.control.AddOn) AddOnChangesResult(org.zaproxy.zap.extension.autoupdate.AddOnDependencyChecker.AddOnChangesResult) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException)

Aggregations

AddOnRunRequirements (org.zaproxy.zap.control.AddOn.AddOnRunRequirements)5 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)1 ConfigurationException (org.apache.commons.configuration.ConfigurationException)1 AddOn (org.zaproxy.zap.control.AddOn)1 AddOnChangesResult (org.zaproxy.zap.extension.autoupdate.AddOnDependencyChecker.AddOnChangesResult)1