Skip to content

Commit

Permalink
Merge pull request #24 from DolphFlynn/listener
Browse files Browse the repository at this point in the history
Listener
  • Loading branch information
DolphFlynn authored Feb 14, 2024
2 parents e3f3e0d + 94b3c57 commit 155482c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public interface KeysModelListener {

void notifyKeyDeleted(Key key);

class InertKeyModelListener implements KeysModelListener {
class InertKeysModelListener implements KeysModelListener {
@Override
public void notifyKeyInserted(Key key) {
}
Expand All @@ -20,4 +20,27 @@ public void notifyKeyDeleted(int rowIndex) {
public void notifyKeyDeleted(Key key) {
}
}

class SimpleKeysModelListener implements KeysModelListener {
private final Runnable action;

public SimpleKeysModelListener(Runnable action) {
this.action = action;
}

@Override
public void notifyKeyInserted(Key key) {
action.run();
}

@Override
public void notifyKeyDeleted(int rowIndex) {
action.run();
}

@Override
public void notifyKeyDeleted(Key key) {
action.run();
}
}
}
24 changes: 5 additions & 19 deletions src/main/java/com/blackberry/jwteditor/view/config/ConfigView.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import burp.scanner.ScannerConfig;
import com.blackberry.jwteditor.model.keys.Key;
import com.blackberry.jwteditor.model.keys.KeysModel;
import com.blackberry.jwteditor.model.keys.KeysModelListener;
import com.blackberry.jwteditor.model.keys.KeysModelListener.SimpleKeysModelListener;
import com.blackberry.jwteditor.view.utils.DocumentAdapter;

import javax.swing.*;
Expand All @@ -38,7 +38,7 @@
import static java.awt.Font.BOLD;


public class ConfigView implements KeysModelListener {
public class ConfigView {
private final IntruderConfig intruderConfig;

private JPanel mainPanel;
Expand All @@ -65,7 +65,6 @@ public ConfigView(BurpConfig burpConfig, UserInterface userInterface, boolean is
this.intruderConfig = burpConfig.intruderConfig();

ProxyConfig proxyConfig = burpConfig.proxyConfig();
keysModel.addKeyModelListener(this);

checkBoxHighlightJWT.setSelected(proxyConfig.highlightJWT());
checkBoxHighlightJWT.addActionListener(e -> {
Expand All @@ -87,9 +86,10 @@ public ConfigView(BurpConfig burpConfig, UserInterface userInterface, boolean is
comboBoxPayloadPosition.setSelectedItem(intruderConfig.fuzzLocation());
comboBoxPayloadPosition.addActionListener(e -> intruderConfig.setFuzzLocation((FuzzLocation) comboBoxPayloadPosition.getSelectedItem()));

this.updateSigningKeyList();
updateSigningKeyList();
comboBoxIntruderSigningKeyId.addActionListener(e -> intruderConfig.setSigningKeyId((String) comboBoxIntruderSigningKeyId.getSelectedItem()));
resignIntruderJWS.addActionListener(e -> intruderConfig.setResign(resignIntruderJWS.isSelected()));
keysModel.addKeyModelListener(new SimpleKeysModelListener(this::updateSigningKeyList));

ScannerConfig scannerConfig = burpConfig.scannerConfig();

Expand All @@ -114,7 +114,7 @@ public ConfigView(BurpConfig burpConfig, UserInterface userInterface, boolean is
comboBoxHighlightColor.setRenderer(new HighlightComboRenderer());
}

public void updateSigningKeyList() {
private void updateSigningKeyList() {
List<Key> signingKeys = keysModel.getSigningKeys();
String[] signingKeyIds = signingKeys.stream().map(Key::getID).toArray(String[]::new);
String selectedSigningId = intruderConfig.signingKeyId();
Expand Down Expand Up @@ -161,18 +161,4 @@ public Component getListCellRendererComponent(JList<? extends HighlightColor> li
return label;
}
}

public void notifyKeyInserted(Key key) {
this.updateSigningKeyList();
}

@Override
public void notifyKeyDeleted(int rowIndex) {
this.updateSigningKeyList();
}

@Override
public void notifyKeyDeleted(Key key) {
this.updateSigningKeyList();
}
}
4 changes: 2 additions & 2 deletions src/test/java/com/blackberry/jwteditor/KeysModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package com.blackberry.jwteditor;

import com.blackberry.jwteditor.model.keys.KeysModel;
import com.blackberry.jwteditor.model.keys.KeysModelListener.InertKeyModelListener;
import com.blackberry.jwteditor.model.keys.KeysModelListener.InertKeysModelListener;
import com.blackberry.jwteditor.model.keys.PasswordKey;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -111,7 +111,7 @@ void deleteMultipleKeys_listenerOnlyFiresOncePerKey() {
.withKey(new PasswordKey("testKeyId", "secret", 8, 1337))
.withKey(new PasswordKey("another", "shrubbery", 8, 1337))
.build();
model.addKeyModelListener(new InertKeyModelListener() {
model.addKeyModelListener(new InertKeysModelListener() {
@Override
public void notifyKeyDeleted(int rowIndex) {
noOfListenerInvocations.incrementAndGet();
Expand Down

0 comments on commit 155482c

Please sign in to comment.