Skip to content

Commit

Permalink
Merge pull request #6004 from psiinon/client/refactor
Browse files Browse the repository at this point in the history
Client: code refactor
  • Loading branch information
kingthorin authored Dec 12, 2024
2 parents 442a017 + e1aa7c9 commit 3894fe0
Show file tree
Hide file tree
Showing 41 changed files with 158 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import java.util.List;
import javax.swing.table.AbstractTableModel;
import org.parosproxy.paros.Constant;
import org.zaproxy.addon.client.internal.ReportedElement;
import org.zaproxy.addon.client.internal.ReportedEvent;
import org.zaproxy.addon.client.internal.ReportedObject;

public class ClientHistoryTableModel extends AbstractTableModel {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
import org.parosproxy.paros.network.HttpHeader;
import org.parosproxy.paros.network.HttpMessage;
import org.parosproxy.paros.network.HttpRequestHeader;
import org.zaproxy.addon.client.internal.ClientNode;
import org.zaproxy.addon.client.internal.ClientSideComponent;
import org.zaproxy.addon.client.internal.ReportedElement;
import org.zaproxy.addon.client.internal.ReportedEvent;
import org.zaproxy.zap.extension.api.API;
import org.zaproxy.zap.extension.api.ApiAction;
import org.zaproxy.zap.extension.api.ApiException;
Expand Down Expand Up @@ -92,22 +96,13 @@ private void handleReportObject(JSONObject json) {
() -> {
ClientNode node =
this.extension.getOrAddClientNode(urlStr, false, false);
ClientSideDetails details = node.getUserObject();
boolean wasVisited = details.isVisited();
ClientSideComponent component = new ClientSideComponent(json);
boolean componentAdded = details.addComponent(component);
if (!wasVisited || componentAdded) {
details.setVisited(true);
this.extension.clientNodeChanged(node);
}
extension.addComponentToNode(node, component);
if (component.isStorageEvent()) {
String storageUrl = node.getSite() + component.getTypeForDisplay();
ClientNode storageNode =
this.extension.getOrAddClientNode(storageUrl, false, true);
ClientSideDetails storageDetails = storageNode.getUserObject();
storageDetails.setStorage(true);
storageDetails.addComponent(component);
this.extension.clientNodeChanged(storageNode);
extension.addComponentToNode(
this.extension.getOrAddClientNode(storageUrl, false, true),
component);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.List;
import javax.swing.table.AbstractTableModel;
import org.parosproxy.paros.Constant;
import org.zaproxy.addon.client.internal.ClientSideComponent;

public class ComponentTableModel extends AbstractTableModel {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -44,16 +45,34 @@
import org.parosproxy.paros.extension.ExtensionHook;
import org.parosproxy.paros.extension.SessionChangedListener;
import org.parosproxy.paros.extension.history.ExtensionHistory;
import org.parosproxy.paros.model.Model;
import org.parosproxy.paros.model.Session;
import org.parosproxy.paros.model.SiteNode;
import org.parosproxy.paros.view.View;
import org.zaproxy.addon.client.impl.ClientZestRecorder;
import org.zaproxy.addon.client.internal.ClientMap;
import org.zaproxy.addon.client.internal.ClientNode;
import org.zaproxy.addon.client.internal.ClientSideComponent;
import org.zaproxy.addon.client.internal.ClientSideDetails;
import org.zaproxy.addon.client.internal.ReportedElement;
import org.zaproxy.addon.client.internal.ReportedEvent;
import org.zaproxy.addon.client.internal.ReportedObject;
import org.zaproxy.addon.client.pscan.ClientPassiveScanController;
import org.zaproxy.addon.client.pscan.ClientPassiveScanHelper;
import org.zaproxy.addon.client.pscan.OptionsPassiveScan;
import org.zaproxy.addon.client.spider.ClientSpider;
import org.zaproxy.addon.client.spider.ClientSpiderDialog;
import org.zaproxy.addon.client.spider.PopupMenuSpider;
import org.zaproxy.addon.client.ui.ClientDetailsPanel;
import org.zaproxy.addon.client.ui.ClientHistoryPanel;
import org.zaproxy.addon.client.ui.ClientMapPanel;
import org.zaproxy.addon.client.ui.PopupMenuClientAttack;
import org.zaproxy.addon.client.ui.PopupMenuClientCopyUrls;
import org.zaproxy.addon.client.ui.PopupMenuClientDelete;
import org.zaproxy.addon.client.ui.PopupMenuClientDetailsCopy;
import org.zaproxy.addon.client.ui.PopupMenuClientHistoryCopy;
import org.zaproxy.addon.client.ui.PopupMenuClientOpenInBrowser;
import org.zaproxy.addon.client.ui.PopupMenuClientShowInSites;
import org.zaproxy.addon.network.ExtensionNetwork;
import org.zaproxy.zap.ZAP;
import org.zaproxy.zap.eventBus.Event;
Expand All @@ -75,7 +94,7 @@ public class ExtensionClientIntegration extends ExtensionAdaptor {

private static final String FIREFOX_PROFILES_INI = "profiles.ini";

protected static final String PREFIX = "client";
public static final String PREFIX = "client";

protected static final String RESOURCES = "resources";

Expand Down Expand Up @@ -112,7 +131,8 @@ public ExtensionClientIntegration() {
}

@Override
public void init() {
public void initModel(Model model) {
super.initModel(model);
clientHistoryTableModel = new ClientHistoryTableModel();
clientTree =
new ClientMap(
Expand Down Expand Up @@ -417,6 +437,14 @@ public void clientNodeChanged(ClientNode node) {
this.clientTree.nodeChanged(node);
}

public boolean addComponentToNode(ClientNode node, ClientSideComponent component) {
if (this.clientTree.addComponentToNode(node, component)) {
this.clientNodeChanged(node);
return true;
}
return false;
}

public void deleteNodes(List<ClientNode> nodes) {
this.clientTree.deleteNodes(nodes);
if (View.isInitialised()) {
Expand Down Expand Up @@ -623,11 +651,18 @@ private ZapMenuItem getMenuItemCustomScan() {

public ImageIcon getIcon() {
if (icon == null) {
icon =
DisplayUtils.getScaledIcon(
ExtensionClientIntegration.class.getResource(
ExtensionClientIntegration.RESOURCES + "/spiderClient.png"));
icon = getIcon("spiderClient.png");
}
return icon;
}

public static ImageIcon getIcon(String name) {
String resourceName = RESOURCES + "/" + name;
URL url = ExtensionClientIntegration.class.getResource(resourceName);
if (url == null) {
LOGGER.error("No icon with name {}", resourceName);
return null;
}
return DisplayUtils.getScaledIcon(url);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.parosproxy.paros.network.HttpRequestHeader;
import org.parosproxy.paros.network.HttpSender;
import org.parosproxy.paros.view.View;
import org.zaproxy.addon.client.internal.ClientNode;
import org.zaproxy.addon.client.internal.ClientSideDetails;
import org.zaproxy.zap.eventBus.Event;
import org.zaproxy.zap.model.SessionStructure;
import org.zaproxy.zap.model.StructuralNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.zaproxy.addon.client;
package org.zaproxy.addon.client.internal;

import java.util.Comparator;
import java.util.HashMap;
Expand All @@ -27,6 +27,7 @@
import javax.swing.tree.TreeNode;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.zaproxy.addon.client.ClientUtils;
import org.zaproxy.zap.ZAP;
import org.zaproxy.zap.eventBus.Event;
import org.zaproxy.zap.eventBus.EventPublisher;
Expand Down Expand Up @@ -156,6 +157,16 @@ public void clear() {
public String getPublisherName() {
return this.getClass().getCanonicalName();
}

public boolean addComponentToNode(ClientNode node, ClientSideComponent component) {
ClientSideDetails details = node.getUserObject();
boolean wasVisited = details.isVisited();
boolean componentAdded = details.addComponent(component);
if (!wasVisited || componentAdded) {
details.setVisited(true);
}
return componentAdded;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.zaproxy.addon.client;
package org.zaproxy.addon.client.internal;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.zaproxy.addon.client;
package org.zaproxy.addon.client.internal;

import java.util.Objects;
import net.sf.json.JSONObject;
import org.parosproxy.paros.Constant;
import org.zaproxy.addon.client.ExtensionClientIntegration;

public class ClientSideComponent {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.zaproxy.addon.client;
package org.zaproxy.addon.client.internal;

import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -57,19 +57,19 @@ public Set<ClientSideComponent> getComponents() {
return components;
}

public void setVisited(boolean visited) {
protected void setVisited(boolean visited) {
this.visited = visited;
}

public boolean addComponent(ClientSideComponent component) {
protected boolean addComponent(ClientSideComponent component) {
return this.components.add(component);
}

public boolean isStorage() {
return storage;
}

public void setStorage(boolean storage) {
protected void setStorage(boolean storage) {
this.storage = storage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.zaproxy.addon.client;
package org.zaproxy.addon.client.internal;

import net.sf.json.JSONObject;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.zaproxy.addon.client;
package org.zaproxy.addon.client.internal;

import net.sf.json.JSONObject;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.zaproxy.addon.client;
package org.zaproxy.addon.client.internal;

import java.util.Date;
import net.sf.json.JSONObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import org.parosproxy.paros.core.scanner.Alert;
import org.parosproxy.paros.core.scanner.Alert.Source;
import org.zaproxy.addon.client.ReportedObject;
import org.zaproxy.addon.client.internal.ReportedObject;

public abstract class ClientPassiveAbstractScanRule implements ClientPassiveScanRule {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
package org.zaproxy.addon.client.pscan;

import org.zaproxy.addon.client.ReportedObject;
import org.zaproxy.addon.client.internal.ReportedObject;
import org.zaproxy.zap.extension.alert.ExampleAlertProvider;

public interface ClientPassiveScanRule extends ExampleAlertProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import org.parosproxy.paros.Constant;
import org.parosproxy.paros.core.scanner.Alert;
import org.zaproxy.addon.client.ClientUtils;
import org.zaproxy.addon.client.ReportedElement;
import org.zaproxy.addon.client.ReportedObject;
import org.zaproxy.addon.client.internal.ReportedElement;
import org.zaproxy.addon.client.internal.ReportedObject;

public class InformationInStorageScanRule extends ClientPassiveAbstractScanRule {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import org.parosproxy.paros.Constant;
import org.parosproxy.paros.core.scanner.Alert;
import org.zaproxy.addon.client.ClientUtils;
import org.zaproxy.addon.client.ReportedElement;
import org.zaproxy.addon.client.ReportedObject;
import org.zaproxy.addon.client.internal.ReportedElement;
import org.zaproxy.addon.client.internal.ReportedObject;

public class JwtInStorageScanRule extends ClientPassiveAbstractScanRule {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import org.parosproxy.paros.core.scanner.Alert;
import org.parosproxy.paros.model.HistoryReference;
import org.zaproxy.addon.client.ClientUtils;
import org.zaproxy.addon.client.ReportedElement;
import org.zaproxy.addon.client.ReportedObject;
import org.zaproxy.addon.client.internal.ReportedElement;
import org.zaproxy.addon.client.internal.ReportedObject;

public class SensitiveInfoInStorageScanRule extends ClientPassiveAbstractScanRule {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
import org.openqa.selenium.WebDriver;
import org.parosproxy.paros.control.Control;
import org.parosproxy.paros.view.View;
import org.zaproxy.addon.client.ClientMap;
import org.zaproxy.addon.client.ClientNode;
import org.zaproxy.addon.client.ClientOptions;
import org.zaproxy.addon.client.ExtensionClientIntegration;
import org.zaproxy.addon.client.internal.ClientMap;
import org.zaproxy.addon.client.internal.ClientNode;
import org.zaproxy.zap.ZAP;
import org.zaproxy.zap.eventBus.Event;
import org.zaproxy.zap.eventBus.EventConsumer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.zaproxy.addon.client;
package org.zaproxy.addon.client.ui;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import org.parosproxy.paros.Constant;
import org.parosproxy.paros.extension.AbstractPanel;
import org.zaproxy.addon.client.ExtensionClientIntegration;
import org.zaproxy.addon.client.internal.ClientNode;
import org.zaproxy.addon.client.internal.ClientSideComponent;
import org.zaproxy.zap.view.LayoutHelper;

public class ClientDetailsPanel extends AbstractPanel {
Expand All @@ -44,11 +46,7 @@ public ClientDetailsPanel() {

this.setLayout(new GridBagLayout());
setName(Constant.messages.getString(ExtensionClientIntegration.PREFIX + ".details.title"));
setIcon(
new ImageIcon(
ExtensionClientIntegration.class.getResource(
ExtensionClientIntegration.RESOURCES
+ "/application-browser.png")));
setIcon(ExtensionClientIntegration.getIcon("application-browser.png"));

introPanel = new JPanel();
introPanel.setLayout(new GridBagLayout());
Expand Down
Loading

0 comments on commit 3894fe0

Please sign in to comment.