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);
}
}
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");
}
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;
}
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);
}
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;
}
Aggregations