summaryrefslogtreecommitdiff
path: root/pdf-over-gui
diff options
context:
space:
mode:
authorTobias Kellner <tobias.kellner@iaik.tugraz.at>2015-02-23 15:29:35 +0100
committerTobias Kellner <tobias.kellner@iaik.tugraz.at>2015-02-23 15:29:35 +0100
commit7b6860087f50b7576c31f7aa50714d3fa7a9b228 (patch)
treec2347315c5a0e4e6565f9020d3e1d7d38d94abfe /pdf-over-gui
parent72cb98966c0d631ed4741bf071c621fd36f33fd6 (diff)
downloadpdf-over-7b6860087f50b7576c31f7aa50714d3fa7a9b228.tar.gz
pdf-over-7b6860087f50b7576c31f7aa50714d3fa7a9b228.tar.bz2
pdf-over-7b6860087f50b7576c31f7aa50714d3fa7a9b228.zip
BASE64 request handling
Diffstat (limited to 'pdf-over-gui')
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/LocalBKUConnector.java61
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustHandler.java2
-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.java10
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java30
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java10
6 files changed, 51 insertions, 64 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/LocalBKUConnector.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/LocalBKUConnector.java
index f862455c..eb1b57d6 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/LocalBKUConnector.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/LocalBKUConnector.java
@@ -47,9 +47,6 @@ public class LocalBKUConnector implements BkuSlConnector {
private static final Logger log = LoggerFactory
.getLogger(LocalBKUConnector.class);
- /** Whether to use Base64 or FileUpload Request */
- private boolean useBase64Request = false;
-
/**
* HTTP Response server HEADER
*/
@@ -65,12 +62,6 @@ public class LocalBKUConnector implements BkuSlConnector {
*/
public final static String BKU_RESPONSE_HEADER_SIGNATURE_LAYOUT = "SignatureLayout"; //$NON-NLS-1$
- /**
- * Null-Operation SL-Request
- */
- private final static String NULL_OPERATION_REQUEST = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + //$NON-NLS-1$
- "<sl:NullOperationRequest xmlns:sl=\"http://www.buergerkarte.at/namespaces/securitylayer/1.2#\"/>"; //$NON-NLS-1$
-
/* (non-Javadoc)
* @see at.asit.pdfover.signator.BkuSlConnector#handleSLRequest(java.lang.String)
*/
@@ -78,54 +69,36 @@ public class LocalBKUConnector implements BkuSlConnector {
public SLResponse handleSLRequest(SLRequest request) throws SignatureException {
try {
HttpClient client = BKUHelper.getHttpClient();
-
PostMethod method = new PostMethod(Constants.LOCAL_BKU_URL);
- String sl_request = NULL_OPERATION_REQUEST;
- method.addParameter("XMLRequest", sl_request); //$NON-NLS-1$
- int returnCode = client.executeMethod(method);
-
- String userAgent = getResponseHeader(method, BKU_RESPONSE_HEADER_USERAGENT);
- String server = getResponseHeader(method, BKU_RESPONSE_HEADER_SERVER);
- if (server != null && server.contains("trustDeskbasic")) //$NON-NLS-1$
- this.useBase64Request = true; // TDB doesn't support MultiPart requests
-
- method = new PostMethod(Constants.LOCAL_BKU_URL);
-
- if (request.getSignatureData() != null) {
- if (this.useBase64Request)
- {
- sl_request = request.getBase64Request();
- method.addParameter("XMLRequest", sl_request); //$NON-NLS-1$
- } else {
- sl_request = request.getFileUploadRequest();
- StringPart xmlpart = new StringPart(
- "XMLRequest", sl_request, "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
-
- FilePart filepart = new FilePart("fileupload", //$NON-NLS-1$
- new FileUploadSource(request.getSignatureData()));
-
- Part[] parts = { xmlpart, filepart };
-
- method.setRequestEntity(new MultipartRequestEntity(parts, method
- .getParams()));
- }
+ String sl_request = request.getRequest();
+ if (request.getSignatureData() == null) {
+ method.addParameter("XMLRequest", sl_request); //$NON-NLS-1$
} else {
- method.addParameter("XMLRequest", request.getRequest()); //$NON-NLS-1$
+ StringPart xmlpart = new StringPart(
+ "XMLRequest", sl_request, "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ FilePart filepart = new FilePart("fileupload", //$NON-NLS-1$
+ new FileUploadSource(request.getSignatureData()));
+
+ Part[] parts = { xmlpart, filepart };
+
+ method.setRequestEntity(new MultipartRequestEntity(parts, method
+ .getParams()));
}
- log.debug("SL REQUEST: " + sl_request); //$NON-NLS-1$
+ log.trace("SL REQUEST: " + sl_request); //$NON-NLS-1$
- returnCode = client.executeMethod(method);
+ int returnCode = client.executeMethod(method);
if (returnCode != HttpStatus.SC_OK) {
throw new HttpException(
method.getResponseBodyAsString());
}
- server = getResponseHeader(method, BKU_RESPONSE_HEADER_SERVER);
+ String server = getResponseHeader(method, BKU_RESPONSE_HEADER_SERVER);
if (server == null)
server = ""; //$NON-NLS-1$
- userAgent = getResponseHeader(method, BKU_RESPONSE_HEADER_USERAGENT);
+ String userAgent = getResponseHeader(method, BKU_RESPONSE_HEADER_USERAGENT);
if (userAgent == null)
userAgent = ""; //$NON-NLS-1$
String signatureLayout = getResponseHeader(method, BKU_RESPONSE_HEADER_SIGNATURE_LAYOUT);
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 7112bd94..12eff95b 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
@@ -239,7 +239,7 @@ public class ATrustHandler extends MobileBKUHandler {
* @see at.asit.pdfover.gui.bku.mobile.MobileBKUHandler#useBase64Request()
*/
@Override
- protected boolean useBase64Request() {
+ public boolean useBase64Request() {
return false;
}
}
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 04338f8b..0904f045 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
@@ -306,7 +306,7 @@ public class IAIKHandler extends MobileBKUHandler {
* @see at.asit.pdfover.gui.bku.mobile.MobileBKUHandler#useBase64Request()
*/
@Override
- protected boolean useBase64Request() {
+ public boolean useBase64Request() {
return false;
}
}
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 4644002e..429000f1 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
@@ -75,17 +75,17 @@ public abstract class MobileBKUHandler {
PostMethod post = new PostMethod(mobileBKUUrl);
String sl_request;
if (request.getSignatureData() != null) {
+ sl_request = request.getRequest();
if (useBase64Request())
{
- sl_request = request.getBase64Request();
post.addParameter("XMLRequest", sl_request); //$NON-NLS-1$
} else {
- sl_request = request.getFileUploadRequest();
StringPart xmlpart = new StringPart(
"XMLRequest", sl_request, "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
- FilePart filepart = new FilePart("fileupload", //$NON-NLS-1$
- new FileUploadSource(request.getSignatureData()));
+ FilePart filepart = new FilePart("fileupload", //$NON-NLS-1$
+ new FileUploadSource(request.getSignatureData()),
+ "application/pdf", "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
Part[] parts = { xmlpart, filepart };
@@ -168,7 +168,7 @@ public abstract class MobileBKUHandler {
* Whether to use a Base64 request
* @return true if base64 request shall be used
*/
- protected abstract boolean useBase64Request();
+ public abstract boolean useBase64Request();
/**
* Execute a post to the mobile BKU, following redirects
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java
index 3962d836..dd47fe9d 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java
@@ -25,8 +25,8 @@ import org.eclipse.swt.SWT;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import at.asit.pdfover.gui.MainWindow.Buttons;
import at.asit.pdfover.gui.Constants;
+import at.asit.pdfover.gui.MainWindow.Buttons;
import at.asit.pdfover.gui.MainWindowBehavior;
import at.asit.pdfover.gui.bku.BKUHelper;
import at.asit.pdfover.gui.bku.LocalBKUConnector;
@@ -36,6 +36,7 @@ import at.asit.pdfover.gui.utils.Messages;
import at.asit.pdfover.gui.workflow.StateMachine;
import at.asit.pdfover.gui.workflow.Status;
import at.asit.pdfover.signator.SLResponse;
+import at.asit.pdfover.signator.SigningState;
/**
* Logical state for performing the BKU Request to a local BKU
@@ -62,10 +63,11 @@ public class LocalBKUState extends State {
*/
public final static String BKU_RESPONSE_HEADER_SIGNATURE_LAYOUT = "SignatureLayout"; //$NON-NLS-1$
- at.asit.pdfover.signator.SigningState signingState;
-
Exception threadException = null;
+ /** Whether to use Base64 or FileUpload Request */
+ boolean useBase64Request = false;
+
/**
* Null-Operation SL-Request
*/
@@ -86,13 +88,16 @@ public class LocalBKUState extends State {
private final class SignLocalBKUThread implements Runnable {
private LocalBKUState state;
+ private SigningState signingState;
/**
* @param localBKUState
+ * @param signingState
*/
- public SignLocalBKUThread(LocalBKUState localBKUState) {
+ public SignLocalBKUThread(LocalBKUState localBKUState, SigningState signingState) {
this.state = localBKUState;
+ this.signingState = signingState;
}
@Override
@@ -117,6 +122,10 @@ public class LocalBKUState extends State {
server = getResponseHeader(method, BKU_RESPONSE_HEADER_SERVER);
if (server == null)
server = ""; //$NON-NLS-1$
+ else
+ if (server.contains("trustDeskbasic")) //$NON-NLS-1$
+ LocalBKUState.this.useBase64Request = true;
+
userAgent = getResponseHeader(method, BKU_RESPONSE_HEADER_USERAGENT);
if (userAgent == null)
userAgent = ""; //$NON-NLS-1$
@@ -126,7 +135,8 @@ public class LocalBKUState extends State {
log.debug("SL Response: " + response); //$NON-NLS-1$
SLResponse slResponse = new SLResponse(response, server,
userAgent, signatureLayout);
- this.state.signingState.setSignatureResponse(slResponse);
+ this.signingState.setSignatureResponse(slResponse);
+ this.signingState.setUseBase64Request(LocalBKUState.this.useBase64Request);
}
} catch (Exception e) {
log.error("SignLocalBKUThread: ", e); //$NON-NLS-1$
@@ -161,15 +171,15 @@ public class LocalBKUState extends State {
public void run() {
Status status = getStateMachine().getStatus();
- this.signingState = status.getSigningState();
+ SigningState signingState = status.getSigningState();
- if (!this.signingState.hasSignatureResponse()
+ if (!signingState.hasSignatureResponse()
&& this.threadException == null) {
- Thread t = new Thread(new SignLocalBKUThread(this));
+ Thread t = new Thread(new SignLocalBKUThread(this, signingState));
t.start();
return;
}
- this.signingState.setBKUConnector(new LocalBKUConnector());
+ signingState.setBKUConnector(new LocalBKUConnector());
if (this.threadException != null) {
ErrorDialog dialog = new ErrorDialog(
@@ -187,7 +197,7 @@ public class LocalBKUState extends State {
}
// OK
- this.setNextState(new SigningState(getStateMachine()));
+ this.setNextState(new at.asit.pdfover.gui.workflow.states.SigningState(getStateMachine()));
}
/*
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 1df8f755..6b0d6684 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
@@ -37,6 +37,8 @@ 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.config.ConfigProvider;
+import at.asit.pdfover.signator.SigningState;
/**
* Logical state for performing the BKU Request to the A-Trust Mobile BKU
@@ -67,7 +69,7 @@ public class MobileBKUState extends State {
private static final Logger log = LoggerFactory
.getLogger(MobileBKUState.class);
- at.asit.pdfover.signator.SigningState signingState;
+ SigningState signingState;
Exception threadException = null;
@@ -138,7 +140,7 @@ public class MobileBKUState extends State {
/**
* @return the signingState
*/
- public at.asit.pdfover.signator.SigningState getSigningState() {
+ public SigningState getSigningState() {
return this.signingState;
}
@@ -315,6 +317,8 @@ public class MobileBKUState extends State {
this.signingState = getStateMachine().getStatus().getSigningState();
this.signingState.setBKUConnector(new MobileBKUConnector(this));
+ log.debug("Setting base64 request to " + this.handler.useBase64Request()); //$NON-NLS-1$
+ this.signingState.setUseBase64Request(this.handler.useBase64Request());
if (this.threadException != null) {
String message = Messages.getString("error.Unexpected"); //$NON-NLS-1$
@@ -335,7 +339,7 @@ public class MobileBKUState extends State {
getStateMachine().getGUIProvider().display(
this.getWaitingComposite());
- this.setNextState(new SigningState(getStateMachine()));
+ this.setNextState(new at.asit.pdfover.gui.workflow.states.SigningState(getStateMachine()));
}
/*