Skip to content

Commit

Permalink
Handle unclassified security context exceptions in validation UI
Browse files Browse the repository at this point in the history
  • Loading branch information
novotnyr committed Feb 11, 2020
1 parent 9589a63 commit 9020ad5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/main/java/com/github/novotnyr/idea/jwt/JwtPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,20 @@ public void onCopyKeyAndValueMenuItemActionPerformed(@SuppressWarnings("unused")
CopyPasteManagerEx.getInstanceEx().setContents(textTransferable);
}

private void onValidateButtonClick(@SuppressWarnings("unused") ActionEvent e) {
JwtValidator jwtValidator = new JwtValidator();

SignatureContext secret = this.secretPanel.getSignatureContext();
jwtValidator.validate(this.jwt, secret);
this.claimsTableModel.setClaimErrors(jwtValidator.getClaimErrors());
if(jwtValidator.hasSignatureError()) {
this.secretPanel.notifySignatureErrors(jwtValidator.getSignatureError());
} else {
this.secretPanel.notifySignatureValid();

private void onValidateButtonClick(@SuppressWarnings("unused") ActionEvent event) {
try {
JwtValidator jwtValidator = new JwtValidator();

SignatureContext secret = this.secretPanel.getSignatureContext();
jwtValidator.validate(this.jwt, secret);
this.claimsTableModel.setClaimErrors(jwtValidator.getClaimErrors());
if(jwtValidator.hasSignatureError()) {
this.secretPanel.notifySignatureErrors(jwtValidator.getSignatureError());
} else {
this.secretPanel.notifySignatureValid();
}
} catch (SignatureContextException e) {
this.secretPanel.notifySecurityContextException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.novotnyr.idea.jwt.ui.secretpanel;

import com.github.novotnyr.idea.jwt.SignatureContext;
import com.github.novotnyr.idea.jwt.SignatureContextException;
import com.github.novotnyr.idea.jwt.validation.SignatureError;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.MessageType;
Expand Down Expand Up @@ -49,6 +50,16 @@ public void notifyEmptySignature() {
Balloon.Position.atRight);
}


public void notifySecurityContextException(SignatureContextException e) {
JBPopupFactory.getInstance()
.createHtmlTextBalloonBuilder("There is an issue with secret, private key or public key: " + e.getMessage(), MessageType.ERROR, null)
.setFadeoutTime(7500)
.createBalloon()
.show(RelativePoint.getNorthWestOf(getBaloonableComponent()),
Balloon.Position.atRight);
}

public JComponent getBaloonableComponent() {
return getRoot();
}
Expand Down

0 comments on commit 9020ad5

Please sign in to comment.