summaryrefslogtreecommitdiff
path: root/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java')
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java281
1 files changed, 143 insertions, 138 deletions
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 823edae8..4a825d17 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
@@ -17,28 +17,26 @@ package at.asit.pdfover.gui.workflow.states;
// Imports
import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import at.asit.pdfover.gui.MainWindow.Buttons;
import at.asit.pdfover.gui.MainWindowBehavior;
+import at.asit.pdfover.gui.bku.MobileBKUConnector;
+import at.asit.pdfover.gui.bku.mobile.ATrustHandler;
+import at.asit.pdfover.gui.bku.mobile.ATrustStatus;
+import at.asit.pdfover.gui.bku.mobile.IAIKHandler;
+import at.asit.pdfover.gui.bku.mobile.IAIKStatus;
+import at.asit.pdfover.gui.bku.mobile.MobileBKUHandler;
+import at.asit.pdfover.gui.bku.mobile.MobileBKUStatus;
import at.asit.pdfover.gui.composites.MobileBKUEnterNumberComposite;
import at.asit.pdfover.gui.composites.MobileBKUEnterTANComposite;
import at.asit.pdfover.gui.composites.WaitingComposite;
-import at.asit.pdfover.gui.controls.ErrorDialog;
import at.asit.pdfover.gui.controls.Dialog.BUTTONS;
+import at.asit.pdfover.gui.controls.ErrorDialog;
import at.asit.pdfover.gui.utils.Messages;
import at.asit.pdfover.gui.workflow.StateMachine;
-import at.asit.pdfover.gui.workflow.states.mobilebku.ATrustHandler;
-import at.asit.pdfover.gui.workflow.states.mobilebku.IAIKHandler;
-import at.asit.pdfover.gui.workflow.states.mobilebku.IAIKStatus;
-import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUCommunicationState;
-import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHandler;
-import at.asit.pdfover.gui.workflow.states.mobilebku.ATrustStatus;
-import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus;
-import at.asit.pdfover.gui.workflow.states.mobilebku.PostCredentialsThread;
-import at.asit.pdfover.gui.workflow.states.mobilebku.PostSLRequestThread;
-import at.asit.pdfover.gui.workflow.states.mobilebku.PostTanThread;
/**
* Logical state for performing the BKU Request to the A-Trust Mobile BKU
@@ -73,8 +71,6 @@ public class MobileBKUState extends State {
Exception threadException = null;
- MobileBKUCommunicationState communicationState = MobileBKUCommunicationState.POST_REQUEST;
-
MobileBKUStatus status = null;
MobileBKUHandler handler = null;
@@ -85,7 +81,7 @@ public class MobileBKUState extends State {
WaitingComposite waitingComposite = null;
- private WaitingComposite getWaitingComposite() {
+ WaitingComposite getWaitingComposite() {
if (this.waitingComposite == null) {
this.waitingComposite = getStateMachine().getGUIProvider()
.createComposite(WaitingComposite.class, SWT.RESIZE, this);
@@ -94,7 +90,7 @@ public class MobileBKUState extends State {
return this.waitingComposite;
}
- private MobileBKUEnterTANComposite getMobileBKUEnterTANComposite() {
+ MobileBKUEnterTANComposite getMobileBKUEnterTANComposite() {
if (this.mobileBKUEnterTANComposite == null) {
this.mobileBKUEnterTANComposite = getStateMachine()
.getGUIProvider().createComposite(
@@ -104,7 +100,7 @@ public class MobileBKUState extends State {
return this.mobileBKUEnterTANComposite;
}
- private MobileBKUEnterNumberComposite getMobileBKUEnterNumberComposite() {
+ MobileBKUEnterNumberComposite getMobileBKUEnterNumberComposite() {
if (this.mobileBKUEnterNumberComposite == null) {
this.mobileBKUEnterNumberComposite = getStateMachine()
.getGUIProvider().createComposite(
@@ -140,22 +136,6 @@ public class MobileBKUState extends State {
}
/**
- * @return the communicationState
- */
- public MobileBKUCommunicationState getCommunicationState() {
- return this.communicationState;
- }
-
- /**
- * @param communicationState
- * the communicationState to set
- */
- public void setCommunicationState(
- MobileBKUCommunicationState communicationState) {
- this.communicationState = communicationState;
- }
-
- /**
* @return the signingState
*/
public at.asit.pdfover.signator.SigningState getSigningState() {
@@ -170,93 +150,63 @@ public class MobileBKUState extends State {
this.threadException = threadException;
}
- /*
- * (non-Javadoc)
+ /**
+ * Display an error message
*
- * @see
- * at.asit.pdfover.gui.workflow.WorkflowState#update(at.asit.pdfover.gui
- * .workflow.Workflow)
+ * @param e
+ * the exception
*/
- @Override
- public void run() {
-
- this.signingState = getStateMachine().getStatus().getSigningState();
+ public void displayError(Exception e) {
+ String message = Messages.getString("error.Unexpected"); //$NON-NLS-1$
+ log.error(message, e);
+ String errormsg = e.getLocalizedMessage();
+ if (errormsg != null && !errormsg.isEmpty())
+ message += ": " + errormsg; //$NON-NLS-1$
+ displayError(message);
+ }
- MobileBKUStatus mobileStatus = this.getStatus();
+ /**
+ * Display an error message
+ *
+ * @param message
+ * the error message
+ */
+ public void displayError(final String message) {
+ log.error(message);
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ ErrorDialog error = new ErrorDialog(getStateMachine().getGUIProvider()
+ .getMainShell(), message, BUTTONS.OK);
+ error.open();
+ }
+ });
+ }
- if (this.threadException != null) {
- String message = Messages.getString("error.Unexpected"); //$NON-NLS-1$
- log.error(message, this.threadException);
- String errormsg = this.threadException.getLocalizedMessage();
- if (errormsg != null && !errormsg.isEmpty())
- message += ": " + errormsg; //$NON-NLS-1$
- ErrorDialog error = new ErrorDialog(
- getStateMachine().getGUIProvider().getMainShell(),
- message, BUTTONS.OK);
- // error.setException(this.threadException);
- // this.setNextState(error);
- error.open();
- getStateMachine().exit();
+ /**
+ * Make sure phone number and password are set in the MobileBKUStatus
+ */
+ public void checkCredentials() {
+ final MobileBKUStatus mobileStatus = this.getStatus();
+ // check if we have everything we need!
+ if (mobileStatus.getPhoneNumber() != null && !mobileStatus.getPhoneNumber().isEmpty() &&
+ mobileStatus.getMobilePassword() != null && !mobileStatus.getMobilePassword().isEmpty())
return;
- }
- switch (this.communicationState) {
- case POST_REQUEST:
- getStateMachine().getGUIProvider().display(
- this.getWaitingComposite());
- Thread postSLRequestThread = new Thread(
- new PostSLRequestThread(this));
- postSLRequestThread.start();
- break;
-
- case POST_NUMBER:
- // Check if number and password is set ...
- // if not show UI
- // else start thread
-
- // check if we have everything we need!
- if (mobileStatus.getPhoneNumber() != null
- && !mobileStatus.getPhoneNumber().isEmpty()
- && mobileStatus.getMobilePassword() != null
- && !mobileStatus.getMobilePassword().isEmpty()) {
- // post to bku
- Thread postCredentialsThread = new Thread(
- new PostCredentialsThread(this));
- postCredentialsThread.start();
- // resets password if incorrect to null
- } else {
-
- MobileBKUEnterNumberComposite ui = this
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ MobileBKUEnterNumberComposite ui = MobileBKUState.this
.getMobileBKUEnterNumberComposite();
-
- if (ui.isUserAck()) {
- // user hit ok
-
- ui.setUserAck(false);
-
- // get number and password from UI
- mobileStatus.setPhoneNumber(ui.getMobileNumber());
- mobileStatus.setMobilePassword(ui.getMobilePassword());
-
- // show waiting composite
- getStateMachine().getGUIProvider().display(
- this.getWaitingComposite());
-
- // post to BKU
- Thread postCredentialsThread = new Thread(
- new PostCredentialsThread(this));
- postCredentialsThread.start();
-
- } else {
+
+ if (!ui.isUserAck()) {
// We need number and password => show UI!
-
if (mobileStatus.getErrorMessage() != null
&& !mobileStatus.getErrorMessage().isEmpty()) {
// set possible error message
ui.setErrorMessage(mobileStatus.getErrorMessage());
mobileStatus.setErrorMessage(null);
}
-
if (ui.getMobileNumber() == null
|| ui.getMobileNumber().isEmpty()) {
@@ -271,17 +221,64 @@ public class MobileBKUState extends State {
}
ui.enableButton();
getStateMachine().getGUIProvider().display(ui);
+
+ Display display = getStateMachine().getGUIProvider().getMainShell().getDisplay();
+ while (!ui.isUserAck()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
}
- }
- break;
- case POST_TAN:
- // Get TAN from UI
+ // user hit ok
+ ui.setUserAck(false);
- MobileBKUEnterTANComposite tan = this
- .getMobileBKUEnterTANComposite();
+ // get number and password from UI
+ mobileStatus.setPhoneNumber(ui.getMobileNumber());
+ mobileStatus.setMobilePassword(ui.getMobilePassword());
+
+ // show waiting composite
+ getStateMachine().getGUIProvider().display(
+ MobileBKUState.this.getWaitingComposite());
+ }
+ });
+ }
+
+ /**
+ * Make sure TAN is set in the MobileBKUStatus
+ */
+ public void checkTAN() {
+ final MobileBKUStatus mobileStatus = this.getStatus();
+
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ MobileBKUEnterTANComposite tan = MobileBKUState.this
+ .getMobileBKUEnterTANComposite();
+
+ if (!tan.isUserAck()) {
+ // we need the TAN
+ tan.setRefVal(mobileStatus.getRefVal());
+ tan.setSignatureData(mobileStatus.getSignatureDataURL());
+ tan.setErrorMessage(mobileStatus.getErrorMessage());
+ if (mobileStatus.getTanTries() < mobileStatus.getMaxTanTries()
+ && mobileStatus.getTanTries() > 0) {
+ // show warning message x tries left!
+ // overrides error message
+
+ tan.setTries(mobileStatus.getTanTries());
+ }
+ tan.enableButton();
+ getStateMachine().getGUIProvider().display(tan);
+
+ Display display = getStateMachine().getGUIProvider().getMainShell().getDisplay();
+ while (!tan.isUserAck()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ }
- if (tan.isUserAck()) {
// user hit ok!
tan.setUserAck(false);
@@ -289,36 +286,44 @@ public class MobileBKUState extends State {
// show waiting composite
getStateMachine().getGUIProvider().display(
- this.getWaitingComposite());
-
- // post to BKU!
- Thread postTanThread = new Thread(new PostTanThread(this));
- postTanThread.start();
-
- } else {
- tan.setRefVal(mobileStatus.getRefVal());
- tan.setSignatureData(mobileStatus.getSignatureDataURL());
- tan.setErrorMessage(mobileStatus.getErrorMessage());
- if (mobileStatus.getTanTries() < mobileStatus.getMaxTanTries()
- && mobileStatus.getTanTries() > 0) {
- // show warning message x tries left!
- // overrides error message
-
- tan.setTries(mobileStatus.getTanTries());
- }
- tan.enableButton();
- getStateMachine().getGUIProvider().display(tan);
+ MobileBKUState.this.getWaitingComposite());
}
- break;
+ });
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * at.asit.pdfover.gui.workflow.WorkflowState#update(at.asit.pdfover.gui
+ * .workflow.Workflow)
+ */
+ @Override
+ public void run() {
+ this.signingState = getStateMachine().getStatus().getSigningState();
- case FINAL:
- this.setNextState(new SigningState(getStateMachine()));
- break;
+ this.signingState.setBKUConnector(new MobileBKUConnector(this));
- case CANCEL:
- this.setNextState(new BKUSelectionState(getStateMachine()));
- break;
+ if (this.threadException != null) {
+ String message = Messages.getString("error.Unexpected"); //$NON-NLS-1$
+ log.error(message, this.threadException);
+ String errormsg = this.threadException.getLocalizedMessage();
+ if (errormsg != null && !errormsg.isEmpty())
+ message += ": " + errormsg; //$NON-NLS-1$
+ ErrorDialog error = new ErrorDialog(
+ getStateMachine().getGUIProvider().getMainShell(),
+ message, BUTTONS.OK);
+ // error.setException(this.threadException);
+ // this.setNextState(error);
+ error.open();
+ getStateMachine().exit();
+ return;
}
+
+ getStateMachine().getGUIProvider().display(
+ this.getWaitingComposite());
+
+ this.setNextState(new SigningState(getStateMachine()));
}
/*