summaryrefslogtreecommitdiff
path: root/pdf-over-gui/src
diff options
context:
space:
mode:
authorJakob Heher <jakob.heher@iaik.tugraz.at>2022-07-06 10:35:23 +0200
committerJakob Heher <jakob.heher@iaik.tugraz.at>2022-07-06 10:35:23 +0200
commitc598f60380077e4e156f3ad4424eb42ec8aa0f28 (patch)
treee3b6026f20f150a3300030523b995171813c5217 /pdf-over-gui/src
parent1d5af6e11631484dc582796d823239d2f46ce6b3 (diff)
downloadpdf-over-c598f60380077e4e156f3ad4424eb42ec8aa0f28.tar.gz
pdf-over-c598f60380077e4e156f3ad4424eb42ec8aa0f28.tar.bz2
pdf-over-c598f60380077e4e156f3ad4424eb42ec8aa0f28.zip
YAGNI cleanup #1
Diffstat (limited to 'pdf-over-gui/src')
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java40
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustHandler.java6
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustStatus.java4
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/IAIKHandler.java2
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHandler.java16
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java112
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java2
7 files changed, 68 insertions, 114 deletions
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 a3b70d00..4ea96f04 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
@@ -58,7 +58,7 @@ public class MobileBKUConnector implements BkuSlConnector {
PdfAs4SigningState signingState = (PdfAs4SigningState) this.state.getSigningState();
signingState.setSignatureRequest(request);
- MobileBKUHandler handler = this.state.getHandler();
+ MobileBKUHandler handler = this.state.handler;
do {
// Post SL Request
@@ -80,8 +80,8 @@ public class MobileBKUConnector implements BkuSlConnector {
// Check if credentials are available, get them from user if not
this.state.checkCredentials();
- if (this.state.getStatus().getErrorMessage() != null &&
- this.state.getStatus().getErrorMessage().equals("cancel")) //$NON-NLS-1$
+ if (this.state.status.getErrorMessage() != null &&
+ this.state.status.getErrorMessage().equals("cancel")) //$NON-NLS-1$
throw new SignatureException(new IllegalStateException());
// Post credentials
@@ -92,7 +92,7 @@ public class MobileBKUConnector implements BkuSlConnector {
// handle polling
this.state.showOpenAppMessageWithSMSandCancel();
- if (((ATrustStatus) this.state.getStatus()).isSmsTan()) {
+ if (((ATrustStatus) this.state.status).isSmsTan()) {
ATrustHandler aHandler = (ATrustHandler) handler;
String response = aHandler.postSMSRequest();
aHandler.handleCredentialsResponse(response);
@@ -111,7 +111,7 @@ public class MobileBKUConnector implements BkuSlConnector {
this.state.setThreadException(new IllegalStateException());
throw new SignatureException(new IllegalStateException());
}
- } while(this.state.getStatus().getErrorMessage() != null);
+ } while(this.state.status.getErrorMessage() != null);
// Check if response is already available
if (signingState.hasSignatureResponse()) {
@@ -121,18 +121,18 @@ public class MobileBKUConnector implements BkuSlConnector {
}
do {
- MobileBKUStatus status = this.state.getStatus();
+ MobileBKUStatus status = this.state.status;
boolean enterTAN = true;
String responseData = null;
if (status instanceof ATrustStatus) {
ATrustStatus aStatus = (ATrustStatus) status;
ATrustHandler aHandler = (ATrustHandler) handler;
- if (aStatus.getQRCode() != null) {
+ if (aStatus.getQRCodeURL() != null) {
this.state.showQR();
- if (this.state.getStatus().getErrorMessage() != null &&
- this.state.getStatus().getErrorMessage().equals("cancel")) //$NON-NLS-1$
+ if (this.state.status.getErrorMessage() != null &&
+ this.state.status.getErrorMessage().equals("cancel")) //$NON-NLS-1$
throw new SignatureException(new IllegalStateException());
- if (aStatus.getQRCode() == null) {
+ if (aStatus.getQRCodeURL() == null) {
try {
String response = aHandler.postSMSRequest();
log.trace("Response from mobile BKU: " + response); //$NON-NLS-1$
@@ -150,8 +150,8 @@ public class MobileBKUConnector implements BkuSlConnector {
try {
this.state.showFingerPrintInformation();
- if (this.state.getStatus().getErrorMessage() != null &&
- this.state.getStatus().getErrorMessage().equals("cancel")) //$NON-NLS-1$
+ if (this.state.status.getErrorMessage() != null &&
+ this.state.status.getErrorMessage().equals("cancel")) //$NON-NLS-1$
throw new SignatureException(new IllegalStateException());
} catch (Exception ex) {
log.error("Error in PostCredentialsThread", ex); //$NON-NLS-1$
@@ -183,8 +183,8 @@ public class MobileBKUConnector implements BkuSlConnector {
this.state.checkTAN();
- if (this.state.getStatus().getErrorMessage() != null &&
- this.state.getStatus().getErrorMessage().equals("cancel")) //$NON-NLS-1$
+ if (this.state.status.getErrorMessage() != null &&
+ this.state.status.getErrorMessage().equals("cancel")) //$NON-NLS-1$
throw new SignatureException(new IllegalStateException());
// Post TAN
@@ -201,21 +201,21 @@ public class MobileBKUConnector implements BkuSlConnector {
throw new SignatureException(ex);
}
}
- } while (this.state.getStatus().getErrorMessage() != null);
- if (this.state.getStatus().getTanTries() == -1)
+ } while (this.state.status.getErrorMessage() != null);
+ if (this.state.status.getTanTries() == -1)
throw new SignatureException(new IllegalStateException());
- } while (this.state.getStatus().getTanTries() == -2);
+ } while (this.state.status.getTanTries() == -2);
return signingState.getSignatureResponse();
}
private boolean handleErrorMessage() {
- if (this.state.getStatus() instanceof ATrustStatus) {
- ATrustStatus aStatus = (ATrustStatus)this.state.getStatus() ;
+ if (this.state.status instanceof ATrustStatus) {
+ ATrustStatus aStatus = (ATrustStatus)this.state.status ;
if (aStatus.getErrorMessage() != null &&
aStatus.getErrorMessage().equals("cancel")) { //$NON-NLS-1$
- ((ATrustStatus)this.state.getStatus()).setErrorMessage(null);
+ ((ATrustStatus)this.state.status).setErrorMessage(null);
return true;
}
}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustHandler.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustHandler.java
index 05168d61..d5353b3e 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustHandler.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustHandler.java
@@ -247,7 +247,7 @@ public class ATrustHandler extends MobileBKUHandler {
try {
qrCode = MobileBKUHelper.extractValueFromTagWithParam(responseData, "img", "class", "qrcode", "src"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
log.debug("QR Code found: " + qrCode); //$NON-NLS-1$
- status.setQRCode(qrCode);
+ status.setQRCodeURL(qrCode);
} catch (Exception e) {
log.debug("No QR Code found"); //$NON-NLS-1$
}
@@ -406,7 +406,7 @@ public class ATrustHandler extends MobileBKUHandler {
HttpClient client = MobileBKUHelper.getHttpClient(getStatus());
GetMethod get = new GetMethod(status.getBaseURL() + "/" + //$NON-NLS-1$
- status.getQRCode());
+ status.getQRCodeURL());
try {
log.debug("Getting " + get.getURI()); //$NON-NLS-1$
@@ -478,7 +478,7 @@ public class ATrustHandler extends MobileBKUHandler {
@Override
public ATrustStatus getStatus() {
- return (ATrustStatus) getState().getStatus();
+ return (ATrustStatus) state.status;
}
/* (non-Javadoc)
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustStatus.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustStatus.java
index fe91dfa9..9994d522 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustStatus.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustStatus.java
@@ -112,7 +112,7 @@ public class ATrustStatus extends AbstractMobileBKUStatusImpl {
/**
* @return the QR code
*/
- public String getQRCode() {
+ public String getQRCodeURL() {
return this.qrcode;
}
@@ -120,7 +120,7 @@ public class ATrustStatus extends AbstractMobileBKUStatusImpl {
* @param qrcode
* the QR code to set
*/
- public void setQRCode(String qrcode) {
+ public void setQRCodeURL(String qrcode) {
this.qrcode = qrcode;
}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/IAIKHandler.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/IAIKHandler.java
index 1d0ec579..ec1c7c66 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/IAIKHandler.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/IAIKHandler.java
@@ -336,7 +336,7 @@ public class IAIKHandler extends MobileBKUHandler {
@Override
public IAIKStatus getStatus() {
- return (IAIKStatus) getState().getStatus();
+ return (IAIKStatus) state.status;
}
private String getRedirect(HttpClient client, String redirectURL) throws HttpException, IOException {
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHandler.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHandler.java
index 4c09c02d..1ada0337 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHandler.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHandler.java
@@ -51,7 +51,7 @@ public abstract class MobileBKUHandler {
static final Logger log = LoggerFactory
.getLogger(MobileBKUHandler.class);
- private MobileBKUState state;
+ public final MobileBKUState state;
/**
* Constructor
@@ -99,7 +99,7 @@ public abstract class MobileBKUHandler {
}
log.trace("SL Request: " + sl_request); //$NON-NLS-1$
- getState().getStatus().setBaseURL(
+ state.status.setBaseURL(
MobileBKUHelper.stripQueryString(mobileBKUUrl));
return executePost(client, post);
@@ -142,19 +142,11 @@ public abstract class MobileBKUHandler {
public abstract void handleTANResponse(String responseData) throws Exception;
/**
- * Get the MobileBKUState
- * @return the MobileBKUState
- */
- protected MobileBKUState getState() {
- return this.state;
- }
-
- /**
* Get the MobileBKUStatus
* @return the MobileBKUStatus
*/
protected MobileBKUStatus getStatus() {
- return this.state.getStatus();
+ return this.state.status;
}
/**
@@ -162,7 +154,7 @@ public abstract class MobileBKUHandler {
* @return the SigningState
*/
protected SigningState getSigningState() {
- return getState().getSigningState();
+ return state.getSigningState();
}
/**
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 2c5fbd48..247a8c3e 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
@@ -53,9 +53,15 @@ import at.asit.pdfover.signator.SigningState;
* Logical state for performing the BKU Request to the A-Trust Mobile BKU
*/
public class MobileBKUState extends State {
- /**
- * @param stateMachine
- */
+ static final Logger log = LoggerFactory.getLogger(MobileBKUState.class);
+
+ SigningState signingState;
+
+ Exception threadException = null;
+
+ public final MobileBKUStatus status;
+ public final MobileBKUHandler handler;
+
public MobileBKUState(StateMachine stateMachine) {
super(stateMachine);
ConfigProvider provider = stateMachine.getConfigProvider();
@@ -72,37 +78,15 @@ public class MobileBKUState extends State {
this.handler = new IAIKHandler(this,
stateMachine.getGUIProvider().getMainShell());
break;
+
+ default:
+ throw new RuntimeException("Unexpected mobileBKUType");
}
-
}
- /**
- * SLF4J Logger instance
- **/
- static final Logger log = LoggerFactory
- .getLogger(MobileBKUState.class);
-
- SigningState signingState;
-
- Exception threadException = null;
-
- MobileBKUStatus status = null;
-
- MobileBKUHandler handler = null;
-
- MobileBKUEnterNumberComposite mobileBKUEnterNumberComposite = null;
-
MobileBKUEnterTANComposite mobileBKUEnterTANComposite = null;
-
- MobileBKUQRComposite mobileBKUQRComposite = null;
-
- MobileBKUFingerprintComposite mobileBKUFingerprintComposite = null;
-
- WaitingComposite waitingComposite = null;
-
- WaitingForAppComposite waitingForAppComposite = null;
-
+ WaitingForAppComposite waitingForAppComposite = null;
WaitingForAppComposite getWaitingForAppComposite() {
if (this.waitingForAppComposite == null) {
this.waitingForAppComposite = getStateMachine().getGUIProvider()
@@ -112,6 +96,7 @@ public class MobileBKUState extends State {
return this.waitingForAppComposite;
}
+ WaitingComposite waitingComposite = null;
WaitingComposite getWaitingComposite() {
if (this.waitingComposite == null) {
this.waitingComposite = getStateMachine().getGUIProvider()
@@ -123,65 +108,42 @@ public class MobileBKUState extends State {
MobileBKUEnterTANComposite getMobileBKUEnterTANComposite() {
if (this.mobileBKUEnterTANComposite == null) {
- this.mobileBKUEnterTANComposite = getStateMachine()
- .getGUIProvider().createComposite(
- MobileBKUEnterTANComposite.class, SWT.RESIZE, this);
+ this.mobileBKUEnterTANComposite = getStateMachine().getGUIProvider()
+ .createComposite(MobileBKUEnterTANComposite.class, SWT.RESIZE, this);
}
return this.mobileBKUEnterTANComposite;
}
+ MobileBKUQRComposite mobileBKUQRComposite = null;
MobileBKUQRComposite getMobileBKUQRComposite() {
if (this.mobileBKUQRComposite == null) {
- this.mobileBKUQRComposite = getStateMachine()
- .getGUIProvider().createComposite(
- MobileBKUQRComposite.class, SWT.RESIZE, this);
+ this.mobileBKUQRComposite = getStateMachine().getGUIProvider()
+ .createComposite(MobileBKUQRComposite.class, SWT.RESIZE, this);
}
return this.mobileBKUQRComposite;
}
+ MobileBKUEnterNumberComposite mobileBKUEnterNumberComposite = null;
MobileBKUEnterNumberComposite getMobileBKUEnterNumberComposite() {
if (this.mobileBKUEnterNumberComposite == null) {
- this.mobileBKUEnterNumberComposite = getStateMachine()
- .getGUIProvider().createComposite(
- MobileBKUEnterNumberComposite.class, SWT.RESIZE,
- this);
+ this.mobileBKUEnterNumberComposite = getStateMachine().getGUIProvider()
+ .createComposite(MobileBKUEnterNumberComposite.class, SWT.RESIZE, this);
}
return this.mobileBKUEnterNumberComposite;
}
-
-
-
+ MobileBKUFingerprintComposite mobileBKUFingerprintComposite = null;
MobileBKUFingerprintComposite getMobileBKUFingerprintComposite() {
if (this.mobileBKUFingerprintComposite == null) {
- this.mobileBKUFingerprintComposite = getStateMachine()
- .getGUIProvider().createComposite(
- MobileBKUFingerprintComposite.class, SWT.RESIZE,
- this);
+ this.mobileBKUFingerprintComposite = getStateMachine().getGUIProvider()
+ .createComposite(MobileBKUFingerprintComposite.class, SWT.RESIZE, this);
}
return this.mobileBKUFingerprintComposite;
}
-
-
- /**
- * Get the MobileBKUStatus
- * @return the MobileBKUStatus
- */
- public MobileBKUStatus getStatus() {
- return this.status;
- }
-
- /**
- * Get the MobileBKUHandler
- * @return the MobileBKUHandler
- */
- public MobileBKUHandler getHandler() {
- return this.handler;
- }
/**
* Get the mobile BKU URL
@@ -243,7 +205,7 @@ public class MobileBKUState extends State {
* Make sure phone number and password are set in the MobileBKUStatus
*/
public void checkCredentials() {
- final MobileBKUStatus mobileStatus = this.getStatus();
+ final MobileBKUStatus mobileStatus = this.status;
// check if we have everything we need!
if (mobileStatus.getPhoneNumber() != null && !mobileStatus.getPhoneNumber().isEmpty() &&
mobileStatus.getMobilePassword() != null && !mobileStatus.getMobilePassword().isEmpty())
@@ -312,7 +274,7 @@ public class MobileBKUState extends State {
* Make sure TAN is set in the MobileBKUStatus
*/
public void checkTAN() {
- final MobileBKUStatus mobileStatus = this.getStatus();
+ final MobileBKUStatus mobileStatus = this.status;
Display.getDefault().syncExec(new Runnable() {
@Override
@@ -365,8 +327,8 @@ public class MobileBKUState extends State {
* Show QR code
*/
public void showQR() {
- final ATrustStatus status = (ATrustStatus) this.getStatus();
- final ATrustHandler handler = (ATrustHandler) this.getHandler();
+ final ATrustStatus status = (ATrustStatus) this.status;
+ final ATrustHandler handler = (ATrustHandler) this.handler;
final Timer checkDone = new Timer();
checkDone.scheduleAtFixedRate(new TimerTask() {
@@ -422,7 +384,7 @@ public class MobileBKUState extends State {
if (qr.isUserSMS()) {
qr.setUserSMS(false);
- status.setQRCode(null);
+ status.setQRCodeURL(null);
}
if (qr.isDone())
@@ -453,7 +415,7 @@ public class MobileBKUState extends State {
*/
public void showOpenAppMessageWithSMSandCancel() throws SignatureException {
- final ATrustStatus status = (ATrustStatus) this.getStatus();
+ final ATrustStatus status = (ATrustStatus) this.status;
Display.getDefault().syncExec(() -> {
WaitingForAppComposite waitingForAppcomposite = MobileBKUState.this.getWaitingForAppComposite();
@@ -477,7 +439,7 @@ public class MobileBKUState extends State {
}
if (waitingForAppcomposite.getUserSMS()) {
- status.setQRCode(null);
+ status.setQRCodeURL(null);
waitingForAppcomposite.setUserSMS(false);
status.setErrorMessage("sms"); //$NON-NLS-1$
status.setSmsTan(true);
@@ -492,7 +454,7 @@ public class MobileBKUState extends State {
if (!(System.nanoTime() < timeoutTime)) {
log.warn("The undecided polling got a timeout");
- status.setQRCode(null);
+ status.setQRCodeURL(null);
status.setErrorMessage("Polling Timeout");
@@ -501,7 +463,7 @@ public class MobileBKUState extends State {
}
private void undecidedPolling(){
- final ATrustHandler handler = (ATrustHandler) this.getHandler();
+ final ATrustHandler handler = (ATrustHandler) this.handler;
Thread pollingThread = new Thread(() -> {
try {
@@ -525,8 +487,8 @@ public class MobileBKUState extends State {
* this information is shown
*/
public void showFingerPrintInformation() {
- final ATrustStatus status = (ATrustStatus) this.getStatus();
- final ATrustHandler handler = (ATrustHandler) this.getHandler();
+ final ATrustStatus status = (ATrustStatus) this.status;
+ final ATrustHandler handler = (ATrustHandler) this.handler;
Timer checkDone = new Timer();
checkDone.scheduleAtFixedRate(new TimerTask() {
@@ -573,7 +535,7 @@ public class MobileBKUState extends State {
if (fingerprintComposite.isUserSMS()) {
// fingerprintComposite.setUserSMS(false);
- status.setQRCode(null);
+ status.setQRCodeURL(null);
}
if (fingerprintComposite.isDone())
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java
index b95b042d..bc6793ec 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/SigningState.java
@@ -97,7 +97,7 @@ public class SigningState extends State {
// this is a bit of a hack...
if (status.getPreviousState() instanceof MobileBKUState)
{
- String mobileBkuError = ((MobileBKUState)status.getPreviousState()).getStatus().getErrorMessage();
+ String mobileBkuError = ((MobileBKUState)status.getPreviousState()).status.getErrorMessage();
if ((mobileBkuError != null) && mobileBkuError.equals("cancel"))
this.threadException = new SignatureException(new IllegalStateException());
}