From 32d17447a258188b2d534bcb0bf65a659ba7b7d0 Mon Sep 17 00:00:00 2001 From: mcentner Date: Fri, 29 Aug 2008 12:11:34 +0000 Subject: Initial import. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@1 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 101 ++++++++ .../at/gv/egiz/bku/online/applet/BKUWorker.java | 286 +++++++++++++++++++++ .../online/applet/InternalSSLSocketFactory.java | 101 ++++++++ .../applet/InternalSSLSocketFactoryException.java | 45 ++++ 4 files changed, 533 insertions(+) create mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java create mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java create mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java create mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactoryException.java (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java new file mode 100644 index 00000000..56cc5ea2 --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -0,0 +1,101 @@ +/* +* Copyright 2008 Federal Chancellery Austria and +* Graz University of Technology +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package at.gv.egiz.bku.online.applet; + +import java.util.Locale; +import java.util.ResourceBundle; + +import javax.net.ssl.HttpsURLConnection; +import javax.swing.JApplet; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.bku.gui.BKUGUIFactory; + +/** + * + * + * + */ +public class BKUApplet extends JApplet { + + private static Log log = LogFactory.getLog(BKUApplet.class); + + public final static String RESOURCE_BUNDLE_BASE = "at/gv/egiz/bku/online/applet/Messages"; + + public final static String LOCALE_PARAM_KEY = "Locale"; + public final static String LOGO_URL_KEY="LogoURL"; + public final static String WSDL_URL="WSDL_URL"; + public final static String SESSION_ID="SessionID"; + + protected ResourceBundle resourceBundle; + protected BKUWorker worker; + protected Thread workerThread; + + public BKUApplet() { + } + + public void init() { + log.debug("Called init()"); + try { + HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getSocketFactory()); + HttpsURLConnection.setDefaultHostnameVerifier(InternalSSLSocketFactory.getHostNameVerifier()); + } catch (InternalSSLSocketFactoryException e) { + log.error(e); + } + String localeString = getMyAppletParameter(LOCALE_PARAM_KEY); + if (localeString != null) { + resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE, + new Locale(localeString)); + } else { + resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE); + } + BKUGUIFacade gui = BKUGUIFactory.createGUI(); + gui.init(getContentPane(), localeString); + worker = new BKUWorker(gui, this, resourceBundle); + } + + public void start() { + log.debug("Called start()"); + workerThread = new Thread(worker); + workerThread.start(); + } + + public void stop() { + log.debug("Called stop()"); + if ((workerThread != null) && (workerThread.isAlive())) { + workerThread.interrupt(); + } + } + + public void destroy() { + log.debug("Called destroy()"); + } + + /** + * Applet configuration parameters + * + * @param paramKey + * @return + */ + public String getMyAppletParameter(String paramKey) { + log.info("Getting parameter: "+paramKey+ ": "+ getParameter(paramKey)); + return getParameter(paramKey); + } +} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java new file mode 100644 index 00000000..38fd6428 --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java @@ -0,0 +1,286 @@ +/* +* Copyright 2008 Federal Chancellery Austria and +* Graz University of Technology +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package at.gv.egiz.bku.online.applet; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.ResourceBundle; + +import javax.xml.namespace.QName; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.bku.smccstal.AbstractSMCCSTAL; +import at.gv.egiz.bku.smccstal.SMCCSTALRequestHandler; +import at.gv.egiz.smcc.SignatureCard; +import at.gv.egiz.smcc.util.SMCCHelper; +import at.gv.egiz.stal.QuitRequest; +import at.gv.egiz.stal.STALRequest; +import at.gv.egiz.stal.STALResponse; +import at.gv.egiz.stal.service.GetNextRequestResponseType; +import at.gv.egiz.stal.service.GetNextRequestType; +import at.gv.egiz.stal.service.ObjectFactory; +import at.gv.egiz.stal.service.STALPortType; +import at.gv.egiz.stal.service.STALService; + +public class BKUWorker extends AbstractSMCCSTAL implements Runnable, + ActionListener, SMCCSTALRequestHandler { + + private static Log log = LogFactory.getLog(BKUWorker.class); + + protected BKUGUIFacade gui; + protected BKUApplet parent; + private STALPortType stalPort; + protected List actionCommandList = new ArrayList(); + protected Boolean actionPerformed = false; + protected boolean finished = false; + protected ResourceBundle errorMessages; + + /** + * + * @param gui + * must not be null + */ + public BKUWorker(BKUGUIFacade gui, BKUApplet parent, + ResourceBundle errorMessageBundle) { + if ((gui == null) || (parent == null) || (errorMessageBundle == null)) { + throw new NullPointerException("Parameter must not be set to null"); + } + this.gui = gui; + this.parent = parent; + this.errorMessages = errorMessageBundle; + addRequestHandler(QuitRequest.class, this); + } + + private STALPortType getSTALPort() throws MalformedURLException { + URL wsdlURL = null; + String wsdlLocation = parent.getMyAppletParameter(BKUApplet.WSDL_URL); + URL codebase = parent.getCodeBase(); + log.debug("Connecting to webservice: " + wsdlLocation); + if (wsdlLocation != null) { + try { + if (codebase.getProtocol().equalsIgnoreCase("file")) { + // for debugging in appletrunner + wsdlURL = new URL(wsdlLocation); + } else { + wsdlURL = new URL(codebase, wsdlLocation); + } + } catch (MalformedURLException ex) { + log.fatal("Paremeter 'wsdlLocation' is not a vailid URL.", ex); + throw new MalformedURLException(ex.getMessage()); + } + } else { + log.fatal("Paremeter 'wsdlLocation' is not set."); + throw new MalformedURLException("Null WSDL url"); + } + log.debug("Found WSDL url: " + wsdlURL); + QName endpointName = new QName("http://www.egiz.gv.at/wsdl/stal", + "STALService"); + STALService stal = new STALService(wsdlURL, endpointName); + return stal.getSTALPort(); + } + + @Override + public void run() { + gui.showWelcomeDialog(); + try { + stalPort = getSTALPort(); + } catch (Exception e) { + log.fatal("Failed to call STAL service.", e); + actionCommandList.clear(); + actionCommandList.add("ok"); + gui.showErrorDialog(errorMessages.getString("failed.WS")); + try { + waitForAction(); + } catch (InterruptedException e1) { + log.error(e1); + } + return; + } + + ObjectFactory factory = new ObjectFactory(); + GetNextRequestType nextRequest = factory.createGetNextRequestType(); + + String sessionId = parent.getMyAppletParameter(BKUApplet.SESSION_ID); + if (sessionId == null) { + // use the testsession for testing + sessionId = "TestSession"; + } + nextRequest.setSessionId(sessionId); + do { + GetNextRequestResponseType resp = stalPort.getNextRequest(nextRequest); + log.info("Got " + resp.getRequest().size() + " requests from server."); + List stalRequests = resp.getRequest(); + List responses = handleRequest(stalRequests); + log.info("Got " + responses.size() + " responses."); + nextRequest = factory.createGetNextRequestType(); + nextRequest.setSessionId(sessionId); + nextRequest.getResponse().addAll(responses); + } while (!finished); + log.info("Done " + Thread.currentThread().getName()); + gui.showWelcomeDialog(); + sendRedirect(); + } + + protected void sendRedirect() { + log.info("Done, sending redirect to get BKU response"); + String redirectURL = parent.getMyAppletParameter("redirectURL"); + String redirectTarget = parent.getMyAppletParameter("redirectTarget"); + log.info("Redirecting to: " + redirectURL + " target: " + redirectTarget); + URL url = null; + if (redirectURL != null) { + try { + url = new URL(parent.getCodeBase(),redirectURL + ";jsessionid=" + + parent.getMyAppletParameter(BKUApplet.SESSION_ID)); + } catch (MalformedURLException ex) { + log.warn("Parameter 'redirectURL': " + redirectURL + + " not a valid URL.", ex); + // gui.showErrorDialog(errorMsg, okListener, actionCommand) + } + if (url != null) { + if (redirectTarget == null) { + log.info("Done. Trying to redirect to " + url + " ..."); + parent.getAppletContext().showDocument(url); + } else { + log.info("Done. Trying to redirect to " + url + " (target=" + + redirectTarget + ") ..."); + parent.getAppletContext().showDocument(url, redirectTarget); + } + } + } else { + log.error("No redirect URL set"); + } + } + + protected synchronized void waitForAction() throws InterruptedException { + log.info("Waiting for Action"); + while (!actionPerformed) { + wait(); + } + actionPerformed = false; + } + + protected synchronized void actionOccured() { + log.info("Received Action"); + actionPerformed = true; + notifyAll(); + } + + @Override + public void actionPerformed(ActionEvent e) { + log.info("Action: " + e); + if (actionCommandList != null) { + if (actionCommandList.contains(e.getActionCommand())) { + actionOccured(); + } + } else { + actionOccured(); + } + } + + @Override + protected boolean waitForCard() { + SMCCHelper smccHelper = new SMCCHelper(); + actionCommandList.clear(); + actionCommandList.add("cancel"); + // while no sigcard found or cancel button pressed + int oldValue = SMCCHelper.PC_SC_NOT_SUPPORTED; // this is a save default + while ((signatureCard == null) && (!actionPerformed)) { + switch (smccHelper.getResultCode()) { + case SMCCHelper.PC_SC_NOT_SUPPORTED: + actionCommandList.clear(); + actionCommandList.add("ok"); + gui.showErrorDialog(errorMessages.getString("nopcscsupport"), this, + "ok"); + try { + waitForAction(); + } catch (InterruptedException e) { + log.error(e); + } + return true; + case SMCCHelper.TERMINAL_NOT_PRESENT: + actionCommandList.clear(); + actionCommandList.add("ok"); + gui.showErrorDialog(errorMessages.getString("nocardterminal"), this, + "ok"); + try { + waitForAction(); + } catch (InterruptedException e) { + log.error(e); + } + return true; + case SMCCHelper.CARD_NOT_SUPPORTED: + if (oldValue != SMCCHelper.CARD_NOT_SUPPORTED) { + actionCommandList.clear(); + actionCommandList.add("cancel"); + gui.showCardNotSupportedDialog(this, "cancel"); + oldValue = SMCCHelper.CARD_NOT_SUPPORTED; + } + break; + case SMCCHelper.NO_CARD: + if (oldValue != SMCCHelper.NO_CARD) { + actionCommandList.clear(); + actionCommandList.add("cancel"); + gui.showInsertCardDialog(this, "cancel"); + oldValue = SMCCHelper.NO_CARD; + } + break; + case SMCCHelper.CARD_FOUND: + gui.showWelcomeDialog(); + signatureCard = smccHelper.getSignatureCard(errorMessages.getLocale()); + return false; + } + smccHelper.update(3000); + } + return signatureCard == null; + } + + @Override + public STALResponse handleRequest(STALRequest request) { + if (request instanceof QuitRequest) { + finished = true; + } else { + log.error("Unexpected request to handle: " + request); + } + return null; + } + + @Override + public void init(SignatureCard sc, BKUGUIFacade gui) { + } + + @Override + public SMCCSTALRequestHandler newInstance() { + return this; + } + + @Override + public boolean requireCard() { + return false; + } + + @Override + protected BKUGUIFacade getGUI() { + return gui; + } +} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java new file mode 100644 index 00000000..ab04d2b6 --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java @@ -0,0 +1,101 @@ +/* +* Copyright 2008 Federal Chancellery Austria and +* Graz University of Technology +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package at.gv.egiz.bku.online.applet; + +import java.io.IOException; +import java.security.KeyManagementException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.X509TrustManager; + +public class InternalSSLSocketFactory { + + private SSLSocketFactory factory; + + public static SSLSocketFactory getSocketFactory() throws InternalSSLSocketFactoryException { + return new InternalSSLSocketFactory().factory; + } + + public static HostnameVerifier getHostNameVerifier() throws InternalSSLSocketFactoryException { + return (new HostnameVerifier() { + @Override + public boolean verify(String hostname, SSLSession session) { + return true; + } + }); + } + + public InternalSSLSocketFactory() throws InternalSSLSocketFactoryException { + SSLContext sslContext; + try { + sslContext = SSLContext.getInstance("TLSv1"); + sslContext.getClientSessionContext().setSessionTimeout(0); + KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509"); + + KeyStore keyStore = KeyStore.getInstance("JKS"); + keyStore.load(null, null); + keyManagerFactory.init(keyStore, null); + + sslContext.init(keyManagerFactory.getKeyManagers(), + new X509TrustManager[] { new AcceptAllTrustManager() }, + null); + } catch (NoSuchAlgorithmException e) { + throw new InternalSSLSocketFactoryException(e); + } catch (CertificateException e) { + throw new InternalSSLSocketFactoryException(e); + } catch (IOException e) { + throw new InternalSSLSocketFactoryException(e); + } catch (KeyStoreException e) { + throw new InternalSSLSocketFactoryException(e); + } catch (UnrecoverableKeyException e) { + throw new InternalSSLSocketFactoryException(e); + } catch (KeyManagementException e) { + throw new InternalSSLSocketFactoryException(e); + } + + this.factory = sslContext.getSocketFactory(); + } + + class AcceptAllTrustManager implements X509TrustManager { + + public X509Certificate[] getAcceptedIssuers() { + return null; + } + + public void checkClientTrusted(X509Certificate[] chain, String authType) { + } + + public void checkServerTrusted(X509Certificate[] chain, String authType) { + //FIXME + } + } +}; diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactoryException.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactoryException.java new file mode 100644 index 00000000..c620284a --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactoryException.java @@ -0,0 +1,45 @@ +/* +* Copyright 2008 Federal Chancellery Austria and +* Graz University of Technology +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package at.gv.egiz.bku.online.applet; + +/** + * + * @author mcentner + */ +public class InternalSSLSocketFactoryException extends Exception { + + public InternalSSLSocketFactoryException(Throwable cause) { + super(cause); + } + + public InternalSSLSocketFactoryException(String message, Throwable cause) { + super(message, cause); + } + + public InternalSSLSocketFactoryException(String message) { + super(message); + } + + public InternalSSLSocketFactoryException() { + } + +} -- cgit v1.2.3 From 63f2a4f1f098cc39bd092fef77a94d73056f51f6 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 5 Sep 2008 13:38:24 +0000 Subject: HashDataInput git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@19 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 4 +- .../at/gv/egiz/bku/online/applet/BKUWorker.java | 543 +++++++++++---------- .../bku/online/applet/WSSignRequestHandler.java | 90 ++++ 3 files changed, 364 insertions(+), 273 deletions(-) create mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 56cc5ea2..5d4d0dab 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -29,9 +29,7 @@ import at.gv.egiz.bku.gui.BKUGUIFacade; import at.gv.egiz.bku.gui.BKUGUIFactory; /** - * - * - * + * Note: all swing code is executed by the event dispatch thread (see BKUGUIFacade) */ public class BKUApplet extends JApplet { diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java index 38fd6428..f7b5fb2f 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java @@ -14,273 +14,276 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package at.gv.egiz.bku.online.applet; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; -import java.util.ResourceBundle; - -import javax.xml.namespace.QName; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import at.gv.egiz.bku.gui.BKUGUIFacade; -import at.gv.egiz.bku.smccstal.AbstractSMCCSTAL; -import at.gv.egiz.bku.smccstal.SMCCSTALRequestHandler; -import at.gv.egiz.smcc.SignatureCard; -import at.gv.egiz.smcc.util.SMCCHelper; -import at.gv.egiz.stal.QuitRequest; -import at.gv.egiz.stal.STALRequest; -import at.gv.egiz.stal.STALResponse; -import at.gv.egiz.stal.service.GetNextRequestResponseType; -import at.gv.egiz.stal.service.GetNextRequestType; -import at.gv.egiz.stal.service.ObjectFactory; -import at.gv.egiz.stal.service.STALPortType; -import at.gv.egiz.stal.service.STALService; - -public class BKUWorker extends AbstractSMCCSTAL implements Runnable, - ActionListener, SMCCSTALRequestHandler { - - private static Log log = LogFactory.getLog(BKUWorker.class); - - protected BKUGUIFacade gui; - protected BKUApplet parent; - private STALPortType stalPort; - protected List actionCommandList = new ArrayList(); - protected Boolean actionPerformed = false; - protected boolean finished = false; - protected ResourceBundle errorMessages; - - /** - * - * @param gui - * must not be null - */ - public BKUWorker(BKUGUIFacade gui, BKUApplet parent, - ResourceBundle errorMessageBundle) { - if ((gui == null) || (parent == null) || (errorMessageBundle == null)) { - throw new NullPointerException("Parameter must not be set to null"); - } - this.gui = gui; - this.parent = parent; - this.errorMessages = errorMessageBundle; - addRequestHandler(QuitRequest.class, this); - } - - private STALPortType getSTALPort() throws MalformedURLException { - URL wsdlURL = null; - String wsdlLocation = parent.getMyAppletParameter(BKUApplet.WSDL_URL); - URL codebase = parent.getCodeBase(); - log.debug("Connecting to webservice: " + wsdlLocation); - if (wsdlLocation != null) { - try { - if (codebase.getProtocol().equalsIgnoreCase("file")) { - // for debugging in appletrunner - wsdlURL = new URL(wsdlLocation); - } else { - wsdlURL = new URL(codebase, wsdlLocation); - } - } catch (MalformedURLException ex) { - log.fatal("Paremeter 'wsdlLocation' is not a vailid URL.", ex); - throw new MalformedURLException(ex.getMessage()); - } - } else { - log.fatal("Paremeter 'wsdlLocation' is not set."); - throw new MalformedURLException("Null WSDL url"); - } - log.debug("Found WSDL url: " + wsdlURL); - QName endpointName = new QName("http://www.egiz.gv.at/wsdl/stal", - "STALService"); - STALService stal = new STALService(wsdlURL, endpointName); - return stal.getSTALPort(); - } - - @Override - public void run() { - gui.showWelcomeDialog(); - try { - stalPort = getSTALPort(); - } catch (Exception e) { - log.fatal("Failed to call STAL service.", e); - actionCommandList.clear(); - actionCommandList.add("ok"); - gui.showErrorDialog(errorMessages.getString("failed.WS")); - try { - waitForAction(); - } catch (InterruptedException e1) { - log.error(e1); - } - return; - } - - ObjectFactory factory = new ObjectFactory(); - GetNextRequestType nextRequest = factory.createGetNextRequestType(); - - String sessionId = parent.getMyAppletParameter(BKUApplet.SESSION_ID); - if (sessionId == null) { - // use the testsession for testing - sessionId = "TestSession"; - } - nextRequest.setSessionId(sessionId); - do { - GetNextRequestResponseType resp = stalPort.getNextRequest(nextRequest); - log.info("Got " + resp.getRequest().size() + " requests from server."); - List stalRequests = resp.getRequest(); - List responses = handleRequest(stalRequests); - log.info("Got " + responses.size() + " responses."); - nextRequest = factory.createGetNextRequestType(); - nextRequest.setSessionId(sessionId); - nextRequest.getResponse().addAll(responses); - } while (!finished); - log.info("Done " + Thread.currentThread().getName()); - gui.showWelcomeDialog(); - sendRedirect(); - } - - protected void sendRedirect() { - log.info("Done, sending redirect to get BKU response"); - String redirectURL = parent.getMyAppletParameter("redirectURL"); - String redirectTarget = parent.getMyAppletParameter("redirectTarget"); - log.info("Redirecting to: " + redirectURL + " target: " + redirectTarget); - URL url = null; - if (redirectURL != null) { - try { - url = new URL(parent.getCodeBase(),redirectURL + ";jsessionid=" - + parent.getMyAppletParameter(BKUApplet.SESSION_ID)); - } catch (MalformedURLException ex) { - log.warn("Parameter 'redirectURL': " + redirectURL - + " not a valid URL.", ex); - // gui.showErrorDialog(errorMsg, okListener, actionCommand) - } - if (url != null) { - if (redirectTarget == null) { - log.info("Done. Trying to redirect to " + url + " ..."); - parent.getAppletContext().showDocument(url); - } else { - log.info("Done. Trying to redirect to " + url + " (target=" - + redirectTarget + ") ..."); - parent.getAppletContext().showDocument(url, redirectTarget); - } - } - } else { - log.error("No redirect URL set"); - } - } - - protected synchronized void waitForAction() throws InterruptedException { - log.info("Waiting for Action"); - while (!actionPerformed) { - wait(); - } - actionPerformed = false; - } - - protected synchronized void actionOccured() { - log.info("Received Action"); - actionPerformed = true; - notifyAll(); - } - - @Override - public void actionPerformed(ActionEvent e) { - log.info("Action: " + e); - if (actionCommandList != null) { - if (actionCommandList.contains(e.getActionCommand())) { - actionOccured(); - } - } else { - actionOccured(); - } - } - - @Override - protected boolean waitForCard() { - SMCCHelper smccHelper = new SMCCHelper(); - actionCommandList.clear(); - actionCommandList.add("cancel"); - // while no sigcard found or cancel button pressed - int oldValue = SMCCHelper.PC_SC_NOT_SUPPORTED; // this is a save default - while ((signatureCard == null) && (!actionPerformed)) { - switch (smccHelper.getResultCode()) { - case SMCCHelper.PC_SC_NOT_SUPPORTED: - actionCommandList.clear(); - actionCommandList.add("ok"); - gui.showErrorDialog(errorMessages.getString("nopcscsupport"), this, - "ok"); - try { - waitForAction(); - } catch (InterruptedException e) { - log.error(e); - } - return true; - case SMCCHelper.TERMINAL_NOT_PRESENT: - actionCommandList.clear(); - actionCommandList.add("ok"); - gui.showErrorDialog(errorMessages.getString("nocardterminal"), this, - "ok"); - try { - waitForAction(); - } catch (InterruptedException e) { - log.error(e); - } - return true; - case SMCCHelper.CARD_NOT_SUPPORTED: - if (oldValue != SMCCHelper.CARD_NOT_SUPPORTED) { - actionCommandList.clear(); - actionCommandList.add("cancel"); - gui.showCardNotSupportedDialog(this, "cancel"); - oldValue = SMCCHelper.CARD_NOT_SUPPORTED; - } - break; - case SMCCHelper.NO_CARD: - if (oldValue != SMCCHelper.NO_CARD) { - actionCommandList.clear(); - actionCommandList.add("cancel"); - gui.showInsertCardDialog(this, "cancel"); - oldValue = SMCCHelper.NO_CARD; - } - break; - case SMCCHelper.CARD_FOUND: - gui.showWelcomeDialog(); - signatureCard = smccHelper.getSignatureCard(errorMessages.getLocale()); - return false; - } - smccHelper.update(3000); - } - return signatureCard == null; - } - - @Override - public STALResponse handleRequest(STALRequest request) { - if (request instanceof QuitRequest) { - finished = true; - } else { - log.error("Unexpected request to handle: " + request); - } - return null; - } - - @Override - public void init(SignatureCard sc, BKUGUIFacade gui) { - } - - @Override - public SMCCSTALRequestHandler newInstance() { - return this; - } - - @Override - public boolean requireCard() { - return false; - } - - @Override - protected BKUGUIFacade getGUI() { - return gui; - } -} +package at.gv.egiz.bku.online.applet; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.ResourceBundle; + +import javax.xml.namespace.QName; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.bku.smccstal.AbstractSMCCSTAL; +import at.gv.egiz.bku.smccstal.SMCCSTALRequestHandler; +import at.gv.egiz.smcc.SignatureCard; +import at.gv.egiz.smcc.util.SMCCHelper; +import at.gv.egiz.stal.QuitRequest; +import at.gv.egiz.stal.STALRequest; +import at.gv.egiz.stal.STALResponse; +import at.gv.egiz.stal.SignRequest; +import at.gv.egiz.stal.service.GetNextRequestResponseType; +import at.gv.egiz.stal.service.GetNextRequestType; +import at.gv.egiz.stal.service.ObjectFactory; +import at.gv.egiz.stal.service.STALPortType; +import at.gv.egiz.stal.service.STALService; + +public class BKUWorker extends AbstractSMCCSTAL implements Runnable, + ActionListener, SMCCSTALRequestHandler { + + private static Log log = LogFactory.getLog(BKUWorker.class); + + protected BKUGUIFacade gui; + protected BKUApplet parent; + private STALPortType stalPort; + protected List actionCommandList = new ArrayList(); + protected Boolean actionPerformed = false; + protected boolean finished = false; + protected ResourceBundle errorMessages; + + /** + * + * @param gui + * must not be null + */ + public BKUWorker(BKUGUIFacade gui, BKUApplet parent, + ResourceBundle errorMessageBundle) { + if ((gui == null) || (parent == null) || (errorMessageBundle == null)) { + throw new NullPointerException("Parameter must not be set to null"); + } + this.gui = gui; + this.parent = parent; + this.errorMessages = errorMessageBundle; + addRequestHandler(QuitRequest.class, this); + //register SignRequestHandler once we have a webservice port + } + + private STALPortType getSTALPort() throws MalformedURLException { + URL wsdlURL = null; + String wsdlLocation = parent.getMyAppletParameter(BKUApplet.WSDL_URL); + URL codebase = parent.getCodeBase(); + log.debug("Connecting to webservice: " + wsdlLocation); + if (wsdlLocation != null) { + try { + if (codebase.getProtocol().equalsIgnoreCase("file")) { + // for debugging in appletrunner + wsdlURL = new URL(wsdlLocation); + } else { + wsdlURL = new URL(codebase, wsdlLocation); + } + } catch (MalformedURLException ex) { + log.fatal("Paremeter 'wsdlLocation' is not a vailid URL.", ex); + throw new MalformedURLException(ex.getMessage()); + } + } else { + log.fatal("Paremeter 'wsdlLocation' is not set."); + throw new MalformedURLException("Null WSDL url"); + } + log.debug("Found WSDL url: " + wsdlURL); + QName endpointName = new QName("http://www.egiz.gv.at/wsdl/stal", + "STALService"); + STALService stal = new STALService(wsdlURL, endpointName); + return stal.getSTALPort(); + } + + @Override + public void run() { + gui.showWelcomeDialog(); + try { + stalPort = getSTALPort(); + } catch (Exception e) { + log.fatal("Failed to call STAL service.", e); + actionCommandList.clear(); + actionCommandList.add("ok"); + gui.showErrorDialog(errorMessages.getString("failed.WS")); + try { + waitForAction(); + } catch (InterruptedException e1) { + log.error(e1); + } + return; + } + + ObjectFactory factory = new ObjectFactory(); + GetNextRequestType nextRequest = factory.createGetNextRequestType(); + + String sessionId = parent.getMyAppletParameter(BKUApplet.SESSION_ID); + if (sessionId == null) { + // use the testsession for testing + sessionId = "TestSession"; + } + nextRequest.setSessionId(sessionId); + addRequestHandler(SignRequest.class, new WSSignRequestHandler(sessionId, stalPort)); + do { + GetNextRequestResponseType resp = stalPort.getNextRequest(nextRequest); + log.info("Got " + resp.getRequest().size() + " requests from server."); + List stalRequests = resp.getRequest(); + List responses = handleRequest(stalRequests); + log.info("Got " + responses.size() + " responses."); + nextRequest = factory.createGetNextRequestType(); + nextRequest.setSessionId(sessionId); + nextRequest.getResponse().addAll(responses); + } while (!finished); + log.info("Done " + Thread.currentThread().getName()); + gui.showWelcomeDialog(); + sendRedirect(); + } + + protected void sendRedirect() { + log.info("Done, sending redirect to get BKU response"); + String redirectURL = parent.getMyAppletParameter("redirectURL"); + String redirectTarget = parent.getMyAppletParameter("redirectTarget"); + log.info("Redirecting to: " + redirectURL + " target: " + redirectTarget); + URL url = null; + if (redirectURL != null) { + try { + url = new URL(parent.getCodeBase(),redirectURL + ";jsessionid=" + + parent.getMyAppletParameter(BKUApplet.SESSION_ID)); + } catch (MalformedURLException ex) { + log.warn("Parameter 'redirectURL': " + redirectURL + + " not a valid URL.", ex); + // gui.showErrorDialog(errorMsg, okListener, actionCommand) + } + if (url != null) { + if (redirectTarget == null) { + log.info("Done. Trying to redirect to " + url + " ..."); + parent.getAppletContext().showDocument(url); + } else { + log.info("Done. Trying to redirect to " + url + " (target=" + + redirectTarget + ") ..."); + parent.getAppletContext().showDocument(url, redirectTarget); + } + } + } else { + log.error("No redirect URL set"); + } + } + + protected synchronized void waitForAction() throws InterruptedException { + log.info("Waiting for Action"); + while (!actionPerformed) { + wait(); + } + actionPerformed = false; + } + + protected synchronized void actionOccured() { + log.info("Received Action"); + actionPerformed = true; + notifyAll(); + } + + @Override + public void actionPerformed(ActionEvent e) { + log.info("Action: " + e); + if (actionCommandList != null) { + if (actionCommandList.contains(e.getActionCommand())) { + actionOccured(); + } + } else { + actionOccured(); + } + } + + @Override + protected boolean waitForCard() { + SMCCHelper smccHelper = new SMCCHelper(); + actionCommandList.clear(); + actionCommandList.add("cancel"); + // while no sigcard found or cancel button pressed + int oldValue = SMCCHelper.PC_SC_NOT_SUPPORTED; // this is a save default + while ((signatureCard == null) && (!actionPerformed)) { + switch (smccHelper.getResultCode()) { + case SMCCHelper.PC_SC_NOT_SUPPORTED: + actionCommandList.clear(); + actionCommandList.add("ok"); + gui.showErrorDialog(errorMessages.getString("nopcscsupport"), this, + "ok"); + try { + waitForAction(); + } catch (InterruptedException e) { + log.error(e); + } + return true; + case SMCCHelper.TERMINAL_NOT_PRESENT: + actionCommandList.clear(); + actionCommandList.add("ok"); + gui.showErrorDialog(errorMessages.getString("nocardterminal"), this, + "ok"); + try { + waitForAction(); + } catch (InterruptedException e) { + log.error(e); + } + return true; + case SMCCHelper.CARD_NOT_SUPPORTED: + if (oldValue != SMCCHelper.CARD_NOT_SUPPORTED) { + actionCommandList.clear(); + actionCommandList.add("cancel"); + gui.showCardNotSupportedDialog(this, "cancel"); + oldValue = SMCCHelper.CARD_NOT_SUPPORTED; + } + break; + case SMCCHelper.NO_CARD: + if (oldValue != SMCCHelper.NO_CARD) { + actionCommandList.clear(); + actionCommandList.add("cancel"); + gui.showInsertCardDialog(this, "cancel"); + oldValue = SMCCHelper.NO_CARD; + } + break; + case SMCCHelper.CARD_FOUND: + gui.showWelcomeDialog(); + signatureCard = smccHelper.getSignatureCard(errorMessages.getLocale()); + return false; + } + smccHelper.update(3000); + } + return signatureCard == null; + } + + @Override + public STALResponse handleRequest(STALRequest request) { + if (request instanceof QuitRequest) { + finished = true; + } else { + log.error("Unexpected request to handle: " + request); + } + return null; + } + + @Override + public void init(SignatureCard sc, BKUGUIFacade gui) { + } + + @Override + public SMCCSTALRequestHandler newInstance() { + return this; + } + + @Override + public boolean requireCard() { + return false; + } + + @Override + protected BKUGUIFacade getGUI() { + return gui; + } +} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java new file mode 100644 index 00000000..f9965240 --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java @@ -0,0 +1,90 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package at.gv.egiz.bku.online.applet; + +import at.gv.egiz.stal.HashDataInput; +import at.gv.egiz.bku.smccstal.SMCCSTALRequestHandler; +import at.gv.egiz.bku.smccstal.SignRequestHandler; +import at.gv.egiz.stal.impl.ByteArrayHashDataInput; +import at.gv.egiz.stal.service.GetHashDataInputResponseType; +import at.gv.egiz.stal.service.GetHashDataInputType; +import at.gv.egiz.stal.service.STALPortType; +import at.gv.egiz.stal.signedinfo.ReferenceType; +import java.util.ArrayList; +import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author clemens + */ +public class WSSignRequestHandler extends SignRequestHandler { + + private static final Log log = LogFactory.getLog(WSSignRequestHandler.class); + STALPortType stalPort; + String sessId; + + public WSSignRequestHandler(String sessId, STALPortType stalPort) { + if (stalPort == null || sessId == null) { + throw new NullPointerException("STAL port must not be null"); + } + this.sessId = sessId; + this.stalPort = stalPort; + } + + @Override + protected List getHashDataInputs(List dsigReferences) throws Exception { + GetHashDataInputType request = new GetHashDataInputType(); + request.setSessionId(sessId); + for (ReferenceType dsigRef : dsigReferences) { + //don't get Manifest, QualifyingProperties, ... + if (dsigRef.getType() == null) { + String dsigRefId = dsigRef.getId(); + if (dsigRefId != null) { + GetHashDataInputType.Reference reference = new GetHashDataInputType.Reference(); + reference.setID(dsigRefId); + request.getReference().add(reference); + } else { + throw new Exception("Cannot get HashDataInput for dsig:Reference without Id attribute"); + } + } + } + + if (log.isDebugEnabled()) { + log.debug("Calling GetHashDataInput for session " + sessId); + } + GetHashDataInputResponseType response = stalPort.getHashDataInput(request); + ArrayList hashDataInputs = new ArrayList(); + for (GetHashDataInputResponseType.Reference reference : response.getReference()) { + byte[] hdi = reference.getValue(); + String id = reference.getID(); + String mimeType = reference.getMimeType(); + + if (log.isDebugEnabled()) { + log.debug("Got HashDataInput " + id + " (" + mimeType + ")"); + } + hashDataInputs.add(new ByteArrayHashDataInput(hdi, id, mimeType)); + } + return hashDataInputs; + } + + @Override + public SMCCSTALRequestHandler newInstance() { + return new WSSignRequestHandler(this.sessId, this.stalPort); + } +} -- cgit v1.2.3 From c7cbf8a12db4fcb77fd374392e88c3fa04b1e100 Mon Sep 17 00:00:00 2001 From: wbauer Date: Tue, 9 Sep 2008 09:54:32 +0000 Subject: added check to avoid sending baseid to non .gv.at domains git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@25 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 139 ++++++------ .../at/gv/egiz/bku/online/applet/BKUWorker.java | 25 ++- .../online/applet/InternalSSLSocketFactory.java | 237 +++++++++++++-------- .../applet/InternalSSLSocketFactoryException.java | 45 ---- 4 files changed, 240 insertions(+), 206 deletions(-) delete mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactoryException.java (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 5d4d0dab..8289f30b 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -1,19 +1,19 @@ /* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package at.gv.egiz.bku.online.applet; import java.util.Locale; @@ -29,71 +29,68 @@ import at.gv.egiz.bku.gui.BKUGUIFacade; import at.gv.egiz.bku.gui.BKUGUIFactory; /** - * Note: all swing code is executed by the event dispatch thread (see BKUGUIFacade) + * Note: all swing code is executed by the event dispatch thread (see + * BKUGUIFacade) */ public class BKUApplet extends JApplet { - private static Log log = LogFactory.getLog(BKUApplet.class); + private static Log log = LogFactory.getLog(BKUApplet.class); + + public final static String RESOURCE_BUNDLE_BASE = "at/gv/egiz/bku/online/applet/Messages"; - public final static String RESOURCE_BUNDLE_BASE = "at/gv/egiz/bku/online/applet/Messages"; + public final static String LOCALE_PARAM_KEY = "Locale"; + public final static String LOGO_URL_KEY = "LogoURL"; + public final static String WSDL_URL = "WSDL_URL"; + public final static String SESSION_ID = "SessionID"; - public final static String LOCALE_PARAM_KEY = "Locale"; - public final static String LOGO_URL_KEY="LogoURL"; - public final static String WSDL_URL="WSDL_URL"; - public final static String SESSION_ID="SessionID"; + protected ResourceBundle resourceBundle; + protected BKUWorker worker; + protected Thread workerThread; - protected ResourceBundle resourceBundle; - protected BKUWorker worker; - protected Thread workerThread; - - public BKUApplet() { - } + public BKUApplet() { + } - public void init() { - log.debug("Called init()"); - try { - HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getSocketFactory()); - HttpsURLConnection.setDefaultHostnameVerifier(InternalSSLSocketFactory.getHostNameVerifier()); - } catch (InternalSSLSocketFactoryException e) { - log.error(e); - } - String localeString = getMyAppletParameter(LOCALE_PARAM_KEY); - if (localeString != null) { - resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE, - new Locale(localeString)); - } else { - resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE); - } - BKUGUIFacade gui = BKUGUIFactory.createGUI(); - gui.init(getContentPane(), localeString); - worker = new BKUWorker(gui, this, resourceBundle); - } + public void init() { + log.debug("Called init()"); + HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory + .getInstance()); + String localeString = getMyAppletParameter(LOCALE_PARAM_KEY); + if (localeString != null) { + resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE, + new Locale(localeString)); + } else { + resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE); + } + BKUGUIFacade gui = BKUGUIFactory.createGUI(); + gui.init(getContentPane(), localeString); + worker = new BKUWorker(gui, this, resourceBundle); + } - public void start() { - log.debug("Called start()"); - workerThread = new Thread(worker); - workerThread.start(); - } + public void start() { + log.debug("Called start()"); + workerThread = new Thread(worker); + workerThread.start(); + } - public void stop() { - log.debug("Called stop()"); - if ((workerThread != null) && (workerThread.isAlive())) { - workerThread.interrupt(); - } - } + public void stop() { + log.debug("Called stop()"); + if ((workerThread != null) && (workerThread.isAlive())) { + workerThread.interrupt(); + } + } - public void destroy() { - log.debug("Called destroy()"); - } + public void destroy() { + log.debug("Called destroy()"); + } - /** - * Applet configuration parameters - * - * @param paramKey - * @return - */ - public String getMyAppletParameter(String paramKey) { - log.info("Getting parameter: "+paramKey+ ": "+ getParameter(paramKey)); - return getParameter(paramKey); - } + /** + * Applet configuration parameters + * + * @param paramKey + * @return + */ + public String getMyAppletParameter(String paramKey) { + log.info("Getting parameter: " + paramKey + ": " + getParameter(paramKey)); + return getParameter(paramKey); + } } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java index f7b5fb2f..042c6a83 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java @@ -34,6 +34,8 @@ import at.gv.egiz.bku.smccstal.AbstractSMCCSTAL; import at.gv.egiz.bku.smccstal.SMCCSTALRequestHandler; import at.gv.egiz.smcc.SignatureCard; import at.gv.egiz.smcc.util.SMCCHelper; +import at.gv.egiz.stal.ErrorResponse; +import at.gv.egiz.stal.InfoboxReadRequest; import at.gv.egiz.stal.QuitRequest; import at.gv.egiz.stal.STALRequest; import at.gv.egiz.stal.STALResponse; @@ -107,6 +109,8 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, gui.showWelcomeDialog(); try { stalPort = getSTALPort(); + + } catch (Exception e) { log.fatal("Failed to call STAL service.", e); actionCommandList.clear(); @@ -134,7 +138,26 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, GetNextRequestResponseType resp = stalPort.getNextRequest(nextRequest); log.info("Got " + resp.getRequest().size() + " requests from server."); List stalRequests = resp.getRequest(); - List responses = handleRequest(stalRequests); + boolean handle = true; + for (STALRequest request : stalRequests) { + if (request instanceof InfoboxReadRequest) { + InfoboxReadRequest infobx = (InfoboxReadRequest) request; + if (infobx.getInfoboxIdentifier().equals("IdentityLink")) { + if (infobx.getDomainIdentifier() == null) { + if (!InternalSSLSocketFactory.getInstance().isEgovAgency()) { + handle = false; + } + } + } + } + } + List responses; + if (handle) { + responses = handleRequest(stalRequests); + } else { + responses = new ArrayList(1); + responses.add(new ErrorResponse(6002)); + } log.info("Got " + responses.size() + " responses."); nextRequest = factory.createGetNextRequestType(); nextRequest.setSessionId(sessionId); diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java index ab04d2b6..79c369a2 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java @@ -1,19 +1,19 @@ /* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /* * To change this template, choose Tools | Templates * and open the template in the editor. @@ -22,80 +22,139 @@ package at.gv.egiz.bku.online.applet; import java.io.IOException; -import java.security.KeyManagementException; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.UnrecoverableKeyException; -import java.security.cert.CertificateException; +import java.net.InetAddress; +import java.net.Socket; +import java.net.UnknownHostException; +import java.security.cert.CertificateParsingException; import java.security.cert.X509Certificate; +import java.util.Collection; +import java.util.List; -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLPeerUnverifiedException; +import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; -import javax.net.ssl.X509TrustManager; - -public class InternalSSLSocketFactory { - - private SSLSocketFactory factory; - - public static SSLSocketFactory getSocketFactory() throws InternalSSLSocketFactoryException { - return new InternalSSLSocketFactory().factory; - } - - public static HostnameVerifier getHostNameVerifier() throws InternalSSLSocketFactoryException { - return (new HostnameVerifier() { - @Override - public boolean verify(String hostname, SSLSession session) { - return true; - } - }); - } - - public InternalSSLSocketFactory() throws InternalSSLSocketFactoryException { - SSLContext sslContext; - try { - sslContext = SSLContext.getInstance("TLSv1"); - sslContext.getClientSessionContext().setSessionTimeout(0); - KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509"); - - KeyStore keyStore = KeyStore.getInstance("JKS"); - keyStore.load(null, null); - keyManagerFactory.init(keyStore, null); - - sslContext.init(keyManagerFactory.getKeyManagers(), - new X509TrustManager[] { new AcceptAllTrustManager() }, - null); - } catch (NoSuchAlgorithmException e) { - throw new InternalSSLSocketFactoryException(e); - } catch (CertificateException e) { - throw new InternalSSLSocketFactoryException(e); - } catch (IOException e) { - throw new InternalSSLSocketFactoryException(e); - } catch (KeyStoreException e) { - throw new InternalSSLSocketFactoryException(e); - } catch (UnrecoverableKeyException e) { - throw new InternalSSLSocketFactoryException(e); - } catch (KeyManagementException e) { - throw new InternalSSLSocketFactoryException(e); - } - - this.factory = sslContext.getSocketFactory(); - } - - class AcceptAllTrustManager implements X509TrustManager { - - public X509Certificate[] getAcceptedIssuers() { - return null; - } - - public void checkClientTrusted(X509Certificate[] chain, String authType) { - } - - public void checkServerTrusted(X509Certificate[] chain, String authType) { - //FIXME - } - } -}; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class InternalSSLSocketFactory extends SSLSocketFactory { + + private static InternalSSLSocketFactory instance = new InternalSSLSocketFactory(); + + private final static Log log = LogFactory + .getLog(InternalSSLSocketFactory.class); + + private final static String GOV_DOMAIN = ".gv.at"; + + private SSLSocket sslSocket; + + private SSLSocketFactory proxy; + + private InternalSSLSocketFactory() { + proxy = HttpsURLConnection.getDefaultSSLSocketFactory(); + } + + public static InternalSSLSocketFactory getInstance() { + return instance; + } + + @Override + public Socket createSocket() throws IOException { + sslSocket = (SSLSocket) proxy.createSocket(); + return sslSocket; + } + + @Override + public Socket createSocket(String arg0, int arg1) throws IOException, + UnknownHostException { + sslSocket = (SSLSocket) proxy.createSocket(arg0, arg1); + + return sslSocket; + } + + @Override + public Socket createSocket(InetAddress arg0, int arg1) throws IOException { + sslSocket = (SSLSocket) proxy.createSocket(arg0, arg1); + return sslSocket; + } + + @Override + public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) + throws IOException, UnknownHostException { + sslSocket = (SSLSocket) proxy.createSocket(arg0, arg1, arg2, arg3); + return sslSocket; + } + + @Override + public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, + int arg3) throws IOException { + sslSocket = (SSLSocket) proxy.createSocket(arg0, arg1, arg2, arg3); + return sslSocket; + } + + @Override + public Socket createSocket(Socket arg0, String arg1, int arg2, boolean arg3) + throws IOException { + sslSocket = (SSLSocket) proxy.createSocket(arg0, arg1, arg2, arg3); + return sslSocket; + } + + @Override + public String[] getDefaultCipherSuites() { + return proxy.getDefaultCipherSuites(); + } + + @Override + public String[] getSupportedCipherSuites() { + return proxy.getSupportedCipherSuites(); + } + + public boolean isEgovAgency() { + log.info("Checking if server is egov agency"); + if (sslSocket != null) { + try { + X509Certificate cert = (X509Certificate) sslSocket.getSession() + .getPeerCertificates()[0]; + log.info("Server cert: " + cert); + return isGovAgency(cert); + } catch (SSLPeerUnverifiedException e) { + log.error(e); + return false; + } + } + log.info("Not a SSL connection"); + return false; + } + + public static boolean isGovAgency(X509Certificate cert) { + String[] rdns = (cert.getSubjectX500Principal().getName()).split(","); + for (String rdn : rdns) { + if (rdn.startsWith("CN=")) { + String dns = rdn.split("=")[1]; + if (dns.endsWith(GOV_DOMAIN)) { + return true; + } + } + } + try { + Collection> sanList = cert.getSubjectAlternativeNames(); + if (sanList != null) { + for (List san : sanList) { + if ((Integer) san.get(0) == 2) { + String dns = (String) san.get(1); + if (dns.endsWith(GOV_DOMAIN)) { + return true; + } + } + } + } + } catch (CertificateParsingException e) { + log.error(e); + } + if (cert.getExtensionValue("1.2.40.0.10.1.1.1") != null) { + return true; + } + return false; + } +} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactoryException.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactoryException.java deleted file mode 100644 index c620284a..00000000 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactoryException.java +++ /dev/null @@ -1,45 +0,0 @@ -/* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package at.gv.egiz.bku.online.applet; - -/** - * - * @author mcentner - */ -public class InternalSSLSocketFactoryException extends Exception { - - public InternalSSLSocketFactoryException(Throwable cause) { - super(cause); - } - - public InternalSSLSocketFactoryException(String message, Throwable cause) { - super(message, cause); - } - - public InternalSSLSocketFactoryException(String message) { - super(message); - } - - public InternalSSLSocketFactoryException() { - } - -} -- cgit v1.2.3 From a3361b40aa8f92849c50db27e349e17b87bebb1e Mon Sep 17 00:00:00 2001 From: wbauer Date: Tue, 9 Sep 2008 12:40:52 +0000 Subject: improved security handling and added shutdown handler git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@27 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java index 79c369a2..fa3587e4 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java @@ -40,13 +40,13 @@ import org.apache.commons.logging.LogFactory; public class InternalSSLSocketFactory extends SSLSocketFactory { + private final static String GOV_DOMAIN = ".gv.at"; + private static InternalSSLSocketFactory instance = new InternalSSLSocketFactory(); private final static Log log = LogFactory .getLog(InternalSSLSocketFactory.class); - private final static String GOV_DOMAIN = ".gv.at"; - private SSLSocket sslSocket; private SSLSocketFactory proxy; -- cgit v1.2.3 From bdc1c691b571e55f6806d3ac9bc3dad4fcb2691d Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 10 Sep 2008 16:53:40 +0000 Subject: waitDialog git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@29 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java index 042c6a83..51ac243c 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java @@ -272,7 +272,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, } break; case SMCCHelper.CARD_FOUND: - gui.showWelcomeDialog(); + gui.showWaitDialog(null); signatureCard = smccHelper.getSignatureCard(errorMessages.getLocale()); return false; } -- cgit v1.2.3 From 3794536434fdbb06067eddcfd248898ce85f85a1 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 12 Sep 2008 13:06:34 +0000 Subject: gui 0.2 git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@34 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 102 ++++++++++----------- 1 file changed, 49 insertions(+), 53 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 8289f30b..c7df0871 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -34,63 +34,59 @@ import at.gv.egiz.bku.gui.BKUGUIFactory; */ public class BKUApplet extends JApplet { - private static Log log = LogFactory.getLog(BKUApplet.class); + private static Log log = LogFactory.getLog(BKUApplet.class); + public final static String RESOURCE_BUNDLE_BASE = "at/gv/egiz/bku/online/applet/Messages"; + public final static String LOCALE_PARAM_KEY = "Locale"; + public final static String LOGO_URL_KEY = "LogoURL"; + public final static String WSDL_URL = "WSDL_URL"; + public final static String SESSION_ID = "SessionID"; + protected ResourceBundle resourceBundle; + protected BKUWorker worker; + protected Thread workerThread; - public final static String RESOURCE_BUNDLE_BASE = "at/gv/egiz/bku/online/applet/Messages"; + public BKUApplet() { + } - public final static String LOCALE_PARAM_KEY = "Locale"; - public final static String LOGO_URL_KEY = "LogoURL"; - public final static String WSDL_URL = "WSDL_URL"; - public final static String SESSION_ID = "SessionID"; + public void init() { + log.debug("Called init()"); + HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getInstance()); + String localeString = getMyAppletParameter(LOCALE_PARAM_KEY); + if (localeString != null) { + resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE, + new Locale(localeString)); + } else { + resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE); + } + BKUGUIFacade gui = BKUGUIFactory.createGUI(); + gui.init(getContentPane(), localeString); + worker = new BKUWorker(gui, this, resourceBundle); + } - protected ResourceBundle resourceBundle; - protected BKUWorker worker; - protected Thread workerThread; + public void start() { + log.debug("Called start()"); + workerThread = new Thread(worker); + workerThread.start(); + } - public BKUApplet() { - } + public void stop() { + log.debug("Called stop()"); + if ((workerThread != null) && (workerThread.isAlive())) { + workerThread.interrupt(); + } + } - public void init() { - log.debug("Called init()"); - HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory - .getInstance()); - String localeString = getMyAppletParameter(LOCALE_PARAM_KEY); - if (localeString != null) { - resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE, - new Locale(localeString)); - } else { - resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE); - } - BKUGUIFacade gui = BKUGUIFactory.createGUI(); - gui.init(getContentPane(), localeString); - worker = new BKUWorker(gui, this, resourceBundle); - } + public void destroy() { + log.debug("Called destroy()"); + } - public void start() { - log.debug("Called start()"); - workerThread = new Thread(worker); - workerThread.start(); - } - - public void stop() { - log.debug("Called stop()"); - if ((workerThread != null) && (workerThread.isAlive())) { - workerThread.interrupt(); - } - } - - public void destroy() { - log.debug("Called destroy()"); - } - - /** - * Applet configuration parameters - * - * @param paramKey - * @return - */ - public String getMyAppletParameter(String paramKey) { - log.info("Getting parameter: " + paramKey + ": " + getParameter(paramKey)); - return getParameter(paramKey); - } + /** + * Applet configuration parameters + * + * @param paramKey + * @return + */ + public String getMyAppletParameter(String paramKey) { + log.info("Getting parameter: " + paramKey + ": " + getParameter(paramKey)); + return getParameter(paramKey); + } } -- cgit v1.2.3 From 0df8bb10302989f41ed420ec0ff29b2fc2005471 Mon Sep 17 00:00:00 2001 From: wbauer Date: Mon, 15 Sep 2008 14:18:53 +0000 Subject: Migrated BKULocal to BKUCommonGUI and minor bug fixes git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@37 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java index 51ac243c..cd96a481 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java @@ -75,6 +75,17 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, addRequestHandler(QuitRequest.class, this); //register SignRequestHandler once we have a webservice port } + + /** + * Used for non applet variants + * @param gui + * @param errorMessageBundle + */ + protected BKUWorker(BKUGUIFacade gui, ResourceBundle errorMessageBundle) { + this.gui = gui; + this.errorMessages = errorMessageBundle; + addRequestHandler(QuitRequest.class, this); + } private STALPortType getSTALPort() throws MalformedURLException { URL wsdlURL = null; -- cgit v1.2.3 From 677bff2bdb7b2cb327930f0596d5f3133363295c Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 15 Sep 2008 18:00:30 +0000 Subject: encoding git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@38 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java index f9965240..5186de1a 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java @@ -74,11 +74,12 @@ public class WSSignRequestHandler extends SignRequestHandler { byte[] hdi = reference.getValue(); String id = reference.getID(); String mimeType = reference.getMimeType(); + String encoding = reference.getEncoding(); if (log.isDebugEnabled()) { - log.debug("Got HashDataInput " + id + " (" + mimeType + ")"); + log.debug("Got HashDataInput " + id + " (" + mimeType + ";" + encoding + ")"); } - hashDataInputs.add(new ByteArrayHashDataInput(hdi, id, mimeType)); + hashDataInputs.add(new ByteArrayHashDataInput(hdi, id, mimeType, encoding)); } return hashDataInputs; } -- cgit v1.2.3 From cf82096145bbdd548e388c1bc25f0e703b9b4624 Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 17 Sep 2008 17:17:10 +0000 Subject: hashdatainput digest verification git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@44 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../bku/online/applet/WSSignRequestHandler.java | 139 ++++++++++++++------- 1 file changed, 94 insertions(+), 45 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java index 5186de1a..6dae264c 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java @@ -16,15 +16,20 @@ */ package at.gv.egiz.bku.online.applet; -import at.gv.egiz.stal.HashDataInput; import at.gv.egiz.bku.smccstal.SMCCSTALRequestHandler; import at.gv.egiz.bku.smccstal.SignRequestHandler; +import at.gv.egiz.stal.HashDataInput; import at.gv.egiz.stal.impl.ByteArrayHashDataInput; import at.gv.egiz.stal.service.GetHashDataInputResponseType; import at.gv.egiz.stal.service.GetHashDataInputType; import at.gv.egiz.stal.service.STALPortType; +import at.gv.egiz.stal.signedinfo.DigestMethodType; import at.gv.egiz.stal.signedinfo.ReferenceType; +import java.security.DigestException; +import java.security.MessageDigest; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -35,57 +40,101 @@ import org.apache.commons.logging.LogFactory; */ public class WSSignRequestHandler extends SignRequestHandler { - private static final Log log = LogFactory.getLog(WSSignRequestHandler.class); - STALPortType stalPort; - String sessId; + private static final Log log = LogFactory.getLog(WSSignRequestHandler.class); + STALPortType stalPort; + String sessId; - public WSSignRequestHandler(String sessId, STALPortType stalPort) { - if (stalPort == null || sessId == null) { - throw new NullPointerException("STAL port must not be null"); - } - this.sessId = sessId; - this.stalPort = stalPort; + public WSSignRequestHandler(String sessId, STALPortType stalPort) { + if (stalPort == null || sessId == null) { + throw new NullPointerException("STAL port must not be null"); } + this.sessId = sessId; + this.stalPort = stalPort; + } - @Override - protected List getHashDataInputs(List dsigReferences) throws Exception { - GetHashDataInputType request = new GetHashDataInputType(); - request.setSessionId(sessId); - for (ReferenceType dsigRef : dsigReferences) { - //don't get Manifest, QualifyingProperties, ... - if (dsigRef.getType() == null) { - String dsigRefId = dsigRef.getId(); - if (dsigRefId != null) { - GetHashDataInputType.Reference reference = new GetHashDataInputType.Reference(); - reference.setID(dsigRefId); - request.getReference().add(reference); - } else { - throw new Exception("Cannot get HashDataInput for dsig:Reference without Id attribute"); - } - } - } + @Override + public List getCashedHashDataInputs(List signedReferences) throws Exception { - if (log.isDebugEnabled()) { - log.debug("Calling GetHashDataInput for session " + sessId); - } - GetHashDataInputResponseType response = stalPort.getHashDataInput(request); - ArrayList hashDataInputs = new ArrayList(); - for (GetHashDataInputResponseType.Reference reference : response.getReference()) { - byte[] hdi = reference.getValue(); - String id = reference.getID(); - String mimeType = reference.getMimeType(); - String encoding = reference.getEncoding(); + GetHashDataInputType request = new GetHashDataInputType(); + request.setSessionId(sessId); + + HashMap idRefMap = new HashMap(); + for (ReferenceType reference : signedReferences) { + //don't get Manifest, QualifyingProperties, ... + if (reference.getType() == null) { + String referenceId = reference.getId(); + if (referenceId != null) { + idRefMap.put(referenceId, reference); + GetHashDataInputType.Reference ref = new GetHashDataInputType.Reference(); + ref.setID(referenceId); + request.getReference().add(ref); - if (log.isDebugEnabled()) { - log.debug("Got HashDataInput " + id + " (" + mimeType + ";" + encoding + ")"); - } - hashDataInputs.add(new ByteArrayHashDataInput(hdi, id, mimeType, encoding)); + } else { + throw new Exception("Cannot resolve HashDataInput for reference without Id attribute"); } - return hashDataInputs; + } } - @Override - public SMCCSTALRequestHandler newInstance() { - return new WSSignRequestHandler(this.sessId, this.stalPort); + if (log.isDebugEnabled()) { + log.debug("Calling GetHashDataInput for session " + sessId); } + GetHashDataInputResponseType response = stalPort.getHashDataInput(request); + ArrayList hashDataInputs = new ArrayList(); + + for (GetHashDataInputResponseType.Reference reference : response.getReference()) { + + String id = reference.getID(); + byte[] hdi = reference.getValue(); + if (hdi == null) { + throw new Exception("Failed to resolve digest value for reference " + id); + } + String mimeType = reference.getMimeType(); + String encoding = reference.getEncoding(); + + if (log.isDebugEnabled()) { + log.debug("Got HashDataInput " + id + " (" + mimeType + ";" + encoding + ")"); + } + + ReferenceType dsigRef = idRefMap.get(id); + DigestMethodType dm = dsigRef.getDigestMethod(); + if (dm == null) { + throw new Exception("Failed to verify digest value for reference " + id + ": no digest algorithm"); + } + //TODO + String mdAlg = dm.getAlgorithm(); + if ("http://www.w3.org/2000/09/xmldsig#sha1".equals(mdAlg)) + mdAlg = "SHA-1"; + else if ("http://www.w3.org/2001/04/xmlenc#sha256".equals(mdAlg)) + mdAlg = "SHA-256"; + else if ("http://www.w3.org/2001/04/xmlenc#sha224 ".equals(mdAlg)) + mdAlg = "SHA-224"; + else if ("http://www.w3.org/2001/04/xmldsig-more#sha224 ".equals(mdAlg)) + mdAlg = "SHA-224"; + else if ("http://www.w3.org/2001/04/xmldsig-more#sha384".equals(mdAlg)) + mdAlg = "SHA-384"; + else if ("http://www.w3.org/2001/04/xmlenc#sha512".equals(mdAlg)) + mdAlg = "SHA-512"; + else if ("http://www.w3.org/2001/04/xmldsig-more#md2 ".equals(mdAlg)) + mdAlg = "MD2"; + else if ("http://www.w3.org/2001/04/xmldsig-more#md5".equals(mdAlg)) + mdAlg = "MD5"; + else if ("http://www.w3.org/2001/04/xmlenc#ripemd160 ".equals(mdAlg)) + mdAlg = "RipeMD-160"; + MessageDigest md = MessageDigest.getInstance(mdAlg); + byte[] hdiDigest = md.digest(hdi); + if (log.isDebugEnabled()) + log.debug("Comparing digest values... "); + if (!Arrays.equals(hdiDigest, dsigRef.getDigestValue())) { + log.error("digest values differ: " + new String(hdiDigest) + ", " + new String(dsigRef.getDigestValue())); + throw new DigestException("Bad digest value for reference " + id + ": " + dsigRef.getDigestValue()); + } + hashDataInputs.add(new ByteArrayHashDataInput(hdi, id, mimeType, encoding)); + } + return hashDataInputs; + } + + @Override + public SMCCSTALRequestHandler newInstance() { + return new WSSignRequestHandler(this.sessId, this.stalPort); + } } -- cgit v1.2.3 From 03f5ae9e9068168b294c042d68a58637e71a54ee Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 23 Sep 2008 14:09:02 +0000 Subject: bitte warten... git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@59 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java index cd96a481..465bde78 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java @@ -283,7 +283,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, } break; case SMCCHelper.CARD_FOUND: - gui.showWaitDialog(null); +// gui.showWaitDialog(null); signatureCard = smccHelper.getSignatureCard(errorMessages.getLocale()); return false; } -- cgit v1.2.3 From 0168154a4a0777fd7ae2bc3a097c12b33781d75a Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 24 Sep 2008 13:08:04 +0000 Subject: git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@61 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java | 1 + BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index c7df0871..34dd9bbd 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -48,6 +48,7 @@ public class BKUApplet extends JApplet { } public void init() { + log.info("Welcome to MOCCA\n"); log.debug("Called init()"); HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getInstance()); String localeString = getMyAppletParameter(LOCALE_PARAM_KEY); diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java index 465bde78..8190e5ec 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java @@ -175,7 +175,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, nextRequest.getResponse().addAll(responses); } while (!finished); log.info("Done " + Thread.currentThread().getName()); - gui.showWelcomeDialog(); +// gui.showWelcomeDialog(); sendRedirect(); } -- cgit v1.2.3 From afa2741d7257ee3e98f400e211d96f584c4ef778 Mon Sep 17 00:00:00 2001 From: wbauer Date: Fri, 26 Sep 2008 13:36:57 +0000 Subject: added error dialog for unexpected internal errors git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@74 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/online/applet/BKUWorker.java | 131 +++++++++++---------- 1 file changed, 70 insertions(+), 61 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java index 8190e5ec..35fe652f 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java @@ -1,19 +1,19 @@ /* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package at.gv.egiz.bku.online.applet; import java.awt.event.ActionEvent; @@ -73,11 +73,12 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, this.parent = parent; this.errorMessages = errorMessageBundle; addRequestHandler(QuitRequest.class, this); - //register SignRequestHandler once we have a webservice port + // register SignRequestHandler once we have a webservice port } - + /** * Used for non applet variants + * * @param gui * @param errorMessageBundle */ @@ -96,7 +97,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, try { if (codebase.getProtocol().equalsIgnoreCase("file")) { // for debugging in appletrunner - wsdlURL = new URL(wsdlLocation); + wsdlURL = new URL(wsdlLocation); } else { wsdlURL = new URL(codebase, wsdlLocation); } @@ -120,8 +121,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, gui.showWelcomeDialog(); try { stalPort = getSTALPort(); - - + } catch (Exception e) { log.fatal("Failed to call STAL service.", e); actionCommandList.clear(); @@ -134,48 +134,57 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, } return; } + try { + ObjectFactory factory = new ObjectFactory(); + GetNextRequestType nextRequest = factory.createGetNextRequestType(); - ObjectFactory factory = new ObjectFactory(); - GetNextRequestType nextRequest = factory.createGetNextRequestType(); - - String sessionId = parent.getMyAppletParameter(BKUApplet.SESSION_ID); - if (sessionId == null) { - // use the testsession for testing - sessionId = "TestSession"; - } - nextRequest.setSessionId(sessionId); - addRequestHandler(SignRequest.class, new WSSignRequestHandler(sessionId, stalPort)); - do { - GetNextRequestResponseType resp = stalPort.getNextRequest(nextRequest); - log.info("Got " + resp.getRequest().size() + " requests from server."); - List stalRequests = resp.getRequest(); - boolean handle = true; - for (STALRequest request : stalRequests) { - if (request instanceof InfoboxReadRequest) { - InfoboxReadRequest infobx = (InfoboxReadRequest) request; - if (infobx.getInfoboxIdentifier().equals("IdentityLink")) { - if (infobx.getDomainIdentifier() == null) { - if (!InternalSSLSocketFactory.getInstance().isEgovAgency()) { - handle = false; - } - } - } - } - } - List responses; - if (handle) { - responses = handleRequest(stalRequests); - } else { - responses = new ArrayList(1); - responses.add(new ErrorResponse(6002)); + String sessionId = parent.getMyAppletParameter(BKUApplet.SESSION_ID); + if (sessionId == null) { + // use the testsession for testing + sessionId = "TestSession"; } - log.info("Got " + responses.size() + " responses."); - nextRequest = factory.createGetNextRequestType(); nextRequest.setSessionId(sessionId); - nextRequest.getResponse().addAll(responses); - } while (!finished); - log.info("Done " + Thread.currentThread().getName()); -// gui.showWelcomeDialog(); + addRequestHandler(SignRequest.class, new WSSignRequestHandler(sessionId, + stalPort)); + do { + GetNextRequestResponseType resp = stalPort.getNextRequest(nextRequest); + log.info("Got " + resp.getRequest().size() + " requests from server."); + List stalRequests = resp.getRequest(); + boolean handle = true; + for (STALRequest request : stalRequests) { + if (request instanceof InfoboxReadRequest) { + InfoboxReadRequest infobx = (InfoboxReadRequest) request; + if (infobx.getInfoboxIdentifier().equals("IdentityLink")) { + if (infobx.getDomainIdentifier() == null) { + if (!InternalSSLSocketFactory.getInstance().isEgovAgency()) { + handle = false; + } + } + } + } + } + List responses; + if (handle) { + responses = handleRequest(stalRequests); + } else { + responses = new ArrayList(1); + responses.add(new ErrorResponse(6002)); + } + log.info("Got " + responses.size() + " responses."); + nextRequest = factory.createGetNextRequestType(); + nextRequest.setSessionId(sessionId); + nextRequest.getResponse().addAll(responses); + } while (!finished); + log.info("Done " + Thread.currentThread().getName()); + // gui.showWelcomeDialog(); + } catch (Exception ex) { + gui.showErrorDialog("Sorry, an internal error occured: " + ex.getMessage()); + try { + waitForAction(); + } catch (InterruptedException e) { + log.error(e); + } + } sendRedirect(); } @@ -187,7 +196,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, URL url = null; if (redirectURL != null) { try { - url = new URL(parent.getCodeBase(),redirectURL + ";jsessionid=" + url = new URL(parent.getCodeBase(), redirectURL + ";jsessionid=" + parent.getMyAppletParameter(BKUApplet.SESSION_ID)); } catch (MalformedURLException ex) { log.warn("Parameter 'redirectURL': " + redirectURL @@ -283,7 +292,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, } break; case SMCCHelper.CARD_FOUND: -// gui.showWaitDialog(null); + // gui.showWaitDialog(null); signatureCard = smccHelper.getSignatureCard(errorMessages.getLocale()); return false; } -- cgit v1.2.3 From d0879e9058943c6afa1912ccbeae936db2811f26 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 30 Sep 2008 13:54:54 +0000 Subject: backport to JAXWS2.0 STALService initial connect() git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@76 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/online/applet/BKUWorker.java | 189 ++++++++++++--------- .../bku/online/applet/WSSignRequestHandler.java | 4 +- 2 files changed, 108 insertions(+), 85 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java index 35fe652f..a87b04c4 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java @@ -34,23 +34,23 @@ import at.gv.egiz.bku.smccstal.AbstractSMCCSTAL; import at.gv.egiz.bku.smccstal.SMCCSTALRequestHandler; import at.gv.egiz.smcc.SignatureCard; import at.gv.egiz.smcc.util.SMCCHelper; -import at.gv.egiz.stal.ErrorResponse; -import at.gv.egiz.stal.InfoboxReadRequest; import at.gv.egiz.stal.QuitRequest; import at.gv.egiz.stal.STALRequest; import at.gv.egiz.stal.STALResponse; -import at.gv.egiz.stal.SignRequest; -import at.gv.egiz.stal.service.GetNextRequestResponseType; -import at.gv.egiz.stal.service.GetNextRequestType; -import at.gv.egiz.stal.service.ObjectFactory; +import at.gv.egiz.stal.service.types.GetNextRequestResponseType; +import at.gv.egiz.stal.service.types.GetNextRequestType; +import at.gv.egiz.stal.service.types.ObjectFactory; import at.gv.egiz.stal.service.STALPortType; import at.gv.egiz.stal.service.STALService; +import at.gv.egiz.stal.service.types.ErrorResponseType; +import at.gv.egiz.stal.service.types.RequestType; +import at.gv.egiz.stal.service.types.ResponseType; +import at.gv.egiz.stal.util.STALTranslator; public class BKUWorker extends AbstractSMCCSTAL implements Runnable, - ActionListener, SMCCSTALRequestHandler { + ActionListener, SMCCSTALRequestHandler { private static Log log = LogFactory.getLog(BKUWorker.class); - protected BKUGUIFacade gui; protected BKUApplet parent; private STALPortType stalPort; @@ -65,7 +65,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, * must not be null */ public BKUWorker(BKUGUIFacade gui, BKUApplet parent, - ResourceBundle errorMessageBundle) { + ResourceBundle errorMessageBundle) { if ((gui == null) || (parent == null) || (errorMessageBundle == null)) { throw new NullPointerException("Parameter must not be set to null"); } @@ -73,7 +73,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, this.parent = parent; this.errorMessages = errorMessageBundle; addRequestHandler(QuitRequest.class, this); - // register SignRequestHandler once we have a webservice port + // register SignRequestHandler once we have a webservice port } /** @@ -111,7 +111,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, } log.debug("Found WSDL url: " + wsdlURL); QName endpointName = new QName("http://www.egiz.gv.at/wsdl/stal", - "STALService"); + "STALService"); STALService stal = new STALService(wsdlURL, endpointName); return stal.getSTALPort(); } @@ -135,49 +135,75 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, return; } try { - ObjectFactory factory = new ObjectFactory(); - GetNextRequestType nextRequest = factory.createGetNextRequestType(); - String sessionId = parent.getMyAppletParameter(BKUApplet.SESSION_ID); if (sessionId == null) { // use the testsession for testing sessionId = "TestSession"; } - nextRequest.setSessionId(sessionId); - addRequestHandler(SignRequest.class, new WSSignRequestHandler(sessionId, - stalPort)); + addRequestHandler(at.gv.egiz.stal.SignRequest.class, new WSSignRequestHandler(sessionId, stalPort)); + + ObjectFactory of = new ObjectFactory(); + GetNextRequestResponseType nextRequestResp = stalPort.connect(sessionId); do { - GetNextRequestResponseType resp = stalPort.getNextRequest(nextRequest); - log.info("Got " + resp.getRequest().size() + " requests from server."); - List stalRequests = resp.getRequest(); + List requests = nextRequestResp.getInfoboxReadRequestOrSignRequestOrQuitRequest(); + List stalRequests = STALTranslator.translateRequests(requests); + + if (log.isInfoEnabled()) { + StringBuilder sb = new StringBuilder("Received "); + sb.append(stalRequests.size()); + sb.append(" STAL requests: "); + for (STALRequest r : stalRequests) { + sb.append(r.getClass()); + sb.append(' '); + } + log.info(sb.toString()); + } + boolean handle = true; for (STALRequest request : stalRequests) { - if (request instanceof InfoboxReadRequest) { - InfoboxReadRequest infobx = (InfoboxReadRequest) request; - if (infobx.getInfoboxIdentifier().equals("IdentityLink")) { - if (infobx.getDomainIdentifier() == null) { - if (!InternalSSLSocketFactory.getInstance().isEgovAgency()) { - handle = false; - } + if (request instanceof at.gv.egiz.stal.InfoboxReadRequest) { + at.gv.egiz.stal.InfoboxReadRequest r = (at.gv.egiz.stal.InfoboxReadRequest) request; + String infoboxId = r.getInfoboxIdentifier(); + String domainId = r.getDomainIdentifier(); + if ("IdentityLink".equals(infoboxId) && domainId == null) { + if (!InternalSSLSocketFactory.getInstance().isEgovAgency()) { + handle = false; } } } } - List responses; + + List responses; if (handle) { - responses = handleRequest(stalRequests); + List stalResponses = handleRequest(stalRequests); + if (log.isInfoEnabled()) { + StringBuilder sb = new StringBuilder(stalResponses.size()); + sb.append(" STAL responses: "); + for (STALResponse r : stalResponses) { + sb.append(r.getClass()); + sb.append(' '); + } + log.info(sb.toString()); + } + responses = STALTranslator.fromSTAL(stalResponses); } else { - responses = new ArrayList(1); - responses.add(new ErrorResponse(6002)); + responses = new ArrayList(1); + ErrorResponseType err = new ErrorResponseType(); + err.setErrorCode(6002); +// err.setErrorMessage(); + responses.add(err); + } + + if (!finished) { + GetNextRequestType nextRequest = of.createGetNextRequestType(); + nextRequest.setSessionId(sessionId); + nextRequest.getInfoboxReadResponseOrSignResponseOrErrorResponse().addAll(responses); + nextRequestResp = stalPort.getNextRequest(nextRequest); } - log.info("Got " + responses.size() + " responses."); - nextRequest = factory.createGetNextRequestType(); - nextRequest.setSessionId(sessionId); - nextRequest.getResponse().addAll(responses); } while (!finished); log.info("Done " + Thread.currentThread().getName()); - // gui.showWelcomeDialog(); } catch (Exception ex) { + log.error(ex.getMessage(), ex); gui.showErrorDialog("Sorry, an internal error occured: " + ex.getMessage()); try { waitForAction(); @@ -196,20 +222,17 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, URL url = null; if (redirectURL != null) { try { - url = new URL(parent.getCodeBase(), redirectURL + ";jsessionid=" - + parent.getMyAppletParameter(BKUApplet.SESSION_ID)); + url = new URL(parent.getCodeBase(), redirectURL + ";jsessionid=" + parent.getMyAppletParameter(BKUApplet.SESSION_ID)); } catch (MalformedURLException ex) { - log.warn("Parameter 'redirectURL': " + redirectURL - + " not a valid URL.", ex); - // gui.showErrorDialog(errorMsg, okListener, actionCommand) + log.warn("Parameter 'redirectURL': " + redirectURL + " not a valid URL.", ex); + // gui.showErrorDialog(errorMsg, okListener, actionCommand) } if (url != null) { if (redirectTarget == null) { log.info("Done. Trying to redirect to " + url + " ..."); parent.getAppletContext().showDocument(url); } else { - log.info("Done. Trying to redirect to " + url + " (target=" - + redirectTarget + ") ..."); + log.info("Done. Trying to redirect to " + url + " (target=" + redirectTarget + ") ..."); parent.getAppletContext().showDocument(url, redirectTarget); } } @@ -253,48 +276,48 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, int oldValue = SMCCHelper.PC_SC_NOT_SUPPORTED; // this is a save default while ((signatureCard == null) && (!actionPerformed)) { switch (smccHelper.getResultCode()) { - case SMCCHelper.PC_SC_NOT_SUPPORTED: - actionCommandList.clear(); - actionCommandList.add("ok"); - gui.showErrorDialog(errorMessages.getString("nopcscsupport"), this, - "ok"); - try { - waitForAction(); - } catch (InterruptedException e) { - log.error(e); - } - return true; - case SMCCHelper.TERMINAL_NOT_PRESENT: - actionCommandList.clear(); - actionCommandList.add("ok"); - gui.showErrorDialog(errorMessages.getString("nocardterminal"), this, - "ok"); - try { - waitForAction(); - } catch (InterruptedException e) { - log.error(e); - } - return true; - case SMCCHelper.CARD_NOT_SUPPORTED: - if (oldValue != SMCCHelper.CARD_NOT_SUPPORTED) { + case SMCCHelper.PC_SC_NOT_SUPPORTED: actionCommandList.clear(); - actionCommandList.add("cancel"); - gui.showCardNotSupportedDialog(this, "cancel"); - oldValue = SMCCHelper.CARD_NOT_SUPPORTED; - } - break; - case SMCCHelper.NO_CARD: - if (oldValue != SMCCHelper.NO_CARD) { + actionCommandList.add("ok"); + gui.showErrorDialog(errorMessages.getString("nopcscsupport"), this, + "ok"); + try { + waitForAction(); + } catch (InterruptedException e) { + log.error(e); + } + return true; + case SMCCHelper.TERMINAL_NOT_PRESENT: actionCommandList.clear(); - actionCommandList.add("cancel"); - gui.showInsertCardDialog(this, "cancel"); - oldValue = SMCCHelper.NO_CARD; - } - break; - case SMCCHelper.CARD_FOUND: - // gui.showWaitDialog(null); - signatureCard = smccHelper.getSignatureCard(errorMessages.getLocale()); - return false; + actionCommandList.add("ok"); + gui.showErrorDialog(errorMessages.getString("nocardterminal"), this, + "ok"); + try { + waitForAction(); + } catch (InterruptedException e) { + log.error(e); + } + return true; + case SMCCHelper.CARD_NOT_SUPPORTED: + if (oldValue != SMCCHelper.CARD_NOT_SUPPORTED) { + actionCommandList.clear(); + actionCommandList.add("cancel"); + gui.showCardNotSupportedDialog(this, "cancel"); + oldValue = SMCCHelper.CARD_NOT_SUPPORTED; + } + break; + case SMCCHelper.NO_CARD: + if (oldValue != SMCCHelper.NO_CARD) { + actionCommandList.clear(); + actionCommandList.add("cancel"); + gui.showInsertCardDialog(this, "cancel"); + oldValue = SMCCHelper.NO_CARD; + } + break; + case SMCCHelper.CARD_FOUND: + // gui.showWaitDialog(null); + signatureCard = smccHelper.getSignatureCard(errorMessages.getLocale()); + return false; } smccHelper.update(3000); } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java index 6dae264c..5f422164 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java @@ -20,9 +20,9 @@ import at.gv.egiz.bku.smccstal.SMCCSTALRequestHandler; import at.gv.egiz.bku.smccstal.SignRequestHandler; import at.gv.egiz.stal.HashDataInput; import at.gv.egiz.stal.impl.ByteArrayHashDataInput; -import at.gv.egiz.stal.service.GetHashDataInputResponseType; -import at.gv.egiz.stal.service.GetHashDataInputType; import at.gv.egiz.stal.service.STALPortType; +import at.gv.egiz.stal.service.types.GetHashDataInputResponseType; +import at.gv.egiz.stal.service.types.GetHashDataInputType; import at.gv.egiz.stal.signedinfo.DigestMethodType; import at.gv.egiz.stal.signedinfo.ReferenceType; import java.security.DigestException; -- cgit v1.2.3 From 8ccd9ab69dc74762567930f4c576a359502f1071 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 30 Sep 2008 16:37:59 +0000 Subject: showErrorDialog l10n git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@77 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java index a87b04c4..12eb9d00 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java @@ -126,7 +126,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, log.fatal("Failed to call STAL service.", e); actionCommandList.clear(); actionCommandList.add("ok"); - gui.showErrorDialog(errorMessages.getString("failed.WS")); + gui.showErrorDialog(BKUGUIFacade.ERR_SERVICE_UNREACHABLE, new Object[] {e.getMessage()}); try { waitForAction(); } catch (InterruptedException e1) { @@ -204,7 +204,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, log.info("Done " + Thread.currentThread().getName()); } catch (Exception ex) { log.error(ex.getMessage(), ex); - gui.showErrorDialog("Sorry, an internal error occured: " + ex.getMessage()); + gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, new Object[] {ex.getMessage()}); try { waitForAction(); } catch (InterruptedException e) { @@ -279,8 +279,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, case SMCCHelper.PC_SC_NOT_SUPPORTED: actionCommandList.clear(); actionCommandList.add("ok"); - gui.showErrorDialog(errorMessages.getString("nopcscsupport"), this, - "ok"); + gui.showErrorDialog(BKUGUIFacade.ERR_NO_PCSC, null, this, "ok"); try { waitForAction(); } catch (InterruptedException e) { @@ -290,8 +289,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, case SMCCHelper.TERMINAL_NOT_PRESENT: actionCommandList.clear(); actionCommandList.add("ok"); - gui.showErrorDialog(errorMessages.getString("nocardterminal"), this, - "ok"); + gui.showErrorDialog(BKUGUIFacade.ERR_NO_CARDTERMINAL,null,this,"ok"); try { waitForAction(); } catch (InterruptedException e) { -- cgit v1.2.3 From 35364f7492308692bd690c17f5527f4157eb583a Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 7 Oct 2008 17:59:28 +0000 Subject: hashdata digest git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@82 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../bku/online/applet/WSSignRequestHandler.java | 60 ++++++++++++++++------ 1 file changed, 44 insertions(+), 16 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java index 5f422164..3a36a290 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java @@ -31,6 +31,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; +import java.util.Map.Entry; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -58,15 +59,18 @@ public class WSSignRequestHandler extends SignRequestHandler { GetHashDataInputType request = new GetHashDataInputType(); request.setSessionId(sessId); - HashMap idRefMap = new HashMap(); - for (ReferenceType reference : signedReferences) { + HashMap idSignedRefMap = new HashMap(); + for (ReferenceType signedRef : signedReferences) { //don't get Manifest, QualifyingProperties, ... - if (reference.getType() == null) { - String referenceId = reference.getId(); - if (referenceId != null) { - idRefMap.put(referenceId, reference); + if (signedRef.getType() == null) { + String signedRefId = signedRef.getId(); + if (signedRefId != null) { + if (log.isTraceEnabled()) { + log.trace("requesting hashdata input for reference " + signedRefId); + } + idSignedRefMap.put(signedRefId, signedRef); GetHashDataInputType.Reference ref = new GetHashDataInputType.Reference(); - ref.setID(referenceId); + ref.setID(signedRefId); request.getReference().add(ref); } else { @@ -76,31 +80,52 @@ public class WSSignRequestHandler extends SignRequestHandler { } if (log.isDebugEnabled()) { - log.debug("Calling GetHashDataInput for session " + sessId); + log.debug("Calling GetHashDataInput for " + request.getReference().size() + " references in session " + sessId); } GetHashDataInputResponseType response = stalPort.getHashDataInput(request); ArrayList hashDataInputs = new ArrayList(); + //hashdata inputs returned from service + HashMap idRefMap = new HashMap(); for (GetHashDataInputResponseType.Reference reference : response.getReference()) { - String id = reference.getID(); byte[] hdi = reference.getValue(); if (hdi == null) { - throw new Exception("Failed to resolve digest value for reference " + id); + throw new Exception("Did not receive hashdata input for reference " + id); + } + idRefMap.put(id, reference); + } + + for (String signedRefId : idSignedRefMap.keySet()) { + log.info("validating hashdata input for reference " + signedRefId); + + GetHashDataInputResponseType.Reference reference = idRefMap.get(signedRefId); + if (reference == null) { + throw new Exception("No hashdata input for reference " + signedRefId + " returned by service"); } + +// } +// +// for (GetHashDataInputResponseType.Reference reference : response.getReference()) { +// +// String id = reference.getID(); + byte[] hdi = reference.getValue(); String mimeType = reference.getMimeType(); String encoding = reference.getEncoding(); + if (hdi == null) { + throw new Exception("No hashdata input provided for reference " + signedRefId); + } if (log.isDebugEnabled()) { - log.debug("Got HashDataInput " + id + " (" + mimeType + ";" + encoding + ")"); + log.debug("Got HashDataInput " + signedRefId + " (" + mimeType + ";" + encoding + ")"); } - ReferenceType dsigRef = idRefMap.get(id); + ReferenceType dsigRef = idSignedRefMap.get(signedRefId); DigestMethodType dm = dsigRef.getDigestMethod(); + if (dm == null) { - throw new Exception("Failed to verify digest value for reference " + id + ": no digest algorithm"); + throw new Exception("Failed to verify digest value for reference " + signedRefId + ": no digest algorithm"); } - //TODO String mdAlg = dm.getAlgorithm(); if ("http://www.w3.org/2000/09/xmldsig#sha1".equals(mdAlg)) mdAlg = "SHA-1"; @@ -120,15 +145,18 @@ public class WSSignRequestHandler extends SignRequestHandler { mdAlg = "MD5"; else if ("http://www.w3.org/2001/04/xmlenc#ripemd160 ".equals(mdAlg)) mdAlg = "RipeMD-160"; + else { + throw new Exception("Failed to verify digest value for reference " + signedRefId + ": unsupported digest algorithm " + mdAlg); + } MessageDigest md = MessageDigest.getInstance(mdAlg); byte[] hdiDigest = md.digest(hdi); if (log.isDebugEnabled()) log.debug("Comparing digest values... "); if (!Arrays.equals(hdiDigest, dsigRef.getDigestValue())) { log.error("digest values differ: " + new String(hdiDigest) + ", " + new String(dsigRef.getDigestValue())); - throw new DigestException("Bad digest value for reference " + id + ": " + dsigRef.getDigestValue()); + throw new DigestException("Bad digest value for reference " + signedRefId + ": " + new String(dsigRef.getDigestValue())); } - hashDataInputs.add(new ByteArrayHashDataInput(hdi, id, mimeType, encoding)); + hashDataInputs.add(new ByteArrayHashDataInput(hdi, signedRefId, mimeType, encoding)); } return hashDataInputs; } -- cgit v1.2.3 From f993d336e51b9f7898aeeff2e5ae6785066d1e5b Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 9 Oct 2008 16:23:52 +0000 Subject: demo integration beta1 git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@94 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../java/at/gv/egiz/bku/online/applet/BKUApplet.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 34dd9bbd..6a781729 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -16,9 +16,12 @@ */ package at.gv.egiz.bku.online.applet; +import java.net.MalformedURLException; import java.util.Locale; import java.util.ResourceBundle; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.net.ssl.HttpsURLConnection; import javax.swing.JApplet; @@ -27,6 +30,7 @@ import org.apache.commons.logging.LogFactory; import at.gv.egiz.bku.gui.BKUGUIFacade; import at.gv.egiz.bku.gui.BKUGUIFactory; +import java.net.URL; /** * Note: all swing code is executed by the event dispatch thread (see @@ -40,6 +44,8 @@ public class BKUApplet extends JApplet { public final static String LOGO_URL_KEY = "LogoURL"; public final static String WSDL_URL = "WSDL_URL"; public final static String SESSION_ID = "SessionID"; + public static final String BACKGROUND_PARAM = "background"; + protected ResourceBundle resourceBundle; protected BKUWorker worker; protected Thread workerThread; @@ -58,8 +64,17 @@ public class BKUApplet extends JApplet { } else { resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE); } + String backgroundString = getMyAppletParameter(BACKGROUND_PARAM); + URL background = null; + if (backgroundString != null) { + try { + background = new URL(backgroundString); + } catch (MalformedURLException ex) { + log.warn(ex.getMessage() + ", using default background"); + } + } BKUGUIFacade gui = BKUGUIFactory.createGUI(); - gui.init(getContentPane(), localeString); + gui.init(getContentPane(), localeString, background); worker = new BKUWorker(gui, this, resourceBundle); } -- cgit v1.2.3 From 8852be703a5cacaf271575ccee04bbe27612d16b Mon Sep 17 00:00:00 2001 From: wbauer Date: Fri, 10 Oct 2008 12:35:07 +0000 Subject: Improved Quit Handling for multiple applet instances git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@101 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 4 + .../at/gv/egiz/bku/online/applet/BKUWorker.java | 125 ++++++++++++--------- .../bku/online/applet/MultiInstanceHandler.java | 49 ++++++++ .../at/gv/egiz/bku/online/applet/QuitHandler.java | 37 ++++++ 4 files changed, 160 insertions(+), 55 deletions(-) create mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/MultiInstanceHandler.java create mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/QuitHandler.java (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 6a781729..ab38c163 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -30,6 +30,9 @@ import org.apache.commons.logging.LogFactory; import at.gv.egiz.bku.gui.BKUGUIFacade; import at.gv.egiz.bku.gui.BKUGUIFactory; +import at.gv.egiz.bku.smccstal.AbstractSMCCSTAL; +import at.gv.egiz.stal.QuitRequest; + import java.net.URL; /** @@ -56,6 +59,7 @@ public class BKUApplet extends JApplet { public void init() { log.info("Welcome to MOCCA\n"); log.debug("Called init()"); + AbstractSMCCSTAL.addRequestHandler(QuitRequest.class, QuitHandler.getInstance()); HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getInstance()); String localeString = getMyAppletParameter(LOCALE_PARAM_KEY); if (localeString != null) { diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java index 12eb9d00..fbf74162 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java @@ -48,7 +48,7 @@ import at.gv.egiz.stal.service.types.ResponseType; import at.gv.egiz.stal.util.STALTranslator; public class BKUWorker extends AbstractSMCCSTAL implements Runnable, - ActionListener, SMCCSTALRequestHandler { + ActionListener, SMCCSTALRequestHandler { private static Log log = LogFactory.getLog(BKUWorker.class); protected BKUGUIFacade gui; @@ -65,15 +65,15 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, * must not be null */ public BKUWorker(BKUGUIFacade gui, BKUApplet parent, - ResourceBundle errorMessageBundle) { + ResourceBundle errorMessageBundle) { if ((gui == null) || (parent == null) || (errorMessageBundle == null)) { throw new NullPointerException("Parameter must not be set to null"); } this.gui = gui; this.parent = parent; this.errorMessages = errorMessageBundle; - addRequestHandler(QuitRequest.class, this); - // register SignRequestHandler once we have a webservice port + QuitHandler.getInstance().registerHandlerInstance(this); + // register SignRequestHandler once we have a webservice port } /** @@ -85,7 +85,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, protected BKUWorker(BKUGUIFacade gui, ResourceBundle errorMessageBundle) { this.gui = gui; this.errorMessages = errorMessageBundle; - addRequestHandler(QuitRequest.class, this); + QuitHandler.getInstance().registerHandlerInstance(this); } private STALPortType getSTALPort() throws MalformedURLException { @@ -111,7 +111,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, } log.debug("Found WSDL url: " + wsdlURL); QName endpointName = new QName("http://www.egiz.gv.at/wsdl/stal", - "STALService"); + "STALService"); STALService stal = new STALService(wsdlURL, endpointName); return stal.getSTALPort(); } @@ -126,7 +126,8 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, log.fatal("Failed to call STAL service.", e); actionCommandList.clear(); actionCommandList.add("ok"); - gui.showErrorDialog(BKUGUIFacade.ERR_SERVICE_UNREACHABLE, new Object[] {e.getMessage()}); + gui.showErrorDialog(BKUGUIFacade.ERR_SERVICE_UNREACHABLE, + new Object[] { e.getMessage() }); try { waitForAction(); } catch (InterruptedException e1) { @@ -140,13 +141,16 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, // use the testsession for testing sessionId = "TestSession"; } - addRequestHandler(at.gv.egiz.stal.SignRequest.class, new WSSignRequestHandler(sessionId, stalPort)); + addRequestHandler(at.gv.egiz.stal.SignRequest.class, + new WSSignRequestHandler(sessionId, stalPort)); ObjectFactory of = new ObjectFactory(); GetNextRequestResponseType nextRequestResp = stalPort.connect(sessionId); do { - List requests = nextRequestResp.getInfoboxReadRequestOrSignRequestOrQuitRequest(); - List stalRequests = STALTranslator.translateRequests(requests); + List requests = nextRequestResp + .getInfoboxReadRequestOrSignRequestOrQuitRequest(); + List stalRequests = STALTranslator + .translateRequests(requests); if (log.isInfoEnabled()) { StringBuilder sb = new StringBuilder("Received "); @@ -190,27 +194,33 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, responses = new ArrayList(1); ErrorResponseType err = new ErrorResponseType(); err.setErrorCode(6002); -// err.setErrorMessage(); + // err.setErrorMessage(); responses.add(err); } if (!finished) { + log.info("Not finished yet (BKUWorker: " + this + + "), sending responses"); GetNextRequestType nextRequest = of.createGetNextRequestType(); nextRequest.setSessionId(sessionId); - nextRequest.getInfoboxReadResponseOrSignResponseOrErrorResponse().addAll(responses); + nextRequest.getInfoboxReadResponseOrSignResponseOrErrorResponse() + .addAll(responses); nextRequestResp = stalPort.getNextRequest(nextRequest); } } while (!finished); log.info("Done " + Thread.currentThread().getName()); } catch (Exception ex) { log.error(ex.getMessage(), ex); - gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, new Object[] {ex.getMessage()}); + gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, new Object[] { ex + .getMessage() }); try { waitForAction(); } catch (InterruptedException e) { log.error(e); } } + signatureCard.disconnect(false); + QuitHandler.getInstance().unregisterHandlerInstance(this); sendRedirect(); } @@ -222,17 +232,20 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, URL url = null; if (redirectURL != null) { try { - url = new URL(parent.getCodeBase(), redirectURL + ";jsessionid=" + parent.getMyAppletParameter(BKUApplet.SESSION_ID)); + url = new URL(parent.getCodeBase(), redirectURL + ";jsessionid=" + + parent.getMyAppletParameter(BKUApplet.SESSION_ID)); } catch (MalformedURLException ex) { - log.warn("Parameter 'redirectURL': " + redirectURL + " not a valid URL.", ex); - // gui.showErrorDialog(errorMsg, okListener, actionCommand) + log.warn("Parameter 'redirectURL': " + redirectURL + + " not a valid URL.", ex); + // gui.showErrorDialog(errorMsg, okListener, actionCommand) } if (url != null) { if (redirectTarget == null) { log.info("Done. Trying to redirect to " + url + " ..."); parent.getAppletContext().showDocument(url); } else { - log.info("Done. Trying to redirect to " + url + " (target=" + redirectTarget + ") ..."); + log.info("Done. Trying to redirect to " + url + " (target=" + + redirectTarget + ") ..."); parent.getAppletContext().showDocument(url, redirectTarget); } } @@ -276,46 +289,46 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, int oldValue = SMCCHelper.PC_SC_NOT_SUPPORTED; // this is a save default while ((signatureCard == null) && (!actionPerformed)) { switch (smccHelper.getResultCode()) { - case SMCCHelper.PC_SC_NOT_SUPPORTED: + case SMCCHelper.PC_SC_NOT_SUPPORTED: + actionCommandList.clear(); + actionCommandList.add("ok"); + gui.showErrorDialog(BKUGUIFacade.ERR_NO_PCSC, null, this, "ok"); + try { + waitForAction(); + } catch (InterruptedException e) { + log.error(e); + } + return true; + case SMCCHelper.TERMINAL_NOT_PRESENT: + actionCommandList.clear(); + actionCommandList.add("ok"); + gui.showErrorDialog(BKUGUIFacade.ERR_NO_CARDTERMINAL, null, this, "ok"); + try { + waitForAction(); + } catch (InterruptedException e) { + log.error(e); + } + return true; + case SMCCHelper.CARD_NOT_SUPPORTED: + if (oldValue != SMCCHelper.CARD_NOT_SUPPORTED) { actionCommandList.clear(); - actionCommandList.add("ok"); - gui.showErrorDialog(BKUGUIFacade.ERR_NO_PCSC, null, this, "ok"); - try { - waitForAction(); - } catch (InterruptedException e) { - log.error(e); - } - return true; - case SMCCHelper.TERMINAL_NOT_PRESENT: + actionCommandList.add("cancel"); + gui.showCardNotSupportedDialog(this, "cancel"); + oldValue = SMCCHelper.CARD_NOT_SUPPORTED; + } + break; + case SMCCHelper.NO_CARD: + if (oldValue != SMCCHelper.NO_CARD) { actionCommandList.clear(); - actionCommandList.add("ok"); - gui.showErrorDialog(BKUGUIFacade.ERR_NO_CARDTERMINAL,null,this,"ok"); - try { - waitForAction(); - } catch (InterruptedException e) { - log.error(e); - } - return true; - case SMCCHelper.CARD_NOT_SUPPORTED: - if (oldValue != SMCCHelper.CARD_NOT_SUPPORTED) { - actionCommandList.clear(); - actionCommandList.add("cancel"); - gui.showCardNotSupportedDialog(this, "cancel"); - oldValue = SMCCHelper.CARD_NOT_SUPPORTED; - } - break; - case SMCCHelper.NO_CARD: - if (oldValue != SMCCHelper.NO_CARD) { - actionCommandList.clear(); - actionCommandList.add("cancel"); - gui.showInsertCardDialog(this, "cancel"); - oldValue = SMCCHelper.NO_CARD; - } - break; - case SMCCHelper.CARD_FOUND: - // gui.showWaitDialog(null); - signatureCard = smccHelper.getSignatureCard(errorMessages.getLocale()); - return false; + actionCommandList.add("cancel"); + gui.showInsertCardDialog(this, "cancel"); + oldValue = SMCCHelper.NO_CARD; + } + break; + case SMCCHelper.CARD_FOUND: + // gui.showWaitDialog(null); + signatureCard = smccHelper.getSignatureCard(errorMessages.getLocale()); + return false; } smccHelper.update(3000); } @@ -325,6 +338,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, @Override public STALResponse handleRequest(STALRequest request) { if (request instanceof QuitRequest) { + log.info("Setting state to: finished for BKUWorker " + this); finished = true; } else { log.error("Unexpected request to handle: " + request); @@ -350,4 +364,5 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, protected BKUGUIFacade getGUI() { return gui; } + } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/MultiInstanceHandler.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/MultiInstanceHandler.java new file mode 100644 index 00000000..a07df559 --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/MultiInstanceHandler.java @@ -0,0 +1,49 @@ +package at.gv.egiz.bku.online.applet; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.bku.smccstal.SMCCSTALRequestHandler; +import at.gv.egiz.smcc.SignatureCard; +import at.gv.egiz.stal.QuitRequest; +import at.gv.egiz.stal.STALRequest; +import at.gv.egiz.stal.STALResponse; + +public abstract class MultiInstanceHandler implements SMCCSTALRequestHandler { + + private static Log log = LogFactory.getLog(MultiInstanceHandler.class); + + protected List handlerList = new ArrayList(); + + + + protected MultiInstanceHandler() { + } + + public void registerHandlerInstance(SMCCSTALRequestHandler handler) { + handlerList.add(handler); + } + + public void unregisterHandlerInstance(SMCCSTALRequestHandler handler) { + handlerList.remove(handler); + } + + + @Override + public void init(SignatureCard sc, BKUGUIFacade gui) { + } + + @Override + public SMCCSTALRequestHandler newInstance() { + return this; + } + + @Override + public boolean requireCard() { + return false; + } +} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/QuitHandler.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/QuitHandler.java new file mode 100644 index 00000000..ab07e1a8 --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/QuitHandler.java @@ -0,0 +1,37 @@ +package at.gv.egiz.bku.online.applet; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.gv.egiz.bku.smccstal.SMCCSTALRequestHandler; +import at.gv.egiz.stal.QuitRequest; +import at.gv.egiz.stal.STALRequest; +import at.gv.egiz.stal.STALResponse; + +public class QuitHandler extends MultiInstanceHandler { + + private static Log log = LogFactory.getLog(QuitHandler.class); + + private static QuitHandler instance = new QuitHandler(); + + private QuitHandler() { + } + + public static QuitHandler getInstance() { + return instance; + } + + @Override + public STALResponse handleRequest(STALRequest request) { + if (request instanceof QuitRequest) { + log.info("Received QuitCommand"); + for (SMCCSTALRequestHandler handler : handlerList) { + handler.handleRequest(request); + } + } else { + log.error("Unexpected request to handle: " + request); + } + return null; + } + +} -- cgit v1.2.3 From 255269ab17404fa1249c257e88815cbbee6e0d0f Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 13 Oct 2008 12:53:57 +0000 Subject: ExternalDisplaySignRequestHandler git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@105 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 1 + .../at/gv/egiz/bku/online/applet/BKUWorker.java | 32 +++- .../applet/ExternalDisplaySignRequestHandler.java | 45 ++++++ .../online/applet/SignRequestHandlerFactory.java | 21 +++ .../bku/online/applet/WSSignRequestHandler.java | 168 --------------------- .../applet/WebServiceSignRequestHandler.java | 167 ++++++++++++++++++++ 6 files changed, 263 insertions(+), 171 deletions(-) create mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalDisplaySignRequestHandler.java create mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/SignRequestHandlerFactory.java delete mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java create mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index ab38c163..32c4feaa 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -46,6 +46,7 @@ public class BKUApplet extends JApplet { public final static String LOCALE_PARAM_KEY = "Locale"; public final static String LOGO_URL_KEY = "LogoURL"; public final static String WSDL_URL = "WSDL_URL"; + public final static String HASHDATA_URL = "HashDataURL"; public final static String SESSION_ID = "SessionID"; public static final String BACKGROUND_PARAM = "background"; diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java index fbf74162..d5ba4e40 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java @@ -46,6 +46,7 @@ import at.gv.egiz.stal.service.types.ErrorResponseType; import at.gv.egiz.stal.service.types.RequestType; import at.gv.egiz.stal.service.types.ResponseType; import at.gv.egiz.stal.util.STALTranslator; +import java.applet.AppletContext; public class BKUWorker extends AbstractSMCCSTAL implements Runnable, ActionListener, SMCCSTALRequestHandler { @@ -54,6 +55,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, protected BKUGUIFacade gui; protected BKUApplet parent; private STALPortType stalPort; + private URL hashDataURL; protected List actionCommandList = new ArrayList(); protected Boolean actionPerformed = false; protected boolean finished = false; @@ -115,13 +117,30 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, STALService stal = new STALService(wsdlURL, endpointName); return stal.getSTALPort(); } + + private URL getHashDataURL() throws MalformedURLException { + String hashDataParam = parent.getMyAppletParameter(BKUApplet.HASHDATA_URL); + URL codebase = parent.getCodeBase(); + if (hashDataParam != null) { + try { + return new URL(codebase, hashDataParam); +// log.debug("Found HashDataInputServlet URL: " + hashDataURL); + } catch (MalformedURLException ex) { + log.fatal("Paremeter " + BKUApplet.HASHDATA_URL + " is not a vailid URL.", ex); + throw new MalformedURLException(ex.getMessage()); + } + } else { + log.fatal("Paremeter " + BKUApplet.HASHDATA_URL + " not set"); + throw new MalformedURLException(BKUApplet.HASHDATA_URL + " not set"); + } + } @Override public void run() { gui.showWelcomeDialog(); try { stalPort = getSTALPort(); - + hashDataURL = getHashDataURL(); } catch (Exception e) { log.fatal("Failed to call STAL service.", e); actionCommandList.clear(); @@ -135,14 +154,21 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, } return; } + + //TODO factory for SignRequestHandler providing either WebServiceHDISignRequestHandler or ExternalHDIDisplaySignRequestHandler + AppletContext ctx = parent.getAppletContext(); + log.debug("register SignRequestHandler for HashDataURL " + hashDataURL); + addRequestHandler(at.gv.egiz.stal.SignRequest.class, new ExternalDisplaySignRequestHandler(ctx, hashDataURL)); + try { String sessionId = parent.getMyAppletParameter(BKUApplet.SESSION_ID); if (sessionId == null) { // use the testsession for testing sessionId = "TestSession"; } - addRequestHandler(at.gv.egiz.stal.SignRequest.class, - new WSSignRequestHandler(sessionId, stalPort)); + +// log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); +// addRequestHandler(at.gv.egiz.stal.SignRequest.class, new WebServiceSignRequestHandler(sessionId, stalPort)); ObjectFactory of = new ObjectFactory(); GetNextRequestResponseType nextRequestResp = stalPort.connect(sessionId); diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalDisplaySignRequestHandler.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalDisplaySignRequestHandler.java new file mode 100644 index 00000000..a9bbc559 --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalDisplaySignRequestHandler.java @@ -0,0 +1,45 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package at.gv.egiz.bku.online.applet; + +import at.gv.egiz.bku.smccstal.SMCCSTALRequestHandler; +import at.gv.egiz.bku.smccstal.SignRequestHandler; +import at.gv.egiz.stal.signedinfo.ReferenceType; +import java.applet.AppletContext; +import java.net.URL; +import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author clemens + */ +public class ExternalDisplaySignRequestHandler extends SignRequestHandler { + + private static final Log log = LogFactory.getLog(ExternalDisplaySignRequestHandler.class); + + AppletContext ctx; + URL hashDataURL; + + public ExternalDisplaySignRequestHandler(AppletContext ctx, URL hashDataURL) { + this.ctx = ctx; + this.hashDataURL = hashDataURL; + } + + @Override + public SMCCSTALRequestHandler newInstance() { + return new ExternalDisplaySignRequestHandler(ctx, hashDataURL); + } + + @Override + public void displayHashDataInputs(List signedReferences) throws Exception { + //TODO pass reference Id's to servlet (TODO servlet) + log.debug("displaying hashdata inputs at " + hashDataURL); + ctx.showDocument(hashDataURL, "_blank"); + } + +} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/SignRequestHandlerFactory.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/SignRequestHandlerFactory.java new file mode 100644 index 00000000..327ea8aa --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/SignRequestHandlerFactory.java @@ -0,0 +1,21 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package at.gv.egiz.bku.online.applet; + +import at.gv.egiz.bku.smccstal.SignRequestHandler; + +/** + * + * @author clemens + */ +public class SignRequestHandlerFactory { + + static SignRequestHandler getInstance() { + //TODO return ExternalDisplaySignRequestHandler by default, WebServiceSignRequestHandler if requested + //TODO get configuration as param + return null; + } +} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java deleted file mode 100644 index 3a36a290..00000000 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WSSignRequestHandler.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright 2008 Federal Chancellery Austria and - * Graz University of Technology - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package at.gv.egiz.bku.online.applet; - -import at.gv.egiz.bku.smccstal.SMCCSTALRequestHandler; -import at.gv.egiz.bku.smccstal.SignRequestHandler; -import at.gv.egiz.stal.HashDataInput; -import at.gv.egiz.stal.impl.ByteArrayHashDataInput; -import at.gv.egiz.stal.service.STALPortType; -import at.gv.egiz.stal.service.types.GetHashDataInputResponseType; -import at.gv.egiz.stal.service.types.GetHashDataInputType; -import at.gv.egiz.stal.signedinfo.DigestMethodType; -import at.gv.egiz.stal.signedinfo.ReferenceType; -import java.security.DigestException; -import java.security.MessageDigest; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map.Entry; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * - * @author clemens - */ -public class WSSignRequestHandler extends SignRequestHandler { - - private static final Log log = LogFactory.getLog(WSSignRequestHandler.class); - STALPortType stalPort; - String sessId; - - public WSSignRequestHandler(String sessId, STALPortType stalPort) { - if (stalPort == null || sessId == null) { - throw new NullPointerException("STAL port must not be null"); - } - this.sessId = sessId; - this.stalPort = stalPort; - } - - @Override - public List getCashedHashDataInputs(List signedReferences) throws Exception { - - GetHashDataInputType request = new GetHashDataInputType(); - request.setSessionId(sessId); - - HashMap idSignedRefMap = new HashMap(); - for (ReferenceType signedRef : signedReferences) { - //don't get Manifest, QualifyingProperties, ... - if (signedRef.getType() == null) { - String signedRefId = signedRef.getId(); - if (signedRefId != null) { - if (log.isTraceEnabled()) { - log.trace("requesting hashdata input for reference " + signedRefId); - } - idSignedRefMap.put(signedRefId, signedRef); - GetHashDataInputType.Reference ref = new GetHashDataInputType.Reference(); - ref.setID(signedRefId); - request.getReference().add(ref); - - } else { - throw new Exception("Cannot resolve HashDataInput for reference without Id attribute"); - } - } - } - - if (log.isDebugEnabled()) { - log.debug("Calling GetHashDataInput for " + request.getReference().size() + " references in session " + sessId); - } - GetHashDataInputResponseType response = stalPort.getHashDataInput(request); - ArrayList hashDataInputs = new ArrayList(); - - //hashdata inputs returned from service - HashMap idRefMap = new HashMap(); - for (GetHashDataInputResponseType.Reference reference : response.getReference()) { - String id = reference.getID(); - byte[] hdi = reference.getValue(); - if (hdi == null) { - throw new Exception("Did not receive hashdata input for reference " + id); - } - idRefMap.put(id, reference); - } - - for (String signedRefId : idSignedRefMap.keySet()) { - log.info("validating hashdata input for reference " + signedRefId); - - GetHashDataInputResponseType.Reference reference = idRefMap.get(signedRefId); - if (reference == null) { - throw new Exception("No hashdata input for reference " + signedRefId + " returned by service"); - } - -// } -// -// for (GetHashDataInputResponseType.Reference reference : response.getReference()) { -// -// String id = reference.getID(); - byte[] hdi = reference.getValue(); - String mimeType = reference.getMimeType(); - String encoding = reference.getEncoding(); - - if (hdi == null) { - throw new Exception("No hashdata input provided for reference " + signedRefId); - } - if (log.isDebugEnabled()) { - log.debug("Got HashDataInput " + signedRefId + " (" + mimeType + ";" + encoding + ")"); - } - - ReferenceType dsigRef = idSignedRefMap.get(signedRefId); - DigestMethodType dm = dsigRef.getDigestMethod(); - - if (dm == null) { - throw new Exception("Failed to verify digest value for reference " + signedRefId + ": no digest algorithm"); - } - String mdAlg = dm.getAlgorithm(); - if ("http://www.w3.org/2000/09/xmldsig#sha1".equals(mdAlg)) - mdAlg = "SHA-1"; - else if ("http://www.w3.org/2001/04/xmlenc#sha256".equals(mdAlg)) - mdAlg = "SHA-256"; - else if ("http://www.w3.org/2001/04/xmlenc#sha224 ".equals(mdAlg)) - mdAlg = "SHA-224"; - else if ("http://www.w3.org/2001/04/xmldsig-more#sha224 ".equals(mdAlg)) - mdAlg = "SHA-224"; - else if ("http://www.w3.org/2001/04/xmldsig-more#sha384".equals(mdAlg)) - mdAlg = "SHA-384"; - else if ("http://www.w3.org/2001/04/xmlenc#sha512".equals(mdAlg)) - mdAlg = "SHA-512"; - else if ("http://www.w3.org/2001/04/xmldsig-more#md2 ".equals(mdAlg)) - mdAlg = "MD2"; - else if ("http://www.w3.org/2001/04/xmldsig-more#md5".equals(mdAlg)) - mdAlg = "MD5"; - else if ("http://www.w3.org/2001/04/xmlenc#ripemd160 ".equals(mdAlg)) - mdAlg = "RipeMD-160"; - else { - throw new Exception("Failed to verify digest value for reference " + signedRefId + ": unsupported digest algorithm " + mdAlg); - } - MessageDigest md = MessageDigest.getInstance(mdAlg); - byte[] hdiDigest = md.digest(hdi); - if (log.isDebugEnabled()) - log.debug("Comparing digest values... "); - if (!Arrays.equals(hdiDigest, dsigRef.getDigestValue())) { - log.error("digest values differ: " + new String(hdiDigest) + ", " + new String(dsigRef.getDigestValue())); - throw new DigestException("Bad digest value for reference " + signedRefId + ": " + new String(dsigRef.getDigestValue())); - } - hashDataInputs.add(new ByteArrayHashDataInput(hdi, signedRefId, mimeType, encoding)); - } - return hashDataInputs; - } - - @Override - public SMCCSTALRequestHandler newInstance() { - return new WSSignRequestHandler(this.sessId, this.stalPort); - } -} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java new file mode 100644 index 00000000..4a87b8b5 --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java @@ -0,0 +1,167 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package at.gv.egiz.bku.online.applet; + +import at.gv.egiz.bku.smccstal.SMCCSTALRequestHandler; +import at.gv.egiz.bku.smccstal.SignRequestHandler; +import at.gv.egiz.stal.HashDataInput; +import at.gv.egiz.stal.impl.ByteArrayHashDataInput; +import at.gv.egiz.stal.service.STALPortType; +import at.gv.egiz.stal.service.types.GetHashDataInputResponseType; +import at.gv.egiz.stal.service.types.GetHashDataInputType; +import at.gv.egiz.stal.signedinfo.DigestMethodType; +import at.gv.egiz.stal.signedinfo.ReferenceType; +import java.security.DigestException; +import java.security.MessageDigest; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * @author clemens + */ +public class WebServiceSignRequestHandler extends SignRequestHandler { + + private static final Log log = LogFactory.getLog(WebServiceSignRequestHandler.class); + STALPortType stalPort; + String sessId; + + public WebServiceSignRequestHandler(String sessId, STALPortType stalPort) { + if (stalPort == null || sessId == null) { + throw new NullPointerException("STAL port must not be null"); + } + this.sessId = sessId; + this.stalPort = stalPort; + } + + @Override + public void displayHashDataInputs(List signedReferences) throws Exception { + + GetHashDataInputType request = new GetHashDataInputType(); + request.setSessionId(sessId); + + HashMap idSignedRefMap = new HashMap(); + for (ReferenceType signedRef : signedReferences) { + //don't get Manifest, QualifyingProperties, ... + if (signedRef.getType() == null) { + String signedRefId = signedRef.getId(); + if (signedRefId != null) { + if (log.isTraceEnabled()) { + log.trace("requesting hashdata input for reference " + signedRefId); + } + idSignedRefMap.put(signedRefId, signedRef); + GetHashDataInputType.Reference ref = new GetHashDataInputType.Reference(); + ref.setID(signedRefId); + request.getReference().add(ref); + + } else { + throw new Exception("Cannot resolve HashDataInput for reference without Id attribute"); + } + } + } + + if (log.isDebugEnabled()) { + log.debug("Calling GetHashDataInput for " + request.getReference().size() + " references in session " + sessId); + } + GetHashDataInputResponseType response = stalPort.getHashDataInput(request); + ArrayList hashDataInputs = new ArrayList(); + + //hashdata inputs returned from service + HashMap idRefMap = new HashMap(); + for (GetHashDataInputResponseType.Reference reference : response.getReference()) { + String id = reference.getID(); + byte[] hdi = reference.getValue(); + if (hdi == null) { + throw new Exception("Did not receive hashdata input for reference " + id); + } + idRefMap.put(id, reference); + } + + for (String signedRefId : idSignedRefMap.keySet()) { + log.info("validating hashdata input for reference " + signedRefId); + + GetHashDataInputResponseType.Reference reference = idRefMap.get(signedRefId); + if (reference == null) { + throw new Exception("No hashdata input for reference " + signedRefId + " returned by service"); + } + +// } +// +// for (GetHashDataInputResponseType.Reference reference : response.getReference()) { +// +// String id = reference.getID(); + byte[] hdi = reference.getValue(); + String mimeType = reference.getMimeType(); + String encoding = reference.getEncoding(); + + if (hdi == null) { + throw new Exception("No hashdata input provided for reference " + signedRefId); + } + if (log.isDebugEnabled()) { + log.debug("Got HashDataInput " + signedRefId + " (" + mimeType + ";" + encoding + ")"); + } + + ReferenceType dsigRef = idSignedRefMap.get(signedRefId); + DigestMethodType dm = dsigRef.getDigestMethod(); + + if (dm == null) { + throw new Exception("Failed to verify digest value for reference " + signedRefId + ": no digest algorithm"); + } + String mdAlg = dm.getAlgorithm(); + if ("http://www.w3.org/2000/09/xmldsig#sha1".equals(mdAlg)) + mdAlg = "SHA-1"; + else if ("http://www.w3.org/2001/04/xmlenc#sha256".equals(mdAlg)) + mdAlg = "SHA-256"; + else if ("http://www.w3.org/2001/04/xmlenc#sha224 ".equals(mdAlg)) + mdAlg = "SHA-224"; + else if ("http://www.w3.org/2001/04/xmldsig-more#sha224 ".equals(mdAlg)) + mdAlg = "SHA-224"; + else if ("http://www.w3.org/2001/04/xmldsig-more#sha384".equals(mdAlg)) + mdAlg = "SHA-384"; + else if ("http://www.w3.org/2001/04/xmlenc#sha512".equals(mdAlg)) + mdAlg = "SHA-512"; + else if ("http://www.w3.org/2001/04/xmldsig-more#md2 ".equals(mdAlg)) + mdAlg = "MD2"; + else if ("http://www.w3.org/2001/04/xmldsig-more#md5".equals(mdAlg)) + mdAlg = "MD5"; + else if ("http://www.w3.org/2001/04/xmlenc#ripemd160 ".equals(mdAlg)) + mdAlg = "RipeMD-160"; + else { + throw new Exception("Failed to verify digest value for reference " + signedRefId + ": unsupported digest algorithm " + mdAlg); + } + MessageDigest md = MessageDigest.getInstance(mdAlg); + byte[] hdiDigest = md.digest(hdi); + if (log.isDebugEnabled()) + log.debug("Comparing digest values... "); + if (!Arrays.equals(hdiDigest, dsigRef.getDigestValue())) { + log.error("digest values differ: " + new String(hdiDigest) + ", " + new String(dsigRef.getDigestValue())); + throw new DigestException("Bad digest value for reference " + signedRefId + ": " + new String(dsigRef.getDigestValue())); + } + hashDataInputs.add(new ByteArrayHashDataInput(hdi, signedRefId, mimeType, encoding)); + } + + gui.showHashDataInputDialog(hashDataInputs, this, "ok"); + } + + @Override + public SMCCSTALRequestHandler newInstance() { + return new WebServiceSignRequestHandler(this.sessId, this.stalPort); + } +} -- cgit v1.2.3 From 128dc80f2e484b224c131abc8de6fab204d71d19 Mon Sep 17 00:00:00 2001 From: wbauer Date: Mon, 13 Oct 2008 13:23:17 +0000 Subject: git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@106 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java index d5ba4e40..b11413d6 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java @@ -245,7 +245,9 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, log.error(e); } } - signatureCard.disconnect(false); + if (signatureCard != null) { + signatureCard.disconnect(false); + } QuitHandler.getInstance().unregisterHandlerInstance(this); sendRedirect(); } -- cgit v1.2.3 From aa099311111a1d53f999705762aceb4005ecc187 Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 13 Oct 2008 13:59:06 +0000 Subject: config guiStyle simple/advanced, hashdatadisplay internal/external git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@107 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 11 ++++++++-- .../at/gv/egiz/bku/online/applet/BKUWorker.java | 25 +++++++++++++++------- .../online/applet/SignRequestHandlerFactory.java | 21 ------------------ 3 files changed, 26 insertions(+), 31 deletions(-) delete mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/SignRequestHandlerFactory.java (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 32c4feaa..96c0e7eb 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -42,13 +42,19 @@ import java.net.URL; public class BKUApplet extends JApplet { private static Log log = LogFactory.getLog(BKUApplet.class); + public static final String GUI_STYLE = "GuiStyle"; public final static String RESOURCE_BUNDLE_BASE = "at/gv/egiz/bku/online/applet/Messages"; public final static String LOCALE_PARAM_KEY = "Locale"; public final static String LOGO_URL_KEY = "LogoURL"; public final static String WSDL_URL = "WSDL_URL"; + public static final String HASHDATA_DISPLAY = "HashDataDisplay"; public final static String HASHDATA_URL = "HashDataURL"; public final static String SESSION_ID = "SessionID"; - public static final String BACKGROUND_PARAM = "background"; + public static final String BACKGROUND_PARAM = "Background"; + public static final String REDIRECT_URL = "RedirectURL"; + public static final String REDIRECT_TARGET = "RedirectTarget"; + + public static final String HASHDATA_DISPLAY_INTERNAL = "internal"; protected ResourceBundle resourceBundle; protected BKUWorker worker; @@ -78,7 +84,8 @@ public class BKUApplet extends JApplet { log.warn(ex.getMessage() + ", using default background"); } } - BKUGUIFacade gui = BKUGUIFactory.createGUI(); + String guiStyle = getMyAppletParameter(GUI_STYLE); + BKUGUIFacade gui = BKUGUIFactory.createGUI(guiStyle); gui.init(getContentPane(), localeString, background); worker = new BKUWorker(gui, this, resourceBundle); } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java index b11413d6..350925ce 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java @@ -55,7 +55,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, protected BKUGUIFacade gui; protected BKUApplet parent; private STALPortType stalPort; - private URL hashDataURL; +// private URL hashDataURL; protected List actionCommandList = new ArrayList(); protected Boolean actionPerformed = false; protected boolean finished = false; @@ -140,7 +140,6 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, gui.showWelcomeDialog(); try { stalPort = getSTALPort(); - hashDataURL = getHashDataURL(); } catch (Exception e) { log.fatal("Failed to call STAL service.", e); actionCommandList.clear(); @@ -155,10 +154,10 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, return; } - //TODO factory for SignRequestHandler providing either WebServiceHDISignRequestHandler or ExternalHDIDisplaySignRequestHandler - AppletContext ctx = parent.getAppletContext(); - log.debug("register SignRequestHandler for HashDataURL " + hashDataURL); - addRequestHandler(at.gv.egiz.stal.SignRequest.class, new ExternalDisplaySignRequestHandler(ctx, hashDataURL)); +// //TODO factory for SignRequestHandler providing either WebServiceHDISignRequestHandler or ExternalHDIDisplaySignRequestHandler +// AppletContext ctx = parent.getAppletContext(); +// log.debug("register SignRequestHandler for HashDataURL " + hashDataURL); +// addRequestHandler(at.gv.egiz.stal.SignRequest.class, new ExternalDisplaySignRequestHandler(ctx, hashDataURL)); try { String sessionId = parent.getMyAppletParameter(BKUApplet.SESSION_ID); @@ -167,6 +166,16 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, sessionId = "TestSession"; } + String hashDataDisplayStyle = parent.getMyAppletParameter(BKUApplet.HASHDATA_DISPLAY); + if (BKUApplet.HASHDATA_DISPLAY_INTERNAL.equals(hashDataDisplayStyle)) { + log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); + addRequestHandler(at.gv.egiz.stal.SignRequest.class, new WebServiceSignRequestHandler(sessionId, stalPort)); + } else { //if (HASHDATADISPLAY_EXTERNAL.equals(displayStyle)) { + URL hashDataURL = getHashDataURL(); + log.debug("register SignRequestHandler for HashDataURL " + hashDataURL); + addRequestHandler(at.gv.egiz.stal.SignRequest.class, new ExternalDisplaySignRequestHandler(parent.getAppletContext(), hashDataURL)); + } + // log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); // addRequestHandler(at.gv.egiz.stal.SignRequest.class, new WebServiceSignRequestHandler(sessionId, stalPort)); @@ -254,8 +263,8 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, protected void sendRedirect() { log.info("Done, sending redirect to get BKU response"); - String redirectURL = parent.getMyAppletParameter("redirectURL"); - String redirectTarget = parent.getMyAppletParameter("redirectTarget"); + String redirectURL = parent.getMyAppletParameter(BKUApplet.REDIRECT_URL); + String redirectTarget = parent.getMyAppletParameter(BKUApplet.REDIRECT_TARGET); log.info("Redirecting to: " + redirectURL + " target: " + redirectTarget); URL url = null; if (redirectURL != null) { diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/SignRequestHandlerFactory.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/SignRequestHandlerFactory.java deleted file mode 100644 index 327ea8aa..00000000 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/SignRequestHandlerFactory.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package at.gv.egiz.bku.online.applet; - -import at.gv.egiz.bku.smccstal.SignRequestHandler; - -/** - * - * @author clemens - */ -public class SignRequestHandlerFactory { - - static SignRequestHandler getInstance() { - //TODO return ExternalDisplaySignRequestHandler by default, WebServiceSignRequestHandler if requested - //TODO get configuration as param - return null; - } -} -- cgit v1.2.3 From d56504bc815d41ac9142967915b7e6224c2cf529 Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 15 Oct 2008 13:41:21 +0000 Subject: remove hashdatainputproxy git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@119 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java | 5 ----- 1 file changed, 5 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java index 350925ce..3f64de3d 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java @@ -154,11 +154,6 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, return; } -// //TODO factory for SignRequestHandler providing either WebServiceHDISignRequestHandler or ExternalHDIDisplaySignRequestHandler -// AppletContext ctx = parent.getAppletContext(); -// log.debug("register SignRequestHandler for HashDataURL " + hashDataURL); -// addRequestHandler(at.gv.egiz.stal.SignRequest.class, new ExternalDisplaySignRequestHandler(ctx, hashDataURL)); - try { String sessionId = parent.getMyAppletParameter(BKUApplet.SESSION_ID); if (sessionId == null) { -- cgit v1.2.3 From ef8dc449ddc60008bce9264c73b4162cc487c174 Mon Sep 17 00:00:00 2001 From: wbauer Date: Thu, 16 Oct 2008 07:51:13 +0000 Subject: Changed STAL Handler from static registration to one Object per STAL instance git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@121 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 8 +--- .../at/gv/egiz/bku/online/applet/BKUWorker.java | 17 +++----- .../applet/ExternalDisplaySignRequestHandler.java | 12 ++---- .../bku/online/applet/MultiInstanceHandler.java | 49 ---------------------- .../at/gv/egiz/bku/online/applet/QuitHandler.java | 37 ---------------- .../applet/WebServiceSignRequestHandler.java | 24 +++++------ 6 files changed, 20 insertions(+), 127 deletions(-) delete mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/MultiInstanceHandler.java delete mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/QuitHandler.java (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 96c0e7eb..97b5869f 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -17,11 +17,10 @@ package at.gv.egiz.bku.online.applet; import java.net.MalformedURLException; +import java.net.URL; import java.util.Locale; import java.util.ResourceBundle; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.net.ssl.HttpsURLConnection; import javax.swing.JApplet; @@ -30,10 +29,6 @@ import org.apache.commons.logging.LogFactory; import at.gv.egiz.bku.gui.BKUGUIFacade; import at.gv.egiz.bku.gui.BKUGUIFactory; -import at.gv.egiz.bku.smccstal.AbstractSMCCSTAL; -import at.gv.egiz.stal.QuitRequest; - -import java.net.URL; /** * Note: all swing code is executed by the event dispatch thread (see @@ -66,7 +61,6 @@ public class BKUApplet extends JApplet { public void init() { log.info("Welcome to MOCCA\n"); log.debug("Called init()"); - AbstractSMCCSTAL.addRequestHandler(QuitRequest.class, QuitHandler.getInstance()); HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getInstance()); String localeString = getMyAppletParameter(LOCALE_PARAM_KEY); if (localeString != null) { diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java index 3f64de3d..f708826d 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java @@ -37,16 +37,15 @@ import at.gv.egiz.smcc.util.SMCCHelper; import at.gv.egiz.stal.QuitRequest; import at.gv.egiz.stal.STALRequest; import at.gv.egiz.stal.STALResponse; -import at.gv.egiz.stal.service.types.GetNextRequestResponseType; -import at.gv.egiz.stal.service.types.GetNextRequestType; -import at.gv.egiz.stal.service.types.ObjectFactory; import at.gv.egiz.stal.service.STALPortType; import at.gv.egiz.stal.service.STALService; import at.gv.egiz.stal.service.types.ErrorResponseType; +import at.gv.egiz.stal.service.types.GetNextRequestResponseType; +import at.gv.egiz.stal.service.types.GetNextRequestType; +import at.gv.egiz.stal.service.types.ObjectFactory; import at.gv.egiz.stal.service.types.RequestType; import at.gv.egiz.stal.service.types.ResponseType; import at.gv.egiz.stal.util.STALTranslator; -import java.applet.AppletContext; public class BKUWorker extends AbstractSMCCSTAL implements Runnable, ActionListener, SMCCSTALRequestHandler { @@ -74,7 +73,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, this.gui = gui; this.parent = parent; this.errorMessages = errorMessageBundle; - QuitHandler.getInstance().registerHandlerInstance(this); + addRequestHandler(QuitRequest.class, this); // register SignRequestHandler once we have a webservice port } @@ -87,7 +86,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, protected BKUWorker(BKUGUIFacade gui, ResourceBundle errorMessageBundle) { this.gui = gui; this.errorMessages = errorMessageBundle; - QuitHandler.getInstance().registerHandlerInstance(this); + addRequestHandler(QuitRequest.class, this); } private STALPortType getSTALPort() throws MalformedURLException { @@ -252,7 +251,6 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, if (signatureCard != null) { signatureCard.disconnect(false); } - QuitHandler.getInstance().unregisterHandlerInstance(this); sendRedirect(); } @@ -382,11 +380,6 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, public void init(SignatureCard sc, BKUGUIFacade gui) { } - @Override - public SMCCSTALRequestHandler newInstance() { - return this; - } - @Override public boolean requireCard() { return false; diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalDisplaySignRequestHandler.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalDisplaySignRequestHandler.java index a9bbc559..2ac1bc62 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalDisplaySignRequestHandler.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalDisplaySignRequestHandler.java @@ -5,15 +5,16 @@ package at.gv.egiz.bku.online.applet; -import at.gv.egiz.bku.smccstal.SMCCSTALRequestHandler; -import at.gv.egiz.bku.smccstal.SignRequestHandler; -import at.gv.egiz.stal.signedinfo.ReferenceType; import java.applet.AppletContext; import java.net.URL; import java.util.List; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import at.gv.egiz.bku.smccstal.SignRequestHandler; +import at.gv.egiz.stal.signedinfo.ReferenceType; + /** * * @author clemens @@ -30,11 +31,6 @@ public class ExternalDisplaySignRequestHandler extends SignRequestHandler { this.hashDataURL = hashDataURL; } - @Override - public SMCCSTALRequestHandler newInstance() { - return new ExternalDisplaySignRequestHandler(ctx, hashDataURL); - } - @Override public void displayHashDataInputs(List signedReferences) throws Exception { //TODO pass reference Id's to servlet (TODO servlet) diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/MultiInstanceHandler.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/MultiInstanceHandler.java deleted file mode 100644 index a07df559..00000000 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/MultiInstanceHandler.java +++ /dev/null @@ -1,49 +0,0 @@ -package at.gv.egiz.bku.online.applet; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import at.gv.egiz.bku.gui.BKUGUIFacade; -import at.gv.egiz.bku.smccstal.SMCCSTALRequestHandler; -import at.gv.egiz.smcc.SignatureCard; -import at.gv.egiz.stal.QuitRequest; -import at.gv.egiz.stal.STALRequest; -import at.gv.egiz.stal.STALResponse; - -public abstract class MultiInstanceHandler implements SMCCSTALRequestHandler { - - private static Log log = LogFactory.getLog(MultiInstanceHandler.class); - - protected List handlerList = new ArrayList(); - - - - protected MultiInstanceHandler() { - } - - public void registerHandlerInstance(SMCCSTALRequestHandler handler) { - handlerList.add(handler); - } - - public void unregisterHandlerInstance(SMCCSTALRequestHandler handler) { - handlerList.remove(handler); - } - - - @Override - public void init(SignatureCard sc, BKUGUIFacade gui) { - } - - @Override - public SMCCSTALRequestHandler newInstance() { - return this; - } - - @Override - public boolean requireCard() { - return false; - } -} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/QuitHandler.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/QuitHandler.java deleted file mode 100644 index ab07e1a8..00000000 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/QuitHandler.java +++ /dev/null @@ -1,37 +0,0 @@ -package at.gv.egiz.bku.online.applet; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import at.gv.egiz.bku.smccstal.SMCCSTALRequestHandler; -import at.gv.egiz.stal.QuitRequest; -import at.gv.egiz.stal.STALRequest; -import at.gv.egiz.stal.STALResponse; - -public class QuitHandler extends MultiInstanceHandler { - - private static Log log = LogFactory.getLog(QuitHandler.class); - - private static QuitHandler instance = new QuitHandler(); - - private QuitHandler() { - } - - public static QuitHandler getInstance() { - return instance; - } - - @Override - public STALResponse handleRequest(STALRequest request) { - if (request instanceof QuitRequest) { - log.info("Received QuitCommand"); - for (SMCCSTALRequestHandler handler : handlerList) { - handler.handleRequest(request); - } - } else { - log.error("Unexpected request to handle: " + request); - } - return null; - } - -} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java index 4a87b8b5..b417fd33 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java @@ -16,24 +16,25 @@ */ package at.gv.egiz.bku.online.applet; -import at.gv.egiz.bku.smccstal.SMCCSTALRequestHandler; -import at.gv.egiz.bku.smccstal.SignRequestHandler; -import at.gv.egiz.stal.HashDataInput; -import at.gv.egiz.stal.impl.ByteArrayHashDataInput; -import at.gv.egiz.stal.service.STALPortType; -import at.gv.egiz.stal.service.types.GetHashDataInputResponseType; -import at.gv.egiz.stal.service.types.GetHashDataInputType; -import at.gv.egiz.stal.signedinfo.DigestMethodType; -import at.gv.egiz.stal.signedinfo.ReferenceType; import java.security.DigestException; import java.security.MessageDigest; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import at.gv.egiz.bku.smccstal.SignRequestHandler; +import at.gv.egiz.stal.HashDataInput; +import at.gv.egiz.stal.impl.ByteArrayHashDataInput; +import at.gv.egiz.stal.service.STALPortType; +import at.gv.egiz.stal.service.types.GetHashDataInputResponseType; +import at.gv.egiz.stal.service.types.GetHashDataInputType; +import at.gv.egiz.stal.signedinfo.DigestMethodType; +import at.gv.egiz.stal.signedinfo.ReferenceType; + /** * @author clemens */ @@ -159,9 +160,4 @@ public class WebServiceSignRequestHandler extends SignRequestHandler { gui.showHashDataInputDialog(hashDataInputs, this, "ok"); } - - @Override - public SMCCSTALRequestHandler newInstance() { - return new WebServiceSignRequestHandler(this.sessId, this.stalPort); - } } -- cgit v1.2.3 From 036dd1a8054c5dc818d01e238eb9480d67da478d Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 30 Oct 2008 17:43:40 +0000 Subject: Help Icon git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@130 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 158 ++++++++++++--------- .../at/gv/egiz/bku/online/applet/BKUWorker.java | 24 +--- .../bku/online/applet/ExternalHelpListener.java | 70 +++++++++ 3 files changed, 168 insertions(+), 84 deletions(-) create mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalHelpListener.java (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 97b5869f..470534da 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -21,6 +21,8 @@ import java.net.URL; import java.util.Locale; import java.util.ResourceBundle; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.net.ssl.HttpsURLConnection; import javax.swing.JApplet; @@ -36,79 +38,105 @@ import at.gv.egiz.bku.gui.BKUGUIFactory; */ public class BKUApplet extends JApplet { - private static Log log = LogFactory.getLog(BKUApplet.class); - public static final String GUI_STYLE = "GuiStyle"; - public final static String RESOURCE_BUNDLE_BASE = "at/gv/egiz/bku/online/applet/Messages"; - public final static String LOCALE_PARAM_KEY = "Locale"; - public final static String LOGO_URL_KEY = "LogoURL"; - public final static String WSDL_URL = "WSDL_URL"; - public static final String HASHDATA_DISPLAY = "HashDataDisplay"; - public final static String HASHDATA_URL = "HashDataURL"; - public final static String SESSION_ID = "SessionID"; - public static final String BACKGROUND_PARAM = "Background"; - public static final String REDIRECT_URL = "RedirectURL"; - public static final String REDIRECT_TARGET = "RedirectTarget"; - - public static final String HASHDATA_DISPLAY_INTERNAL = "internal"; - - protected ResourceBundle resourceBundle; - protected BKUWorker worker; - protected Thread workerThread; + private static Log log = LogFactory.getLog(BKUApplet.class); + public static final String GUI_STYLE = "GuiStyle"; + public final static String RESOURCE_BUNDLE_BASE = "at/gv/egiz/bku/online/applet/Messages"; + public final static String LOCALE_PARAM_KEY = "Locale"; + public final static String LOGO_URL_KEY = "LogoURL"; + public final static String WSDL_URL = "WSDL_URL"; + public static final String HASHDATA_DISPLAY = "HashDataDisplay"; + public final static String HASHDATA_URL = "HashDataURL"; + public final static String HELP_URL = "HelpURL"; + public final static String SESSION_ID = "SessionID"; + public static final String BACKGROUND_PARAM = "Background"; + public static final String REDIRECT_URL = "RedirectURL"; + public static final String REDIRECT_TARGET = "RedirectTarget"; + public static final String HASHDATA_DISPLAY_INTERNAL = "internal"; + protected ResourceBundle resourceBundle; + protected BKUWorker worker; + protected Thread workerThread; - public BKUApplet() { - } + public BKUApplet() { + } - public void init() { - log.info("Welcome to MOCCA\n"); - log.debug("Called init()"); - HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getInstance()); - String localeString = getMyAppletParameter(LOCALE_PARAM_KEY); - if (localeString != null) { - resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE, + @Override + public void init() { + log.info("Welcome to MOCCA\n"); + log.debug("Called init()"); + HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getInstance()); + String localeString = getMyAppletParameter(LOCALE_PARAM_KEY); + if (localeString != null) { + resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE, new Locale(localeString)); - } else { - resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE); - } - String backgroundString = getMyAppletParameter(BACKGROUND_PARAM); - URL background = null; - if (backgroundString != null) { - try { - background = new URL(backgroundString); - } catch (MalformedURLException ex) { - log.warn(ex.getMessage() + ", using default background"); - } - } - String guiStyle = getMyAppletParameter(GUI_STYLE); - BKUGUIFacade gui = BKUGUIFactory.createGUI(guiStyle); - gui.init(getContentPane(), localeString, background); - worker = new BKUWorker(gui, this, resourceBundle); + } else { + resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE); } - - public void start() { - log.debug("Called start()"); - workerThread = new Thread(worker); - workerThread.start(); + String backgroundString = getMyAppletParameter(BACKGROUND_PARAM); + URL background = null; + if (backgroundString != null) { + try { + background = new URL(backgroundString); + } catch (MalformedURLException ex) { + log.warn(ex.getMessage() + ", using default background"); + } } - - public void stop() { - log.debug("Called stop()"); - if ((workerThread != null) && (workerThread.isAlive())) { - workerThread.interrupt(); - } + String guiStyle = getMyAppletParameter(GUI_STYLE); + BKUGUIFacade gui = BKUGUIFactory.createGUI(guiStyle); + ExternalHelpListener helpListener = null; + try { + URL helpURL = getMyAppletParameterURL(HELP_URL); + helpListener = new ExternalHelpListener(getAppletContext(), helpURL, localeString); + } catch (MalformedURLException ex) { + log.error("invalid help URL: " + ex.getMessage()); } + gui.init(getContentPane(), localeString, background, helpListener); + worker = new BKUWorker(gui, this, resourceBundle); + } - public void destroy() { - log.debug("Called destroy()"); + @Override + public void start() { + log.debug("Called start()"); + workerThread = new Thread(worker); + workerThread.start(); + } + + @Override + public void stop() { + log.debug("Called stop()"); + if ((workerThread != null) && (workerThread.isAlive())) { + workerThread.interrupt(); } + } + + @Override + public void destroy() { + log.debug("Called destroy()"); + } + + /** + * Applet configuration parameters + * + * @param paramKey + * @return + */ + String getMyAppletParameter(String paramKey) { + log.info("Getting parameter: " + paramKey + ": " + getParameter(paramKey)); + return getParameter(paramKey); + } - /** - * Applet configuration parameters - * - * @param paramKey - * @return - */ - public String getMyAppletParameter(String paramKey) { - log.info("Getting parameter: " + paramKey + ": " + getParameter(paramKey)); - return getParameter(paramKey); + URL getMyAppletParameterURL(String param) throws MalformedURLException { + String hashDataParam = getMyAppletParameter(param); //BKUApplet.HASHDATA_URL); + if (hashDataParam != null) { + URL codebase = getCodeBase(); + try { + return new URL(codebase, hashDataParam); + } catch (MalformedURLException ex) { + log.error("Paremeter " + param + " is not a valid URL.", ex); + throw new MalformedURLException(ex.getMessage()); + } + } else { + log.error("Paremeter " + param + " not set"); + throw new MalformedURLException(param + " not set"); } + } } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java index f708826d..78f3dc12 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java @@ -24,6 +24,8 @@ import java.util.ArrayList; import java.util.List; import java.util.ResourceBundle; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.xml.namespace.QName; import org.apache.commons.logging.Log; @@ -46,6 +48,7 @@ import at.gv.egiz.stal.service.types.ObjectFactory; import at.gv.egiz.stal.service.types.RequestType; import at.gv.egiz.stal.service.types.ResponseType; import at.gv.egiz.stal.util.STALTranslator; +import javax.naming.ConfigurationException; public class BKUWorker extends AbstractSMCCSTAL implements Runnable, ActionListener, SMCCSTALRequestHandler { @@ -68,7 +71,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, public BKUWorker(BKUGUIFacade gui, BKUApplet parent, ResourceBundle errorMessageBundle) { if ((gui == null) || (parent == null) || (errorMessageBundle == null)) { - throw new NullPointerException("Parameter must not be set to null"); + throw new NullPointerException("Parameter must not be set to null"); } this.gui = gui; this.parent = parent; @@ -117,23 +120,6 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, return stal.getSTALPort(); } - private URL getHashDataURL() throws MalformedURLException { - String hashDataParam = parent.getMyAppletParameter(BKUApplet.HASHDATA_URL); - URL codebase = parent.getCodeBase(); - if (hashDataParam != null) { - try { - return new URL(codebase, hashDataParam); -// log.debug("Found HashDataInputServlet URL: " + hashDataURL); - } catch (MalformedURLException ex) { - log.fatal("Paremeter " + BKUApplet.HASHDATA_URL + " is not a vailid URL.", ex); - throw new MalformedURLException(ex.getMessage()); - } - } else { - log.fatal("Paremeter " + BKUApplet.HASHDATA_URL + " not set"); - throw new MalformedURLException(BKUApplet.HASHDATA_URL + " not set"); - } - } - @Override public void run() { gui.showWelcomeDialog(); @@ -165,7 +151,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); addRequestHandler(at.gv.egiz.stal.SignRequest.class, new WebServiceSignRequestHandler(sessionId, stalPort)); } else { //if (HASHDATADISPLAY_EXTERNAL.equals(displayStyle)) { - URL hashDataURL = getHashDataURL(); + URL hashDataURL = parent.getMyAppletParameterURL(BKUApplet.HASHDATA_URL); log.debug("register SignRequestHandler for HashDataURL " + hashDataURL); addRequestHandler(at.gv.egiz.stal.SignRequest.class, new ExternalDisplaySignRequestHandler(parent.getAppletContext(), hashDataURL)); } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalHelpListener.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalHelpListener.java new file mode 100644 index 00000000..4d6d5851 --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalHelpListener.java @@ -0,0 +1,70 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package at.gv.egiz.bku.online.applet; + +import java.applet.AppletContext; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.net.MalformedURLException; +import java.net.URL; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author clemens + */ +public class ExternalHelpListener implements ActionListener { + + protected final static Log log = LogFactory.getLog(ExternalHelpListener.class); + protected AppletContext ctx; + protected String helpURLBase; + protected String locale; + + public ExternalHelpListener(AppletContext ctx, URL helpURL, String locale) { + if (ctx == null) { + throw new RuntimeException("no applet context provided"); + } + if (helpURL == null || "".equals(helpURL)) { + throw new RuntimeException("no help URL provided"); + } + this.ctx = ctx; + this.helpURLBase = helpURL.toString(); + this.locale = locale; + } + + @Override + public void actionPerformed(ActionEvent e) { + log.debug("received help action: " + e.getActionCommand()); + URL helpURL; + try { + String urlString = helpURLBase; + if (locale != null) { + urlString = appendParameter(urlString, "locale", locale); + } + if (e.getActionCommand() != null && !"".equals(e.getActionCommand())) { + urlString = appendParameter(urlString, "topic", e.getActionCommand()); + } + helpURL = new URL(urlString); + } catch (MalformedURLException ex) { + try { + log.error("failed to create help URL: " + ex.getMessage()); + helpURL = new URL(helpURLBase); + } catch (MalformedURLException ex1) { + log.error("failed to create default help URL, requested help will not be displayed"); + return; + } + } + ctx.showDocument(helpURL, "_blank"); + } + + private String appendParameter(String url, String paramName, String paramValue) { + if (url.indexOf('?') < 0) { + return url + "?" + paramName + "=" + paramValue; + } else { + return url + "&" + paramName + "=" + paramValue; + } + } +} -- cgit v1.2.3 From 8479ef50c84e8998f7909074df6a23c2ff0aa5b0 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 31 Oct 2008 12:33:18 +0000 Subject: Help Icon git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@132 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../applet/ExternalDisplaySignRequestHandler.java | 16 ++++++++++++++-- .../gv/egiz/bku/online/applet/ExternalHelpListener.java | 17 +++++++++++++++-- .../bku/online/applet/InternalSSLSocketFactory.java | 4 ---- .../bku/online/applet/WebServiceSignRequestHandler.java | 1 + 4 files changed, 30 insertions(+), 8 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalDisplaySignRequestHandler.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalDisplaySignRequestHandler.java index 2ac1bc62..2c9fde71 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalDisplaySignRequestHandler.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalDisplaySignRequestHandler.java @@ -1,6 +1,18 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package at.gv.egiz.bku.online.applet; diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalHelpListener.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalHelpListener.java index 4d6d5851..f92a6963 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalHelpListener.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalHelpListener.java @@ -1,7 +1,20 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + package at.gv.egiz.bku.online.applet; import java.applet.AppletContext; diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java index fa3587e4..c3417d63 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java @@ -14,10 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ package at.gv.egiz.bku.online.applet; diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java index b417fd33..ddbe76bf 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package at.gv.egiz.bku.online.applet; import java.security.DigestException; -- cgit v1.2.3 From 4032e46810c24dc3f013de296a2133f4651696b9 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 31 Oct 2008 15:30:34 +0000 Subject: local HelpListener card locked/not activated git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@137 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../egiz/bku/online/applet/AppletHelpListener.java | 46 ++++++++++++ .../at/gv/egiz/bku/online/applet/BKUApplet.java | 4 +- .../bku/online/applet/ExternalHelpListener.java | 83 ---------------------- 3 files changed, 48 insertions(+), 85 deletions(-) create mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHelpListener.java delete mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalHelpListener.java (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHelpListener.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHelpListener.java new file mode 100644 index 00000000..a0305eb4 --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHelpListener.java @@ -0,0 +1,46 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package at.gv.egiz.bku.online.applet; + +import at.gv.egiz.bku.gui.AbstractHelpListener; +import java.applet.AppletContext; +import java.net.URL; + +/** + * + * @author clemens + */ +public class AppletHelpListener extends AbstractHelpListener { + + protected AppletContext ctx; + + public AppletHelpListener(AppletContext ctx, URL helpURL, String locale) { + super(helpURL, locale); + if (ctx == null) { + throw new RuntimeException("no applet context provided"); + } + this.ctx = ctx; + } + + @Override + public void showDocument(URL helpDocument) throws Exception { + ctx.showDocument(helpDocument, "_blank"); + } + + +} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 470534da..2b0188bb 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -82,10 +82,10 @@ public class BKUApplet extends JApplet { } String guiStyle = getMyAppletParameter(GUI_STYLE); BKUGUIFacade gui = BKUGUIFactory.createGUI(guiStyle); - ExternalHelpListener helpListener = null; + AppletHelpListener helpListener = null; try { URL helpURL = getMyAppletParameterURL(HELP_URL); - helpListener = new ExternalHelpListener(getAppletContext(), helpURL, localeString); + helpListener = new AppletHelpListener(getAppletContext(), helpURL, localeString); } catch (MalformedURLException ex) { log.error("invalid help URL: " + ex.getMessage()); } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalHelpListener.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalHelpListener.java deleted file mode 100644 index f92a6963..00000000 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalHelpListener.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2008 Federal Chancellery Austria and - * Graz University of Technology - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package at.gv.egiz.bku.online.applet; - -import java.applet.AppletContext; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.net.MalformedURLException; -import java.net.URL; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * - * @author clemens - */ -public class ExternalHelpListener implements ActionListener { - - protected final static Log log = LogFactory.getLog(ExternalHelpListener.class); - protected AppletContext ctx; - protected String helpURLBase; - protected String locale; - - public ExternalHelpListener(AppletContext ctx, URL helpURL, String locale) { - if (ctx == null) { - throw new RuntimeException("no applet context provided"); - } - if (helpURL == null || "".equals(helpURL)) { - throw new RuntimeException("no help URL provided"); - } - this.ctx = ctx; - this.helpURLBase = helpURL.toString(); - this.locale = locale; - } - - @Override - public void actionPerformed(ActionEvent e) { - log.debug("received help action: " + e.getActionCommand()); - URL helpURL; - try { - String urlString = helpURLBase; - if (locale != null) { - urlString = appendParameter(urlString, "locale", locale); - } - if (e.getActionCommand() != null && !"".equals(e.getActionCommand())) { - urlString = appendParameter(urlString, "topic", e.getActionCommand()); - } - helpURL = new URL(urlString); - } catch (MalformedURLException ex) { - try { - log.error("failed to create help URL: " + ex.getMessage()); - helpURL = new URL(helpURLBase); - } catch (MalformedURLException ex1) { - log.error("failed to create default help URL, requested help will not be displayed"); - return; - } - } - ctx.showDocument(helpURL, "_blank"); - } - - private String appendParameter(String url, String paramName, String paramValue) { - if (url.indexOf('?') < 0) { - return url + "?" + paramName + "=" + paramValue; - } else { - return url + "&" + paramName + "=" + paramValue; - } - } -} -- cgit v1.2.3 From 9829de9c9b19dcca15676aaf9737195cc059a66c Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 3 Nov 2008 09:37:14 +0000 Subject: local HelpListener DesktopAPI git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@138 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/online/applet/AppletHelpListener.java | 3 ++- BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHelpListener.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHelpListener.java index a0305eb4..4040431f 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHelpListener.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHelpListener.java @@ -20,6 +20,7 @@ package at.gv.egiz.bku.online.applet; import at.gv.egiz.bku.gui.AbstractHelpListener; import java.applet.AppletContext; import java.net.URL; +import java.util.Locale; /** * @@ -29,7 +30,7 @@ public class AppletHelpListener extends AbstractHelpListener { protected AppletContext ctx; - public AppletHelpListener(AppletContext ctx, URL helpURL, String locale) { + public AppletHelpListener(AppletContext ctx, URL helpURL, Locale locale) { super(helpURL, locale); if (ctx == null) { throw new RuntimeException("no applet context provided"); diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 2b0188bb..50d66d80 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -65,9 +65,11 @@ public class BKUApplet extends JApplet { log.debug("Called init()"); HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getInstance()); String localeString = getMyAppletParameter(LOCALE_PARAM_KEY); + Locale locale = null; if (localeString != null) { + locale = new Locale(localeString); resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE, - new Locale(localeString)); + locale); } else { resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE); } @@ -85,7 +87,7 @@ public class BKUApplet extends JApplet { AppletHelpListener helpListener = null; try { URL helpURL = getMyAppletParameterURL(HELP_URL); - helpListener = new AppletHelpListener(getAppletContext(), helpURL, localeString); + helpListener = new AppletHelpListener(getAppletContext(), helpURL, locale); } catch (MalformedURLException ex) { log.error("invalid help URL: " + ex.getMessage()); } -- cgit v1.2.3 From 6211ed7f96c4ee6e1616a7c1e44477b9f3e8117f Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 3 Nov 2008 12:36:42 +0000 Subject: localization git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@140 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../java/at/gv/egiz/bku/online/applet/BKUApplet.java | 20 +++++++------------- .../java/at/gv/egiz/bku/online/applet/BKUWorker.java | 17 ++++++----------- 2 files changed, 13 insertions(+), 24 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 50d66d80..bde055ec 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -40,7 +40,6 @@ public class BKUApplet extends JApplet { private static Log log = LogFactory.getLog(BKUApplet.class); public static final String GUI_STYLE = "GuiStyle"; - public final static String RESOURCE_BUNDLE_BASE = "at/gv/egiz/bku/online/applet/Messages"; public final static String LOCALE_PARAM_KEY = "Locale"; public final static String LOGO_URL_KEY = "LogoURL"; public final static String WSDL_URL = "WSDL_URL"; @@ -52,7 +51,6 @@ public class BKUApplet extends JApplet { public static final String REDIRECT_URL = "RedirectURL"; public static final String REDIRECT_TARGET = "RedirectTarget"; public static final String HASHDATA_DISPLAY_INTERNAL = "internal"; - protected ResourceBundle resourceBundle; protected BKUWorker worker; protected Thread workerThread; @@ -64,14 +62,9 @@ public class BKUApplet extends JApplet { log.info("Welcome to MOCCA\n"); log.debug("Called init()"); HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getInstance()); - String localeString = getMyAppletParameter(LOCALE_PARAM_KEY); - Locale locale = null; - if (localeString != null) { - locale = new Locale(localeString); - resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE, - locale); - } else { - resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE); + String locale = getMyAppletParameter(LOCALE_PARAM_KEY); + if (locale != null) { + this.setLocale(new Locale(locale)); } String backgroundString = getMyAppletParameter(BACKGROUND_PARAM); URL background = null; @@ -84,15 +77,16 @@ public class BKUApplet extends JApplet { } String guiStyle = getMyAppletParameter(GUI_STYLE); BKUGUIFacade gui = BKUGUIFactory.createGUI(guiStyle); + log.debug("setting GUI locale to " + getLocale()); AppletHelpListener helpListener = null; try { URL helpURL = getMyAppletParameterURL(HELP_URL); - helpListener = new AppletHelpListener(getAppletContext(), helpURL, locale); + helpListener = new AppletHelpListener(getAppletContext(), helpURL, getLocale()); } catch (MalformedURLException ex) { log.error("invalid help URL: " + ex.getMessage()); } - gui.init(getContentPane(), localeString, background, helpListener); - worker = new BKUWorker(gui, this, resourceBundle); + gui.init(getContentPane(), getLocale(), background, helpListener); + worker = new BKUWorker(gui, this); } @Override diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java index 78f3dc12..843f6c4c 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java @@ -48,7 +48,6 @@ import at.gv.egiz.stal.service.types.ObjectFactory; import at.gv.egiz.stal.service.types.RequestType; import at.gv.egiz.stal.service.types.ResponseType; import at.gv.egiz.stal.util.STALTranslator; -import javax.naming.ConfigurationException; public class BKUWorker extends AbstractSMCCSTAL implements Runnable, ActionListener, SMCCSTALRequestHandler { @@ -57,25 +56,22 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, protected BKUGUIFacade gui; protected BKUApplet parent; private STALPortType stalPort; -// private URL hashDataURL; protected List actionCommandList = new ArrayList(); protected Boolean actionPerformed = false; protected boolean finished = false; - protected ResourceBundle errorMessages; /** * * @param gui * must not be null */ - public BKUWorker(BKUGUIFacade gui, BKUApplet parent, - ResourceBundle errorMessageBundle) { - if ((gui == null) || (parent == null) || (errorMessageBundle == null)) { + public BKUWorker(BKUGUIFacade gui, BKUApplet parent) { + if (gui == null || parent == null) { throw new NullPointerException("Parameter must not be set to null"); } this.gui = gui; + this.locale = gui.getLocale(); this.parent = parent; - this.errorMessages = errorMessageBundle; addRequestHandler(QuitRequest.class, this); // register SignRequestHandler once we have a webservice port } @@ -86,9 +82,9 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, * @param gui * @param errorMessageBundle */ - protected BKUWorker(BKUGUIFacade gui, ResourceBundle errorMessageBundle) { + protected BKUWorker(BKUGUIFacade gui) { this.gui = gui; - this.errorMessages = errorMessageBundle; + this.locale = gui.getLocale(); addRequestHandler(QuitRequest.class, this); } @@ -342,8 +338,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, } break; case SMCCHelper.CARD_FOUND: - // gui.showWaitDialog(null); - signatureCard = smccHelper.getSignatureCard(errorMessages.getLocale()); + signatureCard = smccHelper.getSignatureCard(locale); return false; } smccHelper.update(3000); -- cgit v1.2.3 From c7c00fbb89717c2a3a51f64908ad78a61ae70da0 Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 5 Nov 2008 10:05:54 +0000 Subject: BKUWorker refactoring jssessionId git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@148 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/online/applet/AppletBKUWorker.java | 205 +++++++++++ .../bku/online/applet/AppletParameterProvider.java | 57 ++++ .../at/gv/egiz/bku/online/applet/BKUApplet.java | 125 ++++--- .../at/gv/egiz/bku/online/applet/BKUWorker.java | 374 --------------------- .../applet/WebServiceSignRequestHandler.java | 2 +- 5 files changed, 343 insertions(+), 420 deletions(-) create mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java create mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletParameterProvider.java delete mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java new file mode 100644 index 00000000..2141165b --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java @@ -0,0 +1,205 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package at.gv.egiz.bku.online.applet; + +import at.gv.egiz.bku.smccstal.AbstractBKUWorker; +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.stal.STALRequest; +import at.gv.egiz.stal.STALResponse; +import at.gv.egiz.stal.SignRequest; +import at.gv.egiz.stal.service.STALPortType; +import at.gv.egiz.stal.service.STALService; +import at.gv.egiz.stal.service.types.ErrorResponseType; +import at.gv.egiz.stal.service.types.GetNextRequestResponseType; +import at.gv.egiz.stal.service.types.GetNextRequestType; +import at.gv.egiz.stal.service.types.ObjectFactory; +import at.gv.egiz.stal.service.types.RequestType; +import at.gv.egiz.stal.service.types.ResponseType; +import at.gv.egiz.stal.util.STALTranslator; +import java.applet.AppletContext; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import javax.xml.namespace.QName; + +/** + * + * @author Clemens Orthacker + */ +public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { + + protected AppletContext ctx; + protected AppletParameterProvider params; + protected String sessionId; + protected STALPortType stalPort; + + public AppletBKUWorker(BKUGUIFacade gui, AppletContext ctx, AppletParameterProvider paramProvider) { + super(gui); + if (ctx == null) { + throw new NullPointerException("Applet context not provided"); + } + if (paramProvider == null) { + throw new NullPointerException("No applet parameters provided"); + } + this.ctx = ctx; + this.params = paramProvider; + + sessionId = params.getAppletParameter(BKUApplet.SESSION_ID); + if (sessionId == null) { + sessionId = "TestSession"; + log.info("using dummy sessionId " + sessionId); + } + } + + @Override + public void run() { + gui.showWelcomeDialog(); + try { + stalPort = getSTALPort(); + } catch (Exception e) { + log.fatal("Failed to get STAL web-service port: " + e.getMessage(), e); + actionCommandList.clear(); + actionCommandList.add("ok"); + gui.showErrorDialog(BKUGUIFacade.ERR_SERVICE_UNREACHABLE, + new Object[]{e.getMessage()}); + try { + waitForAction(); + } catch (InterruptedException e1) { + log.error(e1); + } + return; + } + + try { + registerSignRequestHandler(); + + ObjectFactory of = new ObjectFactory(); + + GetNextRequestResponseType nextRequestResp = stalPort.connect(sessionId); + do { + List requests = nextRequestResp.getInfoboxReadRequestOrSignRequestOrQuitRequest(); + List stalRequests = STALTranslator.translateRequests(requests); + + if (log.isInfoEnabled()) { + StringBuilder sb = new StringBuilder("Received "); + sb.append(stalRequests.size()); + sb.append(" STAL requests: "); + for (STALRequest r : stalRequests) { + sb.append(r.getClass()); + sb.append(' '); + } + log.info(sb.toString()); + } + + boolean handle = true; + for (STALRequest request : stalRequests) { + if (request instanceof at.gv.egiz.stal.InfoboxReadRequest) { + at.gv.egiz.stal.InfoboxReadRequest r = (at.gv.egiz.stal.InfoboxReadRequest) request; + String infoboxId = r.getInfoboxIdentifier(); + String domainId = r.getDomainIdentifier(); + if ("IdentityLink".equals(infoboxId) && domainId == null) { + if (!InternalSSLSocketFactory.getInstance().isEgovAgency()) { + handle = false; + } + } + } + } + + List responses; + if (handle) { + List stalResponses = handleRequest(stalRequests); + if (log.isInfoEnabled()) { + StringBuilder sb = new StringBuilder(stalResponses.size()); + sb.append(" STAL responses: "); + for (STALResponse r : stalResponses) { + sb.append(r.getClass()); + sb.append(' '); + } + log.info(sb.toString()); + } + responses = STALTranslator.fromSTAL(stalResponses); + } else { + responses = new ArrayList(1); + ErrorResponseType err = of.createErrorResponseType(); + err.setErrorCode(6002); + // err.setErrorMessage(); + responses.add(err); + } + + if (!finished) { + log.info("Not finished yet (BKUWorker: " + this + "), sending responses"); + GetNextRequestType nextRequest = of.createGetNextRequestType(); + nextRequest.setSessionId(sessionId); + nextRequest.getInfoboxReadResponseOrSignResponseOrErrorResponse().addAll(responses); + nextRequestResp = stalPort.getNextRequest(nextRequest); + } + } while (!finished); + log.info("Done " + Thread.currentThread().getName()); + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, new Object[]{ex.getMessage()}); + try { + waitForAction(); + } catch (InterruptedException e) { + log.error(e); + } + } + if (signatureCard != null) { + signatureCard.disconnect(false); + } + sendRedirect(); + } + + protected void sendRedirect() { + try { + URL redirectURL = params.getURLParameter(BKUApplet.REDIRECT_URL, sessionId); + String redirectTarget = params.getAppletParameter(BKUApplet.REDIRECT_TARGET); + if (redirectTarget == null) { + log.info("Done. Redirecting to " + redirectURL + " ..."); + ctx.showDocument(redirectURL); + } else { + log.info("Done. Redirecting to " + redirectURL + " (target=" + redirectTarget + ") ..."); + ctx.showDocument(redirectURL, redirectTarget); + } + } catch (MalformedURLException ex) { + log.warn("Failed to redirect: " + ex.getMessage(), ex); + // gui.showErrorDialog(errorMsg, okListener, actionCommand) + } + } + + private STALPortType getSTALPort() throws MalformedURLException { + URL wsdlURL = params.getURLParameter(BKUApplet.WSDL_URL); + log.debug("STAL WSDL at " + wsdlURL); + QName endpointName = new QName(BKUApplet.STAL_WSDL_NS, BKUApplet.STAL_SERVICE); + STALService stal = new STALService(wsdlURL, endpointName); + return stal.getSTALPort(); + } + + private void registerSignRequestHandler() throws MalformedURLException { + String hashDataDisplayStyle = params.getAppletParameter(BKUApplet.HASHDATA_DISPLAY); + if (BKUApplet.HASHDATA_DISPLAY_INTERNAL.equals(hashDataDisplayStyle)) { + log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); + addRequestHandler(SignRequest.class, new WebServiceSignRequestHandler(stalPort, sessionId)); + } else { + //if (HASHDATADISPLAY_EXTERNAL.equals(displayStyle)) { + URL hashDataURL = params.getURLParameter(BKUApplet.HASHDATA_URL, sessionId); + log.debug("register SignRequestHandler for HashDataURL " + hashDataURL); + addRequestHandler(SignRequest.class, new ExternalDisplaySignRequestHandler(ctx, hashDataURL)); + } + } +} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletParameterProvider.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletParameterProvider.java new file mode 100644 index 00000000..42e2d6ff --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletParameterProvider.java @@ -0,0 +1,57 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package at.gv.egiz.bku.online.applet; + +import java.net.MalformedURLException; +import java.net.URL; + +/** + * + * @author Clemens Orthacker + */ +public interface AppletParameterProvider { + + /** + * Applet configuration parameters + * + * @param paramKey + * @return null if no parameter is provided for the given key + */ + String getAppletParameter(String paramKey); + + /** + * Get applet configuration parameter as (absolute) URL + * + * @param paramKey + * @return a URL + * @throws MalformedURLException if configured URL is invalid + * or no parameter is provided for the given key + */ + URL getURLParameter(String paramKey) throws MalformedURLException; + + /** + * Get applet configuration parameter as (absolute) URL + * + * @param paramKey + * @param sessionId adds the jsessionid to the URL + * @return a URL + * @throws MalformedURLException if configured URL is invalid + * or no parameter is provided for the given key + */ + URL getURLParameter(String paramKey, String sessionId) throws MalformedURLException; +} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index bde055ec..f3eecdf9 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -16,6 +16,7 @@ */ package at.gv.egiz.bku.online.applet; +import at.gv.egiz.bku.smccstal.AbstractBKUWorker; import java.net.MalformedURLException; import java.net.URL; import java.util.Locale; @@ -36,9 +37,13 @@ import at.gv.egiz.bku.gui.BKUGUIFactory; * Note: all swing code is executed by the event dispatch thread (see * BKUGUIFacade) */ -public class BKUApplet extends JApplet { +public class BKUApplet extends JApplet implements AppletParameterProvider { private static Log log = LogFactory.getLog(BKUApplet.class); + + /** + * Applet parameter keys + */ public static final String GUI_STYLE = "GuiStyle"; public final static String LOCALE_PARAM_KEY = "Locale"; public final static String LOGO_URL_KEY = "LogoURL"; @@ -51,42 +56,59 @@ public class BKUApplet extends JApplet { public static final String REDIRECT_URL = "RedirectURL"; public static final String REDIRECT_TARGET = "RedirectTarget"; public static final String HASHDATA_DISPLAY_INTERNAL = "internal"; - protected BKUWorker worker; + + /** + * STAL WSDL namespace and service name + */ + public static final String STAL_WSDL_NS = "http://www.egiz.gv.at/wsdl/stal"; + public static final String STAL_SERVICE = "STALService"; + + /** + * Dummy session id, used if no sessionId parameter is provided + */ + protected static final String TEST_SESSION_ID = "TestSession"; + + /** + * STAL + */ + protected AppletBKUWorker worker; protected Thread workerThread; - public BKUApplet() { - } - + /** + * Factory method to create and wire HelpListener, GUI and BKUWorker. + */ @Override public void init() { - log.info("Welcome to MOCCA\n"); + log.info("Welcome to MOCCA"); log.debug("Called init()"); + HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getInstance()); - String locale = getMyAppletParameter(LOCALE_PARAM_KEY); - if (locale != null) { - this.setLocale(new Locale(locale)); - } - String backgroundString = getMyAppletParameter(BACKGROUND_PARAM); - URL background = null; - if (backgroundString != null) { - try { - background = new URL(backgroundString); - } catch (MalformedURLException ex) { - log.warn(ex.getMessage() + ", using default background"); - } + + String locale = getAppletParameter(LOCALE_PARAM_KEY); + String guiStyle = getAppletParameter(GUI_STYLE); + URL backgroundImgURL = null; + URL helpURL = null; + try { + helpURL = getURLParameter(HELP_URL, getAppletParameter(SESSION_ID)); + } catch (MalformedURLException ex) { + log.warn("failed to load help URL, disabling help: " + ex.getMessage()); } - String guiStyle = getMyAppletParameter(GUI_STYLE); - BKUGUIFacade gui = BKUGUIFactory.createGUI(guiStyle); - log.debug("setting GUI locale to " + getLocale()); - AppletHelpListener helpListener = null; try { - URL helpURL = getMyAppletParameterURL(HELP_URL); - helpListener = new AppletHelpListener(getAppletContext(), helpURL, getLocale()); + backgroundImgURL = getURLParameter(BACKGROUND_PARAM); } catch (MalformedURLException ex) { - log.error("invalid help URL: " + ex.getMessage()); + log.info("failed to load applet background image, using default: " + ex.getMessage()); } - gui.init(getContentPane(), getLocale(), background, helpListener); - worker = new BKUWorker(gui, this); + + if (locale != null) { + this.setLocale(new Locale(locale)); + } + log.debug("setting locale to " + getLocale()); + + BKUGUIFacade gui = BKUGUIFactory.createGUI(guiStyle); + AppletHelpListener helpListener = new AppletHelpListener(getAppletContext(), helpURL, getLocale()); + gui.init(getContentPane(), getLocale(), backgroundImgURL, helpListener); + + worker = new AppletBKUWorker(gui, getAppletContext(), this); } @Override @@ -109,30 +131,43 @@ public class BKUApplet extends JApplet { log.debug("Called destroy()"); } - /** - * Applet configuration parameters - * - * @param paramKey - * @return - */ - String getMyAppletParameter(String paramKey) { - log.info("Getting parameter: " + paramKey + ": " + getParameter(paramKey)); - return getParameter(paramKey); + @Override + public String getAppletParameter(String paramKey) { + String param = getParameter(paramKey); + log.info("applet parameter: " + paramKey + ": " + param); + return param; } - URL getMyAppletParameterURL(String param) throws MalformedURLException { - String hashDataParam = getMyAppletParameter(param); //BKUApplet.HASHDATA_URL); - if (hashDataParam != null) { + @Override + public URL getURLParameter(String paramKey, String sessionId) throws MalformedURLException { + String urlParam = getParameter(paramKey); + if (urlParam != null) { URL codebase = getCodeBase(); try { - return new URL(codebase, hashDataParam); + URL url; + if (codebase.getProtocol().equalsIgnoreCase("file")) { + // for debugging in appletrunner + url = new URL(urlParam); + } else { + if (sessionId != null) { + urlParam = urlParam + ";jsessionid=" + sessionId; + } + url = new URL(codebase, urlParam); + } + log.info("applet parameter " + url); + return url; } catch (MalformedURLException ex) { - log.error("Paremeter " + param + " is not a valid URL.", ex); - throw new MalformedURLException(ex.getMessage()); - } + log.error("applet paremeter " + urlParam + " is not a valid URL: " + ex.getMessage()); + throw ex; + } } else { - log.error("Paremeter " + param + " not set"); - throw new MalformedURLException(param + " not set"); + log.error("applet paremeter " + urlParam + " not set"); + throw new MalformedURLException(urlParam + " not set"); } } + + @Override + public URL getURLParameter(String paramKey) throws MalformedURLException { + return getURLParameter(paramKey, null); + } } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java deleted file mode 100644 index 843f6c4c..00000000 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java +++ /dev/null @@ -1,374 +0,0 @@ -/* - * Copyright 2008 Federal Chancellery Austria and - * Graz University of Technology - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package at.gv.egiz.bku.online.applet; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; -import java.util.ResourceBundle; - -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.xml.namespace.QName; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import at.gv.egiz.bku.gui.BKUGUIFacade; -import at.gv.egiz.bku.smccstal.AbstractSMCCSTAL; -import at.gv.egiz.bku.smccstal.SMCCSTALRequestHandler; -import at.gv.egiz.smcc.SignatureCard; -import at.gv.egiz.smcc.util.SMCCHelper; -import at.gv.egiz.stal.QuitRequest; -import at.gv.egiz.stal.STALRequest; -import at.gv.egiz.stal.STALResponse; -import at.gv.egiz.stal.service.STALPortType; -import at.gv.egiz.stal.service.STALService; -import at.gv.egiz.stal.service.types.ErrorResponseType; -import at.gv.egiz.stal.service.types.GetNextRequestResponseType; -import at.gv.egiz.stal.service.types.GetNextRequestType; -import at.gv.egiz.stal.service.types.ObjectFactory; -import at.gv.egiz.stal.service.types.RequestType; -import at.gv.egiz.stal.service.types.ResponseType; -import at.gv.egiz.stal.util.STALTranslator; - -public class BKUWorker extends AbstractSMCCSTAL implements Runnable, - ActionListener, SMCCSTALRequestHandler { - - private static Log log = LogFactory.getLog(BKUWorker.class); - protected BKUGUIFacade gui; - protected BKUApplet parent; - private STALPortType stalPort; - protected List actionCommandList = new ArrayList(); - protected Boolean actionPerformed = false; - protected boolean finished = false; - - /** - * - * @param gui - * must not be null - */ - public BKUWorker(BKUGUIFacade gui, BKUApplet parent) { - if (gui == null || parent == null) { - throw new NullPointerException("Parameter must not be set to null"); - } - this.gui = gui; - this.locale = gui.getLocale(); - this.parent = parent; - addRequestHandler(QuitRequest.class, this); - // register SignRequestHandler once we have a webservice port - } - - /** - * Used for non applet variants - * - * @param gui - * @param errorMessageBundle - */ - protected BKUWorker(BKUGUIFacade gui) { - this.gui = gui; - this.locale = gui.getLocale(); - addRequestHandler(QuitRequest.class, this); - } - - private STALPortType getSTALPort() throws MalformedURLException { - URL wsdlURL = null; - String wsdlLocation = parent.getMyAppletParameter(BKUApplet.WSDL_URL); - URL codebase = parent.getCodeBase(); - log.debug("Connecting to webservice: " + wsdlLocation); - if (wsdlLocation != null) { - try { - if (codebase.getProtocol().equalsIgnoreCase("file")) { - // for debugging in appletrunner - wsdlURL = new URL(wsdlLocation); - } else { - wsdlURL = new URL(codebase, wsdlLocation); - } - } catch (MalformedURLException ex) { - log.fatal("Paremeter 'wsdlLocation' is not a vailid URL.", ex); - throw new MalformedURLException(ex.getMessage()); - } - } else { - log.fatal("Paremeter 'wsdlLocation' is not set."); - throw new MalformedURLException("Null WSDL url"); - } - log.debug("Found WSDL url: " + wsdlURL); - QName endpointName = new QName("http://www.egiz.gv.at/wsdl/stal", - "STALService"); - STALService stal = new STALService(wsdlURL, endpointName); - return stal.getSTALPort(); - } - - @Override - public void run() { - gui.showWelcomeDialog(); - try { - stalPort = getSTALPort(); - } catch (Exception e) { - log.fatal("Failed to call STAL service.", e); - actionCommandList.clear(); - actionCommandList.add("ok"); - gui.showErrorDialog(BKUGUIFacade.ERR_SERVICE_UNREACHABLE, - new Object[] { e.getMessage() }); - try { - waitForAction(); - } catch (InterruptedException e1) { - log.error(e1); - } - return; - } - - try { - String sessionId = parent.getMyAppletParameter(BKUApplet.SESSION_ID); - if (sessionId == null) { - // use the testsession for testing - sessionId = "TestSession"; - } - - String hashDataDisplayStyle = parent.getMyAppletParameter(BKUApplet.HASHDATA_DISPLAY); - if (BKUApplet.HASHDATA_DISPLAY_INTERNAL.equals(hashDataDisplayStyle)) { - log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); - addRequestHandler(at.gv.egiz.stal.SignRequest.class, new WebServiceSignRequestHandler(sessionId, stalPort)); - } else { //if (HASHDATADISPLAY_EXTERNAL.equals(displayStyle)) { - URL hashDataURL = parent.getMyAppletParameterURL(BKUApplet.HASHDATA_URL); - log.debug("register SignRequestHandler for HashDataURL " + hashDataURL); - addRequestHandler(at.gv.egiz.stal.SignRequest.class, new ExternalDisplaySignRequestHandler(parent.getAppletContext(), hashDataURL)); - } - -// log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); -// addRequestHandler(at.gv.egiz.stal.SignRequest.class, new WebServiceSignRequestHandler(sessionId, stalPort)); - - ObjectFactory of = new ObjectFactory(); - GetNextRequestResponseType nextRequestResp = stalPort.connect(sessionId); - do { - List requests = nextRequestResp - .getInfoboxReadRequestOrSignRequestOrQuitRequest(); - List stalRequests = STALTranslator - .translateRequests(requests); - - if (log.isInfoEnabled()) { - StringBuilder sb = new StringBuilder("Received "); - sb.append(stalRequests.size()); - sb.append(" STAL requests: "); - for (STALRequest r : stalRequests) { - sb.append(r.getClass()); - sb.append(' '); - } - log.info(sb.toString()); - } - - boolean handle = true; - for (STALRequest request : stalRequests) { - if (request instanceof at.gv.egiz.stal.InfoboxReadRequest) { - at.gv.egiz.stal.InfoboxReadRequest r = (at.gv.egiz.stal.InfoboxReadRequest) request; - String infoboxId = r.getInfoboxIdentifier(); - String domainId = r.getDomainIdentifier(); - if ("IdentityLink".equals(infoboxId) && domainId == null) { - if (!InternalSSLSocketFactory.getInstance().isEgovAgency()) { - handle = false; - } - } - } - } - - List responses; - if (handle) { - List stalResponses = handleRequest(stalRequests); - if (log.isInfoEnabled()) { - StringBuilder sb = new StringBuilder(stalResponses.size()); - sb.append(" STAL responses: "); - for (STALResponse r : stalResponses) { - sb.append(r.getClass()); - sb.append(' '); - } - log.info(sb.toString()); - } - responses = STALTranslator.fromSTAL(stalResponses); - } else { - responses = new ArrayList(1); - ErrorResponseType err = new ErrorResponseType(); - err.setErrorCode(6002); - // err.setErrorMessage(); - responses.add(err); - } - - if (!finished) { - log.info("Not finished yet (BKUWorker: " + this - + "), sending responses"); - GetNextRequestType nextRequest = of.createGetNextRequestType(); - nextRequest.setSessionId(sessionId); - nextRequest.getInfoboxReadResponseOrSignResponseOrErrorResponse() - .addAll(responses); - nextRequestResp = stalPort.getNextRequest(nextRequest); - } - } while (!finished); - log.info("Done " + Thread.currentThread().getName()); - } catch (Exception ex) { - log.error(ex.getMessage(), ex); - gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, new Object[] { ex - .getMessage() }); - try { - waitForAction(); - } catch (InterruptedException e) { - log.error(e); - } - } - if (signatureCard != null) { - signatureCard.disconnect(false); - } - sendRedirect(); - } - - protected void sendRedirect() { - log.info("Done, sending redirect to get BKU response"); - String redirectURL = parent.getMyAppletParameter(BKUApplet.REDIRECT_URL); - String redirectTarget = parent.getMyAppletParameter(BKUApplet.REDIRECT_TARGET); - log.info("Redirecting to: " + redirectURL + " target: " + redirectTarget); - URL url = null; - if (redirectURL != null) { - try { - url = new URL(parent.getCodeBase(), redirectURL + ";jsessionid=" - + parent.getMyAppletParameter(BKUApplet.SESSION_ID)); - } catch (MalformedURLException ex) { - log.warn("Parameter 'redirectURL': " + redirectURL - + " not a valid URL.", ex); - // gui.showErrorDialog(errorMsg, okListener, actionCommand) - } - if (url != null) { - if (redirectTarget == null) { - log.info("Done. Trying to redirect to " + url + " ..."); - parent.getAppletContext().showDocument(url); - } else { - log.info("Done. Trying to redirect to " + url + " (target=" - + redirectTarget + ") ..."); - parent.getAppletContext().showDocument(url, redirectTarget); - } - } - } else { - log.error("No redirect URL set"); - } - } - - protected synchronized void waitForAction() throws InterruptedException { - log.info("Waiting for Action"); - while (!actionPerformed) { - wait(); - } - actionPerformed = false; - } - - protected synchronized void actionOccured() { - log.info("Received Action"); - actionPerformed = true; - notifyAll(); - } - - @Override - public void actionPerformed(ActionEvent e) { - log.info("Action: " + e); - if (actionCommandList != null) { - if (actionCommandList.contains(e.getActionCommand())) { - actionOccured(); - } - } else { - actionOccured(); - } - } - - @Override - protected boolean waitForCard() { - SMCCHelper smccHelper = new SMCCHelper(); - actionCommandList.clear(); - actionCommandList.add("cancel"); - // while no sigcard found or cancel button pressed - int oldValue = SMCCHelper.PC_SC_NOT_SUPPORTED; // this is a save default - while ((signatureCard == null) && (!actionPerformed)) { - switch (smccHelper.getResultCode()) { - case SMCCHelper.PC_SC_NOT_SUPPORTED: - actionCommandList.clear(); - actionCommandList.add("ok"); - gui.showErrorDialog(BKUGUIFacade.ERR_NO_PCSC, null, this, "ok"); - try { - waitForAction(); - } catch (InterruptedException e) { - log.error(e); - } - return true; - case SMCCHelper.TERMINAL_NOT_PRESENT: - actionCommandList.clear(); - actionCommandList.add("ok"); - gui.showErrorDialog(BKUGUIFacade.ERR_NO_CARDTERMINAL, null, this, "ok"); - try { - waitForAction(); - } catch (InterruptedException e) { - log.error(e); - } - return true; - case SMCCHelper.CARD_NOT_SUPPORTED: - if (oldValue != SMCCHelper.CARD_NOT_SUPPORTED) { - actionCommandList.clear(); - actionCommandList.add("cancel"); - gui.showCardNotSupportedDialog(this, "cancel"); - oldValue = SMCCHelper.CARD_NOT_SUPPORTED; - } - break; - case SMCCHelper.NO_CARD: - if (oldValue != SMCCHelper.NO_CARD) { - actionCommandList.clear(); - actionCommandList.add("cancel"); - gui.showInsertCardDialog(this, "cancel"); - oldValue = SMCCHelper.NO_CARD; - } - break; - case SMCCHelper.CARD_FOUND: - signatureCard = smccHelper.getSignatureCard(locale); - return false; - } - smccHelper.update(3000); - } - return signatureCard == null; - } - - @Override - public STALResponse handleRequest(STALRequest request) { - if (request instanceof QuitRequest) { - log.info("Setting state to: finished for BKUWorker " + this); - finished = true; - } else { - log.error("Unexpected request to handle: " + request); - } - return null; - } - - @Override - public void init(SignatureCard sc, BKUGUIFacade gui) { - } - - @Override - public boolean requireCard() { - return false; - } - - @Override - protected BKUGUIFacade getGUI() { - return gui; - } - -} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java index ddbe76bf..014065f2 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java @@ -45,7 +45,7 @@ public class WebServiceSignRequestHandler extends SignRequestHandler { STALPortType stalPort; String sessId; - public WebServiceSignRequestHandler(String sessId, STALPortType stalPort) { + public WebServiceSignRequestHandler(STALPortType stalPort, String sessId) { if (stalPort == null || sessId == null) { throw new NullPointerException("STAL port must not be null"); } -- cgit v1.2.3 From 2cf6fcb31e85b0e3b367121219932ec86b205da8 Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 5 Nov 2008 14:42:05 +0000 Subject: help jsp git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@151 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index f3eecdf9..4eab7e89 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -89,7 +89,7 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { URL backgroundImgURL = null; URL helpURL = null; try { - helpURL = getURLParameter(HELP_URL, getAppletParameter(SESSION_ID)); + helpURL = getURLParameter(HELP_URL); //, getAppletParameter(SESSION_ID)); } catch (MalformedURLException ex) { log.warn("failed to load help URL, disabling help: " + ex.getMessage()); } -- cgit v1.2.3 From 8171050e1b21733a5e55ce97ebc9134f6afb1abb Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 5 Nov 2008 17:22:51 +0000 Subject: java.awt.Desktop BROWSE for help and hashdatadisplay git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@152 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/online/applet/AppletBKUWorker.java | 2 +- .../egiz/bku/online/applet/AppletHelpListener.java | 35 +++++++++++++++------- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 6 +--- .../applet/ExternalDisplaySignRequestHandler.java | 27 ++++++++++++----- 4 files changed, 47 insertions(+), 23 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java index 2141165b..cf842d55 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java @@ -199,7 +199,7 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { //if (HASHDATADISPLAY_EXTERNAL.equals(displayStyle)) { URL hashDataURL = params.getURLParameter(BKUApplet.HASHDATA_URL, sessionId); log.debug("register SignRequestHandler for HashDataURL " + hashDataURL); - addRequestHandler(SignRequest.class, new ExternalDisplaySignRequestHandler(ctx, hashDataURL)); + addRequestHandler(SignRequest.class, new ExternalDisplaySignRequestHandler(hashDataURL)); // } } } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHelpListener.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHelpListener.java index 4040431f..743dc7ef 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHelpListener.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHelpListener.java @@ -18,30 +18,45 @@ package at.gv.egiz.bku.online.applet; import at.gv.egiz.bku.gui.AbstractHelpListener; -import java.applet.AppletContext; +import java.awt.Desktop; import java.net.URL; import java.util.Locale; /** - * + * Now uses java.awt.Desktop, which deprecates + * the distinction between local and applet help listener + * TODO: integrate in AbstractHelpListener + * + * @deprecated * @author clemens */ public class AppletHelpListener extends AbstractHelpListener { - protected AppletContext ctx; +// protected AppletContext ctx; + protected Desktop desktop; - public AppletHelpListener(AppletContext ctx, URL helpURL, Locale locale) { + public AppletHelpListener(URL helpURL, Locale locale) { super(helpURL, locale); - if (ctx == null) { - throw new RuntimeException("no applet context provided"); +// if (ctx == null) { +// throw new RuntimeException("no applet context provided"); +// } +// this.ctx = ctx; + if (Desktop.isDesktopSupported()) { + this.desktop = Desktop.getDesktop(); } - this.ctx = ctx; } @Override public void showDocument(URL helpDocument) throws Exception { - ctx.showDocument(helpDocument, "_blank"); +// ctx.showDocument(helpDocument, "_blank"); + if (desktop == null) { + log.error("Failed to open default browser: Desktop API not available (libgnome installed?)"); + } else { + if (!desktop.isSupported(Desktop.Action.BROWSE)) { + log.error("Failed to open default browser: The system provides the Desktop API, but does not support the BROWSE action"); + } else { + Desktop.getDesktop().browse(helpDocument.toURI()); + } + } } - - } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 4eab7e89..482273b0 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -16,14 +16,10 @@ */ package at.gv.egiz.bku.online.applet; -import at.gv.egiz.bku.smccstal.AbstractBKUWorker; import java.net.MalformedURLException; import java.net.URL; import java.util.Locale; -import java.util.ResourceBundle; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.net.ssl.HttpsURLConnection; import javax.swing.JApplet; @@ -105,7 +101,7 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { log.debug("setting locale to " + getLocale()); BKUGUIFacade gui = BKUGUIFactory.createGUI(guiStyle); - AppletHelpListener helpListener = new AppletHelpListener(getAppletContext(), helpURL, getLocale()); + AppletHelpListener helpListener = new AppletHelpListener(helpURL, getLocale()); //getAppletContext(), gui.init(getContentPane(), getLocale(), backgroundImgURL, helpListener); worker = new AppletBKUWorker(gui, getAppletContext(), this); diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalDisplaySignRequestHandler.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalDisplaySignRequestHandler.java index 2c9fde71..e4567a6c 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalDisplaySignRequestHandler.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalDisplaySignRequestHandler.java @@ -17,7 +17,6 @@ package at.gv.egiz.bku.online.applet; -import java.applet.AppletContext; import java.net.URL; import java.util.List; @@ -26,28 +25,42 @@ import org.apache.commons.logging.LogFactory; import at.gv.egiz.bku.smccstal.SignRequestHandler; import at.gv.egiz.stal.signedinfo.ReferenceType; +import java.awt.Desktop; /** * - * @author clemens + * @author Clemens Orthacker */ public class ExternalDisplaySignRequestHandler extends SignRequestHandler { private static final Log log = LogFactory.getLog(ExternalDisplaySignRequestHandler.class); - AppletContext ctx; - URL hashDataURL; +// AppletContext ctx; + protected URL hashDataURL; + protected Desktop desktop; - public ExternalDisplaySignRequestHandler(AppletContext ctx, URL hashDataURL) { - this.ctx = ctx; + public ExternalDisplaySignRequestHandler(URL hashDataURL) { +// this.ctx = ctx; this.hashDataURL = hashDataURL; + if (Desktop.isDesktopSupported()) { + desktop = Desktop.getDesktop(); + } } @Override public void displayHashDataInputs(List signedReferences) throws Exception { //TODO pass reference Id's to servlet (TODO servlet) log.debug("displaying hashdata inputs at " + hashDataURL); - ctx.showDocument(hashDataURL, "_blank"); +// ctx.showDocument(hashDataURL, "_blank"); + if (desktop == null) { + log.error("Failed to open default browser: Desktop API not available (libgnome installed?)"); + } else { + if (!desktop.isSupported(Desktop.Action.BROWSE)) { + log.error("Failed to open default browser: The system provides the Desktop API, but does not support the BROWSE action"); + } else { + Desktop.getDesktop().browse(hashDataURL.toURI()); + } + } } } -- cgit v1.2.3 From 1a459eb89e4e91308e1022abb8ddd0cae1d8e619 Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 6 Nov 2008 12:24:24 +0000 Subject: error msg ws.unreachable dummy helplistener git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@153 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 482273b0..829cc79d 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -83,9 +83,10 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { String locale = getAppletParameter(LOCALE_PARAM_KEY); String guiStyle = getAppletParameter(GUI_STYLE); URL backgroundImgURL = null; - URL helpURL = null; + AppletHelpListener helpListener = null; try { - helpURL = getURLParameter(HELP_URL); //, getAppletParameter(SESSION_ID)); + URL helpURL = getURLParameter(HELP_URL); //, getAppletParameter(SESSION_ID)); + helpListener = new AppletHelpListener(helpURL, getLocale()); //getAppletContext(), } catch (MalformedURLException ex) { log.warn("failed to load help URL, disabling help: " + ex.getMessage()); } @@ -101,7 +102,6 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { log.debug("setting locale to " + getLocale()); BKUGUIFacade gui = BKUGUIFactory.createGUI(guiStyle); - AppletHelpListener helpListener = new AppletHelpListener(helpURL, getLocale()); //getAppletContext(), gui.init(getContentPane(), getLocale(), backgroundImgURL, helpListener); worker = new AppletBKUWorker(gui, getAppletContext(), this); -- cgit v1.2.3 From 82c59c9d862d3ee9ad43fdc1509d0b5a61cc107c Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 11 Nov 2008 12:15:15 +0000 Subject: Frame HashData Display Interrupt in waitForAction (applet closed) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@161 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/online/applet/AppletBKUWorker.java | 12 +- .../bku/online/applet/AppletHashDataDisplay.java | 167 ++++++++++++++++ .../egiz/bku/online/applet/AppletHelpListener.java | 33 +-- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 4 +- .../bku/online/applet/BrowserHashDataDisplay.java | 52 +++++ .../applet/ExternalDisplaySignRequestHandler.java | 66 ------ .../bku/online/applet/JDialogHashDataDisplay.java | 221 +++++++++++++++++++++ .../applet/WebServiceSignRequestHandler.java | 164 --------------- 8 files changed, 459 insertions(+), 260 deletions(-) create mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java create mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BrowserHashDataDisplay.java delete mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalDisplaySignRequestHandler.java create mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/JDialogHashDataDisplay.java delete mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java index cf842d55..8e88c012 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java @@ -31,6 +31,7 @@ import at.gv.egiz.stal.service.types.RequestType; import at.gv.egiz.stal.service.types.ResponseType; import at.gv.egiz.stal.util.STALTranslator; import java.applet.AppletContext; +import java.awt.Dimension; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; @@ -194,12 +195,15 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { String hashDataDisplayStyle = params.getAppletParameter(BKUApplet.HASHDATA_DISPLAY); if (BKUApplet.HASHDATA_DISPLAY_INTERNAL.equals(hashDataDisplayStyle)) { log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); - addRequestHandler(SignRequest.class, new WebServiceSignRequestHandler(stalPort, sessionId)); - } else { - //if (HASHDATADISPLAY_EXTERNAL.equals(displayStyle)) { + addRequestHandler(SignRequest.class, new AppletHashDataDisplay(stalPort, sessionId)); + } else if (BKUApplet.HASHDATA_DISPLAY_BROWSER.equals(hashDataDisplayStyle)) { URL hashDataURL = params.getURLParameter(BKUApplet.HASHDATA_URL, sessionId); log.debug("register SignRequestHandler for HashDataURL " + hashDataURL); - addRequestHandler(SignRequest.class, new ExternalDisplaySignRequestHandler(hashDataURL)); // + addRequestHandler(SignRequest.class, new BrowserHashDataDisplay(ctx, hashDataURL)); + } else { + //BKUApplet.HASHDATA_DISPLAY_FRAME + log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); + addRequestHandler(SignRequest.class, new JDialogHashDataDisplay(stalPort, sessionId, new Dimension(400, 300), locale)); } } } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java new file mode 100644 index 00000000..b77485d9 --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java @@ -0,0 +1,167 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package at.gv.egiz.bku.online.applet; + +import java.security.DigestException; +import java.security.MessageDigest; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.gv.egiz.bku.smccstal.SignRequestHandler; +import at.gv.egiz.stal.HashDataInput; +import at.gv.egiz.stal.impl.ByteArrayHashDataInput; +import at.gv.egiz.stal.service.STALPortType; +import at.gv.egiz.stal.service.types.GetHashDataInputResponseType; +import at.gv.egiz.stal.service.types.GetHashDataInputType; +import at.gv.egiz.stal.signedinfo.DigestMethodType; +import at.gv.egiz.stal.signedinfo.ReferenceType; + +/** + * A SignRequesthandler displaying hashdata inputs in the applet + * (only plaintext data is displayed, other hashdata inputs may be saved to disk). + * + * @author Clemens Orthacker + */ +public class AppletHashDataDisplay extends SignRequestHandler { + + private static final Log log = LogFactory.getLog(AppletHashDataDisplay.class); + STALPortType stalPort; + String sessId; + + public AppletHashDataDisplay(STALPortType stalPort, String sessId) { + if (stalPort == null || sessId == null) { + throw new NullPointerException("STAL port must not be null"); + } + this.sessId = sessId; + this.stalPort = stalPort; + } + + @Override + public void displayHashDataInputs(List signedReferences) throws Exception { + + GetHashDataInputType request = new GetHashDataInputType(); + request.setSessionId(sessId); + + HashMap idSignedRefMap = new HashMap(); + for (ReferenceType signedRef : signedReferences) { + //don't get Manifest, QualifyingProperties, ... + if (signedRef.getType() == null) { + String signedRefId = signedRef.getId(); + if (signedRefId != null) { + if (log.isTraceEnabled()) { + log.trace("requesting hashdata input for reference " + signedRefId); + } + idSignedRefMap.put(signedRefId, signedRef); + GetHashDataInputType.Reference ref = new GetHashDataInputType.Reference(); + ref.setID(signedRefId); + request.getReference().add(ref); + + } else { + throw new Exception("Cannot resolve HashDataInput for reference without Id attribute"); + } + } + } + + if (log.isDebugEnabled()) { + log.debug("Calling GetHashDataInput for " + request.getReference().size() + " references in session " + sessId); + } + GetHashDataInputResponseType response = stalPort.getHashDataInput(request); + ArrayList hashDataInputs = new ArrayList(); + + //hashdata inputs returned from service + HashMap idRefMap = new HashMap(); + for (GetHashDataInputResponseType.Reference reference : response.getReference()) { + String id = reference.getID(); + byte[] hdi = reference.getValue(); + if (hdi == null) { + throw new Exception("Did not receive hashdata input for reference " + id); + } + idRefMap.put(id, reference); + } + + for (String signedRefId : idSignedRefMap.keySet()) { + log.info("validating hashdata input for reference " + signedRefId); + + GetHashDataInputResponseType.Reference reference = idRefMap.get(signedRefId); + if (reference == null) { + throw new Exception("No hashdata input for reference " + signedRefId + " returned by service"); + } + +// } +// +// for (GetHashDataInputResponseType.Reference reference : response.getReference()) { +// +// String id = reference.getID(); + byte[] hdi = reference.getValue(); + String mimeType = reference.getMimeType(); + String encoding = reference.getEncoding(); + + if (hdi == null) { + throw new Exception("No hashdata input provided for reference " + signedRefId); + } + if (log.isDebugEnabled()) { + log.debug("Got HashDataInput " + signedRefId + " (" + mimeType + ";" + encoding + ")"); + } + + ReferenceType dsigRef = idSignedRefMap.get(signedRefId); + DigestMethodType dm = dsigRef.getDigestMethod(); + + if (dm == null) { + throw new Exception("Failed to verify digest value for reference " + signedRefId + ": no digest algorithm"); + } + String mdAlg = dm.getAlgorithm(); + if ("http://www.w3.org/2000/09/xmldsig#sha1".equals(mdAlg)) + mdAlg = "SHA-1"; + else if ("http://www.w3.org/2001/04/xmlenc#sha256".equals(mdAlg)) + mdAlg = "SHA-256"; + else if ("http://www.w3.org/2001/04/xmlenc#sha224 ".equals(mdAlg)) + mdAlg = "SHA-224"; + else if ("http://www.w3.org/2001/04/xmldsig-more#sha224 ".equals(mdAlg)) + mdAlg = "SHA-224"; + else if ("http://www.w3.org/2001/04/xmldsig-more#sha384".equals(mdAlg)) + mdAlg = "SHA-384"; + else if ("http://www.w3.org/2001/04/xmlenc#sha512".equals(mdAlg)) + mdAlg = "SHA-512"; + else if ("http://www.w3.org/2001/04/xmldsig-more#md2 ".equals(mdAlg)) + mdAlg = "MD2"; + else if ("http://www.w3.org/2001/04/xmldsig-more#md5".equals(mdAlg)) + mdAlg = "MD5"; + else if ("http://www.w3.org/2001/04/xmlenc#ripemd160 ".equals(mdAlg)) + mdAlg = "RipeMD-160"; + else { + throw new Exception("Failed to verify digest value for reference " + signedRefId + ": unsupported digest algorithm " + mdAlg); + } + MessageDigest md = MessageDigest.getInstance(mdAlg); + byte[] hdiDigest = md.digest(hdi); + if (log.isDebugEnabled()) + log.debug("Comparing digest values... "); + if (!Arrays.equals(hdiDigest, dsigRef.getDigestValue())) { + log.error("digest values differ: " + new String(hdiDigest) + ", " + new String(dsigRef.getDigestValue())); + throw new DigestException("Bad digest value for reference " + signedRefId + ": " + new String(dsigRef.getDigestValue())); + } + hashDataInputs.add(new ByteArrayHashDataInput(hdi, signedRefId, mimeType, encoding)); + } + + gui.showHashDataInputDialog(hashDataInputs, false, this, "ok"); + } +} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHelpListener.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHelpListener.java index 743dc7ef..5d199872 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHelpListener.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHelpListener.java @@ -18,45 +18,28 @@ package at.gv.egiz.bku.online.applet; import at.gv.egiz.bku.gui.AbstractHelpListener; -import java.awt.Desktop; +import java.applet.AppletContext; import java.net.URL; import java.util.Locale; /** - * Now uses java.awt.Desktop, which deprecates - * the distinction between local and applet help listener - * TODO: integrate in AbstractHelpListener * - * @deprecated - * @author clemens + * @author Clemens Orthacker */ public class AppletHelpListener extends AbstractHelpListener { -// protected AppletContext ctx; - protected Desktop desktop; + protected AppletContext ctx; - public AppletHelpListener(URL helpURL, Locale locale) { + public AppletHelpListener(AppletContext ctx, URL helpURL, Locale locale) { super(helpURL, locale); -// if (ctx == null) { -// throw new RuntimeException("no applet context provided"); -// } -// this.ctx = ctx; - if (Desktop.isDesktopSupported()) { - this.desktop = Desktop.getDesktop(); + if (ctx == null) { + throw new RuntimeException("no applet context provided"); } + this.ctx = ctx; } @Override public void showDocument(URL helpDocument) throws Exception { -// ctx.showDocument(helpDocument, "_blank"); - if (desktop == null) { - log.error("Failed to open default browser: Desktop API not available (libgnome installed?)"); - } else { - if (!desktop.isSupported(Desktop.Action.BROWSE)) { - log.error("Failed to open default browser: The system provides the Desktop API, but does not support the BROWSE action"); - } else { - Desktop.getDesktop().browse(helpDocument.toURI()); - } - } + ctx.showDocument(helpDocument, "_blank"); } } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 829cc79d..9d640dee 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -52,6 +52,8 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { public static final String REDIRECT_URL = "RedirectURL"; public static final String REDIRECT_TARGET = "RedirectTarget"; public static final String HASHDATA_DISPLAY_INTERNAL = "internal"; + public static final String HASHDATA_DISPLAY_BROWSER = "browser"; + public static final String HASHDATA_DISPLAY_FRAME = "frame"; /** * STAL WSDL namespace and service name @@ -86,7 +88,7 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { AppletHelpListener helpListener = null; try { URL helpURL = getURLParameter(HELP_URL); //, getAppletParameter(SESSION_ID)); - helpListener = new AppletHelpListener(helpURL, getLocale()); //getAppletContext(), + helpListener = new AppletHelpListener(getAppletContext(), helpURL, getLocale()); } catch (MalformedURLException ex) { log.warn("failed to load help URL, disabling help: " + ex.getMessage()); } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BrowserHashDataDisplay.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BrowserHashDataDisplay.java new file mode 100644 index 00000000..c30921da --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BrowserHashDataDisplay.java @@ -0,0 +1,52 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package at.gv.egiz.bku.online.applet; + +import java.net.URL; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.gv.egiz.bku.smccstal.SignRequestHandler; +import at.gv.egiz.stal.signedinfo.ReferenceType; +import java.applet.AppletContext; + +/** + * + * @author Clemens Orthacker + */ +public class BrowserHashDataDisplay extends SignRequestHandler { + + private static final Log log = LogFactory.getLog(BrowserHashDataDisplay.class); + + protected AppletContext ctx; + protected URL hashDataURL; + + public BrowserHashDataDisplay(AppletContext ctx, URL hashDataURL) { + this.ctx = ctx; + this.hashDataURL = hashDataURL; + } + + @Override + public void displayHashDataInputs(List signedReferences) throws Exception { + //TODO pass reference Id's to servlet (TODO servlet) + log.debug("displaying hashdata inputs at " + hashDataURL); + ctx.showDocument(hashDataURL, "_blank"); + } +} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalDisplaySignRequestHandler.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalDisplaySignRequestHandler.java deleted file mode 100644 index e4567a6c..00000000 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalDisplaySignRequestHandler.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2008 Federal Chancellery Austria and - * Graz University of Technology - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package at.gv.egiz.bku.online.applet; - -import java.net.URL; -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import at.gv.egiz.bku.smccstal.SignRequestHandler; -import at.gv.egiz.stal.signedinfo.ReferenceType; -import java.awt.Desktop; - -/** - * - * @author Clemens Orthacker - */ -public class ExternalDisplaySignRequestHandler extends SignRequestHandler { - - private static final Log log = LogFactory.getLog(ExternalDisplaySignRequestHandler.class); - -// AppletContext ctx; - protected URL hashDataURL; - protected Desktop desktop; - - public ExternalDisplaySignRequestHandler(URL hashDataURL) { -// this.ctx = ctx; - this.hashDataURL = hashDataURL; - if (Desktop.isDesktopSupported()) { - desktop = Desktop.getDesktop(); - } - } - - @Override - public void displayHashDataInputs(List signedReferences) throws Exception { - //TODO pass reference Id's to servlet (TODO servlet) - log.debug("displaying hashdata inputs at " + hashDataURL); -// ctx.showDocument(hashDataURL, "_blank"); - if (desktop == null) { - log.error("Failed to open default browser: Desktop API not available (libgnome installed?)"); - } else { - if (!desktop.isSupported(Desktop.Action.BROWSE)) { - log.error("Failed to open default browser: The system provides the Desktop API, but does not support the BROWSE action"); - } else { - Desktop.getDesktop().browse(hashDataURL.toURI()); - } - } - } - -} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/JDialogHashDataDisplay.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/JDialogHashDataDisplay.java new file mode 100644 index 00000000..1f0eda90 --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/JDialogHashDataDisplay.java @@ -0,0 +1,221 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package at.gv.egiz.bku.online.applet; + +import at.gv.egiz.bku.smccstal.SignRequestHandler; +import at.gv.egiz.stal.HashDataInput; +import at.gv.egiz.stal.impl.ByteArrayHashDataInput; +import at.gv.egiz.stal.service.GetHashDataInputFault; +import at.gv.egiz.stal.service.STALPortType; +import at.gv.egiz.stal.service.types.GetHashDataInputResponseType; +import at.gv.egiz.stal.service.types.GetHashDataInputType; +import at.gv.egiz.stal.signedinfo.ReferenceType; +import java.awt.Dimension; +import java.security.DigestException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author Clemens Orthacker + */ +public class JDialogHashDataDisplay extends SignRequestHandler { + + private static final Log log = LogFactory.getLog(JDialogHashDataDisplay.class); + protected STALPortType stalPort; + protected String sessId; +// protected HashDataViewer viewer; + + public JDialogHashDataDisplay(STALPortType stalPort, String sessId, Dimension viewerSize, Locale locale) { + if (stalPort == null || sessId == null) { + throw new NullPointerException("STAL port must not be null"); + } + this.sessId = sessId; + this.stalPort = stalPort; +// this.viewer = new HashDataViewer(viewerSize, locale); + } + + @Override + public void displayHashDataInputs(List signedReferences) throws DigestException, Exception { + + List hdi = getHashDataInput(signedReferences); + final List verifiedHashDataInputs = verifyHashDataInput(signedReferences, hdi); + + if (verifiedHashDataInputs.size() > 1) { + gui.showHashDataInputDialog(verifiedHashDataInputs, false, this, "ok"); + } else if (verifiedHashDataInputs.size() == 1) { + gui.showHashDataInputDialog(verifiedHashDataInputs, true, this, "ok"); +// SwingUtilities.invokeLater(new Runnable() { +// +// @Override +// public void run() { +// viewer.displayHashData(verifiedHashDataInputs.get(0)); +// } +// }); + + } else { + log.error("No hashdata input to display"); + } + + } + + /** + * Get all hashdata inputs that contain an ID attribute and no Type attribute. + * @param signedReferences + * @return + * @throws at.gv.egiz.stal.service.GetHashDataInputFault + */ + private List getHashDataInput(List signedReferences) throws GetHashDataInputFault, Exception { + GetHashDataInputType request = new GetHashDataInputType(); + request.setSessionId(sessId); + +// HashMap idSignedRefMap = new HashMap(); + for (ReferenceType signedRef : signedReferences) { + //don't get Manifest, QualifyingProperties, ... + if (signedRef.getType() == null) { + String signedRefId = signedRef.getId(); + if (signedRefId != null) { + if (log.isTraceEnabled()) { + log.trace("requesting hashdata input for reference " + signedRefId); + } +// idSignedRefMap.put(signedRefId, signedRef); + GetHashDataInputType.Reference ref = new GetHashDataInputType.Reference(); + ref.setID(signedRefId); + request.getReference().add(ref); + + } else { + throw new Exception("Cannot resolve HashDataInput for reference without Id attribute"); + } + } + } + + if (log.isDebugEnabled()) { + log.debug("WebService call GetHashDataInput for " + request.getReference().size() + " references in session " + sessId); + } + GetHashDataInputResponseType response = stalPort.getHashDataInput(request); + return response.getReference(); + } + + /** + * Verifies all signed references and returns STAL HashDataInputs + * @param signedReferences + * @param hashDataInputs + * @return + * @throws java.security.DigestException + * @throws java.security.NoSuchAlgorithmException + * @throws Exception if no hashdata input is provided for a signed reference + */ + private List verifyHashDataInput(List signedReferences, List hashDataInputs) throws DigestException, NoSuchAlgorithmException, Exception { + + ArrayList verifiedHashDataInputs = new ArrayList(); + + //hashdata inputs returned from service +// HashMap idRefMap = new HashMap(); +// for (GetHashDataInputResponseType.Reference hashDataInput : hashDataInputs) { +// String id = hashDataInput.getID(); +// byte[] hdi = hashDataInput.getValue(); +// if (hdi == null) { +// throw new Exception("Did not receive hashdata input for reference " + id); +// } +// idRefMap.put(id, hashDataInput); +// } + + for (ReferenceType signedRef : signedReferences) { + if (signedRef.getType() == null) { + log.info("Verifying digest for signed reference " + signedRef.getId()); + + String signedRefId = signedRef.getId(); + byte[] signedDigest = signedRef.getDigestValue(); + String signedDigestAlg = null; + if (signedRef.getDigestMethod() != null) { + signedDigestAlg = signedRef.getDigestMethod().getAlgorithm(); + } else { + throw new NoSuchAlgorithmException("Failed to verify digest value for reference " + signedRefId + ": no digest algorithm"); + } + + GetHashDataInputResponseType.Reference hashDataInput = null; //idRefMap.get(signedRefId); + for (GetHashDataInputResponseType.Reference hdi : hashDataInputs) { + if (signedRefId.equals(hdi.getID())) { + hashDataInput = hdi; + } + } + if (hashDataInput == null) { + throw new Exception("No hashdata input for reference " + signedRefId + " returned by service"); + } + + byte[] hdi = hashDataInput.getValue(); + String mimeType = hashDataInput.getMimeType(); + String encoding = hashDataInput.getEncoding(); + + if (hdi == null) { + throw new Exception("No hashdata input for reference " + signedRefId + " provided by service"); + } + if (log.isDebugEnabled()) { + log.debug("Got HashDataInput " + signedRefId + " (" + mimeType + ";" + encoding + ")"); + } + + byte[] hashDataInputDigest = digest(hdi, signedDigestAlg); + + if (log.isDebugEnabled()) { + log.debug("Comparing digest values... "); + } + log.warn("DISABLED DIGEST VERIFICATION FOR DEBUGGING"); +// if (!Arrays.equals(hashDataInputDigest, signedDigest)) { +// log.error("Bad digest value for reference " + signedRefId); +// throw new DigestException("Bad digest value for reference " + signedRefId); +// } + + verifiedHashDataInputs.add(new ByteArrayHashDataInput(hdi, signedRefId, mimeType, encoding)); + } + } + + return verifiedHashDataInputs; + } + + //TODO + private byte[] digest(byte[] hashDataInput, String mdAlg) throws NoSuchAlgorithmException { + if ("http://www.w3.org/2000/09/xmldsig#sha1".equals(mdAlg)) { + mdAlg = "SHA-1"; + } else if ("http://www.w3.org/2001/04/xmlenc#sha256".equals(mdAlg)) { + mdAlg = "SHA-256"; + } else if ("http://www.w3.org/2001/04/xmlenc#sha224".equals(mdAlg)) { + mdAlg = "SHA-224"; + } else if ("http://www.w3.org/2001/04/xmldsig-more#sha224".equals(mdAlg)) { + mdAlg = "SHA-224"; + } else if ("http://www.w3.org/2001/04/xmldsig-more#sha384".equals(mdAlg)) { + mdAlg = "SHA-384"; + } else if ("http://www.w3.org/2001/04/xmlenc#sha512".equals(mdAlg)) { + mdAlg = "SHA-512"; + } else if ("http://www.w3.org/2001/04/xmldsig-more#md2 ".equals(mdAlg)) { + mdAlg = "MD2"; + } else if ("http://www.w3.org/2001/04/xmldsig-more#md5".equals(mdAlg)) { + mdAlg = "MD5"; + } else if ("http://www.w3.org/2001/04/xmlenc#ripemd160 ".equals(mdAlg)) { + mdAlg = "RipeMD-160"; + } else { + throw new NoSuchAlgorithmException("Failed to verify digest value: unsupported digest algorithm " + mdAlg); + } + + MessageDigest md = MessageDigest.getInstance(mdAlg); + return md.digest(hashDataInput); + } +} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java deleted file mode 100644 index 014065f2..00000000 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright 2008 Federal Chancellery Austria and - * Graz University of Technology - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package at.gv.egiz.bku.online.applet; - -import java.security.DigestException; -import java.security.MessageDigest; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import at.gv.egiz.bku.smccstal.SignRequestHandler; -import at.gv.egiz.stal.HashDataInput; -import at.gv.egiz.stal.impl.ByteArrayHashDataInput; -import at.gv.egiz.stal.service.STALPortType; -import at.gv.egiz.stal.service.types.GetHashDataInputResponseType; -import at.gv.egiz.stal.service.types.GetHashDataInputType; -import at.gv.egiz.stal.signedinfo.DigestMethodType; -import at.gv.egiz.stal.signedinfo.ReferenceType; - -/** - * @author clemens - */ -public class WebServiceSignRequestHandler extends SignRequestHandler { - - private static final Log log = LogFactory.getLog(WebServiceSignRequestHandler.class); - STALPortType stalPort; - String sessId; - - public WebServiceSignRequestHandler(STALPortType stalPort, String sessId) { - if (stalPort == null || sessId == null) { - throw new NullPointerException("STAL port must not be null"); - } - this.sessId = sessId; - this.stalPort = stalPort; - } - - @Override - public void displayHashDataInputs(List signedReferences) throws Exception { - - GetHashDataInputType request = new GetHashDataInputType(); - request.setSessionId(sessId); - - HashMap idSignedRefMap = new HashMap(); - for (ReferenceType signedRef : signedReferences) { - //don't get Manifest, QualifyingProperties, ... - if (signedRef.getType() == null) { - String signedRefId = signedRef.getId(); - if (signedRefId != null) { - if (log.isTraceEnabled()) { - log.trace("requesting hashdata input for reference " + signedRefId); - } - idSignedRefMap.put(signedRefId, signedRef); - GetHashDataInputType.Reference ref = new GetHashDataInputType.Reference(); - ref.setID(signedRefId); - request.getReference().add(ref); - - } else { - throw new Exception("Cannot resolve HashDataInput for reference without Id attribute"); - } - } - } - - if (log.isDebugEnabled()) { - log.debug("Calling GetHashDataInput for " + request.getReference().size() + " references in session " + sessId); - } - GetHashDataInputResponseType response = stalPort.getHashDataInput(request); - ArrayList hashDataInputs = new ArrayList(); - - //hashdata inputs returned from service - HashMap idRefMap = new HashMap(); - for (GetHashDataInputResponseType.Reference reference : response.getReference()) { - String id = reference.getID(); - byte[] hdi = reference.getValue(); - if (hdi == null) { - throw new Exception("Did not receive hashdata input for reference " + id); - } - idRefMap.put(id, reference); - } - - for (String signedRefId : idSignedRefMap.keySet()) { - log.info("validating hashdata input for reference " + signedRefId); - - GetHashDataInputResponseType.Reference reference = idRefMap.get(signedRefId); - if (reference == null) { - throw new Exception("No hashdata input for reference " + signedRefId + " returned by service"); - } - -// } -// -// for (GetHashDataInputResponseType.Reference reference : response.getReference()) { -// -// String id = reference.getID(); - byte[] hdi = reference.getValue(); - String mimeType = reference.getMimeType(); - String encoding = reference.getEncoding(); - - if (hdi == null) { - throw new Exception("No hashdata input provided for reference " + signedRefId); - } - if (log.isDebugEnabled()) { - log.debug("Got HashDataInput " + signedRefId + " (" + mimeType + ";" + encoding + ")"); - } - - ReferenceType dsigRef = idSignedRefMap.get(signedRefId); - DigestMethodType dm = dsigRef.getDigestMethod(); - - if (dm == null) { - throw new Exception("Failed to verify digest value for reference " + signedRefId + ": no digest algorithm"); - } - String mdAlg = dm.getAlgorithm(); - if ("http://www.w3.org/2000/09/xmldsig#sha1".equals(mdAlg)) - mdAlg = "SHA-1"; - else if ("http://www.w3.org/2001/04/xmlenc#sha256".equals(mdAlg)) - mdAlg = "SHA-256"; - else if ("http://www.w3.org/2001/04/xmlenc#sha224 ".equals(mdAlg)) - mdAlg = "SHA-224"; - else if ("http://www.w3.org/2001/04/xmldsig-more#sha224 ".equals(mdAlg)) - mdAlg = "SHA-224"; - else if ("http://www.w3.org/2001/04/xmldsig-more#sha384".equals(mdAlg)) - mdAlg = "SHA-384"; - else if ("http://www.w3.org/2001/04/xmlenc#sha512".equals(mdAlg)) - mdAlg = "SHA-512"; - else if ("http://www.w3.org/2001/04/xmldsig-more#md2 ".equals(mdAlg)) - mdAlg = "MD2"; - else if ("http://www.w3.org/2001/04/xmldsig-more#md5".equals(mdAlg)) - mdAlg = "MD5"; - else if ("http://www.w3.org/2001/04/xmlenc#ripemd160 ".equals(mdAlg)) - mdAlg = "RipeMD-160"; - else { - throw new Exception("Failed to verify digest value for reference " + signedRefId + ": unsupported digest algorithm " + mdAlg); - } - MessageDigest md = MessageDigest.getInstance(mdAlg); - byte[] hdiDigest = md.digest(hdi); - if (log.isDebugEnabled()) - log.debug("Comparing digest values... "); - if (!Arrays.equals(hdiDigest, dsigRef.getDigestValue())) { - log.error("digest values differ: " + new String(hdiDigest) + ", " + new String(dsigRef.getDigestValue())); - throw new DigestException("Bad digest value for reference " + signedRefId + ": " + new String(dsigRef.getDigestValue())); - } - hashDataInputs.add(new ByteArrayHashDataInput(hdi, signedRefId, mimeType, encoding)); - } - - gui.showHashDataInputDialog(hashDataInputs, this, "ok"); - } -} -- cgit v1.2.3 From 9662ac90b6aa84bc54543d3c8670ba6c8e42bbac Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 13 Nov 2008 18:24:57 +0000 Subject: FRAME HashDataDisplay FRAME Help git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@165 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/online/applet/AppletBKUWorker.java | 6 +- .../bku/online/applet/AppletHashDataDisplay.java | 217 ++++++++++++-------- .../egiz/bku/online/applet/AppletHelpListener.java | 45 ----- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 6 +- .../bku/online/applet/BrowserHelpListener.java | 45 +++++ .../bku/online/applet/DefaultHelpListener.java | 77 +++++++ .../bku/online/applet/JDialogHashDataDisplay.java | 221 --------------------- 7 files changed, 263 insertions(+), 354 deletions(-) delete mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHelpListener.java create mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BrowserHelpListener.java create mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/DefaultHelpListener.java delete mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/JDialogHashDataDisplay.java (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java index 8e88c012..db88c037 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java @@ -195,7 +195,8 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { String hashDataDisplayStyle = params.getAppletParameter(BKUApplet.HASHDATA_DISPLAY); if (BKUApplet.HASHDATA_DISPLAY_INTERNAL.equals(hashDataDisplayStyle)) { log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); - addRequestHandler(SignRequest.class, new AppletHashDataDisplay(stalPort, sessionId)); + AppletHashDataDisplay handler = new AppletHashDataDisplay(stalPort, sessionId, AppletHashDataDisplay.DISPLAY.applet); + addRequestHandler(SignRequest.class, handler); } else if (BKUApplet.HASHDATA_DISPLAY_BROWSER.equals(hashDataDisplayStyle)) { URL hashDataURL = params.getURLParameter(BKUApplet.HASHDATA_URL, sessionId); log.debug("register SignRequestHandler for HashDataURL " + hashDataURL); @@ -203,7 +204,8 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { } else { //BKUApplet.HASHDATA_DISPLAY_FRAME log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); - addRequestHandler(SignRequest.class, new JDialogHashDataDisplay(stalPort, sessionId, new Dimension(400, 300), locale)); + AppletHashDataDisplay handler = new AppletHashDataDisplay(stalPort, sessionId, AppletHashDataDisplay.DISPLAY.frame); + addRequestHandler(SignRequest.class, handler); } } } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java index b77485d9..29a60f1d 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java @@ -14,9 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package at.gv.egiz.bku.online.applet; +import at.gv.egiz.bku.gui.BKUGUIFacade; import java.security.DigestException; import java.security.MessageDigest; import java.util.ArrayList; @@ -30,39 +30,69 @@ import org.apache.commons.logging.LogFactory; import at.gv.egiz.bku.smccstal.SignRequestHandler; import at.gv.egiz.stal.HashDataInput; import at.gv.egiz.stal.impl.ByteArrayHashDataInput; +import at.gv.egiz.stal.service.GetHashDataInputFault; import at.gv.egiz.stal.service.STALPortType; import at.gv.egiz.stal.service.types.GetHashDataInputResponseType; import at.gv.egiz.stal.service.types.GetHashDataInputType; import at.gv.egiz.stal.signedinfo.DigestMethodType; import at.gv.egiz.stal.signedinfo.ReferenceType; +import java.security.NoSuchAlgorithmException; /** - * A SignRequesthandler displaying hashdata inputs in the applet - * (only plaintext data is displayed, other hashdata inputs may be saved to disk). + * A SignRequesthandler that obtains hashdata inputs from a STAL webservice and + * displays these either within the applet or in a separate frame. + * The internal viewer displays plaintext data only, other mimetypes can be saved to disk. + * The standalone (frame) viewer displays all mimetypes. + * + * (This class depends on STALService and therefore is not part of BKUCommonGUI.) * * @author Clemens Orthacker */ public class AppletHashDataDisplay extends SignRequestHandler { + public static enum DISPLAY { + applet, frame + } private static final Log log = LogFactory.getLog(AppletHashDataDisplay.class); - STALPortType stalPort; - String sessId; + protected STALPortType stalPort; + protected String sessId; + protected DISPLAY display; - public AppletHashDataDisplay(STALPortType stalPort, String sessId) { + public AppletHashDataDisplay(STALPortType stalPort, String sessId, DISPLAY display) { if (stalPort == null || sessId == null) { throw new NullPointerException("STAL port must not be null"); } this.sessId = sessId; this.stalPort = stalPort; + this.display = display; } @Override - public void displayHashDataInputs(List signedReferences) throws Exception { - + public void displayHashDataInputs(List signedReferences) throws DigestException, Exception { + + List hdi = getHashDataInput(signedReferences); + List verifiedHashDataInputs = verifyHashDataInput(signedReferences, hdi); + + if (verifiedHashDataInputs.size() > 1) { + gui.showHashDataInputDialog(verifiedHashDataInputs, false, this, "ok"); + } else if (verifiedHashDataInputs.size() == 1) { + gui.showHashDataInputDialog(verifiedHashDataInputs, display==DISPLAY.frame, this, "ok"); + } else { + throw new Exception("No signature data (apart from any QualifyingProperties or a Manifest)"); + } + } + + /** + * Get all hashdata inputs that contain an ID attribute but no Type attribute. + * @param signedReferences + * @return + * @throws at.gv.egiz.stal.service.GetHashDataInputFault + */ + private List getHashDataInput(List signedReferences) throws GetHashDataInputFault, Exception { GetHashDataInputType request = new GetHashDataInputType(); request.setSessionId(sessId); - HashMap idSignedRefMap = new HashMap(); +// HashMap idSignedRefMap = new HashMap(); for (ReferenceType signedRef : signedReferences) { //don't get Manifest, QualifyingProperties, ... if (signedRef.getType() == null) { @@ -71,97 +101,116 @@ public class AppletHashDataDisplay extends SignRequestHandler { if (log.isTraceEnabled()) { log.trace("requesting hashdata input for reference " + signedRefId); } - idSignedRefMap.put(signedRefId, signedRef); +// idSignedRefMap.put(signedRefId, signedRef); GetHashDataInputType.Reference ref = new GetHashDataInputType.Reference(); ref.setID(signedRefId); request.getReference().add(ref); } else { - throw new Exception("Cannot resolve HashDataInput for reference without Id attribute"); + throw new Exception("Cannot resolve signature data for dsig:Reference without Id attribute"); } } } if (log.isDebugEnabled()) { - log.debug("Calling GetHashDataInput for " + request.getReference().size() + " references in session " + sessId); + log.debug("WebService call GetHashDataInput for " + request.getReference().size() + " references in session " + sessId); } GetHashDataInputResponseType response = stalPort.getHashDataInput(request); - ArrayList hashDataInputs = new ArrayList(); - - //hashdata inputs returned from service - HashMap idRefMap = new HashMap(); - for (GetHashDataInputResponseType.Reference reference : response.getReference()) { - String id = reference.getID(); - byte[] hdi = reference.getValue(); - if (hdi == null) { - throw new Exception("Did not receive hashdata input for reference " + id); + return response.getReference(); + } + + /** + * Verifies all signed references and returns STAL HashDataInputs + * @param signedReferences + * @param hashDataInputs + * @return + * @throws java.security.DigestException + * @throws java.security.NoSuchAlgorithmException + * @throws Exception if no hashdata input is provided for a signed reference + */ + private List verifyHashDataInput(List signedReferences, List hashDataInputs) throws DigestException, NoSuchAlgorithmException, Exception { + + ArrayList verifiedHashDataInputs = new ArrayList(); + + for (ReferenceType signedRef : signedReferences) { + if (signedRef.getType() == null) { + log.info("Verifying digest for signed reference " + signedRef.getId()); + + String signedRefId = signedRef.getId(); + byte[] signedDigest = signedRef.getDigestValue(); + String signedDigestAlg = null; + if (signedRef.getDigestMethod() != null) { + signedDigestAlg = signedRef.getDigestMethod().getAlgorithm(); + } else { + throw new NoSuchAlgorithmException("Failed to verify digest value for reference " + signedRefId + ": no digest algorithm"); + } + + // usually, there is just one item here + GetHashDataInputResponseType.Reference hashDataInput = null; + for (GetHashDataInputResponseType.Reference hdi : hashDataInputs) { + if (signedRefId.equals(hdi.getID())) { + hashDataInput = hdi; + break; + } + } + if (hashDataInput == null) { + throw new Exception("No hashdata input for reference " + signedRefId + " returned by service"); + } + + byte[] hdi = hashDataInput.getValue(); + String mimeType = hashDataInput.getMimeType(); + String encoding = hashDataInput.getEncoding(); + + if (hdi == null) { + throw new Exception("No hashdata input for reference " + signedRefId + " provided by service"); + } + if (log.isDebugEnabled()) { + log.debug("Got HashDataInput " + signedRefId + " (" + mimeType + ";" + encoding + ")"); + } + + byte[] hashDataInputDigest = digest(hdi, signedDigestAlg); + + if (log.isDebugEnabled()) { + log.debug("Comparing digest values... "); + } +// log.warn("***************** DISABLED HASHDATA VERIFICATION"); + if (!Arrays.equals(hashDataInputDigest, signedDigest)) { + log.error("Bad digest value for reference " + signedRefId); + throw new DigestException("Bad digest value for reference " + signedRefId); + } + + verifiedHashDataInputs.add(new ByteArrayHashDataInput(hdi, signedRefId, mimeType, encoding)); } - idRefMap.put(id, reference); } - for (String signedRefId : idSignedRefMap.keySet()) { - log.info("validating hashdata input for reference " + signedRefId); - - GetHashDataInputResponseType.Reference reference = idRefMap.get(signedRefId); - if (reference == null) { - throw new Exception("No hashdata input for reference " + signedRefId + " returned by service"); - } - -// } -// -// for (GetHashDataInputResponseType.Reference reference : response.getReference()) { -// -// String id = reference.getID(); - byte[] hdi = reference.getValue(); - String mimeType = reference.getMimeType(); - String encoding = reference.getEncoding(); - - if (hdi == null) { - throw new Exception("No hashdata input provided for reference " + signedRefId); - } - if (log.isDebugEnabled()) { - log.debug("Got HashDataInput " + signedRefId + " (" + mimeType + ";" + encoding + ")"); - } + return verifiedHashDataInputs; + } - ReferenceType dsigRef = idSignedRefMap.get(signedRefId); - DigestMethodType dm = dsigRef.getDigestMethod(); - - if (dm == null) { - throw new Exception("Failed to verify digest value for reference " + signedRefId + ": no digest algorithm"); - } - String mdAlg = dm.getAlgorithm(); - if ("http://www.w3.org/2000/09/xmldsig#sha1".equals(mdAlg)) - mdAlg = "SHA-1"; - else if ("http://www.w3.org/2001/04/xmlenc#sha256".equals(mdAlg)) - mdAlg = "SHA-256"; - else if ("http://www.w3.org/2001/04/xmlenc#sha224 ".equals(mdAlg)) - mdAlg = "SHA-224"; - else if ("http://www.w3.org/2001/04/xmldsig-more#sha224 ".equals(mdAlg)) - mdAlg = "SHA-224"; - else if ("http://www.w3.org/2001/04/xmldsig-more#sha384".equals(mdAlg)) - mdAlg = "SHA-384"; - else if ("http://www.w3.org/2001/04/xmlenc#sha512".equals(mdAlg)) - mdAlg = "SHA-512"; - else if ("http://www.w3.org/2001/04/xmldsig-more#md2 ".equals(mdAlg)) - mdAlg = "MD2"; - else if ("http://www.w3.org/2001/04/xmldsig-more#md5".equals(mdAlg)) - mdAlg = "MD5"; - else if ("http://www.w3.org/2001/04/xmlenc#ripemd160 ".equals(mdAlg)) - mdAlg = "RipeMD-160"; - else { - throw new Exception("Failed to verify digest value for reference " + signedRefId + ": unsupported digest algorithm " + mdAlg); - } - MessageDigest md = MessageDigest.getInstance(mdAlg); - byte[] hdiDigest = md.digest(hdi); - if (log.isDebugEnabled()) - log.debug("Comparing digest values... "); - if (!Arrays.equals(hdiDigest, dsigRef.getDigestValue())) { - log.error("digest values differ: " + new String(hdiDigest) + ", " + new String(dsigRef.getDigestValue())); - throw new DigestException("Bad digest value for reference " + signedRefId + ": " + new String(dsigRef.getDigestValue())); - } - hashDataInputs.add(new ByteArrayHashDataInput(hdi, signedRefId, mimeType, encoding)); + //TODO + private byte[] digest(byte[] hashDataInput, String mdAlg) throws NoSuchAlgorithmException { + if ("http://www.w3.org/2000/09/xmldsig#sha1".equals(mdAlg)) { + mdAlg = "SHA-1"; + } else if ("http://www.w3.org/2001/04/xmlenc#sha256".equals(mdAlg)) { + mdAlg = "SHA-256"; + } else if ("http://www.w3.org/2001/04/xmlenc#sha224".equals(mdAlg)) { + mdAlg = "SHA-224"; + } else if ("http://www.w3.org/2001/04/xmldsig-more#sha224".equals(mdAlg)) { + mdAlg = "SHA-224"; + } else if ("http://www.w3.org/2001/04/xmldsig-more#sha384".equals(mdAlg)) { + mdAlg = "SHA-384"; + } else if ("http://www.w3.org/2001/04/xmlenc#sha512".equals(mdAlg)) { + mdAlg = "SHA-512"; + } else if ("http://www.w3.org/2001/04/xmldsig-more#md2".equals(mdAlg)) { + mdAlg = "MD2"; + } else if ("http://www.w3.org/2001/04/xmldsig-more#md5".equals(mdAlg)) { + mdAlg = "MD5"; + } else if ("http://www.w3.org/2001/04/xmlenc#ripemd160".equals(mdAlg)) { + mdAlg = "RipeMD-160"; + } else { + throw new NoSuchAlgorithmException("Failed to verify digest value: unsupported digest algorithm " + mdAlg); } - - gui.showHashDataInputDialog(hashDataInputs, false, this, "ok"); + + MessageDigest md = MessageDigest.getInstance(mdAlg); + return md.digest(hashDataInput); } } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHelpListener.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHelpListener.java deleted file mode 100644 index 5d199872..00000000 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHelpListener.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2008 Federal Chancellery Austria and - * Graz University of Technology - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package at.gv.egiz.bku.online.applet; - -import at.gv.egiz.bku.gui.AbstractHelpListener; -import java.applet.AppletContext; -import java.net.URL; -import java.util.Locale; - -/** - * - * @author Clemens Orthacker - */ -public class AppletHelpListener extends AbstractHelpListener { - - protected AppletContext ctx; - - public AppletHelpListener(AppletContext ctx, URL helpURL, Locale locale) { - super(helpURL, locale); - if (ctx == null) { - throw new RuntimeException("no applet context provided"); - } - this.ctx = ctx; - } - - @Override - public void showDocument(URL helpDocument) throws Exception { - ctx.showDocument(helpDocument, "_blank"); - } -} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 9d640dee..b4407b22 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -16,6 +16,7 @@ */ package at.gv.egiz.bku.online.applet; +import at.gv.egiz.bku.gui.AbstractHelpListener; import java.net.MalformedURLException; import java.net.URL; import java.util.Locale; @@ -85,10 +86,11 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { String locale = getAppletParameter(LOCALE_PARAM_KEY); String guiStyle = getAppletParameter(GUI_STYLE); URL backgroundImgURL = null; - AppletHelpListener helpListener = null; + AbstractHelpListener helpListener = null; try { URL helpURL = getURLParameter(HELP_URL); //, getAppletParameter(SESSION_ID)); - helpListener = new AppletHelpListener(getAppletContext(), helpURL, getLocale()); +// helpListener = new BrowserHelpListener(getAppletContext(), helpURL, getLocale()); + helpListener = new DefaultHelpListener(helpURL, getLocale()); } catch (MalformedURLException ex) { log.warn("failed to load help URL, disabling help: " + ex.getMessage()); } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BrowserHelpListener.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BrowserHelpListener.java new file mode 100644 index 00000000..265acca0 --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BrowserHelpListener.java @@ -0,0 +1,45 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package at.gv.egiz.bku.online.applet; + +import at.gv.egiz.bku.gui.AbstractHelpListener; +import java.applet.AppletContext; +import java.net.URL; +import java.util.Locale; + +/** + * + * @author Clemens Orthacker + */ +public class BrowserHelpListener extends AbstractHelpListener { + + protected AppletContext ctx; + + public BrowserHelpListener(AppletContext ctx, URL helpURL, Locale locale) { + super(helpURL, locale); + if (ctx == null) { + throw new RuntimeException("no applet context provided"); + } + this.ctx = ctx; + } + + @Override + public void showDocument(URL helpDocument, String helpTopic) throws Exception { + ctx.showDocument(helpDocument, "_blank"); + } +} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/DefaultHelpListener.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/DefaultHelpListener.java new file mode 100644 index 00000000..9876ef7e --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/DefaultHelpListener.java @@ -0,0 +1,77 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package at.gv.egiz.bku.online.applet; + +import at.gv.egiz.bku.gui.AbstractHelpListener; +import at.gv.egiz.bku.gui.ViewerDialog; +import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; +import java.util.Locale; +import javax.swing.SwingUtilities; + +/** + * This class depends on BKU utils, and therefore is not part of BKUCommonGUI + * + * @author Clemens Orthacker + */ +public class DefaultHelpListener extends AbstractHelpListener { + + public DefaultHelpListener(URL helpURL, Locale locale) { + super(helpURL, locale); + } + + @Override + public void showDocument(URL helpURL, final String helpTopic) throws Exception { + log.debug("open connection " + helpURL); + URLConnection conn = helpURL.openConnection(); + + log.debug("show help document " + conn.getContentType()); // + ";" + conn.getContentEncoding()); + +// Charset cs; +// if (conn.getContentEncoding() == null) { +// cs = Charset.forName("UTF-8"); +// } else { +// try { +// cs = Charset.forName(conn.getContentEncoding()); +// } catch (Exception ex) { +// log.debug("charset " + conn.getContentEncoding() + " not supported, assuming UTF-8: " + ex.getMessage()); +// cs = Charset.forName("UTF-8"); +// } +// } + +// InputStreamReader isr = new InputStreamReader(conn.getInputStream(), cs); +// final Reader content = new BufferedReader(isr); + final InputStream content = conn.getInputStream(); + final String mimeType = conn.getContentType(); + + log.debug("schedule help dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show help dialog"); + + ViewerDialog.showHelp(null, helpTopic, content, mimeType, messages); + + } + }); +// gui.showHelpDialog(helpDocument.getStream(), mimetype, encoding); + } +} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/JDialogHashDataDisplay.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/JDialogHashDataDisplay.java deleted file mode 100644 index 1f0eda90..00000000 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/JDialogHashDataDisplay.java +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright 2008 Federal Chancellery Austria and - * Graz University of Technology - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package at.gv.egiz.bku.online.applet; - -import at.gv.egiz.bku.smccstal.SignRequestHandler; -import at.gv.egiz.stal.HashDataInput; -import at.gv.egiz.stal.impl.ByteArrayHashDataInput; -import at.gv.egiz.stal.service.GetHashDataInputFault; -import at.gv.egiz.stal.service.STALPortType; -import at.gv.egiz.stal.service.types.GetHashDataInputResponseType; -import at.gv.egiz.stal.service.types.GetHashDataInputType; -import at.gv.egiz.stal.signedinfo.ReferenceType; -import java.awt.Dimension; -import java.security.DigestException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * - * @author Clemens Orthacker - */ -public class JDialogHashDataDisplay extends SignRequestHandler { - - private static final Log log = LogFactory.getLog(JDialogHashDataDisplay.class); - protected STALPortType stalPort; - protected String sessId; -// protected HashDataViewer viewer; - - public JDialogHashDataDisplay(STALPortType stalPort, String sessId, Dimension viewerSize, Locale locale) { - if (stalPort == null || sessId == null) { - throw new NullPointerException("STAL port must not be null"); - } - this.sessId = sessId; - this.stalPort = stalPort; -// this.viewer = new HashDataViewer(viewerSize, locale); - } - - @Override - public void displayHashDataInputs(List signedReferences) throws DigestException, Exception { - - List hdi = getHashDataInput(signedReferences); - final List verifiedHashDataInputs = verifyHashDataInput(signedReferences, hdi); - - if (verifiedHashDataInputs.size() > 1) { - gui.showHashDataInputDialog(verifiedHashDataInputs, false, this, "ok"); - } else if (verifiedHashDataInputs.size() == 1) { - gui.showHashDataInputDialog(verifiedHashDataInputs, true, this, "ok"); -// SwingUtilities.invokeLater(new Runnable() { -// -// @Override -// public void run() { -// viewer.displayHashData(verifiedHashDataInputs.get(0)); -// } -// }); - - } else { - log.error("No hashdata input to display"); - } - - } - - /** - * Get all hashdata inputs that contain an ID attribute and no Type attribute. - * @param signedReferences - * @return - * @throws at.gv.egiz.stal.service.GetHashDataInputFault - */ - private List getHashDataInput(List signedReferences) throws GetHashDataInputFault, Exception { - GetHashDataInputType request = new GetHashDataInputType(); - request.setSessionId(sessId); - -// HashMap idSignedRefMap = new HashMap(); - for (ReferenceType signedRef : signedReferences) { - //don't get Manifest, QualifyingProperties, ... - if (signedRef.getType() == null) { - String signedRefId = signedRef.getId(); - if (signedRefId != null) { - if (log.isTraceEnabled()) { - log.trace("requesting hashdata input for reference " + signedRefId); - } -// idSignedRefMap.put(signedRefId, signedRef); - GetHashDataInputType.Reference ref = new GetHashDataInputType.Reference(); - ref.setID(signedRefId); - request.getReference().add(ref); - - } else { - throw new Exception("Cannot resolve HashDataInput for reference without Id attribute"); - } - } - } - - if (log.isDebugEnabled()) { - log.debug("WebService call GetHashDataInput for " + request.getReference().size() + " references in session " + sessId); - } - GetHashDataInputResponseType response = stalPort.getHashDataInput(request); - return response.getReference(); - } - - /** - * Verifies all signed references and returns STAL HashDataInputs - * @param signedReferences - * @param hashDataInputs - * @return - * @throws java.security.DigestException - * @throws java.security.NoSuchAlgorithmException - * @throws Exception if no hashdata input is provided for a signed reference - */ - private List verifyHashDataInput(List signedReferences, List hashDataInputs) throws DigestException, NoSuchAlgorithmException, Exception { - - ArrayList verifiedHashDataInputs = new ArrayList(); - - //hashdata inputs returned from service -// HashMap idRefMap = new HashMap(); -// for (GetHashDataInputResponseType.Reference hashDataInput : hashDataInputs) { -// String id = hashDataInput.getID(); -// byte[] hdi = hashDataInput.getValue(); -// if (hdi == null) { -// throw new Exception("Did not receive hashdata input for reference " + id); -// } -// idRefMap.put(id, hashDataInput); -// } - - for (ReferenceType signedRef : signedReferences) { - if (signedRef.getType() == null) { - log.info("Verifying digest for signed reference " + signedRef.getId()); - - String signedRefId = signedRef.getId(); - byte[] signedDigest = signedRef.getDigestValue(); - String signedDigestAlg = null; - if (signedRef.getDigestMethod() != null) { - signedDigestAlg = signedRef.getDigestMethod().getAlgorithm(); - } else { - throw new NoSuchAlgorithmException("Failed to verify digest value for reference " + signedRefId + ": no digest algorithm"); - } - - GetHashDataInputResponseType.Reference hashDataInput = null; //idRefMap.get(signedRefId); - for (GetHashDataInputResponseType.Reference hdi : hashDataInputs) { - if (signedRefId.equals(hdi.getID())) { - hashDataInput = hdi; - } - } - if (hashDataInput == null) { - throw new Exception("No hashdata input for reference " + signedRefId + " returned by service"); - } - - byte[] hdi = hashDataInput.getValue(); - String mimeType = hashDataInput.getMimeType(); - String encoding = hashDataInput.getEncoding(); - - if (hdi == null) { - throw new Exception("No hashdata input for reference " + signedRefId + " provided by service"); - } - if (log.isDebugEnabled()) { - log.debug("Got HashDataInput " + signedRefId + " (" + mimeType + ";" + encoding + ")"); - } - - byte[] hashDataInputDigest = digest(hdi, signedDigestAlg); - - if (log.isDebugEnabled()) { - log.debug("Comparing digest values... "); - } - log.warn("DISABLED DIGEST VERIFICATION FOR DEBUGGING"); -// if (!Arrays.equals(hashDataInputDigest, signedDigest)) { -// log.error("Bad digest value for reference " + signedRefId); -// throw new DigestException("Bad digest value for reference " + signedRefId); -// } - - verifiedHashDataInputs.add(new ByteArrayHashDataInput(hdi, signedRefId, mimeType, encoding)); - } - } - - return verifiedHashDataInputs; - } - - //TODO - private byte[] digest(byte[] hashDataInput, String mdAlg) throws NoSuchAlgorithmException { - if ("http://www.w3.org/2000/09/xmldsig#sha1".equals(mdAlg)) { - mdAlg = "SHA-1"; - } else if ("http://www.w3.org/2001/04/xmlenc#sha256".equals(mdAlg)) { - mdAlg = "SHA-256"; - } else if ("http://www.w3.org/2001/04/xmlenc#sha224".equals(mdAlg)) { - mdAlg = "SHA-224"; - } else if ("http://www.w3.org/2001/04/xmldsig-more#sha224".equals(mdAlg)) { - mdAlg = "SHA-224"; - } else if ("http://www.w3.org/2001/04/xmldsig-more#sha384".equals(mdAlg)) { - mdAlg = "SHA-384"; - } else if ("http://www.w3.org/2001/04/xmlenc#sha512".equals(mdAlg)) { - mdAlg = "SHA-512"; - } else if ("http://www.w3.org/2001/04/xmldsig-more#md2 ".equals(mdAlg)) { - mdAlg = "MD2"; - } else if ("http://www.w3.org/2001/04/xmldsig-more#md5".equals(mdAlg)) { - mdAlg = "MD5"; - } else if ("http://www.w3.org/2001/04/xmlenc#ripemd160 ".equals(mdAlg)) { - mdAlg = "RipeMD-160"; - } else { - throw new NoSuchAlgorithmException("Failed to verify digest value: unsupported digest algorithm " + mdAlg); - } - - MessageDigest md = MessageDigest.getInstance(mdAlg); - return md.digest(hashDataInput); - } -} -- cgit v1.2.3 From fef61ddc786960015c6fc416d4ad2d5d0f2048d1 Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 13 Nov 2008 20:56:23 +0000 Subject: bugfix openwindow blocked bugfix helpTopic always hashdataviewer git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@168 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 2 +- .../bku/online/applet/DefaultHelpListener.java | 38 +++++----------------- 2 files changed, 9 insertions(+), 31 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index b4407b22..4b49c5d5 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -90,7 +90,7 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { try { URL helpURL = getURLParameter(HELP_URL); //, getAppletParameter(SESSION_ID)); // helpListener = new BrowserHelpListener(getAppletContext(), helpURL, getLocale()); - helpListener = new DefaultHelpListener(helpURL, getLocale()); + helpListener = new DefaultHelpListener(getAppletContext(), helpURL, getLocale()); } catch (MalformedURLException ex) { log.warn("failed to load help URL, disabling help: " + ex.getMessage()); } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/DefaultHelpListener.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/DefaultHelpListener.java index 9876ef7e..6eec5665 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/DefaultHelpListener.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/DefaultHelpListener.java @@ -16,49 +16,28 @@ */ package at.gv.egiz.bku.online.applet; +import at.gv.egiz.bku.gui.HelpViewer; import at.gv.egiz.bku.gui.AbstractHelpListener; -import at.gv.egiz.bku.gui.ViewerDialog; -import java.io.InputStream; +import java.applet.AppletContext; import java.net.URL; -import java.net.URLConnection; import java.util.Locale; import javax.swing.SwingUtilities; /** - * This class depends on BKU utils, and therefore is not part of BKUCommonGUI * * @author Clemens Orthacker */ public class DefaultHelpListener extends AbstractHelpListener { - public DefaultHelpListener(URL helpURL, Locale locale) { + protected AppletContext ctx; + + public DefaultHelpListener(AppletContext ctx, URL helpURL, Locale locale) { super(helpURL, locale); + this.ctx = ctx; } @Override - public void showDocument(URL helpURL, final String helpTopic) throws Exception { - log.debug("open connection " + helpURL); - URLConnection conn = helpURL.openConnection(); - - log.debug("show help document " + conn.getContentType()); // + ";" + conn.getContentEncoding()); - -// Charset cs; -// if (conn.getContentEncoding() == null) { -// cs = Charset.forName("UTF-8"); -// } else { -// try { -// cs = Charset.forName(conn.getContentEncoding()); -// } catch (Exception ex) { -// log.debug("charset " + conn.getContentEncoding() + " not supported, assuming UTF-8: " + ex.getMessage()); -// cs = Charset.forName("UTF-8"); -// } -// } - -// InputStreamReader isr = new InputStreamReader(conn.getInputStream(), cs); -// final Reader content = new BufferedReader(isr); - final InputStream content = conn.getInputStream(); - final String mimeType = conn.getContentType(); - + public void showDocument(final URL helpURL, final String helpTopic) throws Exception { log.debug("schedule help dialog"); SwingUtilities.invokeLater(new Runnable() { @@ -68,10 +47,9 @@ public class DefaultHelpListener extends AbstractHelpListener { log.debug("show help dialog"); - ViewerDialog.showHelp(null, helpTopic, content, mimeType, messages); + HelpViewer.showHelpDialog(ctx, helpURL, helpTopic, messages); } }); -// gui.showHelpDialog(helpDocument.getStream(), mimetype, encoding); } } -- cgit v1.2.3 From f09efb78459c7cd49ca4e28d92f170833e7ee32d Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 14 Nov 2008 16:30:28 +0000 Subject: git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@172 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/online/applet/AppletBKUWorker.java | 1 - .../at/gv/egiz/bku/online/applet/BKUApplet.java | 5 +- .../bku/online/applet/DefaultHelpListener.java | 55 ---------------------- 3 files changed, 3 insertions(+), 58 deletions(-) delete mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/DefaultHelpListener.java (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java index db88c037..f862360b 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java @@ -31,7 +31,6 @@ import at.gv.egiz.stal.service.types.RequestType; import at.gv.egiz.stal.service.types.ResponseType; import at.gv.egiz.stal.util.STALTranslator; import java.applet.AppletContext; -import java.awt.Dimension; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 4b49c5d5..7963768e 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -16,6 +16,7 @@ */ package at.gv.egiz.bku.online.applet; +import at.gv.egiz.bku.gui.DefaultHelpListener; import at.gv.egiz.bku.gui.AbstractHelpListener; import java.net.MalformedURLException; import java.net.URL; @@ -92,12 +93,12 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { // helpListener = new BrowserHelpListener(getAppletContext(), helpURL, getLocale()); helpListener = new DefaultHelpListener(getAppletContext(), helpURL, getLocale()); } catch (MalformedURLException ex) { - log.warn("failed to load help URL, disabling help: " + ex.getMessage()); + log.warn("failed to load help URL: " + ex.getMessage() + ", disabling help"); } try { backgroundImgURL = getURLParameter(BACKGROUND_PARAM); } catch (MalformedURLException ex) { - log.info("failed to load applet background image, using default: " + ex.getMessage()); + log.warn("failed to load applet background image: " + ex.getMessage() + ", using default"); } if (locale != null) { diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/DefaultHelpListener.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/DefaultHelpListener.java deleted file mode 100644 index 6eec5665..00000000 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/DefaultHelpListener.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2008 Federal Chancellery Austria and - * Graz University of Technology - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package at.gv.egiz.bku.online.applet; - -import at.gv.egiz.bku.gui.HelpViewer; -import at.gv.egiz.bku.gui.AbstractHelpListener; -import java.applet.AppletContext; -import java.net.URL; -import java.util.Locale; -import javax.swing.SwingUtilities; - -/** - * - * @author Clemens Orthacker - */ -public class DefaultHelpListener extends AbstractHelpListener { - - protected AppletContext ctx; - - public DefaultHelpListener(AppletContext ctx, URL helpURL, Locale locale) { - super(helpURL, locale); - this.ctx = ctx; - } - - @Override - public void showDocument(final URL helpURL, final String helpTopic) throws Exception { - log.debug("schedule help dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show help dialog"); - - HelpViewer.showHelpDialog(ctx, helpURL, helpTopic, messages); - - } - }); - } -} -- cgit v1.2.3 From 28e81afd92a6568ff78736b72c5257a86c0b9b91 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 18 Nov 2008 08:03:35 +0000 Subject: GUI refactoring 1 git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@177 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/online/applet/AppletBKUWorker.java | 13 ++++++------ .../bku/online/applet/AppletHashDataDisplay.java | 24 +++++++++++++--------- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 6 +++--- 3 files changed, 24 insertions(+), 19 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java index f862360b..b2f9f89c 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java @@ -192,18 +192,19 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { private void registerSignRequestHandler() throws MalformedURLException { String hashDataDisplayStyle = params.getAppletParameter(BKUApplet.HASHDATA_DISPLAY); - if (BKUApplet.HASHDATA_DISPLAY_INTERNAL.equals(hashDataDisplayStyle)) { - log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); - AppletHashDataDisplay handler = new AppletHashDataDisplay(stalPort, sessionId, AppletHashDataDisplay.DISPLAY.applet); - addRequestHandler(SignRequest.class, handler); - } else if (BKUApplet.HASHDATA_DISPLAY_BROWSER.equals(hashDataDisplayStyle)) { +// if (BKUApplet.HASHDATA_DISPLAY_INTERNAL.equals(hashDataDisplayStyle)) { +// log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); +// AppletHashDataDisplay handler = new AppletHashDataDisplay(stalPort, sessionId, AppletHashDataDisplay.DISPLAY.applet); +// addRequestHandler(SignRequest.class, handler); +// } else + if (BKUApplet.HASHDATA_DISPLAY_BROWSER.equals(hashDataDisplayStyle)) { URL hashDataURL = params.getURLParameter(BKUApplet.HASHDATA_URL, sessionId); log.debug("register SignRequestHandler for HashDataURL " + hashDataURL); addRequestHandler(SignRequest.class, new BrowserHashDataDisplay(ctx, hashDataURL)); } else { //BKUApplet.HASHDATA_DISPLAY_FRAME log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); - AppletHashDataDisplay handler = new AppletHashDataDisplay(stalPort, sessionId, AppletHashDataDisplay.DISPLAY.frame); + AppletHashDataDisplay handler = new AppletHashDataDisplay(stalPort, sessionId); addRequestHandler(SignRequest.class, handler); } } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java index 29a60f1d..ba502906 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java @@ -50,33 +50,32 @@ import java.security.NoSuchAlgorithmException; */ public class AppletHashDataDisplay extends SignRequestHandler { - public static enum DISPLAY { - applet, frame - } private static final Log log = LogFactory.getLog(AppletHashDataDisplay.class); protected STALPortType stalPort; protected String sessId; - protected DISPLAY display; - public AppletHashDataDisplay(STALPortType stalPort, String sessId, DISPLAY display) { + public AppletHashDataDisplay(STALPortType stalPort, String sessId) { if (stalPort == null || sessId == null) { throw new NullPointerException("STAL port must not be null"); } this.sessId = sessId; this.stalPort = stalPort; - this.display = display; } + /** + * TODO don't throw exceptions + * @param signedReferences + * @throws java.security.DigestException + * @throws java.lang.Exception + */ @Override public void displayHashDataInputs(List signedReferences) throws DigestException, Exception { List hdi = getHashDataInput(signedReferences); List verifiedHashDataInputs = verifyHashDataInput(signedReferences, hdi); - if (verifiedHashDataInputs.size() > 1) { - gui.showHashDataInputDialog(verifiedHashDataInputs, false, this, "ok"); - } else if (verifiedHashDataInputs.size() == 1) { - gui.showHashDataInputDialog(verifiedHashDataInputs, display==DISPLAY.frame, this, "ok"); + if (verifiedHashDataInputs.size() > 0) { + gui.showHashDataInputDialog(verifiedHashDataInputs, this, "ok"); } else { throw new Exception("No signature data (apart from any QualifyingProperties or a Manifest)"); } @@ -111,6 +110,11 @@ public class AppletHashDataDisplay extends SignRequestHandler { } } } + + if (request.getReference().size() < 1) { + log.error("No signature data (apart from any QualifyingProperties or a Manifest) for session " + sessId); + throw new Exception("No signature data (apart from any QualifyingProperties or a Manifest)"); + } if (log.isDebugEnabled()) { log.debug("WebService call GetHashDataInput for " + request.getReference().size() + " references in session " + sessId); diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 7963768e..5b45c8e1 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -53,7 +53,7 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { public static final String BACKGROUND_PARAM = "Background"; public static final String REDIRECT_URL = "RedirectURL"; public static final String REDIRECT_TARGET = "RedirectTarget"; - public static final String HASHDATA_DISPLAY_INTERNAL = "internal"; +// public static final String HASHDATA_DISPLAY_INTERNAL = "internal"; public static final String HASHDATA_DISPLAY_BROWSER = "browser"; public static final String HASHDATA_DISPLAY_FRAME = "frame"; @@ -106,8 +106,8 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { } log.debug("setting locale to " + getLocale()); - BKUGUIFacade gui = BKUGUIFactory.createGUI(guiStyle); - gui.init(getContentPane(), getLocale(), backgroundImgURL, helpListener); + BKUGUIFacade gui = BKUGUIFactory.createGUI(getContentPane(), getLocale(), guiStyle, backgroundImgURL, helpListener); +// gui.init(getContentPane(), getLocale(), BKUGUIFacade.Style.advanced, backgroundImgURL, helpListener); worker = new AppletBKUWorker(gui, getAppletContext(), this); } -- cgit v1.2.3 From 6d2cd68c8adff8c27a6a3a18711ea44a2e7bfe30 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 18 Nov 2008 18:00:44 +0000 Subject: GUI refactoring 2 git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@178 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../bku/online/applet/AppletHashDataDisplay.java | 2 +- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 46 +++++++++++++--------- .../bku/online/applet/BrowserHelpListener.java | 45 --------------------- 3 files changed, 29 insertions(+), 64 deletions(-) delete mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BrowserHelpListener.java (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java index ba502906..7be40d65 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java @@ -75,7 +75,7 @@ public class AppletHashDataDisplay extends SignRequestHandler { List verifiedHashDataInputs = verifyHashDataInput(signedReferences, hdi); if (verifiedHashDataInputs.size() > 0) { - gui.showHashDataInputDialog(verifiedHashDataInputs, this, "ok"); + gui.showHashDataInputDialog(verifiedHashDataInputs, this, "hashDataDone"); } else { throw new Exception("No signature data (apart from any QualifyingProperties or a Manifest)"); } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 5b45c8e1..d0eed607 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -43,14 +43,13 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { * Applet parameter keys */ public static final String GUI_STYLE = "GuiStyle"; - public final static String LOCALE_PARAM_KEY = "Locale"; - public final static String LOGO_URL_KEY = "LogoURL"; + public final static String LOCALE = "Locale"; public final static String WSDL_URL = "WSDL_URL"; public static final String HASHDATA_DISPLAY = "HashDataDisplay"; public final static String HASHDATA_URL = "HashDataURL"; public final static String HELP_URL = "HelpURL"; public final static String SESSION_ID = "SessionID"; - public static final String BACKGROUND_PARAM = "Background"; + public static final String BACKGROUND_IMG = "Background"; public static final String REDIRECT_URL = "RedirectURL"; public static final String REDIRECT_TARGET = "RedirectTarget"; // public static final String HASHDATA_DISPLAY_INTERNAL = "internal"; @@ -76,6 +75,7 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { /** * Factory method to create and wire HelpListener, GUI and BKUWorker. + * (Config via applet parameters as constants BKUApplet.*) */ @Override public void init() { @@ -84,30 +84,40 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getInstance()); - String locale = getAppletParameter(LOCALE_PARAM_KEY); - String guiStyle = getAppletParameter(GUI_STYLE); + String locale = getAppletParameter(LOCALE); + if (locale != null) { + this.setLocale(new Locale(locale)); + } + log.debug("setting locale to " + getLocale()); + + BKUGUIFacade.Style guiStyle; + if ("advanced".equals(getAppletParameter(GUI_STYLE))) { + guiStyle = BKUGUIFacade.Style.advanced; + } else { + guiStyle = BKUGUIFacade.Style.simple; + } + URL backgroundImgURL = null; + try { + backgroundImgURL = getURLParameter(BACKGROUND_IMG); + } catch (MalformedURLException ex) { + log.warn("failed to load applet background image: " + ex.getMessage() + ", using default"); + } + AbstractHelpListener helpListener = null; try { - URL helpURL = getURLParameter(HELP_URL); //, getAppletParameter(SESSION_ID)); + URL helpURL = getURLParameter(HELP_URL); // helpListener = new BrowserHelpListener(getAppletContext(), helpURL, getLocale()); helpListener = new DefaultHelpListener(getAppletContext(), helpURL, getLocale()); } catch (MalformedURLException ex) { log.warn("failed to load help URL: " + ex.getMessage() + ", disabling help"); } - try { - backgroundImgURL = getURLParameter(BACKGROUND_PARAM); - } catch (MalformedURLException ex) { - log.warn("failed to load applet background image: " + ex.getMessage() + ", using default"); - } - if (locale != null) { - this.setLocale(new Locale(locale)); - } - log.debug("setting locale to " + getLocale()); - - BKUGUIFacade gui = BKUGUIFactory.createGUI(getContentPane(), getLocale(), guiStyle, backgroundImgURL, helpListener); -// gui.init(getContentPane(), getLocale(), BKUGUIFacade.Style.advanced, backgroundImgURL, helpListener); + BKUGUIFacade gui = BKUGUIFactory.createGUI(getContentPane(), + getLocale(), + guiStyle, + backgroundImgURL, + helpListener); worker = new AppletBKUWorker(gui, getAppletContext(), this); } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BrowserHelpListener.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BrowserHelpListener.java deleted file mode 100644 index 265acca0..00000000 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BrowserHelpListener.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2008 Federal Chancellery Austria and - * Graz University of Technology - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package at.gv.egiz.bku.online.applet; - -import at.gv.egiz.bku.gui.AbstractHelpListener; -import java.applet.AppletContext; -import java.net.URL; -import java.util.Locale; - -/** - * - * @author Clemens Orthacker - */ -public class BrowserHelpListener extends AbstractHelpListener { - - protected AppletContext ctx; - - public BrowserHelpListener(AppletContext ctx, URL helpURL, Locale locale) { - super(helpURL, locale); - if (ctx == null) { - throw new RuntimeException("no applet context provided"); - } - this.ctx = ctx; - } - - @Override - public void showDocument(URL helpDocument, String helpTopic) throws Exception { - ctx.showDocument(helpDocument, "_blank"); - } -} -- cgit v1.2.3 From 0177d75af235f00063e8b0866106002237a41d05 Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 24 Nov 2008 17:33:08 +0000 Subject: cleanup git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@199 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java | 5 ----- 1 file changed, 5 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java index b2f9f89c..03e4b7c9 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java @@ -192,11 +192,6 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { private void registerSignRequestHandler() throws MalformedURLException { String hashDataDisplayStyle = params.getAppletParameter(BKUApplet.HASHDATA_DISPLAY); -// if (BKUApplet.HASHDATA_DISPLAY_INTERNAL.equals(hashDataDisplayStyle)) { -// log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); -// AppletHashDataDisplay handler = new AppletHashDataDisplay(stalPort, sessionId, AppletHashDataDisplay.DISPLAY.applet); -// addRequestHandler(SignRequest.class, handler); -// } else if (BKUApplet.HASHDATA_DISPLAY_BROWSER.equals(hashDataDisplayStyle)) { URL hashDataURL = params.getURLParameter(BKUApplet.HASHDATA_URL, sessionId); log.debug("register SignRequestHandler for HashDataURL " + hashDataURL); -- cgit v1.2.3 From b7a21dac485edf28d6201ab210d7263cf052e21f Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 1 Dec 2008 12:39:54 +0000 Subject: cleanup git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@226 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index d0eed607..d0f6d489 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -75,7 +75,7 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { /** * Factory method to create and wire HelpListener, GUI and BKUWorker. - * (Config via applet parameters as constants BKUApplet.*) + * (Config via applet parameters, see BKUApplet.* constants) */ @Override public void init() { @@ -83,7 +83,7 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { log.debug("Called init()"); HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getInstance()); - + String locale = getAppletParameter(LOCALE); if (locale != null) { this.setLocale(new Locale(locale)); -- cgit v1.2.3 From 77a19e106e4128c21dd2d1270fdc8d930e415247 Mon Sep 17 00:00:00 2001 From: wbauer Date: Thu, 18 Dec 2008 08:58:39 +0000 Subject: Fixed BUG #366, changed applet name in BKUOnline to have no version number git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@253 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/online/applet/AppletBKUWorker.java | 59 ++++-- .../online/applet/InternalSSLSocketFactory.java | 235 +++++++++++---------- 2 files changed, 155 insertions(+), 139 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java index 03e4b7c9..9fc21df8 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java @@ -38,7 +38,7 @@ import java.util.List; import javax.xml.namespace.QName; /** - * + * * @author Clemens Orthacker */ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { @@ -48,7 +48,8 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { protected String sessionId; protected STALPortType stalPort; - public AppletBKUWorker(BKUGUIFacade gui, AppletContext ctx, AppletParameterProvider paramProvider) { + public AppletBKUWorker(BKUGUIFacade gui, AppletContext ctx, + AppletParameterProvider paramProvider) { super(gui); if (ctx == null) { throw new NullPointerException("Applet context not provided"); @@ -76,7 +77,7 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { actionCommandList.clear(); actionCommandList.add("ok"); gui.showErrorDialog(BKUGUIFacade.ERR_SERVICE_UNREACHABLE, - new Object[]{e.getMessage()}); + new Object[] { e.getMessage() }); try { waitForAction(); } catch (InterruptedException e1) { @@ -92,8 +93,10 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { GetNextRequestResponseType nextRequestResp = stalPort.connect(sessionId); do { - List requests = nextRequestResp.getInfoboxReadRequestOrSignRequestOrQuitRequest(); - List stalRequests = STALTranslator.translateRequests(requests); + List requests = nextRequestResp + .getInfoboxReadRequestOrSignRequestOrQuitRequest(); + List stalRequests = STALTranslator + .translateRequests(requests); if (log.isInfoEnabled()) { StringBuilder sb = new StringBuilder("Received "); @@ -142,64 +145,76 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { } if (!finished) { - log.info("Not finished yet (BKUWorker: " + this + "), sending responses"); + log.info("Not finished yet (BKUWorker: " + this + + "), sending responses"); GetNextRequestType nextRequest = of.createGetNextRequestType(); nextRequest.setSessionId(sessionId); - nextRequest.getInfoboxReadResponseOrSignResponseOrErrorResponse().addAll(responses); + nextRequest.getInfoboxReadResponseOrSignResponseOrErrorResponse() + .addAll(responses); nextRequestResp = stalPort.getNextRequest(nextRequest); } } while (!finished); log.info("Done " + Thread.currentThread().getName()); } catch (Exception ex) { log.error(ex.getMessage(), ex); - gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, new Object[]{ex.getMessage()}); + gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, new Object[] { ex + .getMessage() }); try { waitForAction(); } catch (InterruptedException e) { log.error(e); } - } - if (signatureCard != null) { - signatureCard.disconnect(false); + if (signatureCard != null) { + signatureCard.disconnect(false); + } } sendRedirect(); } protected void sendRedirect() { try { - URL redirectURL = params.getURLParameter(BKUApplet.REDIRECT_URL, sessionId); - String redirectTarget = params.getAppletParameter(BKUApplet.REDIRECT_TARGET); + URL redirectURL = params.getURLParameter(BKUApplet.REDIRECT_URL, + sessionId); + String redirectTarget = params + .getAppletParameter(BKUApplet.REDIRECT_TARGET); if (redirectTarget == null) { log.info("Done. Redirecting to " + redirectURL + " ..."); ctx.showDocument(redirectURL); } else { - log.info("Done. Redirecting to " + redirectURL + " (target=" + redirectTarget + ") ..."); + log.info("Done. Redirecting to " + redirectURL + " (target=" + + redirectTarget + ") ..."); ctx.showDocument(redirectURL, redirectTarget); } } catch (MalformedURLException ex) { log.warn("Failed to redirect: " + ex.getMessage(), ex); - // gui.showErrorDialog(errorMsg, okListener, actionCommand) + // gui.showErrorDialog(errorMsg, okListener, actionCommand) } } private STALPortType getSTALPort() throws MalformedURLException { URL wsdlURL = params.getURLParameter(BKUApplet.WSDL_URL); log.debug("STAL WSDL at " + wsdlURL); - QName endpointName = new QName(BKUApplet.STAL_WSDL_NS, BKUApplet.STAL_SERVICE); + QName endpointName = new QName(BKUApplet.STAL_WSDL_NS, + BKUApplet.STAL_SERVICE); STALService stal = new STALService(wsdlURL, endpointName); return stal.getSTALPort(); } private void registerSignRequestHandler() throws MalformedURLException { - String hashDataDisplayStyle = params.getAppletParameter(BKUApplet.HASHDATA_DISPLAY); + String hashDataDisplayStyle = params + .getAppletParameter(BKUApplet.HASHDATA_DISPLAY); if (BKUApplet.HASHDATA_DISPLAY_BROWSER.equals(hashDataDisplayStyle)) { - URL hashDataURL = params.getURLParameter(BKUApplet.HASHDATA_URL, sessionId); + URL hashDataURL = params.getURLParameter(BKUApplet.HASHDATA_URL, + sessionId); log.debug("register SignRequestHandler for HashDataURL " + hashDataURL); - addRequestHandler(SignRequest.class, new BrowserHashDataDisplay(ctx, hashDataURL)); + addRequestHandler(SignRequest.class, new BrowserHashDataDisplay(ctx, + hashDataURL)); } else { - //BKUApplet.HASHDATA_DISPLAY_FRAME - log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); - AppletHashDataDisplay handler = new AppletHashDataDisplay(stalPort, sessionId); + // BKUApplet.HASHDATA_DISPLAY_FRAME + log.debug("register SignRequestHandler for STAL port " + + BKUApplet.WSDL_URL); + AppletHashDataDisplay handler = new AppletHashDataDisplay(stalPort, + sessionId); addRequestHandler(SignRequest.class, handler); } } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java index c3417d63..a02e56eb 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java @@ -36,121 +36,122 @@ import org.apache.commons.logging.LogFactory; public class InternalSSLSocketFactory extends SSLSocketFactory { - private final static String GOV_DOMAIN = ".gv.at"; - - private static InternalSSLSocketFactory instance = new InternalSSLSocketFactory(); - - private final static Log log = LogFactory - .getLog(InternalSSLSocketFactory.class); - - private SSLSocket sslSocket; - - private SSLSocketFactory proxy; - - private InternalSSLSocketFactory() { - proxy = HttpsURLConnection.getDefaultSSLSocketFactory(); - } - - public static InternalSSLSocketFactory getInstance() { - return instance; - } - - @Override - public Socket createSocket() throws IOException { - sslSocket = (SSLSocket) proxy.createSocket(); - return sslSocket; - } - - @Override - public Socket createSocket(String arg0, int arg1) throws IOException, - UnknownHostException { - sslSocket = (SSLSocket) proxy.createSocket(arg0, arg1); - - return sslSocket; - } - - @Override - public Socket createSocket(InetAddress arg0, int arg1) throws IOException { - sslSocket = (SSLSocket) proxy.createSocket(arg0, arg1); - return sslSocket; - } - - @Override - public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) - throws IOException, UnknownHostException { - sslSocket = (SSLSocket) proxy.createSocket(arg0, arg1, arg2, arg3); - return sslSocket; - } - - @Override - public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, - int arg3) throws IOException { - sslSocket = (SSLSocket) proxy.createSocket(arg0, arg1, arg2, arg3); - return sslSocket; - } - - @Override - public Socket createSocket(Socket arg0, String arg1, int arg2, boolean arg3) - throws IOException { - sslSocket = (SSLSocket) proxy.createSocket(arg0, arg1, arg2, arg3); - return sslSocket; - } - - @Override - public String[] getDefaultCipherSuites() { - return proxy.getDefaultCipherSuites(); - } - - @Override - public String[] getSupportedCipherSuites() { - return proxy.getSupportedCipherSuites(); - } - - public boolean isEgovAgency() { - log.info("Checking if server is egov agency"); - if (sslSocket != null) { - try { - X509Certificate cert = (X509Certificate) sslSocket.getSession() - .getPeerCertificates()[0]; - log.info("Server cert: " + cert); - return isGovAgency(cert); - } catch (SSLPeerUnverifiedException e) { - log.error(e); - return false; - } - } - log.info("Not a SSL connection"); - return false; - } - - public static boolean isGovAgency(X509Certificate cert) { - String[] rdns = (cert.getSubjectX500Principal().getName()).split(","); - for (String rdn : rdns) { - if (rdn.startsWith("CN=")) { - String dns = rdn.split("=")[1]; - if (dns.endsWith(GOV_DOMAIN)) { - return true; - } - } - } - try { - Collection> sanList = cert.getSubjectAlternativeNames(); - if (sanList != null) { - for (List san : sanList) { - if ((Integer) san.get(0) == 2) { - String dns = (String) san.get(1); - if (dns.endsWith(GOV_DOMAIN)) { - return true; - } - } - } - } - } catch (CertificateParsingException e) { - log.error(e); - } - if (cert.getExtensionValue("1.2.40.0.10.1.1.1") != null) { - return true; - } - return false; - } + private final static String GOV_DOMAIN = ".gv.at"; + + private static InternalSSLSocketFactory instance = new InternalSSLSocketFactory(); + + private final static Log log = LogFactory + .getLog(InternalSSLSocketFactory.class); + + private SSLSocket sslSocket; + + private SSLSocketFactory proxy; + + private InternalSSLSocketFactory() { + proxy = HttpsURLConnection.getDefaultSSLSocketFactory(); + } + + public static InternalSSLSocketFactory getInstance() { + return instance; + } + + @Override + public Socket createSocket() throws IOException { + sslSocket = (SSLSocket) proxy.createSocket(); + return sslSocket; + } + + @Override + public Socket createSocket(String arg0, int arg1) throws IOException, + UnknownHostException { + sslSocket = (SSLSocket) proxy.createSocket(arg0, arg1); + + return sslSocket; + } + + @Override + public Socket createSocket(InetAddress arg0, int arg1) throws IOException { + sslSocket = (SSLSocket) proxy.createSocket(arg0, arg1); + return sslSocket; + } + + @Override + public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) + throws IOException, UnknownHostException { + sslSocket = (SSLSocket) proxy.createSocket(arg0, arg1, arg2, arg3); + return sslSocket; + } + + @Override + public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, + int arg3) throws IOException { + sslSocket = (SSLSocket) proxy.createSocket(arg0, arg1, arg2, arg3); + return sslSocket; + } + + @Override + public Socket createSocket(Socket arg0, String arg1, int arg2, boolean arg3) + throws IOException { + sslSocket = (SSLSocket) proxy.createSocket(arg0, arg1, arg2, arg3); + return sslSocket; + } + + @Override + public String[] getDefaultCipherSuites() { + return proxy.getDefaultCipherSuites(); + } + + @Override + public String[] getSupportedCipherSuites() { + return proxy.getSupportedCipherSuites(); + } + + public boolean isEgovAgency() { + log.info("Checking if server is egov agency"); + if (sslSocket != null) { + try { + X509Certificate cert = (X509Certificate) sslSocket.getSession() + .getPeerCertificates()[0]; + log.info("Server cert: " + cert); + return isGovAgency(cert); + } catch (SSLPeerUnverifiedException e) { + log.error(e); + return false; + } + } + log.info("Not a SSL connection"); + return false; + } + + public static boolean isGovAgency(X509Certificate cert) { + String[] rdns = (cert.getSubjectX500Principal().getName()).split(","); + for (String rdn : rdns) { + if (rdn.startsWith("CN=")) { + String dns = rdn.split("=")[1]; + if (dns.endsWith(GOV_DOMAIN)) { + return true; + } + } + } + try { + Collection> sanList = cert.getSubjectAlternativeNames(); + if (sanList != null) { + for (List san : sanList) { + if ((Integer) san.get(0) == 2) { + String dns = (String) san.get(1); + if (dns.endsWith(GOV_DOMAIN)) { + return true; + } + } + } + } + } catch (CertificateParsingException e) { + log.error(e); + } + if ((cert.getExtensionValue("1.2.40.0.10.1.1.1") != null) + || (cert.getExtensionValue("1.2.40.0.10.1.1.2") != null)) { + return true; + } + return false; + } } -- cgit v1.2.3 From 9676c9eb710bf10ecb4812043fedacd2f6e6278c Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 20 Jan 2009 14:24:43 +0000 Subject: prepare for stal service extension git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@269 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/online/applet/AppletBKUWorker.java | 67 +++++++++++----------- 1 file changed, 33 insertions(+), 34 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java index 9fc21df8..3903bf10 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java @@ -35,6 +35,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.List; +import javax.xml.bind.JAXBElement; import javax.xml.namespace.QName; /** @@ -47,9 +48,10 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { protected AppletParameterProvider params; protected String sessionId; protected STALPortType stalPort; + private ObjectFactory stalObjFactory = new ObjectFactory(); public AppletBKUWorker(BKUGUIFacade gui, AppletContext ctx, - AppletParameterProvider paramProvider) { + AppletParameterProvider paramProvider) { super(gui); if (ctx == null) { throw new NullPointerException("Applet context not provided"); @@ -77,7 +79,7 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { actionCommandList.clear(); actionCommandList.add("ok"); gui.showErrorDialog(BKUGUIFacade.ERR_SERVICE_UNREACHABLE, - new Object[] { e.getMessage() }); + new Object[]{e.getMessage()}); try { waitForAction(); } catch (InterruptedException e1) { @@ -89,14 +91,17 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { try { registerSignRequestHandler(); - ObjectFactory of = new ObjectFactory(); - GetNextRequestResponseType nextRequestResp = stalPort.connect(sessionId); do { - List requests = nextRequestResp - .getInfoboxReadRequestOrSignRequestOrQuitRequest(); - List stalRequests = STALTranslator - .translateRequests(requests); + List> requests = nextRequestResp.getInfoboxReadRequestOrSignRequestOrQuitRequest(); + + // (rather use validator) + if (requests.size() == 0) { + log.error("Received empty NextRequestResponse: no STAL requests to handle. (STAL-X requests might not have gotten unmarshalled)"); + throw new Exception("No STAL requests to handle."); + } + + List stalRequests = STALTranslator.translateRequests(requests); if (log.isInfoEnabled()) { StringBuilder sb = new StringBuilder("Received "); @@ -117,13 +122,13 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { String domainId = r.getDomainIdentifier(); if ("IdentityLink".equals(infoboxId) && domainId == null) { if (!InternalSSLSocketFactory.getInstance().isEgovAgency()) { - handle = false; + handle = false; } } } } - List responses; + List> responses; if (handle) { List stalResponses = handleRequest(stalRequests); if (log.isInfoEnabled()) { @@ -137,28 +142,26 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { } responses = STALTranslator.fromSTAL(stalResponses); } else { - responses = new ArrayList(1); - ErrorResponseType err = of.createErrorResponseType(); + log.error("Insufficient rights to execute command InfoboxReadRequest for Infobox IdentityLink, return Error 6002"); + responses = new ArrayList>(1); + ErrorResponseType err = stalObjFactory.createErrorResponseType(); err.setErrorCode(6002); // err.setErrorMessage(); - responses.add(err); + responses.add(stalObjFactory.createGetNextRequestTypeErrorResponse(err)); } if (!finished) { - log.info("Not finished yet (BKUWorker: " + this - + "), sending responses"); - GetNextRequestType nextRequest = of.createGetNextRequestType(); + log.info("Not finished yet (BKUWorker: " + this + "), sending responses"); + GetNextRequestType nextRequest = stalObjFactory.createGetNextRequestType(); nextRequest.setSessionId(sessionId); - nextRequest.getInfoboxReadResponseOrSignResponseOrErrorResponse() - .addAll(responses); + nextRequest.getInfoboxReadResponseOrSignResponseOrErrorResponse().addAll(responses); nextRequestResp = stalPort.getNextRequest(nextRequest); } } while (!finished); log.info("Done " + Thread.currentThread().getName()); } catch (Exception ex) { log.error(ex.getMessage(), ex); - gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, new Object[] { ex - .getMessage() }); + gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, new Object[]{ex.getMessage()}); try { waitForAction(); } catch (InterruptedException e) { @@ -174,20 +177,18 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { protected void sendRedirect() { try { URL redirectURL = params.getURLParameter(BKUApplet.REDIRECT_URL, - sessionId); - String redirectTarget = params - .getAppletParameter(BKUApplet.REDIRECT_TARGET); + sessionId); + String redirectTarget = params.getAppletParameter(BKUApplet.REDIRECT_TARGET); if (redirectTarget == null) { log.info("Done. Redirecting to " + redirectURL + " ..."); ctx.showDocument(redirectURL); } else { - log.info("Done. Redirecting to " + redirectURL + " (target=" - + redirectTarget + ") ..."); + log.info("Done. Redirecting to " + redirectURL + " (target=" + redirectTarget + ") ..."); ctx.showDocument(redirectURL, redirectTarget); } } catch (MalformedURLException ex) { log.warn("Failed to redirect: " + ex.getMessage(), ex); - // gui.showErrorDialog(errorMsg, okListener, actionCommand) + // gui.showErrorDialog(errorMsg, okListener, actionCommand) } } @@ -195,26 +196,24 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { URL wsdlURL = params.getURLParameter(BKUApplet.WSDL_URL); log.debug("STAL WSDL at " + wsdlURL); QName endpointName = new QName(BKUApplet.STAL_WSDL_NS, - BKUApplet.STAL_SERVICE); + BKUApplet.STAL_SERVICE); STALService stal = new STALService(wsdlURL, endpointName); return stal.getSTALPort(); } private void registerSignRequestHandler() throws MalformedURLException { - String hashDataDisplayStyle = params - .getAppletParameter(BKUApplet.HASHDATA_DISPLAY); + String hashDataDisplayStyle = params.getAppletParameter(BKUApplet.HASHDATA_DISPLAY); if (BKUApplet.HASHDATA_DISPLAY_BROWSER.equals(hashDataDisplayStyle)) { URL hashDataURL = params.getURLParameter(BKUApplet.HASHDATA_URL, - sessionId); + sessionId); log.debug("register SignRequestHandler for HashDataURL " + hashDataURL); addRequestHandler(SignRequest.class, new BrowserHashDataDisplay(ctx, - hashDataURL)); + hashDataURL)); } else { // BKUApplet.HASHDATA_DISPLAY_FRAME - log.debug("register SignRequestHandler for STAL port " - + BKUApplet.WSDL_URL); + log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); AppletHashDataDisplay handler = new AppletHashDataDisplay(stalPort, - sessionId); + sessionId); addRequestHandler(SignRequest.class, handler); } } -- cgit v1.2.3 From 212bbffc24ccc1cd909cabdc9650491dd221cd60 Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 22 Jan 2009 13:21:50 +0000 Subject: STALTranslator git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@283 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/online/applet/AppletBKUWorker.java | 204 ++++++++++++--------- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 2 +- 2 files changed, 119 insertions(+), 87 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java index 3903bf10..3b6d007a 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java @@ -23,13 +23,14 @@ import at.gv.egiz.stal.STALResponse; import at.gv.egiz.stal.SignRequest; import at.gv.egiz.stal.service.STALPortType; import at.gv.egiz.stal.service.STALService; +import at.gv.egiz.stal.service.translator.STALTranslator; +import at.gv.egiz.stal.service.translator.TranslationException; import at.gv.egiz.stal.service.types.ErrorResponseType; import at.gv.egiz.stal.service.types.GetNextRequestResponseType; import at.gv.egiz.stal.service.types.GetNextRequestType; import at.gv.egiz.stal.service.types.ObjectFactory; import at.gv.egiz.stal.service.types.RequestType; import at.gv.egiz.stal.service.types.ResponseType; -import at.gv.egiz.stal.util.STALTranslator; import java.applet.AppletContext; import java.net.MalformedURLException; import java.net.URL; @@ -37,6 +38,7 @@ import java.util.ArrayList; import java.util.List; import javax.xml.bind.JAXBElement; import javax.xml.namespace.QName; +import javax.xml.ws.WebServiceException; /** * @@ -49,6 +51,7 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { protected String sessionId; protected STALPortType stalPort; private ObjectFactory stalObjFactory = new ObjectFactory(); + private STALTranslator translator = new STALTranslator(); public AppletBKUWorker(BKUGUIFacade gui, AppletContext ctx, AppletParameterProvider paramProvider) { @@ -72,108 +75,147 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { @Override public void run() { gui.showWelcomeDialog(); + try { stalPort = getSTALPort(); - } catch (Exception e) { - log.fatal("Failed to get STAL web-service port: " + e.getMessage(), e); - actionCommandList.clear(); - actionCommandList.add("ok"); - gui.showErrorDialog(BKUGUIFacade.ERR_SERVICE_UNREACHABLE, - new Object[]{e.getMessage()}); - try { - waitForAction(); - } catch (InterruptedException e1) { - log.error(e1); - } - return; - } - try { - registerSignRequestHandler(); + registerSignRequestHandler(stalPort, sessionId); GetNextRequestResponseType nextRequestResp = stalPort.connect(sessionId); + do { - List> requests = nextRequestResp.getInfoboxReadRequestOrSignRequestOrQuitRequest(); + List> requests; + List> responses = new ArrayList>(); - // (rather use validator) - if (requests.size() == 0) { - log.error("Received empty NextRequestResponse: no STAL requests to handle. (STAL-X requests might not have gotten unmarshalled)"); - throw new Exception("No STAL requests to handle."); - } + try { + requests = nextRequestResp.getInfoboxReadRequestOrSignRequestOrQuitRequest(); + responses.clear(); - List stalRequests = STALTranslator.translateRequests(requests); + // (rather use validator) + if (requests.size() == 0) { + log.error("Received empty NextRequestResponse: no STAL requests to handle. (STAL-X requests might not have gotten unmarshalled)"); + throw new RuntimeException("No STAL requests to handle."); + } - if (log.isInfoEnabled()) { - StringBuilder sb = new StringBuilder("Received "); - sb.append(stalRequests.size()); - sb.append(" STAL requests: "); - for (STALRequest r : stalRequests) { - sb.append(r.getClass()); - sb.append(' '); + if (log.isInfoEnabled()) { + StringBuilder sb = new StringBuilder("Received "); + sb.append(requests.size()); + sb.append(" requests: "); + for (JAXBElement r : requests) { + sb.append(r.getValue().getClass()); + sb.append(' '); + } + log.info(sb.toString()); } - log.info(sb.toString()); - } - boolean handle = true; - for (STALRequest request : stalRequests) { - if (request instanceof at.gv.egiz.stal.InfoboxReadRequest) { - at.gv.egiz.stal.InfoboxReadRequest r = (at.gv.egiz.stal.InfoboxReadRequest) request; - String infoboxId = r.getInfoboxIdentifier(); - String domainId = r.getDomainIdentifier(); - if ("IdentityLink".equals(infoboxId) && domainId == null) { - if (!InternalSSLSocketFactory.getInstance().isEgovAgency()) { - handle = false; - } + List stalRequests = new ArrayList(); + for (JAXBElement req : requests) { + try { + stalRequests.add(translator.translate(req)); + } catch (TranslationException ex) { + log.error("Received unknown request from server STAL: " + ex.getMessage()); + throw new RuntimeException(ex); } } - } - List> responses; - if (handle) { + checkPermission(stalRequests); + List stalResponses = handleRequest(stalRequests); - if (log.isInfoEnabled()) { - StringBuilder sb = new StringBuilder(stalResponses.size()); - sb.append(" STAL responses: "); - for (STALResponse r : stalResponses) { - sb.append(r.getClass()); - sb.append(' '); + for (STALResponse stalResponse : stalResponses) { + try { + responses.add(translator.translate(stalResponse)); + } catch (TranslationException ex) { + log.error("Received unknown response from STAL: " + ex.getMessage()); + throw new RuntimeException(ex); } - log.info(sb.toString()); } - responses = STALTranslator.fromSTAL(stalResponses); - } else { - log.error("Insufficient rights to execute command InfoboxReadRequest for Infobox IdentityLink, return Error 6002"); - responses = new ArrayList>(1); + + } catch (RuntimeException ex) { + // return ErrorResponse to server, which displays error page + log.error(ex.getMessage()); + Throwable cause = ex.getCause(); ErrorResponseType err = stalObjFactory.createErrorResponseType(); - err.setErrorCode(6002); - // err.setErrorMessage(); + if (cause != null) { + log.error("caused by: " + cause.getMessage()); + if (cause instanceof SecurityException) { + err.setErrorCode(6002); + } else { + err.setErrorCode(4000); + } + } else { + err.setErrorCode(4000); + } + responses.clear(); responses.add(stalObjFactory.createGetNextRequestTypeErrorResponse(err)); - } - if (!finished) { - log.info("Not finished yet (BKUWorker: " + this + "), sending responses"); - GetNextRequestType nextRequest = stalObjFactory.createGetNextRequestType(); - nextRequest.setSessionId(sessionId); - nextRequest.getInfoboxReadResponseOrSignResponseOrErrorResponse().addAll(responses); - nextRequestResp = stalPort.getNextRequest(nextRequest); + } finally { + if (!finished) { + if (log.isInfoEnabled()) { + StringBuilder sb = new StringBuilder("Sending "); + sb.append(responses.size()); + sb.append(" responses: "); + for (JAXBElement r : responses) { + sb.append(r.getValue().getClass()); + sb.append(' '); + } + log.info(sb.toString()); + } + GetNextRequestType nextRequest = stalObjFactory.createGetNextRequestType(); + nextRequest.setSessionId(sessionId); + nextRequest.getInfoboxReadResponseOrSignResponseOrErrorResponse().addAll(responses); + nextRequestResp = stalPort.getNextRequest(nextRequest); + } } + + } while (!finished); log.info("Done " + Thread.currentThread().getName()); + + } catch (WebServiceException ex) { + log.fatal("communication error with server STAL: " + ex.getMessage(), ex); + showErrorDialog(BKUGUIFacade.ERR_SERVICE_UNREACHABLE, ex); + } catch (MalformedURLException ex) { + log.fatal(ex.getMessage(), ex); + showErrorDialog(BKUGUIFacade.ERR_CONFIG, ex); } catch (Exception ex) { log.error(ex.getMessage(), ex); - gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, new Object[]{ex.getMessage()}); - try { - waitForAction(); - } catch (InterruptedException e) { - log.error(e); - } + showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, ex); + } finally { if (signatureCard != null) { signatureCard.disconnect(false); } } + sendRedirect(); } + private void checkPermission(List stalRequests) { + for (STALRequest request : stalRequests) { + if (request instanceof at.gv.egiz.stal.InfoboxReadRequest) { + at.gv.egiz.stal.InfoboxReadRequest r = (at.gv.egiz.stal.InfoboxReadRequest) request; + String infoboxId = r.getInfoboxIdentifier(); + String domainId = r.getDomainIdentifier(); + if ("IdentityLink".equals(infoboxId) && domainId == null) { + if (!InternalSSLSocketFactory.getInstance().isEgovAgency()) { + throw new RuntimeException(new SecurityException("Insufficient rights to execute command InfoboxReadRequest for Infobox IdentityLink")); + } + } + } + } + } + + private void showErrorDialog(String err_code, Exception ex) { + actionCommandList.clear(); + actionCommandList.add("ok"); + gui.showErrorDialog(err_code, + new Object[]{ex.getMessage()}, this, "ok"); + try { + waitForAction(); + } catch (InterruptedException e) { + log.error(e); + } + } + protected void sendRedirect() { try { URL redirectURL = params.getURLParameter(BKUApplet.REDIRECT_URL, @@ -201,20 +243,10 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { return stal.getSTALPort(); } - private void registerSignRequestHandler() throws MalformedURLException { - String hashDataDisplayStyle = params.getAppletParameter(BKUApplet.HASHDATA_DISPLAY); - if (BKUApplet.HASHDATA_DISPLAY_BROWSER.equals(hashDataDisplayStyle)) { - URL hashDataURL = params.getURLParameter(BKUApplet.HASHDATA_URL, - sessionId); - log.debug("register SignRequestHandler for HashDataURL " + hashDataURL); - addRequestHandler(SignRequest.class, new BrowserHashDataDisplay(ctx, - hashDataURL)); - } else { - // BKUApplet.HASHDATA_DISPLAY_FRAME - log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); - AppletHashDataDisplay handler = new AppletHashDataDisplay(stalPort, - sessionId); - addRequestHandler(SignRequest.class, handler); - } + private void registerSignRequestHandler(STALPortType stalPort, String sessionId) { + log.debug("register SignRequestHandler (resolve hashdata via STAL Webservice)"); + AppletHashDataDisplay handler = new AppletHashDataDisplay(stalPort, + sessionId); + addRequestHandler(SignRequest.class, handler); } } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index d0f6d489..41dae3ba 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -53,7 +53,7 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { public static final String REDIRECT_URL = "RedirectURL"; public static final String REDIRECT_TARGET = "RedirectTarget"; // public static final String HASHDATA_DISPLAY_INTERNAL = "internal"; - public static final String HASHDATA_DISPLAY_BROWSER = "browser"; +// public static final String HASHDATA_DISPLAY_BROWSER = "browser"; public static final String HASHDATA_DISPLAY_FRAME = "frame"; /** -- cgit v1.2.3 From 2d66c2f9ea2efd596287ad1be61e89d5bc1f1da9 Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 22 Jan 2009 13:48:33 +0000 Subject: STALTranslator git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@284 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/online/applet/AppletBKUWorker.java | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java index 3b6d007a..6ac892ec 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java @@ -133,16 +133,14 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { } catch (RuntimeException ex) { // return ErrorResponse to server, which displays error page log.error(ex.getMessage()); - Throwable cause = ex.getCause(); ErrorResponseType err = stalObjFactory.createErrorResponseType(); - if (cause != null) { - log.error("caused by: " + cause.getMessage()); - if (cause instanceof SecurityException) { - err.setErrorCode(6002); - } else { - err.setErrorCode(4000); - } + if (ex instanceof SecurityException) { + err.setErrorCode(6002); } else { + Throwable cause = ex.getCause(); + if (cause != null) { + log.error("caused by: " + cause.getMessage()); + } err.setErrorCode(4000); } responses.clear(); @@ -189,6 +187,11 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { sendRedirect(); } + /** + * throws RuntimeException if requests contain InfoboxReadRequest for IdentityLink + * and STAL Service Endpoint is no e-Gov agency + * @param stalRequests + */ private void checkPermission(List stalRequests) { for (STALRequest request : stalRequests) { if (request instanceof at.gv.egiz.stal.InfoboxReadRequest) { @@ -197,7 +200,7 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { String domainId = r.getDomainIdentifier(); if ("IdentityLink".equals(infoboxId) && domainId == null) { if (!InternalSSLSocketFactory.getInstance().isEgovAgency()) { - throw new RuntimeException(new SecurityException("Insufficient rights to execute command InfoboxReadRequest for Infobox IdentityLink")); + throw new SecurityException("Insufficient rights to execute command InfoboxReadRequest for Infobox IdentityLink"); } } } -- cgit v1.2.3 From 9ef5d25ffec1c26ccf76ad46131e33a861335da1 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 23 Jan 2009 13:45:39 +0000 Subject: tiny applet git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@286 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 41dae3ba..5e60ed3e 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -91,8 +91,11 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { log.debug("setting locale to " + getLocale()); BKUGUIFacade.Style guiStyle; - if ("advanced".equals(getAppletParameter(GUI_STYLE))) { + String guiStyleParam = getAppletParameter(GUI_STYLE); + if ("advanced".equals(guiStyleParam)) { guiStyle = BKUGUIFacade.Style.advanced; + } else if ("tiny".equals(guiStyleParam)) { + guiStyle = BKUGUIFacade.Style.tiny; } else { guiStyle = BKUGUIFacade.Style.simple; } -- cgit v1.2.3 From 54aa4703e3d66c5b1a63b8d925fd4c9c1766687c Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 28 Jan 2009 19:40:11 +0000 Subject: activation git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@291 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/online/applet/AppletBKUWorker.java | 74 +++----------- .../bku/online/applet/AppletParameterProvider.java | 57 ----------- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 106 ++++++++++++++------- 3 files changed, 85 insertions(+), 152 deletions(-) delete mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletParameterProvider.java (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java index 6ac892ec..388f045f 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java @@ -22,7 +22,6 @@ import at.gv.egiz.stal.STALRequest; import at.gv.egiz.stal.STALResponse; import at.gv.egiz.stal.SignRequest; import at.gv.egiz.stal.service.STALPortType; -import at.gv.egiz.stal.service.STALService; import at.gv.egiz.stal.service.translator.STALTranslator; import at.gv.egiz.stal.service.translator.TranslationException; import at.gv.egiz.stal.service.types.ErrorResponseType; @@ -31,13 +30,10 @@ import at.gv.egiz.stal.service.types.GetNextRequestType; import at.gv.egiz.stal.service.types.ObjectFactory; import at.gv.egiz.stal.service.types.RequestType; import at.gv.egiz.stal.service.types.ResponseType; -import java.applet.AppletContext; import java.net.MalformedURLException; -import java.net.URL; import java.util.ArrayList; import java.util.List; import javax.xml.bind.JAXBElement; -import javax.xml.namespace.QName; import javax.xml.ws.WebServiceException; /** @@ -46,29 +42,19 @@ import javax.xml.ws.WebServiceException; */ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { - protected AppletContext ctx; - protected AppletParameterProvider params; + protected BKUApplet applet; protected String sessionId; - protected STALPortType stalPort; + private ObjectFactory stalObjFactory = new ObjectFactory(); - private STALTranslator translator = new STALTranslator(); - public AppletBKUWorker(BKUGUIFacade gui, AppletContext ctx, - AppletParameterProvider paramProvider) { + public AppletBKUWorker(BKUApplet applet, BKUGUIFacade gui) { super(gui); - if (ctx == null) { - throw new NullPointerException("Applet context not provided"); - } - if (paramProvider == null) { - throw new NullPointerException("No applet parameters provided"); - } - this.ctx = ctx; - this.params = paramProvider; - - sessionId = params.getAppletParameter(BKUApplet.SESSION_ID); + this.applet = applet; + + sessionId = applet.getParameter(BKUApplet.SESSION_ID); if (sessionId == null) { sessionId = "TestSession"; - log.info("using dummy sessionId " + sessionId); + log.warn("using dummy sessionId " + sessionId); } } @@ -77,9 +63,11 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { gui.showWelcomeDialog(); try { - stalPort = getSTALPort(); + STALPortType stalPort = applet.getSTALPort(); + STALTranslator stalTranslator = applet.getSTALTranslator(); - registerSignRequestHandler(stalPort, sessionId); + addRequestHandler(SignRequest.class, + new AppletHashDataDisplay(stalPort, sessionId)); GetNextRequestResponseType nextRequestResp = stalPort.connect(sessionId); @@ -111,7 +99,7 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { List stalRequests = new ArrayList(); for (JAXBElement req : requests) { try { - stalRequests.add(translator.translate(req)); + stalRequests.add(stalTranslator.translate(req)); } catch (TranslationException ex) { log.error("Received unknown request from server STAL: " + ex.getMessage()); throw new RuntimeException(ex); @@ -123,7 +111,7 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { List stalResponses = handleRequest(stalRequests); for (STALResponse stalResponse : stalResponses) { try { - responses.add(translator.translate(stalResponse)); + responses.add(stalTranslator.translate(stalResponse)); } catch (TranslationException ex) { log.error("Received unknown response from STAL: " + ex.getMessage()); throw new RuntimeException(ex); @@ -184,7 +172,7 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { } } - sendRedirect(); + applet.sendRedirect(sessionId); } /** @@ -218,38 +206,4 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { log.error(e); } } - - protected void sendRedirect() { - try { - URL redirectURL = params.getURLParameter(BKUApplet.REDIRECT_URL, - sessionId); - String redirectTarget = params.getAppletParameter(BKUApplet.REDIRECT_TARGET); - if (redirectTarget == null) { - log.info("Done. Redirecting to " + redirectURL + " ..."); - ctx.showDocument(redirectURL); - } else { - log.info("Done. Redirecting to " + redirectURL + " (target=" + redirectTarget + ") ..."); - ctx.showDocument(redirectURL, redirectTarget); - } - } catch (MalformedURLException ex) { - log.warn("Failed to redirect: " + ex.getMessage(), ex); - // gui.showErrorDialog(errorMsg, okListener, actionCommand) - } - } - - private STALPortType getSTALPort() throws MalformedURLException { - URL wsdlURL = params.getURLParameter(BKUApplet.WSDL_URL); - log.debug("STAL WSDL at " + wsdlURL); - QName endpointName = new QName(BKUApplet.STAL_WSDL_NS, - BKUApplet.STAL_SERVICE); - STALService stal = new STALService(wsdlURL, endpointName); - return stal.getSTALPort(); - } - - private void registerSignRequestHandler(STALPortType stalPort, String sessionId) { - log.debug("register SignRequestHandler (resolve hashdata via STAL Webservice)"); - AppletHashDataDisplay handler = new AppletHashDataDisplay(stalPort, - sessionId); - addRequestHandler(SignRequest.class, handler); - } } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletParameterProvider.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletParameterProvider.java deleted file mode 100644 index 42e2d6ff..00000000 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletParameterProvider.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2008 Federal Chancellery Austria and - * Graz University of Technology - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package at.gv.egiz.bku.online.applet; - -import java.net.MalformedURLException; -import java.net.URL; - -/** - * - * @author Clemens Orthacker - */ -public interface AppletParameterProvider { - - /** - * Applet configuration parameters - * - * @param paramKey - * @return null if no parameter is provided for the given key - */ - String getAppletParameter(String paramKey); - - /** - * Get applet configuration parameter as (absolute) URL - * - * @param paramKey - * @return a URL - * @throws MalformedURLException if configured URL is invalid - * or no parameter is provided for the given key - */ - URL getURLParameter(String paramKey) throws MalformedURLException; - - /** - * Get applet configuration parameter as (absolute) URL - * - * @param paramKey - * @param sessionId adds the jsessionid to the URL - * @return a URL - * @throws MalformedURLException if configured URL is invalid - * or no parameter is provided for the given key - */ - URL getURLParameter(String paramKey, String sessionId) throws MalformedURLException; -} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 5e60ed3e..d4b2018d 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -16,8 +16,10 @@ */ package at.gv.egiz.bku.online.applet; +import at.gv.egiz.bku.gui.BKUGUIFacade.Style; import at.gv.egiz.bku.gui.DefaultHelpListener; import at.gv.egiz.bku.gui.AbstractHelpListener; +import at.gv.egiz.stal.service.translator.STALTranslator; import java.net.MalformedURLException; import java.net.URL; import java.util.Locale; @@ -30,15 +32,18 @@ import org.apache.commons.logging.LogFactory; import at.gv.egiz.bku.gui.BKUGUIFacade; import at.gv.egiz.bku.gui.BKUGUIFactory; +import at.gv.egiz.stal.service.STALPortType; +import at.gv.egiz.stal.service.STALService; +import java.awt.Container; +import javax.xml.namespace.QName; /** * Note: all swing code is executed by the event dispatch thread (see * BKUGUIFacade) */ -public class BKUApplet extends JApplet implements AppletParameterProvider { +public class BKUApplet extends JApplet { private static Log log = LogFactory.getLog(BKUApplet.class); - /** * Applet parameter keys */ @@ -55,18 +60,15 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { // public static final String HASHDATA_DISPLAY_INTERNAL = "internal"; // public static final String HASHDATA_DISPLAY_BROWSER = "browser"; public static final String HASHDATA_DISPLAY_FRAME = "frame"; - /** * STAL WSDL namespace and service name */ public static final String STAL_WSDL_NS = "http://www.egiz.gv.at/wsdl/stal"; public static final String STAL_SERVICE = "STALService"; - /** * Dummy session id, used if no sessionId parameter is provided */ protected static final String TEST_SESSION_ID = "TestSession"; - /** * STAL */ @@ -81,17 +83,17 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { public void init() { log.info("Welcome to MOCCA"); log.debug("Called init()"); - + HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getInstance()); - String locale = getAppletParameter(LOCALE); + String locale = getParameter(LOCALE); if (locale != null) { this.setLocale(new Locale(locale)); } - log.debug("setting locale to " + getLocale()); + log.debug("setting locale: " + getLocale()); BKUGUIFacade.Style guiStyle; - String guiStyleParam = getAppletParameter(GUI_STYLE); + String guiStyleParam = getParameter(GUI_STYLE); if ("advanced".equals(guiStyleParam)) { guiStyle = BKUGUIFacade.Style.advanced; } else if ("tiny".equals(guiStyleParam)) { @@ -99,30 +101,33 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { } else { guiStyle = BKUGUIFacade.Style.simple; } - + log.debug("setting gui-style: " + guiStyle); + URL backgroundImgURL = null; try { - backgroundImgURL = getURLParameter(BACKGROUND_IMG); + backgroundImgURL = getURLParameter(BACKGROUND_IMG, null); + log.debug("setting background: " + backgroundImgURL); } catch (MalformedURLException ex) { log.warn("failed to load applet background image: " + ex.getMessage() + ", using default"); } - + AbstractHelpListener helpListener = null; try { - URL helpURL = getURLParameter(HELP_URL); -// helpListener = new BrowserHelpListener(getAppletContext(), helpURL, getLocale()); - helpListener = new DefaultHelpListener(getAppletContext(), helpURL, getLocale()); + helpListener = new DefaultHelpListener(getAppletContext(), + getURLParameter(HELP_URL, null), getLocale()); + if (log.isDebugEnabled()) { + log.debug("setting helpURL: " + getURLParameter(HELP_URL, null)); + } } catch (MalformedURLException ex) { log.warn("failed to load help URL: " + ex.getMessage() + ", disabling help"); } - - BKUGUIFacade gui = BKUGUIFactory.createGUI(getContentPane(), - getLocale(), - guiStyle, - backgroundImgURL, + + BKUGUIFacade gui = createGUI(getContentPane(), getLocale(), + guiStyle, + backgroundImgURL, helpListener); - worker = new AppletBKUWorker(gui, getAppletContext(), this); + worker = new AppletBKUWorker(this, gui); } @Override @@ -145,15 +150,7 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { log.debug("Called destroy()"); } - @Override - public String getAppletParameter(String paramKey) { - String param = getParameter(paramKey); - log.info("applet parameter: " + paramKey + ": " + param); - return param; - } - - @Override - public URL getURLParameter(String paramKey, String sessionId) throws MalformedURLException { + protected URL getURLParameter(String paramKey, String sessionId) throws MalformedURLException { String urlParam = getParameter(paramKey); if (urlParam != null) { URL codebase = getCodeBase(); @@ -173,15 +170,54 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { } catch (MalformedURLException ex) { log.error("applet paremeter " + urlParam + " is not a valid URL: " + ex.getMessage()); throw ex; - } + } } else { log.error("applet paremeter " + urlParam + " not set"); throw new MalformedURLException(urlParam + " not set"); } } - - @Override - public URL getURLParameter(String paramKey) throws MalformedURLException { - return getURLParameter(paramKey, null); + + /** + * provides a means to for subclasses to inject a different GUI + */ + protected BKUGUIFacade createGUI(Container contentPane, + Locale locale, + Style guiStyle, + URL backgroundImgURL, + AbstractHelpListener helpListener) { + return BKUGUIFactory.createGUI(contentPane, + locale, + guiStyle, + backgroundImgURL, + helpListener); + } + + protected STALPortType getSTALPort() throws MalformedURLException { + URL wsdlURL = getURLParameter(WSDL_URL, null); + log.debug("setting STAL WSDL: " + wsdlURL); + QName endpointName = new QName(STAL_WSDL_NS, STAL_SERVICE); + STALService stal = new STALService(wsdlURL, endpointName); + return stal.getSTALPort(); + } + + protected STALTranslator getSTALTranslator() { + return new STALTranslator(); + } + + protected void sendRedirect(String sessionId) { + try { + URL redirectURL = getURLParameter(REDIRECT_URL, sessionId); + String redirectTarget = getParameter(REDIRECT_TARGET); + if (redirectTarget == null) { + log.info("Done. Redirecting to " + redirectURL + " ..."); + getAppletContext().showDocument(redirectURL); + } else { + log.info("Done. Redirecting to " + redirectURL + " (target=" + redirectTarget + ") ..."); + getAppletContext().showDocument(redirectURL, redirectTarget); + } + } catch (MalformedURLException ex) { + log.warn("Failed to redirect: " + ex.getMessage(), ex); + // gui.showErrorDialog(errorMsg, okListener, actionCommand) + } } } -- cgit v1.2.3 From 754cb731b2d5f4888815c16c530fc3674264a4f2 Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 11 Feb 2009 19:59:02 +0000 Subject: make applet better extensible (override BKUWorker,...) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@294 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/online/applet/AppletBKUWorker.java | 4 +- .../bku/online/applet/AppletHashDataDisplay.java | 3 - .../at/gv/egiz/bku/online/applet/BKUApplet.java | 122 +++++++++++++-------- .../bku/online/applet/BrowserHashDataDisplay.java | 52 --------- 4 files changed, 79 insertions(+), 102 deletions(-) delete mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BrowserHashDataDisplay.java (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java index 388f045f..5a57ef18 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java @@ -165,7 +165,7 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { showErrorDialog(BKUGUIFacade.ERR_CONFIG, ex); } catch (Exception ex) { log.error(ex.getMessage(), ex); - showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, ex); + showErrorDialog(BKUGUIFacade.ERR_UNKNOWN_WITH_PARAM, ex); } finally { if (signatureCard != null) { signatureCard.disconnect(false); @@ -195,7 +195,7 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { } } - private void showErrorDialog(String err_code, Exception ex) { + protected void showErrorDialog(String err_code, Exception ex) { actionCommandList.clear(); actionCommandList.add("ok"); gui.showErrorDialog(err_code, diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java index 7be40d65..2ed9aa5b 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java @@ -16,12 +16,10 @@ */ package at.gv.egiz.bku.online.applet; -import at.gv.egiz.bku.gui.BKUGUIFacade; import java.security.DigestException; import java.security.MessageDigest; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.List; import org.apache.commons.logging.Log; @@ -34,7 +32,6 @@ import at.gv.egiz.stal.service.GetHashDataInputFault; import at.gv.egiz.stal.service.STALPortType; import at.gv.egiz.stal.service.types.GetHashDataInputResponseType; import at.gv.egiz.stal.service.types.GetHashDataInputType; -import at.gv.egiz.stal.signedinfo.DigestMethodType; import at.gv.egiz.stal.signedinfo.ReferenceType; import java.security.NoSuchAlgorithmException; diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index d4b2018d..a4337bbd 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -31,7 +31,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import at.gv.egiz.bku.gui.BKUGUIFacade; -import at.gv.egiz.bku.gui.BKUGUIFactory; +import at.gv.egiz.bku.gui.BKUGUIImpl; import at.gv.egiz.stal.service.STALPortType; import at.gv.egiz.stal.service.STALService; import java.awt.Container; @@ -57,8 +57,6 @@ public class BKUApplet extends JApplet { public static final String BACKGROUND_IMG = "Background"; public static final String REDIRECT_URL = "RedirectURL"; public static final String REDIRECT_TARGET = "RedirectTarget"; -// public static final String HASHDATA_DISPLAY_INTERNAL = "internal"; -// public static final String HASHDATA_DISPLAY_BROWSER = "browser"; public static final String HASHDATA_DISPLAY_FRAME = "frame"; /** * STAL WSDL namespace and service name @@ -69,6 +67,14 @@ public class BKUApplet extends JApplet { * Dummy session id, used if no sessionId parameter is provided */ protected static final String TEST_SESSION_ID = "TestSession"; + + static { + if (log.isTraceEnabled()) { + log.trace("enabling webservice communication dump"); + System.setProperty("com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", "true"); + } + } + /** * STAL */ @@ -82,7 +88,7 @@ public class BKUApplet extends JApplet { @Override public void init() { log.info("Welcome to MOCCA"); - log.debug("Called init()"); + log.trace("Called init()"); HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getInstance()); @@ -127,19 +133,19 @@ public class BKUApplet extends JApplet { backgroundImgURL, helpListener); - worker = new AppletBKUWorker(this, gui); + worker = createBKUWorker(this, gui); } @Override public void start() { - log.debug("Called start()"); + log.trace("Called start()"); workerThread = new Thread(worker); workerThread.start(); } @Override public void stop() { - log.debug("Called stop()"); + log.trace("Called stop()"); if ((workerThread != null) && (workerThread.isAlive())) { workerThread.interrupt(); } @@ -147,52 +153,36 @@ public class BKUApplet extends JApplet { @Override public void destroy() { - log.debug("Called destroy()"); + log.trace("Called destroy()"); } - protected URL getURLParameter(String paramKey, String sessionId) throws MalformedURLException { - String urlParam = getParameter(paramKey); - if (urlParam != null) { - URL codebase = getCodeBase(); - try { - URL url; - if (codebase.getProtocol().equalsIgnoreCase("file")) { - // for debugging in appletrunner - url = new URL(urlParam); - } else { - if (sessionId != null) { - urlParam = urlParam + ";jsessionid=" + sessionId; - } - url = new URL(codebase, urlParam); - } - log.info("applet parameter " + url); - return url; - } catch (MalformedURLException ex) { - log.error("applet paremeter " + urlParam + " is not a valid URL: " + ex.getMessage()); - throw ex; - } - } else { - log.error("applet paremeter " + urlParam + " not set"); - throw new MalformedURLException(urlParam + " not set"); - } - } - - /** - * provides a means to for subclasses to inject a different GUI - */ + ///////////////////////////////////////////////////////////////////////////// + // factory methods for subclasses to inject different components + ///////////////////////////////////////////////////////////////////////////// + protected BKUGUIFacade createGUI(Container contentPane, Locale locale, Style guiStyle, URL backgroundImgURL, AbstractHelpListener helpListener) { - return BKUGUIFactory.createGUI(contentPane, - locale, - guiStyle, - backgroundImgURL, - helpListener); + return new BKUGUIImpl(contentPane, locale, guiStyle, backgroundImgURL, helpListener); + } + + protected AppletBKUWorker createBKUWorker(BKUApplet applet, BKUGUIFacade gui) { + return new AppletBKUWorker(applet, gui); } - protected STALPortType getSTALPort() throws MalformedURLException { + + ///////////////////////////////////////////////////////////////////////////// + // callback for BKUWorker to allow extension + ///////////////////////////////////////////////////////////////////////////// + + /** + * Callback for BKUWorker to allow extension + * @return + * @throws java.net.MalformedURLException + */ + public STALPortType getSTALPort() throws MalformedURLException { URL wsdlURL = getURLParameter(WSDL_URL, null); log.debug("setting STAL WSDL: " + wsdlURL); QName endpointName = new QName(STAL_WSDL_NS, STAL_SERVICE); @@ -200,10 +190,21 @@ public class BKUApplet extends JApplet { return stal.getSTALPort(); } - protected STALTranslator getSTALTranslator() { + /** + * Callback for BKUWorker to allow extension + * (TODO STALPort could know its STALTranslator) + * @return + * @throws java.net.MalformedURLException + */ + public STALTranslator getSTALTranslator() { return new STALTranslator(); } + /** + * Callback for BKUWorker to keep applet context out of BKUWorker + * @return + * @throws java.net.MalformedURLException + */ protected void sendRedirect(String sessionId) { try { URL redirectURL = getURLParameter(REDIRECT_URL, sessionId); @@ -220,4 +221,35 @@ public class BKUApplet extends JApplet { // gui.showErrorDialog(errorMsg, okListener, actionCommand) } } + + + ///////////////////////////////////////////////////////////////////////////// + // utility methods + ///////////////////////////////////////////////////////////////////////////// + + protected URL getURLParameter(String paramKey, String sessionId) throws MalformedURLException { + String urlParam = getParameter(paramKey); + if (urlParam != null) { + URL codebase = getCodeBase(); + try { + URL url; + if (codebase.getProtocol().equalsIgnoreCase("file")) { + // for debugging in appletrunner + url = new URL(urlParam); + } else { + if (sessionId != null) { + urlParam = urlParam + ";jsessionid=" + sessionId; + } + url = new URL(codebase, urlParam); + } + return url; + } catch (MalformedURLException ex) { + log.error("applet paremeter " + urlParam + " is not a valid URL: " + ex.getMessage()); + throw ex; + } + } else { + log.error("applet paremeter " + urlParam + " not set"); + throw new MalformedURLException(urlParam + " not set"); + } + } } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BrowserHashDataDisplay.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BrowserHashDataDisplay.java deleted file mode 100644 index c30921da..00000000 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BrowserHashDataDisplay.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2008 Federal Chancellery Austria and - * Graz University of Technology - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package at.gv.egiz.bku.online.applet; - -import java.net.URL; -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import at.gv.egiz.bku.smccstal.SignRequestHandler; -import at.gv.egiz.stal.signedinfo.ReferenceType; -import java.applet.AppletContext; - -/** - * - * @author Clemens Orthacker - */ -public class BrowserHashDataDisplay extends SignRequestHandler { - - private static final Log log = LogFactory.getLog(BrowserHashDataDisplay.class); - - protected AppletContext ctx; - protected URL hashDataURL; - - public BrowserHashDataDisplay(AppletContext ctx, URL hashDataURL) { - this.ctx = ctx; - this.hashDataURL = hashDataURL; - } - - @Override - public void displayHashDataInputs(List signedReferences) throws Exception { - //TODO pass reference Id's to servlet (TODO servlet) - log.debug("displaying hashdata inputs at " + hashDataURL); - ctx.showDocument(hashDataURL, "_blank"); - } -} -- cgit v1.2.3 From 6576428966f1e3d688269a407b072fb01f9f7647 Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 26 Feb 2009 19:39:00 +0000 Subject: 1.1 candidate (activation) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@309 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java index 5a57ef18..8c1bd2bd 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java @@ -195,11 +195,16 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { } } + /** + * + * @param err_code + * @param ex if not null, the message will be appended as parameter to the error message + */ protected void showErrorDialog(String err_code, Exception ex) { actionCommandList.clear(); actionCommandList.add("ok"); - gui.showErrorDialog(err_code, - new Object[]{ex.getMessage()}, this, "ok"); + Object[] params = (ex != null) ? new Object[] { ex.getMessage() } : null; + gui.showErrorDialog(err_code, params, this, "ok"); try { waitForAction(); } catch (InterruptedException e) { -- cgit v1.2.3 From 7cc403b3ce468e82a57811336def347cb6c9025e Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 10 Mar 2009 13:36:34 +0000 Subject: do not return errorResponse on interrupt git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@319 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java index 8c1bd2bd..eb6cf30b 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java @@ -126,8 +126,9 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { err.setErrorCode(6002); } else { Throwable cause = ex.getCause(); - if (cause != null) { - log.error("caused by: " + cause.getMessage()); + if (cause != null && cause instanceof InterruptedException) { + log.info("do not return error response, client might want to resume session"); + finished = true; } err.setErrorCode(4000); } @@ -155,7 +156,7 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { } while (!finished); - log.info("Done " + Thread.currentThread().getName()); + log.info("Finished " + Thread.currentThread().getName()); } catch (WebServiceException ex) { log.fatal("communication error with server STAL: " + ex.getMessage(), ex); -- cgit v1.2.3 From 2a1df5e58e44f8d77f34eb80df74e8c0d27caceb Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 18 Mar 2009 22:27:28 +0000 Subject: 1.1-rc5 (pinProviderFactories, gui refactoring, signatureCard, secureViewer) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@322 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/online/applet/AppletBKUWorker.java | 5 +- .../bku/online/applet/AppletHashDataDisplay.java | 217 -------------------- .../egiz/bku/online/applet/AppletSecureViewer.java | 221 +++++++++++++++++++++ 3 files changed, 224 insertions(+), 219 deletions(-) delete mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java create mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java index eb6cf30b..9b9735f6 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java @@ -60,14 +60,15 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { @Override public void run() { - gui.showWelcomeDialog(); + gui.showMessageDialog(BKUGUIFacade.TITLE_WELCOME, + BKUGUIFacade.MESSAGE_WELCOME); try { STALPortType stalPort = applet.getSTALPort(); STALTranslator stalTranslator = applet.getSTALTranslator(); addRequestHandler(SignRequest.class, - new AppletHashDataDisplay(stalPort, sessionId)); + new AppletSecureViewer(stalPort, sessionId)); GetNextRequestResponseType nextRequestResp = stalPort.connect(sessionId); diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java deleted file mode 100644 index 2ed9aa5b..00000000 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright 2008 Federal Chancellery Austria and - * Graz University of Technology - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package at.gv.egiz.bku.online.applet; - -import java.security.DigestException; -import java.security.MessageDigest; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import at.gv.egiz.bku.smccstal.SignRequestHandler; -import at.gv.egiz.stal.HashDataInput; -import at.gv.egiz.stal.impl.ByteArrayHashDataInput; -import at.gv.egiz.stal.service.GetHashDataInputFault; -import at.gv.egiz.stal.service.STALPortType; -import at.gv.egiz.stal.service.types.GetHashDataInputResponseType; -import at.gv.egiz.stal.service.types.GetHashDataInputType; -import at.gv.egiz.stal.signedinfo.ReferenceType; -import java.security.NoSuchAlgorithmException; - -/** - * A SignRequesthandler that obtains hashdata inputs from a STAL webservice and - * displays these either within the applet or in a separate frame. - * The internal viewer displays plaintext data only, other mimetypes can be saved to disk. - * The standalone (frame) viewer displays all mimetypes. - * - * (This class depends on STALService and therefore is not part of BKUCommonGUI.) - * - * @author Clemens Orthacker - */ -public class AppletHashDataDisplay extends SignRequestHandler { - - private static final Log log = LogFactory.getLog(AppletHashDataDisplay.class); - protected STALPortType stalPort; - protected String sessId; - - public AppletHashDataDisplay(STALPortType stalPort, String sessId) { - if (stalPort == null || sessId == null) { - throw new NullPointerException("STAL port must not be null"); - } - this.sessId = sessId; - this.stalPort = stalPort; - } - - /** - * TODO don't throw exceptions - * @param signedReferences - * @throws java.security.DigestException - * @throws java.lang.Exception - */ - @Override - public void displayHashDataInputs(List signedReferences) throws DigestException, Exception { - - List hdi = getHashDataInput(signedReferences); - List verifiedHashDataInputs = verifyHashDataInput(signedReferences, hdi); - - if (verifiedHashDataInputs.size() > 0) { - gui.showHashDataInputDialog(verifiedHashDataInputs, this, "hashDataDone"); - } else { - throw new Exception("No signature data (apart from any QualifyingProperties or a Manifest)"); - } - } - - /** - * Get all hashdata inputs that contain an ID attribute but no Type attribute. - * @param signedReferences - * @return - * @throws at.gv.egiz.stal.service.GetHashDataInputFault - */ - private List getHashDataInput(List signedReferences) throws GetHashDataInputFault, Exception { - GetHashDataInputType request = new GetHashDataInputType(); - request.setSessionId(sessId); - -// HashMap idSignedRefMap = new HashMap(); - for (ReferenceType signedRef : signedReferences) { - //don't get Manifest, QualifyingProperties, ... - if (signedRef.getType() == null) { - String signedRefId = signedRef.getId(); - if (signedRefId != null) { - if (log.isTraceEnabled()) { - log.trace("requesting hashdata input for reference " + signedRefId); - } -// idSignedRefMap.put(signedRefId, signedRef); - GetHashDataInputType.Reference ref = new GetHashDataInputType.Reference(); - ref.setID(signedRefId); - request.getReference().add(ref); - - } else { - throw new Exception("Cannot resolve signature data for dsig:Reference without Id attribute"); - } - } - } - - if (request.getReference().size() < 1) { - log.error("No signature data (apart from any QualifyingProperties or a Manifest) for session " + sessId); - throw new Exception("No signature data (apart from any QualifyingProperties or a Manifest)"); - } - - if (log.isDebugEnabled()) { - log.debug("WebService call GetHashDataInput for " + request.getReference().size() + " references in session " + sessId); - } - GetHashDataInputResponseType response = stalPort.getHashDataInput(request); - return response.getReference(); - } - - /** - * Verifies all signed references and returns STAL HashDataInputs - * @param signedReferences - * @param hashDataInputs - * @return - * @throws java.security.DigestException - * @throws java.security.NoSuchAlgorithmException - * @throws Exception if no hashdata input is provided for a signed reference - */ - private List verifyHashDataInput(List signedReferences, List hashDataInputs) throws DigestException, NoSuchAlgorithmException, Exception { - - ArrayList verifiedHashDataInputs = new ArrayList(); - - for (ReferenceType signedRef : signedReferences) { - if (signedRef.getType() == null) { - log.info("Verifying digest for signed reference " + signedRef.getId()); - - String signedRefId = signedRef.getId(); - byte[] signedDigest = signedRef.getDigestValue(); - String signedDigestAlg = null; - if (signedRef.getDigestMethod() != null) { - signedDigestAlg = signedRef.getDigestMethod().getAlgorithm(); - } else { - throw new NoSuchAlgorithmException("Failed to verify digest value for reference " + signedRefId + ": no digest algorithm"); - } - - // usually, there is just one item here - GetHashDataInputResponseType.Reference hashDataInput = null; - for (GetHashDataInputResponseType.Reference hdi : hashDataInputs) { - if (signedRefId.equals(hdi.getID())) { - hashDataInput = hdi; - break; - } - } - if (hashDataInput == null) { - throw new Exception("No hashdata input for reference " + signedRefId + " returned by service"); - } - - byte[] hdi = hashDataInput.getValue(); - String mimeType = hashDataInput.getMimeType(); - String encoding = hashDataInput.getEncoding(); - - if (hdi == null) { - throw new Exception("No hashdata input for reference " + signedRefId + " provided by service"); - } - if (log.isDebugEnabled()) { - log.debug("Got HashDataInput " + signedRefId + " (" + mimeType + ";" + encoding + ")"); - } - - byte[] hashDataInputDigest = digest(hdi, signedDigestAlg); - - if (log.isDebugEnabled()) { - log.debug("Comparing digest values... "); - } -// log.warn("***************** DISABLED HASHDATA VERIFICATION"); - if (!Arrays.equals(hashDataInputDigest, signedDigest)) { - log.error("Bad digest value for reference " + signedRefId); - throw new DigestException("Bad digest value for reference " + signedRefId); - } - - verifiedHashDataInputs.add(new ByteArrayHashDataInput(hdi, signedRefId, mimeType, encoding)); - } - } - - return verifiedHashDataInputs; - } - - //TODO - private byte[] digest(byte[] hashDataInput, String mdAlg) throws NoSuchAlgorithmException { - if ("http://www.w3.org/2000/09/xmldsig#sha1".equals(mdAlg)) { - mdAlg = "SHA-1"; - } else if ("http://www.w3.org/2001/04/xmlenc#sha256".equals(mdAlg)) { - mdAlg = "SHA-256"; - } else if ("http://www.w3.org/2001/04/xmlenc#sha224".equals(mdAlg)) { - mdAlg = "SHA-224"; - } else if ("http://www.w3.org/2001/04/xmldsig-more#sha224".equals(mdAlg)) { - mdAlg = "SHA-224"; - } else if ("http://www.w3.org/2001/04/xmldsig-more#sha384".equals(mdAlg)) { - mdAlg = "SHA-384"; - } else if ("http://www.w3.org/2001/04/xmlenc#sha512".equals(mdAlg)) { - mdAlg = "SHA-512"; - } else if ("http://www.w3.org/2001/04/xmldsig-more#md2".equals(mdAlg)) { - mdAlg = "MD2"; - } else if ("http://www.w3.org/2001/04/xmldsig-more#md5".equals(mdAlg)) { - mdAlg = "MD5"; - } else if ("http://www.w3.org/2001/04/xmlenc#ripemd160".equals(mdAlg)) { - mdAlg = "RipeMD-160"; - } else { - throw new NoSuchAlgorithmException("Failed to verify digest value: unsupported digest algorithm " + mdAlg); - } - - MessageDigest md = MessageDigest.getInstance(mdAlg); - return md.digest(hashDataInput); - } -} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java new file mode 100644 index 00000000..e2551e2d --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java @@ -0,0 +1,221 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package at.gv.egiz.bku.online.applet; + +import at.gv.egiz.bku.smccstal.SecureViewer; +import java.security.DigestException; +import java.security.MessageDigest; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.gv.egiz.bku.smccstal.SignRequestHandler; +import at.gv.egiz.stal.HashDataInput; +import at.gv.egiz.stal.impl.ByteArrayHashDataInput; +import at.gv.egiz.stal.service.GetHashDataInputFault; +import at.gv.egiz.stal.service.STALPortType; +import at.gv.egiz.stal.service.types.GetHashDataInputResponseType; +import at.gv.egiz.stal.service.types.GetHashDataInputType; +import at.gv.egiz.stal.signedinfo.ReferenceType; +import java.security.NoSuchAlgorithmException; + +/** + * A SignRequesthandler that obtains hashdata inputs from a STAL webservice and + * displays these either within the applet or in a separate frame. + * The internal viewer displays plaintext data only, other mimetypes can be saved to disk. + * The standalone (frame) viewer displays all mimetypes. + * + * (This class depends on STALService and therefore is not part of BKUCommonGUI.) + * + * @author Clemens Orthacker + */ +public class AppletSecureViewer extends SignRequestHandler { + + private static final Log log = LogFactory.getLog(AppletSecureViewer.class); + protected STALPortType stalPort; + protected String sessId; + + public AppletSecureViewer(STALPortType stalPort, String sessId) { + if (stalPort == null || sessId == null) { + throw new NullPointerException("STAL port must not be null"); + } + this.sessId = sessId; + this.stalPort = stalPort; + } + + /** + * TODO don't throw exceptions + * @param signedReferences + * @throws java.security.DigestException + * @throws java.lang.Exception + */ + @Override + public void displayDataToBeSigned(List signedReferences) + throws DigestException, Exception { + + List hdi = getHashDataInput(signedReferences); + List verifiedHashDataInputs = verifyHashDataInput(signedReferences, hdi); + + if (verifiedHashDataInputs.size() > 0) { + gui.showSecureViewer(verifiedHashDataInputs, this, "hashDataDone"); + } else { + throw new Exception("No signature data (apart from any QualifyingProperties or a Manifest)"); + } + } + + /** + * Get all hashdata inputs that contain an ID attribute but no Type attribute. + * @param signedReferences + * @return + * @throws at.gv.egiz.stal.service.GetHashDataInputFault + */ + private List getHashDataInput(List signedReferences) + throws GetHashDataInputFault, Exception { + GetHashDataInputType request = new GetHashDataInputType(); + request.setSessionId(sessId); + +// HashMap idSignedRefMap = new HashMap(); + for (ReferenceType signedRef : signedReferences) { + //don't get Manifest, QualifyingProperties, ... + if (signedRef.getType() == null) { + String signedRefId = signedRef.getId(); + if (signedRefId != null) { + if (log.isTraceEnabled()) { + log.trace("requesting hashdata input for reference " + signedRefId); + } +// idSignedRefMap.put(signedRefId, signedRef); + GetHashDataInputType.Reference ref = new GetHashDataInputType.Reference(); + ref.setID(signedRefId); + request.getReference().add(ref); + + } else { + throw new Exception("Cannot resolve signature data for dsig:Reference without Id attribute"); + } + } + } + + if (request.getReference().size() < 1) { + log.error("No signature data (apart from any QualifyingProperties or a Manifest) for session " + sessId); + throw new Exception("No signature data (apart from any QualifyingProperties or a Manifest)"); + } + + if (log.isDebugEnabled()) { + log.debug("WebService call GetHashDataInput for " + request.getReference().size() + " references in session " + sessId); + } + GetHashDataInputResponseType response = stalPort.getHashDataInput(request); + return response.getReference(); + } + + /** + * Verifies all signed references and returns STAL HashDataInputs + * @param signedReferences + * @param hashDataInputs + * @return + * @throws java.security.DigestException + * @throws java.security.NoSuchAlgorithmException + * @throws Exception if no hashdata input is provided for a signed reference + */ + private List verifyHashDataInput(List signedReferences, List hashDataInputs) + throws DigestException, NoSuchAlgorithmException, Exception { + + ArrayList verifiedHashDataInputs = new ArrayList(); + + for (ReferenceType signedRef : signedReferences) { + if (signedRef.getType() == null) { + log.info("Verifying digest for signed reference " + signedRef.getId()); + + String signedRefId = signedRef.getId(); + byte[] signedDigest = signedRef.getDigestValue(); + String signedDigestAlg = null; + if (signedRef.getDigestMethod() != null) { + signedDigestAlg = signedRef.getDigestMethod().getAlgorithm(); + } else { + throw new NoSuchAlgorithmException("Failed to verify digest value for reference " + signedRefId + ": no digest algorithm"); + } + + // usually, there is just one item here + GetHashDataInputResponseType.Reference hashDataInput = null; + for (GetHashDataInputResponseType.Reference hdi : hashDataInputs) { + if (signedRefId.equals(hdi.getID())) { + hashDataInput = hdi; + break; + } + } + if (hashDataInput == null) { + throw new Exception("No hashdata input for reference " + signedRefId + " returned by service"); + } + + byte[] hdi = hashDataInput.getValue(); + String mimeType = hashDataInput.getMimeType(); + String encoding = hashDataInput.getEncoding(); + + if (hdi == null) { + throw new Exception("No hashdata input for reference " + signedRefId + " provided by service"); + } + if (log.isDebugEnabled()) { + log.debug("Got HashDataInput " + signedRefId + " (" + mimeType + ";" + encoding + ")"); + } + + byte[] hashDataInputDigest = digest(hdi, signedDigestAlg); + + if (log.isDebugEnabled()) { + log.debug("Comparing digest values... "); + } +// log.warn("***************** DISABLED HASHDATA VERIFICATION"); + if (!Arrays.equals(hashDataInputDigest, signedDigest)) { + log.error("Bad digest value for reference " + signedRefId); + throw new DigestException("Bad digest value for reference " + signedRefId); + } + + verifiedHashDataInputs.add(new ByteArrayHashDataInput(hdi, signedRefId, mimeType, encoding)); + } + } + + return verifiedHashDataInputs; + } + + //TODO + private byte[] digest(byte[] hashDataInput, String mdAlg) throws NoSuchAlgorithmException { + if ("http://www.w3.org/2000/09/xmldsig#sha1".equals(mdAlg)) { + mdAlg = "SHA-1"; + } else if ("http://www.w3.org/2001/04/xmlenc#sha256".equals(mdAlg)) { + mdAlg = "SHA-256"; + } else if ("http://www.w3.org/2001/04/xmlenc#sha224".equals(mdAlg)) { + mdAlg = "SHA-224"; + } else if ("http://www.w3.org/2001/04/xmldsig-more#sha224".equals(mdAlg)) { + mdAlg = "SHA-224"; + } else if ("http://www.w3.org/2001/04/xmldsig-more#sha384".equals(mdAlg)) { + mdAlg = "SHA-384"; + } else if ("http://www.w3.org/2001/04/xmlenc#sha512".equals(mdAlg)) { + mdAlg = "SHA-512"; + } else if ("http://www.w3.org/2001/04/xmldsig-more#md2".equals(mdAlg)) { + mdAlg = "MD2"; + } else if ("http://www.w3.org/2001/04/xmldsig-more#md5".equals(mdAlg)) { + mdAlg = "MD5"; + } else if ("http://www.w3.org/2001/04/xmlenc#ripemd160".equals(mdAlg)) { + mdAlg = "RipeMD-160"; + } else { + throw new NoSuchAlgorithmException("Failed to verify digest value: unsupported digest algorithm " + mdAlg); + } + + MessageDigest md = MessageDigest.getInstance(mdAlg); + return md.digest(hashDataInput); + } +} -- cgit v1.2.3 From 616e06910051528674165319a1d6d161dff5859c Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 27 Mar 2009 17:33:11 +0000 Subject: 1.1-RC6 (pinpad, pinmgmt, secureviewer) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@323 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/online/applet/AppletBKUWorker.java | 5 +- .../egiz/bku/online/applet/AppletSecureViewer.java | 79 +++++++++++++--------- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 10 ++- 3 files changed, 59 insertions(+), 35 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java index 9b9735f6..e8d8976d 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java @@ -18,6 +18,7 @@ package at.gv.egiz.bku.online.applet; import at.gv.egiz.bku.smccstal.AbstractBKUWorker; import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.bku.smccstal.SignRequestHandler; import at.gv.egiz.stal.STALRequest; import at.gv.egiz.stal.STALResponse; import at.gv.egiz.stal.SignRequest; @@ -67,8 +68,10 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { STALPortType stalPort = applet.getSTALPort(); STALTranslator stalTranslator = applet.getSTALTranslator(); + AppletSecureViewer secureViewer = + new AppletSecureViewer(gui, stalPort, sessionId); addRequestHandler(SignRequest.class, - new AppletSecureViewer(stalPort, sessionId)); + new SignRequestHandler(secureViewer)); GetNextRequestResponseType nextRequestResp = stalPort.connect(sessionId); diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java index e2551e2d..929cecb1 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java @@ -16,17 +16,8 @@ */ package at.gv.egiz.bku.online.applet; +import at.gv.egiz.bku.gui.BKUGUIFacade; import at.gv.egiz.bku.smccstal.SecureViewer; -import java.security.DigestException; -import java.security.MessageDigest; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import at.gv.egiz.bku.smccstal.SignRequestHandler; import at.gv.egiz.stal.HashDataInput; import at.gv.egiz.stal.impl.ByteArrayHashDataInput; import at.gv.egiz.stal.service.GetHashDataInputFault; @@ -34,49 +25,73 @@ import at.gv.egiz.stal.service.STALPortType; import at.gv.egiz.stal.service.types.GetHashDataInputResponseType; import at.gv.egiz.stal.service.types.GetHashDataInputType; import at.gv.egiz.stal.signedinfo.ReferenceType; +import at.gv.egiz.stal.signedinfo.SignedInfoType; +import java.awt.event.ActionListener; +import java.security.DigestException; +import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** - * A SignRequesthandler that obtains hashdata inputs from a STAL webservice and - * displays these either within the applet or in a separate frame. - * The internal viewer displays plaintext data only, other mimetypes can be saved to disk. - * The standalone (frame) viewer displays all mimetypes. - * - * (This class depends on STALService and therefore is not part of BKUCommonGUI.) - * + * * @author Clemens Orthacker */ -public class AppletSecureViewer extends SignRequestHandler { +public class AppletSecureViewer implements SecureViewer { private static final Log log = LogFactory.getLog(AppletSecureViewer.class); + + protected BKUGUIFacade gui; protected STALPortType stalPort; protected String sessId; + protected List verifiedDataToBeSigned; - public AppletSecureViewer(STALPortType stalPort, String sessId) { - if (stalPort == null || sessId == null) { + public AppletSecureViewer(BKUGUIFacade gui, STALPortType stalPort, + String sessId) { + if (gui == null) { + throw new NullPointerException("GUI must not be null"); + } + if (stalPort == null) { throw new NullPointerException("STAL port must not be null"); } - this.sessId = sessId; + if (sessId == null) { + throw new NullPointerException("session id must not be null"); + } + this.gui = gui; this.stalPort = stalPort; + this.sessId = sessId; } /** - * TODO don't throw exceptions + * retrieves the data to be signed for * @param signedReferences + * @param okListener + * @param okCommand + * @param cancelListener + * @param cancelCommand * @throws java.security.DigestException * @throws java.lang.Exception */ @Override - public void displayDataToBeSigned(List signedReferences) + public void displayDataToBeSigned(SignedInfoType signedInfo, + ActionListener okListener, String okCommand) throws DigestException, Exception { - - List hdi = getHashDataInput(signedReferences); - List verifiedHashDataInputs = verifyHashDataInput(signedReferences, hdi); - - if (verifiedHashDataInputs.size() > 0) { - gui.showSecureViewer(verifiedHashDataInputs, this, "hashDataDone"); + + if (verifiedDataToBeSigned == null) { + log.info("retrieve data to be signed for dsig:SignedInfo " + + signedInfo.getId()); + List hdi = + getHashDataInput(signedInfo.getReference()); + verifiedDataToBeSigned = verifyHashDataInput(signedInfo.getReference(), + hdi); + } + if (verifiedDataToBeSigned.size() > 0) { + gui.showSecureViewer(verifiedDataToBeSigned, okListener, okCommand); } else { - throw new Exception("No signature data (apart from any QualifyingProperties or a Manifest)"); + throw new Exception("No data to be signed (apart from any QualifyingProperties or a Manifest)"); } } @@ -110,7 +125,7 @@ public class AppletSecureViewer extends SignRequestHandler { } } } - + if (request.getReference().size() < 1) { log.error("No signature data (apart from any QualifyingProperties or a Manifest) for session " + sessId); throw new Exception("No signature data (apart from any QualifyingProperties or a Manifest)"); @@ -187,7 +202,7 @@ public class AppletSecureViewer extends SignRequestHandler { verifiedHashDataInputs.add(new ByteArrayHashDataInput(hdi, signedRefId, mimeType, encoding)); } } - + return verifiedHashDataInputs; } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index a4337bbd..0ddb6dc6 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -34,6 +34,7 @@ import at.gv.egiz.bku.gui.BKUGUIFacade; import at.gv.egiz.bku.gui.BKUGUIImpl; import at.gv.egiz.stal.service.STALPortType; import at.gv.egiz.stal.service.STALService; +import java.applet.AppletContext; import java.awt.Container; import javax.xml.namespace.QName; @@ -207,14 +208,19 @@ public class BKUApplet extends JApplet { */ protected void sendRedirect(String sessionId) { try { + AppletContext ctx = getAppletContext(); + if (ctx == null) { + log.error("no applet context (applet might already have been destroyed)"); + return; + } URL redirectURL = getURLParameter(REDIRECT_URL, sessionId); String redirectTarget = getParameter(REDIRECT_TARGET); if (redirectTarget == null) { log.info("Done. Redirecting to " + redirectURL + " ..."); - getAppletContext().showDocument(redirectURL); + ctx.showDocument(redirectURL); } else { log.info("Done. Redirecting to " + redirectURL + " (target=" + redirectTarget + ") ..."); - getAppletContext().showDocument(redirectURL, redirectTarget); + ctx.showDocument(redirectURL, redirectTarget); } } catch (MalformedURLException ex) { log.warn("Failed to redirect: " + ex.getMessage(), ex); -- cgit v1.2.3 From 2dd863b4b2ccd75a8e0202053239ba14f452bda4 Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 9 Jul 2009 12:06:13 +0000 Subject: log default locale git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@401 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java | 1 + 1 file changed, 1 insertion(+) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 0ddb6dc6..43bc2dae 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -97,6 +97,7 @@ public class BKUApplet extends JApplet { if (locale != null) { this.setLocale(new Locale(locale)); } + log.trace("default locale: " + Locale.getDefault()); log.debug("setting locale: " + getLocale()); BKUGUIFacade.Style guiStyle; -- cgit v1.2.3 From 5bff0a3288bd2b5e1f1030c6e47430735cd09463 Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 9 Jul 2009 16:34:07 +0000 Subject: [#393] loading of default background fails git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@407 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 43bc2dae..95ac3553 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -116,7 +116,7 @@ public class BKUApplet extends JApplet { backgroundImgURL = getURLParameter(BACKGROUND_IMG, null); log.debug("setting background: " + backgroundImgURL); } catch (MalformedURLException ex) { - log.warn("failed to load applet background image: " + ex.getMessage() + ", using default"); + log.warn("cannot load applet background image: " + ex.getMessage()); } AbstractHelpListener helpListener = null; @@ -236,7 +236,7 @@ public class BKUApplet extends JApplet { protected URL getURLParameter(String paramKey, String sessionId) throws MalformedURLException { String urlParam = getParameter(paramKey); - if (urlParam != null) { + if (urlParam != null && !"".equals(urlParam)) { URL codebase = getCodeBase(); try { URL url; -- cgit v1.2.3 From 3ca1928f20603069058bf89dce1a47599d064091 Mon Sep 17 00:00:00 2001 From: mcentner Date: Tue, 8 Sep 2009 15:55:46 +0000 Subject: Fixed Bug [#467] Border between Background image and border. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@505 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 45 ++++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 95ac3553..94673266 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -26,6 +26,7 @@ import java.util.Locale; import javax.net.ssl.HttpsURLConnection; import javax.swing.JApplet; +import javax.swing.JPanel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -35,6 +36,7 @@ import at.gv.egiz.bku.gui.BKUGUIImpl; import at.gv.egiz.stal.service.STALPortType; import at.gv.egiz.stal.service.STALService; import java.applet.AppletContext; +import java.awt.Color; import java.awt.Container; import javax.xml.namespace.QName; @@ -44,6 +46,8 @@ import javax.xml.namespace.QName; */ public class BKUApplet extends JApplet { + private static final long serialVersionUID = 1L; + private static Log log = LogFactory.getLog(BKUApplet.class); /** * Applet parameter keys @@ -56,6 +60,7 @@ public class BKUApplet extends JApplet { public final static String HELP_URL = "HelpURL"; public final static String SESSION_ID = "SessionID"; public static final String BACKGROUND_IMG = "Background"; + public static final String BACKGROUND_COLOR = "BackgroundColor"; public static final String REDIRECT_URL = "RedirectURL"; public static final String REDIRECT_TARGET = "RedirectTarget"; public static final String HASHDATA_DISPLAY_FRAME = "frame"; @@ -82,6 +87,23 @@ public class BKUApplet extends JApplet { protected AppletBKUWorker worker; protected Thread workerThread; + /* (non-Javadoc) + * @see java.applet.Applet#getParameterInfo() + */ + @Override + public String[][] getParameterInfo() { + return new String[][] { + {WSDL_URL, "url", "URL of the WSDL of the MOCCA server side STAL"}, + {REDIRECT_URL, "url", "URL to redirect the browser to when finished"}, + {REDIRECT_TARGET, "frame target", "name of the target frame for redirection when finished"}, + {LOCALE, "locale", "locale for UI localization (optional, default: system default)"}, + {GUI_STYLE, "simple, advanced, tiny", "GUI style (optional, default: simple)"}, + {BACKGROUND_COLOR, "#hhhhhh", "background color, e.g. '#333333' (optional, default: look and feel dependend)"}, + {BACKGROUND_IMG, "url", "URL of a background image for the GUI (optional, default: no image)"}, + {HELP_URL, "url", "URL for locating help files, e.g. '../help/' (no help provided if missing)"} + }; + } + /** * Factory method to create and wire HelpListener, GUI and BKUWorker. * (Config via applet parameters, see BKUApplet.* constants) @@ -130,7 +152,24 @@ public class BKUApplet extends JApplet { log.warn("failed to load help URL: " + ex.getMessage() + ", disabling help"); } - BKUGUIFacade gui = createGUI(getContentPane(), getLocale(), + // Note: We need a panel in order to be able to set the background properly. + // Setting the background without a panel has side effects with the + // different java plugins. + JPanel contentPanel = new JPanel(); + getContentPane().add(contentPanel); + + String backgroundColor = getParameter(BACKGROUND_COLOR); + if (backgroundColor != null && backgroundColor.startsWith("#")) { + try { + Color color = new Color(Integer.parseInt(backgroundColor.substring(1), 16)); + log.debug("setting background color to " + color); + contentPanel.setBackground(color); + } catch (NumberFormatException e) { + log.debug("failed to set background color '" + backgroundColor + "'"); + } + } + + BKUGUIFacade gui = createGUI(contentPanel, getLocale(), guiStyle, backgroundImgURL, helpListener); @@ -255,8 +294,8 @@ public class BKUApplet extends JApplet { throw ex; } } else { - log.error("applet paremeter " + urlParam + " not set"); - throw new MalformedURLException(urlParam + " not set"); + log.error("applet paremeter " + paramKey + " not set"); + throw new MalformedURLException(paramKey + " not set"); } } } -- cgit v1.2.3 From 68fcf98895e0a1a8072c5a0541a08ae0f599a239 Mon Sep 17 00:00:00 2001 From: tzefferer Date: Fri, 16 Oct 2009 09:53:37 +0000 Subject: Keyboard accessibility for Online-BKU git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@526 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/online/applet/AppletBKUWorker.java | 5 + .../at/gv/egiz/bku/online/applet/BKUApplet.java | 541 +++++++++++---------- 2 files changed, 292 insertions(+), 254 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java index e8d8976d..d5f8dd69 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java @@ -216,4 +216,9 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { log.error(e); } } + + public void getFocusFromBrowser() { + + gui.getFocusFromBrowser(); + } } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 94673266..6346b7f4 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -19,6 +19,7 @@ package at.gv.egiz.bku.online.applet; import at.gv.egiz.bku.gui.BKUGUIFacade.Style; import at.gv.egiz.bku.gui.DefaultHelpListener; import at.gv.egiz.bku.gui.AbstractHelpListener; +import at.gv.egiz.bku.gui.SwitchFocusListener; import at.gv.egiz.stal.service.translator.STALTranslator; import java.net.MalformedURLException; import java.net.URL; @@ -38,264 +39,296 @@ import at.gv.egiz.stal.service.STALService; import java.applet.AppletContext; import java.awt.Color; import java.awt.Container; + import javax.xml.namespace.QName; /** * Note: all swing code is executed by the event dispatch thread (see * BKUGUIFacade) */ -public class BKUApplet extends JApplet { - - private static final long serialVersionUID = 1L; - - private static Log log = LogFactory.getLog(BKUApplet.class); - /** - * Applet parameter keys - */ - public static final String GUI_STYLE = "GuiStyle"; - public final static String LOCALE = "Locale"; - public final static String WSDL_URL = "WSDL_URL"; - public static final String HASHDATA_DISPLAY = "HashDataDisplay"; - public final static String HASHDATA_URL = "HashDataURL"; - public final static String HELP_URL = "HelpURL"; - public final static String SESSION_ID = "SessionID"; - public static final String BACKGROUND_IMG = "Background"; - public static final String BACKGROUND_COLOR = "BackgroundColor"; - public static final String REDIRECT_URL = "RedirectURL"; - public static final String REDIRECT_TARGET = "RedirectTarget"; - public static final String HASHDATA_DISPLAY_FRAME = "frame"; - /** - * STAL WSDL namespace and service name - */ - public static final String STAL_WSDL_NS = "http://www.egiz.gv.at/wsdl/stal"; - public static final String STAL_SERVICE = "STALService"; - /** - * Dummy session id, used if no sessionId parameter is provided - */ - protected static final String TEST_SESSION_ID = "TestSession"; - - static { - if (log.isTraceEnabled()) { - log.trace("enabling webservice communication dump"); - System.setProperty("com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", "true"); - } - } - - /** - * STAL - */ - protected AppletBKUWorker worker; - protected Thread workerThread; - - /* (non-Javadoc) - * @see java.applet.Applet#getParameterInfo() - */ - @Override - public String[][] getParameterInfo() { - return new String[][] { - {WSDL_URL, "url", "URL of the WSDL of the MOCCA server side STAL"}, - {REDIRECT_URL, "url", "URL to redirect the browser to when finished"}, - {REDIRECT_TARGET, "frame target", "name of the target frame for redirection when finished"}, - {LOCALE, "locale", "locale for UI localization (optional, default: system default)"}, - {GUI_STYLE, "simple, advanced, tiny", "GUI style (optional, default: simple)"}, - {BACKGROUND_COLOR, "#hhhhhh", "background color, e.g. '#333333' (optional, default: look and feel dependend)"}, - {BACKGROUND_IMG, "url", "URL of a background image for the GUI (optional, default: no image)"}, - {HELP_URL, "url", "URL for locating help files, e.g. '../help/' (no help provided if missing)"} - }; - } - - /** - * Factory method to create and wire HelpListener, GUI and BKUWorker. - * (Config via applet parameters, see BKUApplet.* constants) - */ - @Override - public void init() { - log.info("Welcome to MOCCA"); - log.trace("Called init()"); - - HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getInstance()); - - String locale = getParameter(LOCALE); - if (locale != null) { - this.setLocale(new Locale(locale)); - } - log.trace("default locale: " + Locale.getDefault()); - log.debug("setting locale: " + getLocale()); - - BKUGUIFacade.Style guiStyle; - String guiStyleParam = getParameter(GUI_STYLE); - if ("advanced".equals(guiStyleParam)) { - guiStyle = BKUGUIFacade.Style.advanced; - } else if ("tiny".equals(guiStyleParam)) { - guiStyle = BKUGUIFacade.Style.tiny; - } else { - guiStyle = BKUGUIFacade.Style.simple; - } - log.debug("setting gui-style: " + guiStyle); - - URL backgroundImgURL = null; - try { - backgroundImgURL = getURLParameter(BACKGROUND_IMG, null); - log.debug("setting background: " + backgroundImgURL); - } catch (MalformedURLException ex) { - log.warn("cannot load applet background image: " + ex.getMessage()); - } - - AbstractHelpListener helpListener = null; - try { - helpListener = new DefaultHelpListener(getAppletContext(), - getURLParameter(HELP_URL, null), getLocale()); - if (log.isDebugEnabled()) { - log.debug("setting helpURL: " + getURLParameter(HELP_URL, null)); - } - } catch (MalformedURLException ex) { - log.warn("failed to load help URL: " + ex.getMessage() + ", disabling help"); - } - - // Note: We need a panel in order to be able to set the background properly. - // Setting the background without a panel has side effects with the - // different java plugins. - JPanel contentPanel = new JPanel(); - getContentPane().add(contentPanel); - - String backgroundColor = getParameter(BACKGROUND_COLOR); - if (backgroundColor != null && backgroundColor.startsWith("#")) { - try { - Color color = new Color(Integer.parseInt(backgroundColor.substring(1), 16)); - log.debug("setting background color to " + color); - contentPanel.setBackground(color); - } catch (NumberFormatException e) { - log.debug("failed to set background color '" + backgroundColor + "'"); - } - } - - BKUGUIFacade gui = createGUI(contentPanel, getLocale(), - guiStyle, - backgroundImgURL, - helpListener); - - worker = createBKUWorker(this, gui); - } - - @Override - public void start() { - log.trace("Called start()"); - workerThread = new Thread(worker); - workerThread.start(); - } - - @Override - public void stop() { - log.trace("Called stop()"); - if ((workerThread != null) && (workerThread.isAlive())) { - workerThread.interrupt(); - } - } - - @Override - public void destroy() { - log.trace("Called destroy()"); - } - - ///////////////////////////////////////////////////////////////////////////// - // factory methods for subclasses to inject different components - ///////////////////////////////////////////////////////////////////////////// - - protected BKUGUIFacade createGUI(Container contentPane, - Locale locale, - Style guiStyle, - URL backgroundImgURL, - AbstractHelpListener helpListener) { - return new BKUGUIImpl(contentPane, locale, guiStyle, backgroundImgURL, helpListener); - } - - protected AppletBKUWorker createBKUWorker(BKUApplet applet, BKUGUIFacade gui) { - return new AppletBKUWorker(applet, gui); - } - - - ///////////////////////////////////////////////////////////////////////////// - // callback for BKUWorker to allow extension - ///////////////////////////////////////////////////////////////////////////// - - /** - * Callback for BKUWorker to allow extension - * @return - * @throws java.net.MalformedURLException - */ - public STALPortType getSTALPort() throws MalformedURLException { - URL wsdlURL = getURLParameter(WSDL_URL, null); - log.debug("setting STAL WSDL: " + wsdlURL); - QName endpointName = new QName(STAL_WSDL_NS, STAL_SERVICE); - STALService stal = new STALService(wsdlURL, endpointName); - return stal.getSTALPort(); - } - - /** - * Callback for BKUWorker to allow extension - * (TODO STALPort could know its STALTranslator) - * @return - * @throws java.net.MalformedURLException - */ - public STALTranslator getSTALTranslator() { - return new STALTranslator(); - } - - /** - * Callback for BKUWorker to keep applet context out of BKUWorker - * @return - * @throws java.net.MalformedURLException - */ - protected void sendRedirect(String sessionId) { - try { - AppletContext ctx = getAppletContext(); - if (ctx == null) { - log.error("no applet context (applet might already have been destroyed)"); - return; - } - URL redirectURL = getURLParameter(REDIRECT_URL, sessionId); - String redirectTarget = getParameter(REDIRECT_TARGET); - if (redirectTarget == null) { - log.info("Done. Redirecting to " + redirectURL + " ..."); - ctx.showDocument(redirectURL); - } else { - log.info("Done. Redirecting to " + redirectURL + " (target=" + redirectTarget + ") ..."); - ctx.showDocument(redirectURL, redirectTarget); - } - } catch (MalformedURLException ex) { - log.warn("Failed to redirect: " + ex.getMessage(), ex); - // gui.showErrorDialog(errorMsg, okListener, actionCommand) - } - } - - - ///////////////////////////////////////////////////////////////////////////// - // utility methods - ///////////////////////////////////////////////////////////////////////////// - - protected URL getURLParameter(String paramKey, String sessionId) throws MalformedURLException { - String urlParam = getParameter(paramKey); - if (urlParam != null && !"".equals(urlParam)) { - URL codebase = getCodeBase(); - try { - URL url; - if (codebase.getProtocol().equalsIgnoreCase("file")) { - // for debugging in appletrunner - url = new URL(urlParam); - } else { - if (sessionId != null) { - urlParam = urlParam + ";jsessionid=" + sessionId; - } - url = new URL(codebase, urlParam); - } - return url; - } catch (MalformedURLException ex) { - log.error("applet paremeter " + urlParam + " is not a valid URL: " + ex.getMessage()); - throw ex; - } - } else { - log.error("applet paremeter " + paramKey + " not set"); - throw new MalformedURLException(paramKey + " not set"); - } - } +public class BKUApplet extends JApplet { + + private static final long serialVersionUID = 1L; + + private static Log log = LogFactory.getLog(BKUApplet.class); + /** + * Applet parameter keys + */ + public static final String GUI_STYLE = "GuiStyle"; + public final static String LOCALE = "Locale"; + public final static String WSDL_URL = "WSDL_URL"; + public static final String HASHDATA_DISPLAY = "HashDataDisplay"; + public final static String HASHDATA_URL = "HashDataURL"; + public final static String HELP_URL = "HelpURL"; + public final static String SESSION_ID = "SessionID"; + public static final String BACKGROUND_IMG = "Background"; + public static final String BACKGROUND_COLOR = "BackgroundColor"; + public static final String REDIRECT_URL = "RedirectURL"; + public static final String REDIRECT_TARGET = "RedirectTarget"; + public static final String HASHDATA_DISPLAY_FRAME = "frame"; + /** + * STAL WSDL namespace and service name + */ + public static final String STAL_WSDL_NS = "http://www.egiz.gv.at/wsdl/stal"; + public static final String STAL_SERVICE = "STALService"; + /** + * Dummy session id, used if no sessionId parameter is provided + */ + protected static final String TEST_SESSION_ID = "TestSession"; + + static { + if (log.isTraceEnabled()) { + log.trace("enabling webservice communication dump"); + System + .setProperty( + "com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", + "true"); + } + } + + /** + * STAL + */ + protected AppletBKUWorker worker; + protected Thread workerThread; + + /* + * (non-Javadoc) + * + * @see java.applet.Applet#getParameterInfo() + */ + @Override + public String[][] getParameterInfo() { + return new String[][] { + { WSDL_URL, "url", + "URL of the WSDL of the MOCCA server side STAL" }, + { REDIRECT_URL, "url", + "URL to redirect the browser to when finished" }, + { REDIRECT_TARGET, "frame target", + "name of the target frame for redirection when finished" }, + { LOCALE, "locale", + "locale for UI localization (optional, default: system default)" }, + { GUI_STYLE, "simple, advanced, tiny", + "GUI style (optional, default: simple)" }, + { BACKGROUND_COLOR, "#hhhhhh", + "background color, e.g. '#333333' (optional, default: look and feel dependend)" }, + { BACKGROUND_IMG, "url", + "URL of a background image for the GUI (optional, default: no image)" }, + { HELP_URL, "url", + "URL for locating help files, e.g. '../help/' (no help provided if missing)" } }; + } + + /** + * Factory method to create and wire HelpListener, GUI and BKUWorker. + * (Config via applet parameters, see BKUApplet.* constants) + */ + @Override + public void init() { + log.info("Welcome to MOCCA"); + log.trace("Called init()"); + + HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory + .getInstance()); + + String locale = getParameter(LOCALE); + if (locale != null) { + this.setLocale(new Locale(locale)); + } + log.trace("default locale: " + Locale.getDefault()); + log.debug("setting locale: " + getLocale()); + + BKUGUIFacade.Style guiStyle; + String guiStyleParam = getParameter(GUI_STYLE); + if ("advanced".equals(guiStyleParam)) { + guiStyle = BKUGUIFacade.Style.advanced; + } else if ("tiny".equals(guiStyleParam)) { + guiStyle = BKUGUIFacade.Style.tiny; + } else { + guiStyle = BKUGUIFacade.Style.simple; + } + log.debug("setting gui-style: " + guiStyle); + + URL backgroundImgURL = null; + try { + backgroundImgURL = getURLParameter(BACKGROUND_IMG, null); + log.debug("setting background: " + backgroundImgURL); + } catch (MalformedURLException ex) { + log.warn("cannot load applet background image: " + ex.getMessage()); + } + + AbstractHelpListener helpListener = null; + try { + helpListener = new DefaultHelpListener(getAppletContext(), + getURLParameter(HELP_URL, null), getLocale()); + if (log.isDebugEnabled()) { + log + .debug("setting helpURL: " + + getURLParameter(HELP_URL, null)); + } + } catch (MalformedURLException ex) { + log.warn("failed to load help URL: " + ex.getMessage() + + ", disabling help"); + } + + SwitchFocusListener switchFocusListener = new SwitchFocusListener( + getAppletContext(), "focusToBrowser()"); + + // Note: We need a panel in order to be able to set the background + // properly. + // Setting the background without a panel has side effects with the + // different java plugins. + JPanel contentPanel = new JPanel(); + getContentPane().add(contentPanel); + + String backgroundColor = getParameter(BACKGROUND_COLOR); + if (backgroundColor != null && backgroundColor.startsWith("#")) { + try { + Color color = new Color(Integer.parseInt(backgroundColor + .substring(1), 16)); + log.debug("setting background color to " + color); + contentPanel.setBackground(color); + } catch (NumberFormatException e) { + log.debug("failed to set background color '" + backgroundColor + + "'"); + } + } + + BKUGUIFacade gui = createGUI(contentPanel, getLocale(), guiStyle, + backgroundImgURL, helpListener, switchFocusListener); + + worker = createBKUWorker(this, gui); + } + + @Override + public void start() { + log.trace("Called start()"); + workerThread = new Thread(worker); + workerThread.start(); + } + + @Override + public void stop() { + log.trace("Called stop()"); + if ((workerThread != null) && (workerThread.isAlive())) { + workerThread.interrupt(); + } + } + + @Override + public void destroy() { + log.trace("Called destroy()"); + } + + // /////////////////////////////////////////////////////////////////////////// + // factory methods for subclasses to inject different components + // /////////////////////////////////////////////////////////////////////////// + + protected BKUGUIFacade createGUI(Container contentPane, Locale locale, + Style guiStyle, URL backgroundImgURL, + AbstractHelpListener helpListener, + SwitchFocusListener switchFocusListener) { + return new BKUGUIImpl(contentPane, locale, guiStyle, backgroundImgURL, + helpListener, switchFocusListener); + } + + protected AppletBKUWorker createBKUWorker(BKUApplet applet, BKUGUIFacade gui) { + return new AppletBKUWorker(applet, gui); + } + + // /////////////////////////////////////////////////////////////////////////// + // callback for BKUWorker to allow extension + // /////////////////////////////////////////////////////////////////////////// + + /** + * Callback for BKUWorker to allow extension + * + * @return + * @throws java.net.MalformedURLException + */ + public STALPortType getSTALPort() throws MalformedURLException { + URL wsdlURL = getURLParameter(WSDL_URL, null); + log.debug("setting STAL WSDL: " + wsdlURL); + QName endpointName = new QName(STAL_WSDL_NS, STAL_SERVICE); + STALService stal = new STALService(wsdlURL, endpointName); + return stal.getSTALPort(); + } + + /** + * Callback for BKUWorker to allow extension (TODO STALPort could know its + * STALTranslator) + * + * @return + * @throws java.net.MalformedURLException + */ + public STALTranslator getSTALTranslator() { + return new STALTranslator(); + } + + /** + * Callback for BKUWorker to keep applet context out of BKUWorker + * + * @return + * @throws java.net.MalformedURLException + */ + protected void sendRedirect(String sessionId) { + try { + AppletContext ctx = getAppletContext(); + if (ctx == null) { + log + .error("no applet context (applet might already have been destroyed)"); + return; + } + URL redirectURL = getURLParameter(REDIRECT_URL, sessionId); + String redirectTarget = getParameter(REDIRECT_TARGET); + if (redirectTarget == null) { + log.info("Done. Redirecting to " + redirectURL + " ..."); + ctx.showDocument(redirectURL); + } else { + log.info("Done. Redirecting to " + redirectURL + " (target=" + + redirectTarget + ") ..."); + ctx.showDocument(redirectURL, redirectTarget); + } + } catch (MalformedURLException ex) { + log.warn("Failed to redirect: " + ex.getMessage(), ex); + // gui.showErrorDialog(errorMsg, okListener, actionCommand) + } + } + + public void getFocusFromBrowser() { + + worker.getFocusFromBrowser(); + } + + // /////////////////////////////////////////////////////////////////////////// + // utility methods + // /////////////////////////////////////////////////////////////////////////// + + protected URL getURLParameter(String paramKey, String sessionId) + throws MalformedURLException { + String urlParam = getParameter(paramKey); + if (urlParam != null && !"".equals(urlParam)) { + URL codebase = getCodeBase(); + try { + URL url; + if (codebase.getProtocol().equalsIgnoreCase("file")) { + // for debugging in appletrunner + url = new URL(urlParam); + } else { + if (sessionId != null) { + urlParam = urlParam + ";jsessionid=" + sessionId; + } + url = new URL(codebase, urlParam); + } + return url; + } catch (MalformedURLException ex) { + log.error("applet paremeter " + urlParam + + " is not a valid URL: " + ex.getMessage()); + throw ex; + } + } else { + log.error("applet paremeter " + paramKey + " not set"); + throw new MalformedURLException(paramKey + " not set"); + } + } + } -- cgit v1.2.3 From 83e8c95ea7d257166d350a59bfd81e9833ec14fd Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 5 Nov 2009 19:05:14 +0000 Subject: [#484] European Language support git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@535 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 572 +++++++++++---------- .../bku/online/applet/viewer/URLFontLoader.java | 82 +++ 2 files changed, 369 insertions(+), 285 deletions(-) create mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/viewer/URLFontLoader.java (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 6346b7f4..7a15f7a5 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -16,6 +16,7 @@ */ package at.gv.egiz.bku.online.applet; +import at.gv.egiz.bku.online.applet.viewer.URLFontLoader; import at.gv.egiz.bku.gui.BKUGUIFacade.Style; import at.gv.egiz.bku.gui.DefaultHelpListener; import at.gv.egiz.bku.gui.AbstractHelpListener; @@ -25,6 +26,8 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Locale; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.net.ssl.HttpsURLConnection; import javax.swing.JApplet; import javax.swing.JPanel; @@ -34,6 +37,7 @@ import org.apache.commons.logging.LogFactory; import at.gv.egiz.bku.gui.BKUGUIFacade; import at.gv.egiz.bku.gui.BKUGUIImpl; +import at.gv.egiz.bku.gui.viewer.FontProvider; import at.gv.egiz.stal.service.STALPortType; import at.gv.egiz.stal.service.STALService; import java.applet.AppletContext; @@ -46,289 +50,287 @@ import javax.xml.namespace.QName; * Note: all swing code is executed by the event dispatch thread (see * BKUGUIFacade) */ -public class BKUApplet extends JApplet { - - private static final long serialVersionUID = 1L; - - private static Log log = LogFactory.getLog(BKUApplet.class); - /** - * Applet parameter keys - */ - public static final String GUI_STYLE = "GuiStyle"; - public final static String LOCALE = "Locale"; - public final static String WSDL_URL = "WSDL_URL"; - public static final String HASHDATA_DISPLAY = "HashDataDisplay"; - public final static String HASHDATA_URL = "HashDataURL"; - public final static String HELP_URL = "HelpURL"; - public final static String SESSION_ID = "SessionID"; - public static final String BACKGROUND_IMG = "Background"; - public static final String BACKGROUND_COLOR = "BackgroundColor"; - public static final String REDIRECT_URL = "RedirectURL"; - public static final String REDIRECT_TARGET = "RedirectTarget"; - public static final String HASHDATA_DISPLAY_FRAME = "frame"; - /** - * STAL WSDL namespace and service name - */ - public static final String STAL_WSDL_NS = "http://www.egiz.gv.at/wsdl/stal"; - public static final String STAL_SERVICE = "STALService"; - /** - * Dummy session id, used if no sessionId parameter is provided - */ - protected static final String TEST_SESSION_ID = "TestSession"; - - static { - if (log.isTraceEnabled()) { - log.trace("enabling webservice communication dump"); - System - .setProperty( - "com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", - "true"); - } - } - - /** - * STAL - */ - protected AppletBKUWorker worker; - protected Thread workerThread; - - /* - * (non-Javadoc) - * - * @see java.applet.Applet#getParameterInfo() - */ - @Override - public String[][] getParameterInfo() { - return new String[][] { - { WSDL_URL, "url", - "URL of the WSDL of the MOCCA server side STAL" }, - { REDIRECT_URL, "url", - "URL to redirect the browser to when finished" }, - { REDIRECT_TARGET, "frame target", - "name of the target frame for redirection when finished" }, - { LOCALE, "locale", - "locale for UI localization (optional, default: system default)" }, - { GUI_STYLE, "simple, advanced, tiny", - "GUI style (optional, default: simple)" }, - { BACKGROUND_COLOR, "#hhhhhh", - "background color, e.g. '#333333' (optional, default: look and feel dependend)" }, - { BACKGROUND_IMG, "url", - "URL of a background image for the GUI (optional, default: no image)" }, - { HELP_URL, "url", - "URL for locating help files, e.g. '../help/' (no help provided if missing)" } }; - } - - /** - * Factory method to create and wire HelpListener, GUI and BKUWorker. - * (Config via applet parameters, see BKUApplet.* constants) - */ - @Override - public void init() { - log.info("Welcome to MOCCA"); - log.trace("Called init()"); - - HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory - .getInstance()); - - String locale = getParameter(LOCALE); - if (locale != null) { - this.setLocale(new Locale(locale)); - } - log.trace("default locale: " + Locale.getDefault()); - log.debug("setting locale: " + getLocale()); - - BKUGUIFacade.Style guiStyle; - String guiStyleParam = getParameter(GUI_STYLE); - if ("advanced".equals(guiStyleParam)) { - guiStyle = BKUGUIFacade.Style.advanced; - } else if ("tiny".equals(guiStyleParam)) { - guiStyle = BKUGUIFacade.Style.tiny; - } else { - guiStyle = BKUGUIFacade.Style.simple; - } - log.debug("setting gui-style: " + guiStyle); - - URL backgroundImgURL = null; - try { - backgroundImgURL = getURLParameter(BACKGROUND_IMG, null); - log.debug("setting background: " + backgroundImgURL); - } catch (MalformedURLException ex) { - log.warn("cannot load applet background image: " + ex.getMessage()); - } - - AbstractHelpListener helpListener = null; - try { - helpListener = new DefaultHelpListener(getAppletContext(), - getURLParameter(HELP_URL, null), getLocale()); - if (log.isDebugEnabled()) { - log - .debug("setting helpURL: " - + getURLParameter(HELP_URL, null)); - } - } catch (MalformedURLException ex) { - log.warn("failed to load help URL: " + ex.getMessage() - + ", disabling help"); - } - - SwitchFocusListener switchFocusListener = new SwitchFocusListener( - getAppletContext(), "focusToBrowser()"); - - // Note: We need a panel in order to be able to set the background - // properly. - // Setting the background without a panel has side effects with the - // different java plugins. - JPanel contentPanel = new JPanel(); - getContentPane().add(contentPanel); - - String backgroundColor = getParameter(BACKGROUND_COLOR); - if (backgroundColor != null && backgroundColor.startsWith("#")) { - try { - Color color = new Color(Integer.parseInt(backgroundColor - .substring(1), 16)); - log.debug("setting background color to " + color); - contentPanel.setBackground(color); - } catch (NumberFormatException e) { - log.debug("failed to set background color '" + backgroundColor - + "'"); - } - } - - BKUGUIFacade gui = createGUI(contentPanel, getLocale(), guiStyle, - backgroundImgURL, helpListener, switchFocusListener); - - worker = createBKUWorker(this, gui); - } - - @Override - public void start() { - log.trace("Called start()"); - workerThread = new Thread(worker); - workerThread.start(); - } - - @Override - public void stop() { - log.trace("Called stop()"); - if ((workerThread != null) && (workerThread.isAlive())) { - workerThread.interrupt(); - } - } - - @Override - public void destroy() { - log.trace("Called destroy()"); - } - - // /////////////////////////////////////////////////////////////////////////// - // factory methods for subclasses to inject different components - // /////////////////////////////////////////////////////////////////////////// - - protected BKUGUIFacade createGUI(Container contentPane, Locale locale, - Style guiStyle, URL backgroundImgURL, - AbstractHelpListener helpListener, - SwitchFocusListener switchFocusListener) { - return new BKUGUIImpl(contentPane, locale, guiStyle, backgroundImgURL, - helpListener, switchFocusListener); - } - - protected AppletBKUWorker createBKUWorker(BKUApplet applet, BKUGUIFacade gui) { - return new AppletBKUWorker(applet, gui); - } - - // /////////////////////////////////////////////////////////////////////////// - // callback for BKUWorker to allow extension - // /////////////////////////////////////////////////////////////////////////// - - /** - * Callback for BKUWorker to allow extension - * - * @return - * @throws java.net.MalformedURLException - */ - public STALPortType getSTALPort() throws MalformedURLException { - URL wsdlURL = getURLParameter(WSDL_URL, null); - log.debug("setting STAL WSDL: " + wsdlURL); - QName endpointName = new QName(STAL_WSDL_NS, STAL_SERVICE); - STALService stal = new STALService(wsdlURL, endpointName); - return stal.getSTALPort(); - } - - /** - * Callback for BKUWorker to allow extension (TODO STALPort could know its - * STALTranslator) - * - * @return - * @throws java.net.MalformedURLException - */ - public STALTranslator getSTALTranslator() { - return new STALTranslator(); - } - - /** - * Callback for BKUWorker to keep applet context out of BKUWorker - * - * @return - * @throws java.net.MalformedURLException - */ - protected void sendRedirect(String sessionId) { - try { - AppletContext ctx = getAppletContext(); - if (ctx == null) { - log - .error("no applet context (applet might already have been destroyed)"); - return; - } - URL redirectURL = getURLParameter(REDIRECT_URL, sessionId); - String redirectTarget = getParameter(REDIRECT_TARGET); - if (redirectTarget == null) { - log.info("Done. Redirecting to " + redirectURL + " ..."); - ctx.showDocument(redirectURL); - } else { - log.info("Done. Redirecting to " + redirectURL + " (target=" - + redirectTarget + ") ..."); - ctx.showDocument(redirectURL, redirectTarget); - } - } catch (MalformedURLException ex) { - log.warn("Failed to redirect: " + ex.getMessage(), ex); - // gui.showErrorDialog(errorMsg, okListener, actionCommand) - } - } - - public void getFocusFromBrowser() { - - worker.getFocusFromBrowser(); - } - - // /////////////////////////////////////////////////////////////////////////// - // utility methods - // /////////////////////////////////////////////////////////////////////////// - - protected URL getURLParameter(String paramKey, String sessionId) - throws MalformedURLException { - String urlParam = getParameter(paramKey); - if (urlParam != null && !"".equals(urlParam)) { - URL codebase = getCodeBase(); - try { - URL url; - if (codebase.getProtocol().equalsIgnoreCase("file")) { - // for debugging in appletrunner - url = new URL(urlParam); - } else { - if (sessionId != null) { - urlParam = urlParam + ";jsessionid=" + sessionId; - } - url = new URL(codebase, urlParam); - } - return url; - } catch (MalformedURLException ex) { - log.error("applet paremeter " + urlParam - + " is not a valid URL: " + ex.getMessage()); - throw ex; - } - } else { - log.error("applet paremeter " + paramKey + " not set"); - throw new MalformedURLException(paramKey + " not set"); - } - } - +public class BKUApplet extends JApplet { + + private static final long serialVersionUID = 1L; + private static Log log = LogFactory.getLog(BKUApplet.class); + /** + * Applet parameter keys + */ + public static final String GUI_STYLE = "GuiStyle"; + public final static String LOCALE = "Locale"; + public final static String WSDL_URL = "WSDL_URL"; + public static final String HASHDATA_DISPLAY = "HashDataDisplay"; + public final static String HASHDATA_URL = "HashDataURL"; + public final static String HELP_URL = "HelpURL"; + public final static String SESSION_ID = "SessionID"; + public static final String BACKGROUND_IMG = "Background"; + public static final String BACKGROUND_COLOR = "BackgroundColor"; + public static final String REDIRECT_URL = "RedirectURL"; + public static final String REDIRECT_TARGET = "RedirectTarget"; + public static final String HASHDATA_DISPLAY_FRAME = "frame"; + /** + * STAL WSDL namespace and service name + */ + public static final String STAL_WSDL_NS = "http://www.egiz.gv.at/wsdl/stal"; + public static final String STAL_SERVICE = "STALService"; + /** + * Dummy session id, used if no sessionId parameter is provided + */ + protected static final String TEST_SESSION_ID = "TestSession"; + + static { + if (log.isTraceEnabled()) { + log.trace("enabling webservice communication dump"); + System.setProperty( + "com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", + "true"); + } + } + /** + * STAL + */ + protected AppletBKUWorker worker; + protected Thread workerThread; + + /* + * (non-Javadoc) + * + * @see java.applet.Applet#getParameterInfo() + */ + @Override + public String[][] getParameterInfo() { + return new String[][]{ + {WSDL_URL, "url", + "URL of the WSDL of the MOCCA server side STAL"}, + {REDIRECT_URL, "url", + "URL to redirect the browser to when finished"}, + {REDIRECT_TARGET, "frame target", + "name of the target frame for redirection when finished"}, + {LOCALE, "locale", + "locale for UI localization (optional, default: system default)"}, + {GUI_STYLE, "simple, advanced, tiny", + "GUI style (optional, default: simple)"}, + {BACKGROUND_COLOR, "#hhhhhh", + "background color, e.g. '#333333' (optional, default: look and feel dependend)"}, + {BACKGROUND_IMG, "url", + "URL of a background image for the GUI (optional, default: no image)"}, + {HELP_URL, "url", + "URL for locating help files, e.g. '../help/' (no help provided if missing)"}}; + } + + /** + * Factory method to create and wire HelpListener, GUI and BKUWorker. + * (Config via applet parameters, see BKUApplet.* constants) + */ + @Override + public void init() { + log.info("Welcome to MOCCA"); + log.trace("Called init()"); + showStatus("Initializing MOCCA applet"); + + HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getInstance()); + + String locale = getParameter(LOCALE); + if (locale != null) { + this.setLocale(new Locale(locale)); + } + log.trace("default locale: " + Locale.getDefault()); + log.debug("setting locale: " + getLocale()); + + BKUGUIFacade.Style guiStyle; + String guiStyleParam = getParameter(GUI_STYLE); + if ("advanced".equals(guiStyleParam)) { + guiStyle = BKUGUIFacade.Style.advanced; + } else if ("tiny".equals(guiStyleParam)) { + guiStyle = BKUGUIFacade.Style.tiny; + } else { + guiStyle = BKUGUIFacade.Style.simple; + } + log.debug("setting gui-style: " + guiStyle); + + URL backgroundImgURL = null; + try { + backgroundImgURL = getURLParameter(BACKGROUND_IMG, null); + log.debug("setting background: " + backgroundImgURL); + } catch (MalformedURLException ex) { + log.warn("cannot load applet background image: " + ex.getMessage()); + } + + AbstractHelpListener helpListener = null; + try { + helpListener = new DefaultHelpListener(getAppletContext(), + getURLParameter(HELP_URL, null), getLocale()); + if (log.isDebugEnabled()) { + log.debug("setting helpURL: " + getURLParameter(HELP_URL, null)); + } + } catch (MalformedURLException ex) { + log.warn("failed to load help URL: " + ex.getMessage() + ", disabling help"); + } + + SwitchFocusListener switchFocusListener = new SwitchFocusListener( + getAppletContext(), "focusToBrowser()"); + + // Note: We need a panel in order to be able to set the background + // properly. + // Setting the background without a panel has side effects with the + // different java plugins. + JPanel contentPanel = new JPanel(); + getContentPane().add(contentPanel); + + String backgroundColor = getParameter(BACKGROUND_COLOR); + if (backgroundColor != null && backgroundColor.startsWith("#")) { + try { + Color color = new Color(Integer.parseInt(backgroundColor.substring(1), 16)); + log.debug("setting background color to " + color); + contentPanel.setBackground(color); + } catch (NumberFormatException e) { + log.debug("failed to set background color '" + backgroundColor + "'"); + } + } + + try { + URLFontLoader fontProvider = new URLFontLoader(getCodeBase()); + fontProvider.loadInBackground(); + BKUGUIFacade gui = createGUI(contentPanel, getLocale(), guiStyle, + backgroundImgURL, fontProvider, helpListener, switchFocusListener); + + worker = createBKUWorker(this, gui); + } catch (MalformedURLException ex) { + log.fatal("failed to load font provider URL", ex); + System.err.println("invalid font provider URL " + ex.getMessage()); + } + } + + @Override + public void start() { + log.trace("Called start()"); + if (worker != null) { + showStatus("Starting MOCCA applet"); + workerThread = new Thread(worker); + workerThread.start(); + } else { + log.debug("cannot start uninitialzed MOCCA applet"); + } + } + + @Override + public void stop() { + log.trace("Called stop()"); + showStatus("Stopping MOCCA applet"); + if ((workerThread != null) && (workerThread.isAlive())) { + workerThread.interrupt(); + } + } + + @Override + public void destroy() { + log.trace("Called destroy()"); + } + + // /////////////////////////////////////////////////////////////////////////// + // factory methods for subclasses to inject different components + // /////////////////////////////////////////////////////////////////////////// + protected BKUGUIFacade createGUI(Container contentPane, Locale locale, + Style guiStyle, URL backgroundImgURL, + FontProvider fontProvider, AbstractHelpListener helpListener, + SwitchFocusListener switchFocusListener) { + return new BKUGUIImpl(contentPane, locale, guiStyle, backgroundImgURL, + fontProvider, helpListener, switchFocusListener); + } + + protected AppletBKUWorker createBKUWorker(BKUApplet applet, BKUGUIFacade gui) { + return new AppletBKUWorker(applet, gui); + } + + // /////////////////////////////////////////////////////////////////////////// + // callback for BKUWorker to allow extension + // /////////////////////////////////////////////////////////////////////////// + /** + * Callback for BKUWorker to allow extension + * + * @return + * @throws java.net.MalformedURLException + */ + public STALPortType getSTALPort() throws MalformedURLException { + URL wsdlURL = getURLParameter(WSDL_URL, null); + log.debug("setting STAL WSDL: " + wsdlURL); + QName endpointName = new QName(STAL_WSDL_NS, STAL_SERVICE); + STALService stal = new STALService(wsdlURL, endpointName); + return stal.getSTALPort(); + } + + /** + * Callback for BKUWorker to allow extension (TODO STALPort could know its + * STALTranslator) + * + * @return + * @throws java.net.MalformedURLException + */ + public STALTranslator getSTALTranslator() { + return new STALTranslator(); + } + + /** + * Callback for BKUWorker to keep applet context out of BKUWorker + * + * @return + * @throws java.net.MalformedURLException + */ + protected void sendRedirect(String sessionId) { + try { + AppletContext ctx = getAppletContext(); + if (ctx == null) { + log.error("no applet context (applet might already have been destroyed)"); + return; + } + URL redirectURL = getURLParameter(REDIRECT_URL, sessionId); + String redirectTarget = getParameter(REDIRECT_TARGET); + if (redirectTarget == null) { + log.info("Done. Redirecting to " + redirectURL + " ..."); + ctx.showDocument(redirectURL); + } else { + log.info("Done. Redirecting to " + redirectURL + " (target=" + redirectTarget + ") ..."); + ctx.showDocument(redirectURL, redirectTarget); + } + } catch (MalformedURLException ex) { + log.warn("Failed to redirect: " + ex.getMessage(), ex); + // gui.showErrorDialog(errorMsg, okListener, actionCommand) + } + } + + public void getFocusFromBrowser() { + + worker.getFocusFromBrowser(); + } + + // /////////////////////////////////////////////////////////////////////////// + // utility methods + // /////////////////////////////////////////////////////////////////////////// + protected URL getURLParameter(String paramKey, String sessionId) + throws MalformedURLException { + String urlParam = getParameter(paramKey); + if (urlParam != null && !"".equals(urlParam)) { + URL codebase = getCodeBase(); + try { + URL url; + if (codebase.getProtocol().equalsIgnoreCase("file")) { + // for debugging in appletrunner + url = new URL(urlParam); + } else { + if (sessionId != null) { + urlParam = urlParam + ";jsessionid=" + sessionId; + } + url = new URL(codebase, urlParam); + } + return url; + } catch (MalformedURLException ex) { + log.error("applet paremeter " + urlParam + " is not a valid URL: " + ex.getMessage()); + throw ex; + } + } else { + log.error("applet paremeter " + paramKey + " not set"); + throw new MalformedURLException(paramKey + " not set"); + } + } } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/viewer/URLFontLoader.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/viewer/URLFontLoader.java new file mode 100644 index 00000000..f914aed7 --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/viewer/URLFontLoader.java @@ -0,0 +1,82 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package at.gv.egiz.bku.online.applet.viewer; + +import at.gv.egiz.bku.gui.viewer.FontProviderException; +import at.gv.egiz.bku.gui.viewer.FontProvider; +import java.awt.Font; +import java.awt.FontFormatException; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.concurrent.ExecutionException; +import javax.swing.SwingWorker; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author Clemens Orthacker + */ +public class URLFontLoader extends SwingWorker implements FontProvider { + + protected static final Log log = LogFactory.getLog(URLFontLoader.class); + protected URL fontURL; + protected Font font; + + public URLFontLoader(URL codebase) throws MalformedURLException { + this.fontURL = new URL(codebase, SANSMONO_FONT_RESOURCE); + if (log.isDebugEnabled()) { + log.debug(Thread.currentThread() + " setting font load URL: " + fontURL); + } + } + + public void loadInBackground() { + if (log.isDebugEnabled()) { + log.debug(Thread.currentThread() + " scheduling font loading in background: " + fontURL); + } + this.execute(); + } + + @Override + protected Font doInBackground() throws MalformedURLException, FontFormatException, IOException { + if (log.isDebugEnabled()) { + log.debug(Thread.currentThread() + " loading font in background..."); + } + return Font.createFont(Font.TRUETYPE_FONT, fontURL.openStream()); + } + + /** + * waits for loadInBackground to finish + * @return the font loaded in loadInbackground + * @throws Exception + */ + @Override + public Font getFont() throws FontProviderException { + log.debug(Thread.currentThread() + " get font"); + try { + return get(); + } catch (InterruptedException ex) { + log.error("font loader interrupted"); +// Thread.currentThread().interrupt(); + throw new FontProviderException("font loader interrupted", ex); + } catch (ExecutionException ex) { + log.error("failed to load font", ex.getCause()); + throw new FontProviderException("failed to load font", ex.getCause()); + } + } +} -- cgit v1.2.3 From 5bb4d11327fcfe0fdc4234eeb02f4b09d108109e Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 9 Nov 2009 17:05:57 +0000 Subject: applet version BKUFonts .project git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@536 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 35 +++++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 7a15f7a5..2094e55c 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -22,12 +22,14 @@ import at.gv.egiz.bku.gui.DefaultHelpListener; import at.gv.egiz.bku.gui.AbstractHelpListener; import at.gv.egiz.bku.gui.SwitchFocusListener; import at.gv.egiz.stal.service.translator.STALTranslator; + +import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.Locale; -import java.util.logging.Level; -import java.util.logging.Logger; +import java.util.jar.Attributes; +import java.util.jar.Manifest; import javax.net.ssl.HttpsURLConnection; import javax.swing.JApplet; import javax.swing.JPanel; @@ -79,14 +81,30 @@ public class BKUApplet extends JApplet { */ protected static final String TEST_SESSION_ID = "TestSession"; + public static final String VERSION; + public static final String UNKNOWN_VERSION = "UNKNOWN"; + static { - if (log.isTraceEnabled()) { - log.trace("enabling webservice communication dump"); - System.setProperty( - "com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", - "true"); + String tmp = UNKNOWN_VERSION; + try { + String BKUAppletJar = BKUApplet.class.getProtectionDomain().getCodeSource().getLocation().toString(); + URL manifestURL = new URL("jar:" + BKUAppletJar + "!/META-INF/MANIFEST.MF"); + if (log.isTraceEnabled()) { + log.trace("read version information from " + manifestURL); + } + Manifest manifest = new Manifest(manifestURL.openStream()); + Attributes atts = manifest.getMainAttributes(); + if (atts != null) { + tmp = atts.getValue("Implementation-Build"); + } + } catch (IOException ex) { + log.error("failed to read version", ex); + } finally { + VERSION = tmp; + log.debug("BKU Applet " + VERSION); } } + /** * STAL */ @@ -119,13 +137,14 @@ public class BKUApplet extends JApplet { "URL for locating help files, e.g. '../help/' (no help provided if missing)"}}; } + /** * Factory method to create and wire HelpListener, GUI and BKUWorker. * (Config via applet parameters, see BKUApplet.* constants) */ @Override public void init() { - log.info("Welcome to MOCCA"); + log.info("Welcome to MOCCA " + VERSION); log.trace("Called init()"); showStatus("Initializing MOCCA applet"); -- cgit v1.2.3 From caca721368d8c24559b1cd5ea2018884b4874f6b Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 10 Nov 2009 15:30:16 +0000 Subject: Removed switchFocusListener due to problem with viewer/help dialogs on Firefox/Mac git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@539 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java | 5 +---- .../java/at/gv/egiz/bku/online/applet/viewer/URLFontLoader.java | 8 ++++---- 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 2094e55c..895fdbb5 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -187,9 +187,6 @@ public class BKUApplet extends JApplet { log.warn("failed to load help URL: " + ex.getMessage() + ", disabling help"); } - SwitchFocusListener switchFocusListener = new SwitchFocusListener( - getAppletContext(), "focusToBrowser()"); - // Note: We need a panel in order to be able to set the background // properly. // Setting the background without a panel has side effects with the @@ -212,7 +209,7 @@ public class BKUApplet extends JApplet { URLFontLoader fontProvider = new URLFontLoader(getCodeBase()); fontProvider.loadInBackground(); BKUGUIFacade gui = createGUI(contentPanel, getLocale(), guiStyle, - backgroundImgURL, fontProvider, helpListener, switchFocusListener); + backgroundImgURL, fontProvider, helpListener, null); worker = createBKUWorker(this, gui); } catch (MalformedURLException ex) { diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/viewer/URLFontLoader.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/viewer/URLFontLoader.java index f914aed7..49615887 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/viewer/URLFontLoader.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/viewer/URLFontLoader.java @@ -41,13 +41,13 @@ public class URLFontLoader extends SwingWorker implements FontProv public URLFontLoader(URL codebase) throws MalformedURLException { this.fontURL = new URL(codebase, SANSMONO_FONT_RESOURCE); if (log.isDebugEnabled()) { - log.debug(Thread.currentThread() + " setting font load URL: " + fontURL); + log.debug("[" + Thread.currentThread().getName() + "] setting font load URL: " + fontURL); } } public void loadInBackground() { if (log.isDebugEnabled()) { - log.debug(Thread.currentThread() + " scheduling font loading in background: " + fontURL); + log.debug("[" + Thread.currentThread().getName() + "] scheduling font loading in background: " + fontURL); } this.execute(); } @@ -55,7 +55,7 @@ public class URLFontLoader extends SwingWorker implements FontProv @Override protected Font doInBackground() throws MalformedURLException, FontFormatException, IOException { if (log.isDebugEnabled()) { - log.debug(Thread.currentThread() + " loading font in background..."); + log.debug("[" + Thread.currentThread().getName() + "] loading font in background..."); } return Font.createFont(Font.TRUETYPE_FONT, fontURL.openStream()); } @@ -67,7 +67,7 @@ public class URLFontLoader extends SwingWorker implements FontProv */ @Override public Font getFont() throws FontProviderException { - log.debug(Thread.currentThread() + " get font"); + log.debug("[" + Thread.currentThread().getName() + "] get font (EDT?)"); try { return get(); } catch (InterruptedException ex) { -- cgit v1.2.3 From 68651bf67987905980734f5c2199f337a232f427 Mon Sep 17 00:00:00 2001 From: mcentner Date: Thu, 12 Nov 2009 20:48:57 +0000 Subject: Added support for enforcing a PIN length in a CHANGE REFERENCE DATA to match the recommended PIN length via Applet parameter. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@541 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 895fdbb5..85612d6e 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -21,6 +21,7 @@ import at.gv.egiz.bku.gui.BKUGUIFacade.Style; import at.gv.egiz.bku.gui.DefaultHelpListener; import at.gv.egiz.bku.gui.AbstractHelpListener; import at.gv.egiz.bku.gui.SwitchFocusListener; +import at.gv.egiz.smcc.SignatureCardFactory; import at.gv.egiz.stal.service.translator.STALTranslator; import java.io.IOException; @@ -71,6 +72,7 @@ public class BKUApplet extends JApplet { public static final String REDIRECT_URL = "RedirectURL"; public static final String REDIRECT_TARGET = "RedirectTarget"; public static final String HASHDATA_DISPLAY_FRAME = "frame"; + public static final String ENFORCE_RECOMMENDED_PIN_LENGTH = "EnforceRecommendedPINLength"; /** * STAL WSDL namespace and service name */ @@ -157,6 +159,11 @@ public class BKUApplet extends JApplet { log.trace("default locale: " + Locale.getDefault()); log.debug("setting locale: " + getLocale()); + if (Boolean.parseBoolean(getParameter(ENFORCE_RECOMMENDED_PIN_LENGTH))) { + SignatureCardFactory.ENFORCE_RECOMMENDED_PIN_LENGTH = true; + log.debug("enforce recommended pin length = " + SignatureCardFactory.ENFORCE_RECOMMENDED_PIN_LENGTH); + } + BKUGUIFacade.Style guiStyle; String guiStyleParam = getParameter(GUI_STYLE); if ("advanced".equals(guiStyleParam)) { -- cgit v1.2.3 From b7dd29046e232e4d42623655efc28965cce942b8 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 13 Nov 2009 15:13:21 +0000 Subject: git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@546 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java index 929cecb1..2e0cb331 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java @@ -185,13 +185,13 @@ public class AppletSecureViewer implements SecureViewer { throw new Exception("No hashdata input for reference " + signedRefId + " provided by service"); } if (log.isDebugEnabled()) { - log.debug("Got HashDataInput " + signedRefId + " (" + mimeType + ";" + encoding + ")"); + log.debug("Digesting reference " + signedRefId + " (" + mimeType + ";" + encoding + ")"); } byte[] hashDataInputDigest = digest(hdi, signedDigestAlg); if (log.isDebugEnabled()) { - log.debug("Comparing digest values... "); + log.debug("Comparing digest to claimed digest value for reference " + signedRefId); } // log.warn("***************** DISABLED HASHDATA VERIFICATION"); if (!Arrays.equals(hashDataInputDigest, signedDigest)) { -- cgit v1.2.3 From 5af9b75dccc1b52d1382fe0f2df30affd509f5b9 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 24 Nov 2009 18:48:00 +0000 Subject: Filenames derived from reference URI git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@553 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java index 2e0cb331..c67699af 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java @@ -180,6 +180,7 @@ public class AppletSecureViewer implements SecureViewer { byte[] hdi = hashDataInput.getValue(); String mimeType = hashDataInput.getMimeType(); String encoding = hashDataInput.getEncoding(); + String filename = hashDataInput.getFilename(); if (hdi == null) { throw new Exception("No hashdata input for reference " + signedRefId + " provided by service"); @@ -199,7 +200,7 @@ public class AppletSecureViewer implements SecureViewer { throw new DigestException("Bad digest value for reference " + signedRefId); } - verifiedHashDataInputs.add(new ByteArrayHashDataInput(hdi, signedRefId, mimeType, encoding)); + verifiedHashDataInputs.add(new ByteArrayHashDataInput(hdi, signedRefId, mimeType, encoding, filename)); } } -- cgit v1.2.3 From 3eaf40f3d8d9393857c13d95a678f2b161b75613 Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 18 Jan 2010 15:42:48 +0000 Subject: ignore case in guiStyle param git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@575 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'BKUApplet/src/main/java/at') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 85612d6e..2fa4889a 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -166,9 +166,9 @@ public class BKUApplet extends JApplet { BKUGUIFacade.Style guiStyle; String guiStyleParam = getParameter(GUI_STYLE); - if ("advanced".equals(guiStyleParam)) { + if ("advanced".equalsIgnoreCase(guiStyleParam)) { guiStyle = BKUGUIFacade.Style.advanced; - } else if ("tiny".equals(guiStyleParam)) { + } else if ("tiny".equalsIgnoreCase(guiStyleParam)) { guiStyle = BKUGUIFacade.Style.tiny; } else { guiStyle = BKUGUIFacade.Style.simple; -- cgit v1.2.3