From 5a8c5930033509d66010069bd7cdfc6458c30050 Mon Sep 17 00:00:00 2001 From: Jakob Heher Date: Fri, 30 Sep 2022 13:50:32 +0200 Subject: get rid of now-unnecessary instanceof/upcast checks --- .../asit/pdfover/gui/bku/MobileBKUConnector.java | 96 ++++++++++------------ .../gui/workflow/states/MobileBKUState.java | 16 ++-- 2 files changed, 52 insertions(+), 60 deletions(-) (limited to 'pdf-over-gui/src/main') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java index 33524457..a56b5ce7 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java @@ -78,7 +78,7 @@ public class MobileBKUConnector implements BkuSlConnector { // Check if credentials are available, get them from user if not this.state.checkCredentials(); - if ("cancel".equals(this.state.status.errorMessage)) + if (consumeCancelError()) throw new SignatureException(new IllegalStateException()); // Post credentials @@ -89,10 +89,9 @@ public class MobileBKUConnector implements BkuSlConnector { // handle polling this.state.showOpenAppMessageWithSMSandCancel(); - if (((ATrustStatus) this.state.status).isSMSTan) { - ATrustHandler aHandler = (ATrustHandler) handler; - String response = aHandler.postSMSRequest(); - aHandler.handleCredentialsResponse(response); + if (this.state.status.isSMSTan) { + String response = handler.postSMSRequest(); + handler.handleCredentialsResponse(response); } else if (consumeCancelError()) { throw new SignatureException(new IllegalStateException()); } @@ -121,56 +120,52 @@ public class MobileBKUConnector implements BkuSlConnector { ATrustStatus status = this.state.status; boolean enterTAN = true; String responseData = null; - if (status instanceof ATrustStatus) { - ATrustStatus aStatus = (ATrustStatus) status; - ATrustHandler aHandler = (ATrustHandler) handler; - if (aStatus.qrCodeURL != null) { - this.state.showQR(); - if ("cancel".equals(this.state.status.errorMessage)) - throw new SignatureException(new IllegalStateException()); - if (aStatus.qrCodeURL == null) { - try { - String response = aHandler.postSMSRequest(); - log.trace("Response from mobile BKU: " + response); - handler.handleCredentialsResponse(response); - } catch (Exception ex) { - log.error("Error in PostCredentialsThread", ex); - this.state.threadException = new IllegalStateException(); - throw new SignatureException(new IllegalStateException()); - } - } else { - enterTAN = false; - } - } - if (enterTAN && !aStatus.tanField) { + if (status.qrCodeURL != null) { + this.state.showQR(); + if ("cancel".equals(this.state.status.errorMessage)) + throw new SignatureException(new IllegalStateException()); + if (status.qrCodeURL == null) { try { - - this.state.showFingerPrintInformation(); - if ("cancel".equals(this.state.status.errorMessage)) - throw new SignatureException(new IllegalStateException()); + String response = handler.postSMSRequest(); + log.trace("Response from mobile BKU: " + response); + handler.handleCredentialsResponse(response); } catch (Exception ex) { log.error("Error in PostCredentialsThread", ex); this.state.threadException = new IllegalStateException(); - //this.state.displayError(ex); throw new SignatureException(new IllegalStateException()); } + } else { + enterTAN = false; + } + } + if (enterTAN && !status.tanField) { + try { - if (this.state.getSMSStatus()) { - String response; - try { - response = aHandler.postSMSRequest(); - handler.handleCredentialsResponse(response); - } catch (Exception e) { - log.error("Error in PostCredentialsThread", e); - this.state.threadException = e; - this.state.displayError(e); - throw new SignatureException(e); - } - } - else { - enterTAN = false; + this.state.showFingerPrintInformation(); + if ("cancel".equals(this.state.status.errorMessage)) + throw new SignatureException(new IllegalStateException()); + } catch (Exception ex) { + log.error("Error in PostCredentialsThread", ex); + this.state.threadException = new IllegalStateException(); + //this.state.displayError(ex); + throw new SignatureException(new IllegalStateException()); + } + + if (this.state.getSMSStatus()) { + String response; + try { + response = handler.postSMSRequest(); + handler.handleCredentialsResponse(response); + } catch (Exception e) { + log.error("Error in PostCredentialsThread", e); + this.state.threadException = e; + this.state.displayError(e); + throw new SignatureException(e); } } + else { + enterTAN = false; + } } if (enterTAN) { @@ -203,12 +198,9 @@ public class MobileBKUConnector implements BkuSlConnector { } private boolean consumeCancelError() { - - if (this.state.status instanceof ATrustStatus) { - if ("cancel".equals(this.state.status.errorMessage)) { - this.state.status.errorMessage = null; - return true; - } + if ("cancel".equals(this.state.status.errorMessage)) { + this.state.status.errorMessage = null; + return true; } return false; } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java index 96ba725d..2d443185 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java @@ -208,7 +208,7 @@ public class MobileBKUState extends State { // set possible error message ui.setErrorMessage(mobileStatus.errorMessage); mobileStatus.errorMessage = null; - } else if (mobileStatus instanceof ATrustStatus) { + } else { ui.setErrorMessage(Messages.getString("mobileBKU.aTrustDisclaimer")); } @@ -311,8 +311,8 @@ public class MobileBKUState extends State { * Show QR code */ public void showQR() { - final ATrustStatus status = (ATrustStatus) this.status; - final ATrustHandler handler = (ATrustHandler) this.handler; + final ATrustStatus status = this.status; + final ATrustHandler handler = this.handler; final Timer checkDone = new Timer(); checkDone.scheduleAtFixedRate(new TimerTask() { @@ -383,7 +383,7 @@ public class MobileBKUState extends State { */ public void showOpenAppMessageWithSMSandCancel() throws SignatureException { - final ATrustStatus status = (ATrustStatus) this.status; + final ATrustStatus status = this.status; Display.getDefault().syncExec(() -> { WaitingForAppComposite waitingForAppcomposite = this.getWaitingForAppComposite(); @@ -431,7 +431,7 @@ public class MobileBKUState extends State { } private void undecidedPolling(){ - final ATrustHandler handler = (ATrustHandler) this.handler; + final ATrustHandler handler = this.handler; Thread pollingThread = new Thread(() -> { try { @@ -455,8 +455,8 @@ public class MobileBKUState extends State { * this information is shown */ public void showFingerPrintInformation() { - final ATrustStatus status = (ATrustStatus) this.status; - final ATrustHandler handler = (ATrustHandler) this.handler; + final ATrustStatus status = this.status; + final ATrustHandler handler = this.handler; Timer checkDone = new Timer(); checkDone.scheduleAtFixedRate(new TimerTask() { @@ -545,7 +545,7 @@ public class MobileBKUState extends State { getStateMachine().display( this.getWaitingComposite()); - this.setNextState(new at.asit.pdfover.gui.workflow.states.SigningState(getStateMachine())); + this.setNextState(new SigningState(getStateMachine())); } /* -- cgit v1.2.3