summaryrefslogtreecommitdiff
path: root/pdf-over-gui/src/main/java/at/asit
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit')
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java3
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHandler.java9
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/IAIKHandler.java13
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHandler.java7
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHelper.java30
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/TrustedSocketFactory.java27
6 files changed, 64 insertions, 25 deletions
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 c9833c87..66c0f061 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
@@ -37,6 +37,7 @@ import at.asit.pdfover.gui.utils.FileUploadSource;
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.gui.workflow.states.mobilebku.MobileBKUHelper;
import at.asit.pdfover.signator.SLRequest;
import at.asit.pdfover.signator.SLResponse;
@@ -107,7 +108,7 @@ public class LocalBKUState extends State {
SLRequest request = this.state.signingState
.getSignatureRequest();
- HttpClient client = new HttpClient();
+ HttpClient client = MobileBKUHelper.getHttpClient();
PostMethod method = new PostMethod(
"http://127.0.0.1:3495/http-security-layer-request"); //$NON-NLS-1$
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHandler.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHandler.java
index cfe53ef8..78153156 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHandler.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHandler.java
@@ -27,7 +27,6 @@ import org.eclipse.swt.widgets.Shell;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import at.asit.pdfover.gui.Constants;
import at.asit.pdfover.gui.controls.Dialog;
import at.asit.pdfover.gui.controls.Dialog.BUTTONS;
import at.asit.pdfover.gui.controls.Dialog.ICON;
@@ -94,9 +93,7 @@ public class ATrustHandler extends MobileBKUHandler {
Protocol.registerProtocol("https", //$NON-NLS-1$
new Protocol("https", new TrustedSocketFactory(), 443)); //$NON-NLS-1$
- HttpClient client = new HttpClient();
- client.getParams().setParameter("http.useragent", //$NON-NLS-1$
- Constants.USER_AGENT_STRING);
+ HttpClient client = MobileBKUHelper.getHttpClient();
PostMethod post = new PostMethod(status.getBaseURL() + "/identification.aspx?sid=" + status.getSessionID()); //$NON-NLS-1$
post.getParams().setContentCharset("utf-8"); //$NON-NLS-1$
@@ -167,9 +164,7 @@ public class ATrustHandler extends MobileBKUHandler {
Protocol.registerProtocol("https", //$NON-NLS-1$
new Protocol("https", new TrustedSocketFactory(), 443)); //$NON-NLS-1$
- HttpClient client = new HttpClient();
- client.getParams().setParameter("http.useragent", //$NON-NLS-1$
- Constants.USER_AGENT_STRING);
+ HttpClient client = MobileBKUHelper.getHttpClient();
PostMethod post = new PostMethod(status.getBaseURL()
+ "/signature.aspx?sid=" + status.getSessionID()); //$NON-NLS-1$
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/IAIKHandler.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/IAIKHandler.java
index 59519050..1587b66b 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/IAIKHandler.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/IAIKHandler.java
@@ -31,7 +31,6 @@ import org.eclipse.swt.widgets.Shell;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import at.asit.pdfover.gui.Constants;
import at.asit.pdfover.gui.controls.Dialog;
import at.asit.pdfover.gui.controls.Dialog.BUTTONS;
import at.asit.pdfover.gui.controls.Dialog.ICON;
@@ -101,9 +100,7 @@ public class IAIKHandler extends MobileBKUHandler {
Protocol.registerProtocol("https", //$NON-NLS-1$
new Protocol("https", new TrustedSocketFactory(), 443)); //$NON-NLS-1$
- HttpClient client = new HttpClient();
- client.getParams().setParameter("http.useragent", //$NON-NLS-1$
- Constants.USER_AGENT_STRING);
+ HttpClient client = MobileBKUHelper.getHttpClient();
PostMethod post = new PostMethod(status.getBaseURL());
post.getParams().setContentCharset("utf-8"); //$NON-NLS-1$
@@ -149,9 +146,7 @@ public class IAIKHandler extends MobileBKUHandler {
return;
}
- HttpClient client = new HttpClient();
- client.getParams().setParameter("http.useragent", //$NON-NLS-1$
- Constants.USER_AGENT_STRING);
+ HttpClient client = MobileBKUHelper.getHttpClient();
String redirectURL = status.getBaseURL().substring(0,
status.getBaseURL().lastIndexOf('/',
@@ -245,9 +240,7 @@ public class IAIKHandler extends MobileBKUHandler {
Protocol.registerProtocol("https", //$NON-NLS-1$
new Protocol("https", new TrustedSocketFactory(), 443)); //$NON-NLS-1$
- HttpClient client = new HttpClient();
- client.getParams().setParameter("http.useragent", //$NON-NLS-1$
- Constants.USER_AGENT_STRING);
+ HttpClient client = MobileBKUHelper.getHttpClient();
PostMethod post = new PostMethod(status.getBaseURL());
post.getParams().setContentCharset("utf-8"); //$NON-NLS-1$
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHandler.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHandler.java
index 5d387351..4448bdd3 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHandler.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHandler.java
@@ -32,7 +32,6 @@ import org.apache.commons.httpclient.protocol.Protocol;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import at.asit.pdfover.gui.Constants;
import at.asit.pdfover.gui.utils.FileUploadSource;
import at.asit.pdfover.gui.workflow.states.LocalBKUState;
import at.asit.pdfover.gui.workflow.states.MobileBKUState;
@@ -78,9 +77,7 @@ public abstract class MobileBKUHandler {
Protocol.registerProtocol("https", //$NON-NLS-1$
new Protocol("https", new TrustedSocketFactory(), 443)); //$NON-NLS-1$
- HttpClient client = new HttpClient();
- client.getParams().setParameter("http.useragent", //$NON-NLS-1$
- Constants.USER_AGENT_STRING);
+ HttpClient client = MobileBKUHelper.getHttpClient();
PostMethod post = new PostMethod(mobileBKUUrl);
@@ -97,7 +94,7 @@ public abstract class MobileBKUHandler {
post.setRequestEntity(new MultipartRequestEntity(parts, post
.getParams()));
- this.state.getStatus().setBaseURL(
+ getState().getStatus().setBaseURL(
MobileBKUHelper.stripQueryString(mobileBKUUrl));
return executePost(client, post);
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHelper.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHelper.java
index b5f781cc..65ffc9b0 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHelper.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHelper.java
@@ -19,9 +19,13 @@ package at.asit.pdfover.gui.workflow.states.mobilebku;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import at.asit.pdfover.gui.Constants;
import at.asit.pdfover.gui.exceptions.InvalidNumberException;
import at.asit.pdfover.gui.exceptions.InvalidPasswordException;
import at.asit.pdfover.gui.exceptions.PasswordTooLongException;
@@ -145,4 +149,30 @@ public class MobileBKUHelper {
}
return query;
}
+
+ /**
+ * Get a HTTP Client instance
+ * @return the HttpClient
+ */
+ public static HttpClient getHttpClient() {
+ HttpClient client = new HttpClient();
+ client.getParams().setParameter("http.useragent", //$NON-NLS-1$
+ Constants.USER_AGENT_STRING);
+
+ String host = System.getProperty("http.proxyHost"); //$NON-NLS-1$
+ String port = System.getProperty("http.proxyPort"); //$NON-NLS-1$
+ if (host != null && !host.isEmpty() &&
+ port != null && !port.isEmpty()) {
+ int p = Integer.parseInt(port);
+ client.getHostConfiguration().setProxy(host, p);
+ String user = System.getProperty("http.proxyUser"); //$NON-NLS-1$
+ String pass = System.getProperty("http.proxyPassword"); //$NON-NLS-1$
+ if (user != null && !user.isEmpty() && pass != null) {
+ client.getState().setProxyCredentials(new AuthScope(host, p),
+ new UsernamePasswordCredentials(user, pass));
+ }
+ }
+
+ return client;
+ }
}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/TrustedSocketFactory.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/TrustedSocketFactory.java
index add31972..c39edbca 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/TrustedSocketFactory.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/TrustedSocketFactory.java
@@ -32,7 +32,7 @@ import javax.net.ssl.TrustManager;
import org.apache.commons.httpclient.ConnectTimeoutException;
import org.apache.commons.httpclient.params.HttpConnectionParams;
-import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
+import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,7 +41,7 @@ import at.asit.pdfover.gui.utils.Messages;
/**
*
*/
-public class TrustedSocketFactory implements ProtocolSocketFactory {
+public class TrustedSocketFactory implements SecureProtocolSocketFactory {
/**
* SLF4J Logger instance
**/
@@ -158,4 +158,27 @@ public class TrustedSocketFactory implements ProtocolSocketFactory {
}
}
+ /* (non-Javadoc)
+ * @see org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory#createSocket(java.net.Socket, java.lang.String, int, boolean)
+ */
+ @Override
+ public Socket createSocket(Socket socket, String host, int port,
+ boolean autoClose) throws IOException, UnknownHostException {
+ try {
+ SSLSocket sslSocket = (SSLSocket) getFactory().createSocket(socket, host, port, autoClose);
+
+ return sslSocket;
+ } catch (Exception ex) {
+ log.error("TrustedSocketFactory: ", ex); //$NON-NLS-1$
+ if (ex instanceof IOException) {
+ throw (IOException) ex;
+ } else if (ex instanceof UnknownHostException) {
+ throw (UnknownHostException) ex;
+ } else {
+ throw new IOException(
+ Messages.getString("TrustedSocketFactory.FailedToCreateSecureConnection"), ex); //$NON-NLS-1$
+ }
+ }
+ }
+
}