From 10488f89a0c8992b951f340cea92a8e00af2dec7 Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 10 Apr 2013 19:32:27 +0000 Subject: split mobile BKU status git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@373 174cde9d-5d70-4d2a-aa98-46368bc2aaf7 --- .../gui/workflow/states/MobileBKUState.java | 5 +- .../workflow/states/mobilebku/ATrustHandler.java | 69 +++++- .../workflow/states/mobilebku/ATrustStatus.java | 241 +++++++++++++++++++++ .../states/mobilebku/MobileBKUHandler.java | 52 +---- .../workflow/states/mobilebku/MobileBKUStatus.java | 174 ++++----------- 5 files changed, 351 insertions(+), 190 deletions(-) create mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustStatus.java (limited to 'pdf-over-gui/src') 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 4d7c5985..827dcf70 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 @@ -32,6 +32,7 @@ import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.states.mobilebku.ATrustHandler; 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; @@ -46,9 +47,9 @@ public class MobileBKUState extends State { */ public MobileBKUState(StateMachine stateMachine) { super(stateMachine); - this.status = new MobileBKUStatus(this.stateMachine.getConfigProvider()); switch(this.stateMachine.getConfigProvider().getMobileBKUType()) { case A_TRUST: + this.status = new ATrustStatus(this.stateMachine.getConfigProvider()); this.handler = new ATrustHandler(this); break; @@ -283,7 +284,7 @@ public class MobileBKUState extends State { } else { tan.setRefVal(mobileStatus.getRefVal()); - if (mobileStatus.getTanTries() < MobileBKUStatus.MOBILE_MAX_TAN_TRIES + if (mobileStatus.getTanTries() < mobileStatus.getMaxTanTries() && mobileStatus.getTanTries() > 0) { // show warning message x tries left! 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 cb98aea3..593edede 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 @@ -16,9 +16,15 @@ package at.asit.pdfover.gui.workflow.states.mobilebku; // Imports +import java.io.IOException; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.protocol.Protocol; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.workflow.states.LocalBKUState; import at.asit.pdfover.gui.workflow.states.MobileBKUState; import at.asit.pdfover.signator.SLResponse; @@ -44,6 +50,8 @@ public class ATrustHandler extends MobileBKUHandler { */ @Override public void handleSLRequestResponse(String responseData) throws Exception { + ATrustStatus status = (ATrustStatus) getStatus(); + // Extract infos: String sessionID = MobileBKUHelper.extractTag(responseData, @@ -59,11 +67,36 @@ public class ATrustHandler extends MobileBKUHandler { log.info("viewState: " + viewState); //$NON-NLS-1$ log.info("eventValidation: " + eventValidation); //$NON-NLS-1$ - getStatus().setSessionID(sessionID); + status.setSessionID(sessionID); + + status.setViewstate(viewState); - getStatus().setViewstate(viewState); + status.setEventvalidation(eventValidation); + } - getStatus().setEventvalidation(eventValidation); + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHandler#postCredentials() + */ + @Override + public String postCredentials() throws Exception { + ATrustStatus status = (ATrustStatus) getStatus(); + + 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$ + LocalBKUState.PDF_OVER_USER_AGENT_STRING); + + PostMethod post = new PostMethod(status.getBaseURL() + "/identification.aspx?sid=" + status.getSessionID()); //$NON-NLS-1$ + post.getParams().setContentCharset("utf-8"); //$NON-NLS-1$ + post.addParameter("__VIEWSTATE", status.getViewstate()); //$NON-NLS-1$ + post.addParameter("__EVENTVALIDATION", status.getEventvalidation()); //$NON-NLS-1$ + post.addParameter("handynummer", status.getPhoneNumber()); //$NON-NLS-1$ + post.addParameter("signaturpasswort", status.getMobilePassword()); //$NON-NLS-1$ + post.addParameter("Button_Identification", "Identifizieren"); //$NON-NLS-1$ //$NON-NLS-2$ + + return executePost(client, post); } /* (non-Javadoc) @@ -71,7 +104,7 @@ public class ATrustHandler extends MobileBKUHandler { */ @Override public void handleCredentialsResponse(String responseData) throws Exception { - MobileBKUStatus status = getStatus(); + ATrustStatus status = (ATrustStatus) getStatus(); String viewState = status.getViewstate(); String eventValidation = status.getEventvalidation(); String sessionID = status.getSessionID(); @@ -110,6 +143,33 @@ public class ATrustHandler extends MobileBKUHandler { status.setEventvalidation(eventValidation); } + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHandler#postTAN() + */ + @Override + public String postTAN() throws IOException { + ATrustStatus status = (ATrustStatus) getStatus(); + + 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$ + LocalBKUState.PDF_OVER_USER_AGENT_STRING); + + PostMethod post = new PostMethod(status.getBaseURL() + + "/signature.aspx?sid=" + status.getSessionID()); //$NON-NLS-1$ + post.getParams().setContentCharset("utf-8"); //$NON-NLS-1$ + post.addParameter("__VIEWSTATE", status.getViewstate()); //$NON-NLS-1$ + post.addParameter( + "__EVENTVALIDATION", status.getEventvalidation()); //$NON-NLS-1$ + post.addParameter("input_tan", status.getTan()); //$NON-NLS-1$ + post.addParameter("SignButton", "Signieren"); //$NON-NLS-1$ //$NON-NLS-2$ + post.addParameter("Button1", "Identifizieren"); //$NON-NLS-1$ //$NON-NLS-2$ + + return executePost(client, post); + } + /* (non-Javadoc) * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHandler#handleTANResponse(java.lang.String) */ @@ -136,5 +196,4 @@ public class ATrustHandler extends MobileBKUHandler { } } } - } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustStatus.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustStatus.java new file mode 100644 index 00000000..d970c6ca --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustStatus.java @@ -0,0 +1,241 @@ +/* + * Copyright 2012 by A-SIT, Secure Information Technology Center Austria + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ +package at.asit.pdfover.gui.workflow.states.mobilebku; + +// Imports +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.asit.pdfover.gui.workflow.ConfigProvider; + +/** + * + */ +public class ATrustStatus implements MobileBKUStatus { + /** + * SLF4J Logger instance + **/ + @SuppressWarnings("unused") + private static final Logger log = LoggerFactory + .getLogger(ATrustStatus.class); + + /** + * Maximum number of TAN tries! + */ + public static final int MOBILE_MAX_TAN_TRIES = 3; + + private String viewstate; + private String eventvalidation; + private String sessionID; + private String phoneNumber; + private String mobilePassword; + private String baseURL; + private String refVal; + private String errorMessage; + private String tan; + private String server; + private int tanTries = MOBILE_MAX_TAN_TRIES; + + /** + * Constructor + * @param provider + */ + public ATrustStatus(ConfigProvider provider) { + this.setPhoneNumber(provider.getDefaultMobileNumber()); + this.setMobilePassword(provider.getDefaultMobilePassword()); + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus#getMaxTanTries() + */ + @Override + public int getMaxTanTries() { + return MOBILE_MAX_TAN_TRIES; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus#getTanTries() + */ + @Override + public int getTanTries() { + return this.tanTries; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus#setTanTries(int) + */ + @Override + public void setTanTries(int tries) { + this.tanTries = tries; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus#getTan() + */ + @Override + public String getTan() { + return this.tan; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus#setTan(java.lang.String) + */ + @Override + public void setTan(String tan) { + this.tan = tan; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus#getErrorMessage() + */ + @Override + public String getErrorMessage() { + return this.errorMessage; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus#setErrorMessage(java.lang.String) + */ + @Override + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus#getRefVal() + */ + @Override + public String getRefVal() { + return this.refVal; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus#setRefVal(java.lang.String) + */ + @Override + public void setRefVal(String refVal) { + this.refVal = refVal; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus#getBaseURL() + */ + @Override + public String getBaseURL() { + return this.baseURL; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus#setBaseURL(java.lang.String) + */ + @Override + public void setBaseURL(String baseURL) { + this.baseURL = baseURL; + } + + /** + * @return the viewstate + */ + public String getViewstate() { + return this.viewstate; + } + + /** + * @param viewstate + * the viewstate to set + */ + public void setViewstate(String viewstate) { + this.viewstate = viewstate; + } + + /** + * @return the eventvalidation + */ + public String getEventvalidation() { + return this.eventvalidation; + } + + /** + * @param eventvalidation the eventvalidation to set + */ + public void setEventvalidation(String eventvalidation) { + this.eventvalidation = eventvalidation; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus#getPhoneNumber() + */ + @Override + public String getPhoneNumber() { + return this.phoneNumber; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus#setPhoneNumber(java.lang.String) + */ + @Override + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus#getMobilePassword() + */ + @Override + public String getMobilePassword() { + return this.mobilePassword; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus#setMobilePassword(java.lang.String) + */ + @Override + public void setMobilePassword(String mobilePassword) { + this.mobilePassword = mobilePassword; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus#getSessionID() + */ + @Override + public String getSessionID() { + return this.sessionID; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus#setSessionID(java.lang.String) + */ + @Override + public void setSessionID(String sessionID) { + this.sessionID = sessionID; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus#getServer() + */ + @Override + public String getServer() { + return this.server; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUStatus#setServer(java.lang.String) + */ + @Override + public void setServer(String server) { + this.server = server; + } +} 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 3cef5edf..1193ffcd 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 @@ -147,29 +147,9 @@ public abstract class MobileBKUHandler { /** * Post the credentials * @return the response - * @throws IOException IO error - * @throws HttpException HTTP error + * @throws Exception Error during posting */ - public String postCredentials() throws HttpException, IOException { - MobileBKUStatus status = getStatus(); - - 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$ - LocalBKUState.PDF_OVER_USER_AGENT_STRING); - - PostMethod post = new PostMethod(status.getBaseURL() + "/identification.aspx?sid=" + status.getSessionID()); //$NON-NLS-1$ - post.getParams().setContentCharset("utf-8"); //$NON-NLS-1$ - post.addParameter("__VIEWSTATE", status.getViewstate()); //$NON-NLS-1$ - post.addParameter("__EVENTVALIDATION", status.getEventvalidation()); //$NON-NLS-1$ - post.addParameter("handynummer", status.getPhoneNumber()); //$NON-NLS-1$ - post.addParameter("signaturpasswort", status.getMobilePassword()); //$NON-NLS-1$ - post.addParameter("Button_Identification", "Identifizieren"); //$NON-NLS-1$ //$NON-NLS-2$ - - return executePost(client, post); - } + public abstract String postCredentials() throws Exception; /** * Handle the response to credentials post @@ -181,31 +161,9 @@ public abstract class MobileBKUHandler { /** * Post the TAN * @return the response - * @throws IOException IO error - * @throws HttpException HTTP error + * @throws Exception Error during posting */ - public String postTAN() throws HttpException, IOException { - MobileBKUStatus status = this.state.getStatus(); - - 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$ - LocalBKUState.PDF_OVER_USER_AGENT_STRING); - - PostMethod post = new PostMethod(status.getBaseURL() - + "/signature.aspx?sid=" + status.getSessionID()); //$NON-NLS-1$ - post.getParams().setContentCharset("utf-8"); //$NON-NLS-1$ - post.addParameter("__VIEWSTATE", status.getViewstate()); //$NON-NLS-1$ - post.addParameter( - "__EVENTVALIDATION", status.getEventvalidation()); //$NON-NLS-1$ - post.addParameter("input_tan", status.getTan()); //$NON-NLS-1$ - post.addParameter("SignButton", "Signieren"); //$NON-NLS-1$ //$NON-NLS-2$ - post.addParameter("Button1", "Identifizieren"); //$NON-NLS-1$ //$NON-NLS-2$ - - return executePost(client, post); - } + public abstract String postTAN() throws Exception; /** * Handle the response to TAN post @@ -253,7 +211,7 @@ public abstract class MobileBKUHandler { * @return the response * @throws IOException IO error */ - private String executePost(HttpClient client, PostMethod post) throws IOException { + protected String executePost(HttpClient client, PostMethod post) throws IOException { int returnCode = client.executeMethod(post); String redirectLocation = null; diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUStatus.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUStatus.java index 01e10e1d..44e24c30 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUStatus.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUStatus.java @@ -15,205 +15,107 @@ */ package at.asit.pdfover.gui.workflow.states.mobilebku; -// Imports -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.gui.workflow.ConfigProvider; - /** * */ -public class MobileBKUStatus { - /** - * SLF4J Logger instance - **/ - @SuppressWarnings("unused") - private static final Logger log = LoggerFactory - .getLogger(MobileBKUStatus.class); - - /** - * Maximum number of TAN tries! - */ - public static final int MOBILE_MAX_TAN_TRIES = 3; - - private String viewstate; - private String eventvalidation; - private String sessionID; - private String phoneNumber; - private String mobilePassword; - private String baseURL; - private String refVal; - private String errorMessage; - private String tan; - private String server; - private int tanTries = MOBILE_MAX_TAN_TRIES; - - /** - * Constructor - * @param provider - */ - public MobileBKUStatus(ConfigProvider provider) { - this.setPhoneNumber(provider.getDefaultMobileNumber()); - this.setMobilePassword(provider.getDefaultMobilePassword()); - } - +public interface MobileBKUStatus { /** - * Get number of TAN tries left - * @return the number of TAN tries left + * @return the identification_url */ - public int getTanTries() { - return this.tanTries; - } + public abstract String getSessionID(); /** - * Set number of TAN tries left - * @param tries the number of TAN tries left + * @param sessionID the identification_url to set */ - public void setTanTries(int tries) { - this.tanTries = tries; - } + public abstract void setSessionID(String sessionID); /** - * @return the tan + * @return the phoneNumber */ - public String getTan() { - return this.tan; - } + public abstract String getPhoneNumber(); /** - * @param tan the tan to set + * @param phoneNumber the phoneNumber to set */ - public void setTan(String tan) { - this.tan = tan; - } + public abstract void setPhoneNumber(String phoneNumber); /** - * @return the errorMessage + * @return the mobilePassword */ - public String getErrorMessage() { - return this.errorMessage; - } + public abstract String getMobilePassword(); /** - * @param errorMessage the errorMessage to set + * @param mobilePassword the mobilePassword to set */ - public void setErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; - } + public abstract void setMobilePassword(String mobilePassword); /** * @return the reference value */ - public String getRefVal() { - return this.refVal; - } + public abstract String getRefVal(); /** * @param refVal the reference value to set */ - public void setRefVal(String refVal) { - this.refVal = refVal; - } + public abstract void setRefVal(String refVal); /** - * @return the credentialsFormAction + * @return the tan */ - public String getBaseURL() { - return this.baseURL; - } + public abstract String getTan(); /** - * @param baseURL + * @param tan the tan to set */ - public void setBaseURL(String baseURL) { - this.baseURL = baseURL; - } + public abstract void setTan(String tan); /** - * @return the viewstate + * Get maximum number of TAN tries + * @return the maximum number of TAN tries */ - public String getViewstate() { - return this.viewstate; - } + public abstract int getMaxTanTries(); /** - * @param viewstate - * the viewstate to set - */ - public void setViewstate(String viewstate) { - this.viewstate = viewstate; - } - - /** - * @return the eventvalidation + * Get number of TAN tries left + * @return the number of TAN tries left */ - public String getEventvalidation() { - return this.eventvalidation; - } + public abstract int getTanTries(); /** - * @param eventvalidation the eventvalidation to set - */ - public void setEventvalidation(String eventvalidation) { - this.eventvalidation = eventvalidation; - } - - /** - * @return the phoneNumber + * Set number of TAN tries left + * @param tries the number of TAN tries left */ - public String getPhoneNumber() { - return this.phoneNumber; - } + public abstract void setTanTries(int tries); /** - * @param phoneNumber the phoneNumber to set + * @return the errorMessage */ - public void setPhoneNumber(String phoneNumber) { - this.phoneNumber = phoneNumber; - } + public abstract String getErrorMessage(); /** - * @return the mobilePassword + * @param errorMessage the errorMessage to set */ - public String getMobilePassword() { - return this.mobilePassword; - } + public abstract void setErrorMessage(String errorMessage); /** - * @param mobilePassword the mobilePassword to set + * @return the baseURL */ - public void setMobilePassword(String mobilePassword) { - this.mobilePassword = mobilePassword; - } - - /** - * @return the identification_url - */ - public String getSessionID() { - return this.sessionID; - } + public abstract String getBaseURL(); /** - * @param sessionID the identification_url to set + * @param baseURL */ - public void setSessionID(String sessionID) { - this.sessionID = sessionID; - } + public abstract void setBaseURL(String baseURL); /** * Return the SL request server * @return the SL request server */ - public String getServer() { - return this.server; - } + public abstract String getServer(); /** * Set the SL request server * @param server the SL request server */ - public void setServer(String server) { - this.server = server; - } + public abstract void setServer(String server); } -- cgit v1.2.3