Skip to content

A free, open-source alternative to Burp Suite: an intercepting proxy and web app security testing suite with Repeater, Intruder, Collaborator and a built-in OWASP ZAP scanner. Linux, AGPL-3.0.

1.8 KB
Raw Blame
package hello;

import opensuite.core.SuiteContext;
import opensuite.core.ToolModule;
import opensuite.ui.Ui;

import javax.swing.*;
import java.awt.BorderLayout;
import java.io.Serializable;

/**
 * The smallest extension Open Suite can load from a jar: one tab, a Send to
 * entry, and a little saved state. Its package is outside {@code opensuite.}
 * on purpose: an extension jar carries no class of the suite's, and the test
 * that loads this one checks that it does not.
 */
public class HelloExtension implements ToolModule {
    private SuiteContext ctx;
    private int sends;
    private String restored = "nothing";

    @Override public String name() { return "hello"; }

    @Override public void init(SuiteContext ctx) { this.ctx = ctx; }

    /** A listener that this class registers itself, wherever it is called from. The test calls it on the event thread. */
    public void listenFrom(SuiteContext ctx) { ctx.settings().addListener(key -> { }); }

    @Override public SuiteContext.MessageSink sink() {
        return (svc, req, resp, caption) -> { sends++; ctx.touch(); };
    }

    @Override public Tab[] tabs() {
        JPanel p = new JPanel(new BorderLayout());
        p.add(Ui.label("Hello from an extension loaded at run time."), BorderLayout.NORTH);
        return new Tab[]{ new Tab("hello", p) };
    }

    @Override public void shutdown() { ctx.alert("hello", "shutdown"); }

    /** What happened to it, on the thread it happened on; the test cannot reach its fields through its own class loader. */
    @Override public Serializable saveState() {
        return "sends=" + sends + ";restored=" + restored + ";thread=" + Thread.currentThread().getName();
    }

    @Override public void restoreState(Serializable state) { restored = String.valueOf(state); }
}