From 4bbf0adc1281e431c1e77481803c5b53de4795df Mon Sep 17 00:00:00 2001 From: Tobias Kellner Date: Thu, 30 Jun 2016 14:47:45 +0200 Subject: Allow mobile BKU implementations to parse and set cookies --- .../asit/pdfover/gui/bku/mobile/ATrustStatus.java | 19 +++++++++++++- .../at/asit/pdfover/gui/bku/mobile/IAIKStatus.java | 29 ++++++++++++++++++++-- .../pdfover/gui/bku/mobile/MobileBKUHandler.java | 4 +++ .../pdfover/gui/bku/mobile/MobileBKUHelper.java | 11 ++++++++ .../pdfover/gui/bku/mobile/MobileBKUStatus.java | 14 +++++++++++ 5 files changed, 74 insertions(+), 3 deletions(-) (limited to 'pdf-over-gui/src/main') 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 a97826b2..ecfd9f2b 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 @@ -16,6 +16,7 @@ package at.asit.pdfover.gui.bku.mobile; // Imports +import org.apache.commons.httpclient.Cookie; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -99,5 +100,21 @@ public class ATrustStatus extends AbstractMobileBKUStatusImpl { public void setQRCode(String qrcode) { this.qrcode = qrcode; } - + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.bku.mobile.MobileBKUStatus#parseCookies(org.apache.commons.httpclient.Cookie[]) + */ + @Override + public void parseCookies(Cookie[] cookies) { + //not needed yet + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.bku.mobile.MobileBKUStatus#getCookies() + */ + @Override + public Cookie[] getCookies() { + //not needed yet + return null; + } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/IAIKStatus.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/IAIKStatus.java index 3f354f94..92e88c77 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/IAIKStatus.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/IAIKStatus.java @@ -16,6 +16,7 @@ package at.asit.pdfover.gui.bku.mobile; // Imports +import org.apache.commons.httpclient.Cookie; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,7 +29,6 @@ public class IAIKStatus extends AbstractMobileBKUStatusImpl { /** * SLF4J Logger instance **/ - @SuppressWarnings("unused") private static final Logger log = LoggerFactory.getLogger(IAIKStatus.class); /** Maximum number of TAN tries */ @@ -68,13 +68,38 @@ public class IAIKStatus extends AbstractMobileBKUStatusImpl { this.viewState = viewState; } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.bku.mobile.MobileBKUStatus#parseCookies(org.apache.commons.httpclient.Cookie[]) + */ + @Override + public void parseCookies(Cookie[] cookies) { + for (Cookie cookie : cookies) { + if (cookie.getName().equals("JSESSIONID")) { //$NON-NLS-1$ + log.debug("Got session ID: " + cookie.toExternalForm()); //$NON-NLS-1$ + setSessionID(cookie.getValue()); + } + } + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.bku.mobile.MobileBKUStatus#getCookies() + */ + @Override + public Cookie[] getCookies() { + // Currently not used + return null; + } + @Override public String ensureSessionID(String url) { if (url.contains("jsessionid=")) //$NON-NLS-1$ return url; - url += ";jsessionid=" + getSessionID(); //$NON-NLS-1$ + String sid = getSessionID(); + if (sid != null) + url += ";jsessionid=" + sid; //$NON-NLS-1$ return url; } } 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 434a351a..da6505d3 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 @@ -261,6 +261,8 @@ public abstract class MobileBKUHandler { if (server != null) log.info("Server: " + server); //$NON-NLS-1$ + getStatus().parseCookies(client.getState().getCookies()); + return responseData; } @@ -342,6 +344,8 @@ public abstract class MobileBKUHandler { if (server != null) log.info("Server: " + server); //$NON-NLS-1$ + getStatus().parseCookies(client.getState().getCookies()); + return responseData; } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHelper.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHelper.java index 38ca66e3..213aea08 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHelper.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUHelper.java @@ -19,6 +19,9 @@ package at.asit.pdfover.gui.bku.mobile; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.httpclient.Cookie; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpState; import org.apache.commons.httpclient.protocol.Protocol; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -260,6 +263,14 @@ public class MobileBKUHelper { */ public static HttpClient getHttpClient(MobileBKUStatus status) { HttpClient client = BKUHelper.getHttpClient(true); + Cookie[] cookies = status.getCookies(); + if (cookies != null) { + HttpState state = new HttpState(); + for (Cookie cookie : cookies) { + state.addCookie(cookie); + } + client.setState(state); + } return client; } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUStatus.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUStatus.java index 321faac5..2a5bb4e7 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUStatus.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/MobileBKUStatus.java @@ -15,6 +15,8 @@ */ package at.asit.pdfover.gui.bku.mobile; +import org.apache.commons.httpclient.Cookie; + /** * */ @@ -131,6 +133,18 @@ public interface MobileBKUStatus { */ public void setSignatureDataURL(String signatureDataURL); + /** + * Parse the cookies set by the SL request server + * @param cookies the cookies + */ + void parseCookies(Cookie[] cookies); + + /** + * Get the cookies to set during a request to the SL server + * @return the cookies to set + */ + public Cookie[] getCookies(); + /** * Ensure that given URL contains a session ID (if necessary) * @param url URL to check for session ID -- cgit v1.2.3