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 --- .../at/gv/egiz/bku/gui/AbstractHelpListener.java | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java new file mode 100644 index 00000000..68d61bef --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java @@ -0,0 +1,84 @@ +/* + * 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.gui; + +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 Orthacker + */ +public abstract class AbstractHelpListener implements ActionListener { + + protected final static Log log = LogFactory.getLog(AbstractHelpListener.class); + protected String helpURLBase; + protected String locale; + + public AbstractHelpListener(URL baseURL, String locale) { + if (baseURL == null || "".equals(baseURL)) { + throw new RuntimeException("no help URL provided"); + } + this.helpURLBase = baseURL.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; + } + } + try { + showDocument(helpURL); + } catch (Exception ex) { + log.error("could not display help document " + helpURL + ": " + ex.getMessage()); + } + } + + private String appendParameter(String url, String paramName, String paramValue) { + if (url.indexOf('?') < 0) { + return url + "?" + paramName + "=" + paramValue; + } else { + return url + "&" + paramName + "=" + paramValue; + } + } + + public abstract void showDocument(URL helpDocument) throws Exception; + +} -- 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 --- .../egiz/bku/online/applet/AppletHelpListener.java | 3 +- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 6 ++-- .../at/gv/egiz/bku/gui/AbstractHelpListener.java | 7 +++-- .../gv/egiz/bku/local/gui/LocalHelpListener.java | 20 +++++++++--- .../at/gv/egiz/bku/local/stal/SMCCSTALFactory.java | 30 +++++++++++++----- .../egiz/bku/local/webapp/BKURequestHandler.java | 5 +-- .../src/main/webapp/WEB-INF/applicationContext.xml | 36 ++++++++++++---------- 7 files changed, 69 insertions(+), 38 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java') 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()); } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java index 68d61bef..6e3167c1 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java @@ -21,6 +21,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.net.MalformedURLException; import java.net.URL; +import java.util.Locale; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -32,9 +33,9 @@ public abstract class AbstractHelpListener implements ActionListener { protected final static Log log = LogFactory.getLog(AbstractHelpListener.class); protected String helpURLBase; - protected String locale; + protected Locale locale; - public AbstractHelpListener(URL baseURL, String locale) { + public AbstractHelpListener(URL baseURL, Locale locale) { if (baseURL == null || "".equals(baseURL)) { throw new RuntimeException("no help URL provided"); } @@ -49,7 +50,7 @@ public abstract class AbstractHelpListener implements ActionListener { try { String urlString = helpURLBase; if (locale != null) { - urlString = appendParameter(urlString, "locale", locale); + urlString = appendParameter(urlString, "locale", locale.toString()); } if (e.getActionCommand() != null && !"".equals(e.getActionCommand())) { urlString = appendParameter(urlString, "topic", e.getActionCommand()); diff --git a/BKULocal/src/main/java/at/gv/egiz/bku/local/gui/LocalHelpListener.java b/BKULocal/src/main/java/at/gv/egiz/bku/local/gui/LocalHelpListener.java index ebec9c65..e32c9c3d 100644 --- a/BKULocal/src/main/java/at/gv/egiz/bku/local/gui/LocalHelpListener.java +++ b/BKULocal/src/main/java/at/gv/egiz/bku/local/gui/LocalHelpListener.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package at.gv.egiz.bku.local.gui; import at.gv.egiz.bku.gui.AbstractHelpListener; @@ -22,6 +21,7 @@ import java.awt.Desktop; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; +import java.util.Locale; /** * @@ -29,13 +29,25 @@ import java.net.URL; */ public class LocalHelpListener extends AbstractHelpListener { - public LocalHelpListener(URL baseURL, String locale) { + protected Desktop desktop; + + public LocalHelpListener(URL baseURL, Locale locale) { super(baseURL, locale); + if (Desktop.isDesktopSupported()) { + desktop = Desktop.getDesktop(); + } } @Override public void showDocument(URL helpDocument) throws IOException, URISyntaxException { - Desktop.getDesktop().browse(helpDocument.toURI()); + 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/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/SMCCSTALFactory.java b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/SMCCSTALFactory.java index d3530332..4cc7bcd3 100644 --- a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/SMCCSTALFactory.java +++ b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/SMCCSTALFactory.java @@ -32,30 +32,38 @@ import at.gv.egiz.bku.online.applet.BKUApplet; import at.gv.egiz.stal.STAL; import at.gv.egiz.stal.STALFactory; import java.net.URL; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; public class SMCCSTALFactory implements STALFactory { - private Locale locale; + protected static final Log log = LogFactory.getLog(SMCCSTALFactory.class); + protected String helpURL; + protected Locale locale; @Override public STAL createSTAL() { - + SMCCSTAL stal; JDialog dialog; ResourceBundle resourceBundle; if (locale != null) { resourceBundle = ResourceBundle.getBundle(BKUApplet.RESOURCE_BUNDLE_BASE, - locale); + locale); } else { resourceBundle = ResourceBundle.getBundle(BKUApplet.RESOURCE_BUNDLE_BASE); } dialog = new JDialog(); BKUGUIFacade gui = BKUGUIFactory.createGUI(BKUGUIFactory.ADVANCED_GUI); - LocalHelpListener helpListener =null; + LocalHelpListener helpListener = null; try { - helpListener = new LocalHelpListener(new URL("http://localhost:3495/help"), "en"); + if (helpURL != null) { + helpListener = new LocalHelpListener(new URL(helpURL), locale); + } else { + log.warn("no HELP URL configured, help system disabled"); + } } catch (MalformedURLException ex) { - ex.printStackTrace(); + log.error("failed to configure help listener: " + ex.getMessage(), ex); } gui.init(dialog.getContentPane(), locale.toString(), null, helpListener); stal = new SMCCSTAL(new BKUGuiProxy(dialog, gui), dialog, resourceBundle); @@ -72,7 +80,7 @@ public class SMCCSTALFactory implements STALFactory { frameSize.width = screenSize.width; } dialog.setLocation((screenSize.width - frameSize.width) / 2, - (screenSize.height - frameSize.height) / 2); + (screenSize.height - frameSize.height) / 2); return stal; } @@ -80,4 +88,12 @@ public class SMCCSTALFactory implements STALFactory { public void setLocale(Locale locale) { this.locale = locale; } + + public String getHelpURL() { + return helpURL; + } + + public void setHelpURL(String helpURL) { + this.helpURL = helpURL; + } } diff --git a/BKULocal/src/main/java/at/gv/egiz/bku/local/webapp/BKURequestHandler.java b/BKULocal/src/main/java/at/gv/egiz/bku/local/webapp/BKURequestHandler.java index f19b86b5..62705d1e 100644 --- a/BKULocal/src/main/java/at/gv/egiz/bku/local/webapp/BKURequestHandler.java +++ b/BKULocal/src/main/java/at/gv/egiz/bku/local/webapp/BKURequestHandler.java @@ -16,7 +16,6 @@ */ package at.gv.egiz.bku.local.webapp; -import java.io.IOException; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; @@ -30,12 +29,10 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.web.HttpRequestHandler; import at.gv.egiz.bku.binding.BindingProcessorManager; import at.gv.egiz.bku.binding.HTTPBindingProcessor; import at.gv.egiz.bku.binding.HttpUtil; -import at.gv.egiz.bku.utils.StreamUtil; import at.gv.egiz.org.apache.tomcat.util.http.AcceptLanguage; public abstract class BKURequestHandler extends HttpServlet { @@ -68,7 +65,7 @@ public abstract class BKURequestHandler extends HttpServlet { bindingProcessor.setHTTPHeaders(headerMap); bindingProcessor.consumeRequestStream(req.getInputStream()); - // fixxme just for testing + // fixxme just for testing bindingProcessor.run(); if (bindingProcessor.getRedirectURL() != null) { resp.sendRedirect(bindingProcessor.getRedirectURL()); diff --git a/BKULocal/src/main/webapp/WEB-INF/applicationContext.xml b/BKULocal/src/main/webapp/WEB-INF/applicationContext.xml index a951f056..3191f82f 100644 --- a/BKULocal/src/main/webapp/WEB-INF/applicationContext.xml +++ b/BKULocal/src/main/webapp/WEB-INF/applicationContext.xml @@ -1,25 +1,27 @@ - + + scope="singleton"> + + 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 --- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 2 +- .../at/gv/egiz/bku/gui/AbstractHelpListener.java | 45 +++++++++------------- BKUOnline/src/main/webapp/WEB-INF/web.xml | 11 ++++-- BKUOnline/src/main/webapp/appletPage.jsp | 2 +- BKUOnline/src/main/webapp/help.jsp | 7 ++++ BKUOnline/src/main/webapp/helpfiles/index.html | 17 ++++++++ 6 files changed, 53 insertions(+), 31 deletions(-) create mode 100644 BKUOnline/src/main/webapp/help.jsp create mode 100644 BKUOnline/src/main/webapp/helpfiles/index.html (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java') 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()); } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java index 6e3167c1..a249a376 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java @@ -32,39 +32,22 @@ import org.apache.commons.logging.LogFactory; public abstract class AbstractHelpListener implements ActionListener { protected final static Log log = LogFactory.getLog(AbstractHelpListener.class); - protected String helpURLBase; +// protected String helpURLBase; + protected URL baseURL; protected Locale locale; public AbstractHelpListener(URL baseURL, Locale locale) { if (baseURL == null || "".equals(baseURL)) { throw new RuntimeException("no help URL provided"); } - this.helpURLBase = baseURL.toString(); + this.baseURL = baseURL; 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.toString()); - } - 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; - } - } + URL helpURL = constructHelpURL(baseURL, e.getActionCommand()); try { showDocument(helpURL); } catch (Exception ex) { @@ -72,12 +55,22 @@ public abstract class AbstractHelpListener implements ActionListener { } } - private String appendParameter(String url, String paramName, String paramValue) { - if (url.indexOf('?') < 0) { - return url + "?" + paramName + "=" + paramValue; - } else { - return url + "&" + paramName + "=" + paramValue; + private URL constructHelpURL(URL baseURL, String helpItem) { + URL helpURL = baseURL; + log.trace("constructing help URL: " + helpURL); + try { + if (locale != null) { + helpURL = new URL(helpURL, locale.toString() + "/"); + log.trace("constructing help URL: " + helpURL); + } + if (helpItem != null && !"".equals(helpItem)) { + helpURL = new URL(helpURL, helpItem + ".html"); + log.trace("constructing help URL: " + helpURL); + } + } catch (MalformedURLException ex) { + log.error("Failed to construct help URL for help item " + helpItem + ": " + ex.getMessage()); } + return helpURL; } public abstract void showDocument(URL helpDocument) throws Exception; diff --git a/BKUOnline/src/main/webapp/WEB-INF/web.xml b/BKUOnline/src/main/webapp/WEB-INF/web.xml index 6b2ec35c..f6fdbefc 100644 --- a/BKUOnline/src/main/webapp/WEB-INF/web.xml +++ b/BKUOnline/src/main/webapp/WEB-INF/web.xml @@ -52,6 +52,10 @@ HashDataInputServlet at.gv.egiz.bku.online.webapp.HashDataInputServlet + + help + /help.jsp + BKUServlet /http-security-layer-request @@ -68,9 +72,10 @@ HashDataInputServlet /hashDataInput - - - + + help + /help/* + diff --git a/BKUOnline/src/main/webapp/appletPage.jsp b/BKUOnline/src/main/webapp/appletPage.jsp index 8ddbed13..ff52fe51 100644 --- a/BKUOnline/src/main/webapp/appletPage.jsp +++ b/BKUOnline/src/main/webapp/appletPage.jsp @@ -53,7 +53,7 @@ GuiStyle : '<%=guiStyle%>', Background : '<%=backgroundImg%>', WSDL_URL :'../stal?wsdl', - HelpURL : '../help', + HelpURL : '../help/', HashDataDisplay : 'external', HashDataURL : '../hashDataInput', SessionID : '<%=session.getId()%>', diff --git a/BKUOnline/src/main/webapp/help.jsp b/BKUOnline/src/main/webapp/help.jsp new file mode 100644 index 00000000..29343171 --- /dev/null +++ b/BKUOnline/src/main/webapp/help.jsp @@ -0,0 +1,7 @@ +<%-- + Document : help + Created on : 05.11.2008, 10:55:52 + Author : Clemens Orthacker +--%> + + diff --git a/BKUOnline/src/main/webapp/helpfiles/index.html b/BKUOnline/src/main/webapp/helpfiles/index.html new file mode 100644 index 00000000..84db59c6 --- /dev/null +++ b/BKUOnline/src/main/webapp/helpfiles/index.html @@ -0,0 +1,17 @@ + + + + + + + + + +

No help item provided

+ + + -- 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 ------------- .../at/gv/egiz/bku/gui/AbstractHelpListener.java | 41 ++- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 219 +++++++------ .../at/gv/egiz/bku/gui/HashDataTableModel.java | 10 +- .../java/at/gv/egiz/bku/gui/HashDataViewer.java | 260 --------------- .../java/at/gv/egiz/bku/gui/HyperLinkRenderer.java | 47 +++ .../main/java/at/gv/egiz/bku/gui/SimpleGUI.java | 35 +- .../gv/egiz/bku/gui/SimpleHashDataTableModel.java | 60 ++++ .../main/java/at/gv/egiz/bku/gui/ViewerDialog.java | 354 +++++++++++++++++++++ .../at/gv/egiz/bku/gui/Messages.properties | 20 +- .../at/gv/egiz/bku/gui/Messages_en.properties | 17 +- BKUCommonGUI/src/main/resources/images/help.png | Bin 746 -> 303 bytes .../test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java | 2 +- .../gv/egiz/stal/service/impl/STALServiceImpl.java | 8 +- .../at/gv/egiz/bku/online/conf/SSLConfigTest.java | 3 +- STALService/pom.xml | 4 +- .../at/gv/egiz/stal/util/HashDataInputProxy.java | 67 ---- .../gv/egiz/bku/smccstal/HashDataInputDisplay.java | 20 +- .../gv/egiz/bku/smccstal/SignRequestHandler.java | 16 +- 25 files changed, 961 insertions(+), 839 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 delete mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperLinkRenderer.java create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleHashDataTableModel.java create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ViewerDialog.java delete mode 100644 STALService/src/main/java/at/gv/egiz/stal/util/HashDataInputProxy.java (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java') 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); - } -} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java index a249a376..f46f5227 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package at.gv.egiz.bku.gui; import java.awt.event.ActionEvent; @@ -22,19 +21,24 @@ import java.awt.event.ActionListener; import java.net.MalformedURLException; import java.net.URL; import java.util.Locale; +import java.util.ResourceBundle; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** - * + * Implement the showDocument(URL) method to provide an actual HelpListener. + * This class does not keep a GUI reference and subclasses should not interfere with the GUI. + * Therefore, any errors occurring in showDocument() should be handled/displayed within + * showDocument() and exceptions thrown from showDocument() are logged, not displayed in the GUI. + * * @author Clemens Orthacker */ public abstract class AbstractHelpListener implements ActionListener { protected final static Log log = LogFactory.getLog(AbstractHelpListener.class); -// protected String helpURLBase; protected URL baseURL; protected Locale locale; + protected ResourceBundle messages; public AbstractHelpListener(URL baseURL, Locale locale) { if (baseURL == null || "".equals(baseURL)) { @@ -42,6 +46,11 @@ public abstract class AbstractHelpListener implements ActionListener { } this.baseURL = baseURL; this.locale = locale; + if (locale != null) { + messages = ResourceBundle.getBundle(BKUGUIFacade.MESSAGES_BUNDLE, locale); + } else { + messages = ResourceBundle.getBundle(BKUGUIFacade.MESSAGES_BUNDLE); + } } @Override @@ -49,30 +58,36 @@ public abstract class AbstractHelpListener implements ActionListener { log.debug("received help action: " + e.getActionCommand()); URL helpURL = constructHelpURL(baseURL, e.getActionCommand()); try { - showDocument(helpURL); + showDocument(helpURL, e.getActionCommand()); } catch (Exception ex) { log.error("could not display help document " + helpURL + ": " + ex.getMessage()); } } - - private URL constructHelpURL(URL baseURL, String helpItem) { + + private URL constructHelpURL(URL baseURL, String helpTopic) { URL helpURL = baseURL; log.trace("constructing help URL: " + helpURL); try { if (locale != null) { helpURL = new URL(helpURL, locale.toString() + "/"); log.trace("constructing help URL: " + helpURL); - } - if (helpItem != null && !"".equals(helpItem)) { - helpURL = new URL(helpURL, helpItem + ".html"); + } + if (helpTopic != null && !"".equals(helpTopic)) { + helpURL = new URL(helpURL, helpTopic + ".html"); log.trace("constructing help URL: " + helpURL); } } catch (MalformedURLException ex) { - log.error("Failed to construct help URL for help item " + helpItem + ": " + ex.getMessage()); + log.error("Failed to construct help URL for help item " + helpTopic + ": " + ex.getMessage()); } return helpURL; } - - public abstract void showDocument(URL helpDocument) throws Exception; - + + /** + * Errors from HelpListeners should not (are not) displayed in the applet, + * but should rather be in the HelpListener specific way. + * Therefore, implementations SHOULD NOT throw exceptions (these are only logged). + * @param helpDocument + * @throws java.lang.Exception + */ + public abstract void showDocument(URL helpDocument, String helpTopic) throws Exception; } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java index 38638b5d..2daf3300 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java @@ -1,20 +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.gui; import at.gv.egiz.stal.HashDataInput; @@ -27,7 +26,7 @@ import java.util.List; import java.util.Locale; public interface BKUGUIFacade { - + public static final String ERR_UNKNOWN = "error.unknown"; public static final String ERR_SERVICE_UNREACHABLE = "error.ws.unreachable"; public static final String ERR_NO_PCSC = "error.pcsc"; @@ -38,92 +37,108 @@ public interface BKUGUIFacade { public static final String ERR_INVALID_HASH = "error.invalid.hash"; public static final String ERR_CARD_LOCKED = "error.card.locked"; public static final String ERR_CARD_NOTACTIVATED = "error.card.notactivated"; + public static final String ERR_VIEWER = "error.viewer"; - public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; - public static final String DEFAULT_BACKGROUND = "/images/BackgroundChipperling.png"; - public static final String HELP_IMG = "/images/help.png"; - public static final String HASHDATA_FONT = "Monospaced"; - public static final Color ERROR_COLOR = Color.RED; - public static final Color HYPERLINK_COLOR = Color.BLUE; - public static final String TITLE_WELCOME = "title.welcome"; - public static final String TITLE_INSERTCARD = "title.insertcard"; - public static final String TITLE_CARD_NOT_SUPPORTED = "title.cardnotsupported"; - public static final String TITLE_CARDPIN = "title.cardpin"; - public static final String TITLE_SIGN = "title.sign"; - public static final String TITLE_ERROR = "title.error"; - public static final String TITLE_RETRY = "title.retry"; - public static final String TITLE_WAIT = "title.wait"; - public static final String TITLE_HASHDATA = "title.hashdata"; - public static final String WINDOWTITLE_SAVE = "windowtitle.save"; - public static final String WINDOWTITLE_SAVEDIR = "windowtitle.savedir"; - public static final String WINDOWTITLE_OVERWRITE = "windowtitle.overwrite"; - public static final String WINDOWTITLE_VIEWER = "windowtitle.viewer"; - public static final String MESSAGE_WAIT = "message.wait"; - public static final String MESSAGE_INSERTCARD = "message.insertcard"; - public static final String MESSAGE_ENTERPIN = "message.enterpin"; - public static final String MESSAGE_HASHDATALINK = "message.hashdatalink"; - public static final String MESSAGE_HASHDATA = "message.hashdata"; - public static final String MESSAGE_HASHDATALIST = "message.hashdatalist"; - public static final String MESSAGE_RETRIES = "message.retries"; - public static final String MESSAGE_OVERWRITE = "message.overwrite"; - public static final String LABEL_PIN = "label.pin"; - public static final String LABEL_PINSIZE = "label.pinsize"; + public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; + public static final String DEFAULT_BACKGROUND = "/images/BackgroundChipperling.png"; + public static final String HELP_IMG = "/images/help.png"; + public static final String HASHDATA_FONT = "Monospaced"; + public static final Color ERROR_COLOR = Color.RED; + public static final Color HYPERLINK_COLOR = Color.BLUE; + public static final String TITLE_WELCOME = "title.welcome"; + public static final String TITLE_INSERTCARD = "title.insertcard"; + public static final String TITLE_CARD_NOT_SUPPORTED = "title.cardnotsupported"; + public static final String TITLE_CARDPIN = "title.cardpin"; + public static final String TITLE_SIGN = "title.sign"; + public static final String TITLE_ERROR = "title.error"; + public static final String TITLE_RETRY = "title.retry"; + public static final String TITLE_WAIT = "title.wait"; + public static final String TITLE_HASHDATA = "title.hashdata"; + public static final String WINDOWTITLE_SAVE = "windowtitle.save"; + public static final String WINDOWTITLE_SAVEDIR = "windowtitle.savedir"; + public static final String WINDOWTITLE_OVERWRITE = "windowtitle.overwrite"; + public static final String WINDOWTITLE_VIEWER = "windowtitle.viewer"; + public static final String WINDOWTITLE_HELP = "windowtitle.help"; + public static final String MESSAGE_WAIT = "message.wait"; + public static final String MESSAGE_INSERTCARD = "message.insertcard"; + public static final String MESSAGE_ENTERPIN = "message.enterpin"; + public static final String MESSAGE_HASHDATALINK = "message.hashdatalink"; + public static final String MESSAGE_HASHDATA = "message.hashdata"; + public static final String MESSAGE_HASHDATALIST = "message.hashdatalist"; + public static final String MESSAGE_RETRIES = "message.retries"; + public static final String MESSAGE_OVERWRITE = "message.overwrite"; + public static final String MESSAGE_HELP = "message.help"; + public static final String LABEL_PIN = "label.pin"; + public static final String LABEL_PINSIZE = "label.pinsize"; // public static final String ERROR_NO_HASHDATA = "error.no.hashdata"; - public static final String HELP_WELCOME = "help.welcome"; - public static final String HELP_WAIT = "help.wait"; - public static final String HELP_CARDNOTSUPPORTED = "help.cardnotsupported"; - public static final String HELP_INSERTCARD = "help.insertcard"; - public static final String HELP_CARDPIN = "help.cardpin"; - public static final String HELP_SIGNPIN = "help.signpin"; - public static final String HELP_RETRY = "help.retry"; - public static final String HELP_HASHDATA = "help.hashdata"; - public static final String HELP_HASHDATALIST = "help.hashdatalist"; - public static final String HELP_HASHDATAVIEWER = "help.hashdataviewer"; - - public static final String BUTTON_OK = "button.ok"; - public static final String BUTTON_CANCEL = "button.cancel"; - public static final String BUTTON_BACK = "button.back"; - public static final String BUTTON_SIGN = "button.sign"; - public static final String BUTTON_SAVE = "button.save"; - public static final String BUTTON_CLOSE = "button.close"; - public static final String SAVE_HASHDATAINPUT_PREFIX = "save.hashdatainput.prefix"; - - - public void init(Container contentPane, Locale locale, URL background, ActionListener helpListener); - - /** - * - * @return the locale of the message bundle (what if no message bundle could be loaded for the requested locale?) - */ - public Locale getLocale(); - - public void showWelcomeDialog(); - - /** - * - * @param waitMessage if null, a simple 'wait' text is displayed - */ - public void showWaitDialog(String waitMessage); - - public void showInsertCardDialog(ActionListener cancelListener, String actionCommand); - - public void showCardNotSupportedDialog(ActionListener cancelListener, String actionCommand); - - public void showCardPINDialog(PINSpec pinSpec, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand); - - public void showCardPINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand); - - public void showSignaturePINDialog(PINSpec pinSpec, ActionListener signListener, String signCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand); - - public void showSignaturePINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand); - - public char[] getPin(); - - public void showHashDataInputDialog(List signedReferences, boolean standalone, ActionListener okListener, String actionCommand); - + public static final String HELP_WELCOME = "help.welcome"; + public static final String HELP_WAIT = "help.wait"; + public static final String HELP_CARDNOTSUPPORTED = "help.cardnotsupported"; + public static final String HELP_INSERTCARD = "help.insertcard"; + public static final String HELP_CARDPIN = "help.cardpin"; + public static final String HELP_SIGNPIN = "help.signpin"; + public static final String HELP_RETRY = "help.retry"; + public static final String HELP_HASHDATA = "help.hashdata"; + public static final String HELP_HASHDATALIST = "help.hashdatalist"; + public static final String HELP_HASHDATAVIEWER = "help.hashdataviewer"; + public static final String BUTTON_OK = "button.ok"; + public static final String BUTTON_CANCEL = "button.cancel"; + public static final String BUTTON_BACK = "button.back"; + public static final String BUTTON_SIGN = "button.sign"; + public static final String BUTTON_SAVE = "button.save"; + public static final String BUTTON_CLOSE = "button.close"; + public static final String SAVE_HASHDATAINPUT_PREFIX = "save.hashdatainput.prefix"; + + public void init(Container contentPane, Locale locale, URL background, ActionListener helpListener); + + /** + * + * @return the locale of the message bundle (what if no message bundle could be loaded for the requested locale?) + */ + public Locale getLocale(); + + public void showWelcomeDialog(); + + /** + * + * @param waitMessage if null, a simple 'wait' text is displayed + */ + public void showWaitDialog(String waitMessage); + + public void showInsertCardDialog(ActionListener cancelListener, String actionCommand); + + public void showCardNotSupportedDialog(ActionListener cancelListener, String actionCommand); + + public void showCardPINDialog(PINSpec pinSpec, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand); + + public void showCardPINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand); + + public void showSignaturePINDialog(PINSpec pinSpec, ActionListener signListener, String signCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand); + + public void showSignaturePINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand); + + public char[] getPin(); + + /** + * TODO move to HashDataDisplay implementations + * @param signedReferences + * @param externalDisplay + * @param okListener + * @param okCommand + */ + public void showHashDataInputDialog(List signedReferences, boolean externalDisplay, ActionListener okListener, String okCommand); + + /** + * TODO pull out from BKUGUIFacade. (or make this strictly an applet internal version) + * Problem: if standalone flag is provided, we also need the actionlistener.. + * @param helpDocument + * @param mimeType + * @param encoding + */ +// public void showHelpDialog(InputStream helpDocument, String mimeType, String encoding); //, boolean standalone); //, ActionListener okListener, String okCommand); + // public void showPlainTextHashDataInputDialog(String text, ActionListener saveListener, String saveCommand, ActionListener cancelListener, String cancelCommand); - - public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams, ActionListener okListener, String actionCommand); - - public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams); + public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams, ActionListener okListener, String actionCommand); + + public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams); } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java index aea85523..e8566fa6 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java @@ -64,13 +64,5 @@ class HashDataTableModel extends DefaultTableModel { } } return selection; - }// public List getSelectedReferenceIds() { -// ArrayList selection = new ArrayList(); -// for (Object row : dataVector) { -// if ((Boolean) ((Vector) row).elementAt(1)) { -// selection.add((String) ((Vector) row).elementAt(0)); -// } -// } -// return selection; -// } + } } \ No newline at end of file diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java deleted file mode 100644 index 3db06e19..00000000 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java +++ /dev/null @@ -1,260 +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.gui; - -import at.gv.egiz.stal.HashDataInput; -import java.awt.Component; -import java.awt.Container; -import java.awt.Cursor; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Frame; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.WindowEvent; -import java.awt.event.WindowListener; -import java.io.InputStreamReader; -import java.io.Reader; -import java.text.MessageFormat; -import java.util.List; -import java.util.ResourceBundle; -import javax.swing.GroupLayout; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JEditorPane; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.LayoutStyle; -import javax.swing.text.Document; -import javax.swing.text.EditorKit; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * - * @author Clemens Orthacker - */ -public class HashDataViewer extends JDialog - implements ActionListener, WindowListener { - - public static final String PLAINTEXT_FONT = "Monospaced"; - - protected static final Log log = LogFactory.getLog(HashDataViewer.class); - private static HashDataViewer dialog; - - public static void showDialog(Component frameComp, List signedReferences, ResourceBundle messages, ActionListener saveListener, String saveCommand, HelpMouseListener helpListener) { - - log.info("******************* SHOW HASHDATA DIALOG"); - - Frame frame = JOptionPane.getFrameForComponent(frameComp); - - dialog = new HashDataViewer(frame, signedReferences.get(0), messages, saveListener, saveCommand, helpListener); - dialog.addWindowListener(dialog); - dialog.setVisible(true); - - } - - private HashDataViewer(Frame frame, HashDataInput hashData, ResourceBundle messages, ActionListener saveListener, String saveCommand, HelpMouseListener helpListener) { - super(frame, messages.getString(BKUGUIFacade.WINDOWTITLE_VIEWER), true); - - JPanel viewerPanel = createViewerPanel(messages, hashData, helpListener); - JPanel buttonPanel = createButtonPanel(messages, saveListener, saveCommand); - - - Container contentPane = getContentPane(); - contentPane.setPreferredSize(new Dimension(400, 300)); - - GroupLayout mainLayout = new GroupLayout(contentPane); - contentPane.setLayout(mainLayout); - - mainLayout.setHorizontalGroup( - mainLayout.createSequentialGroup() - .addContainerGap() - .addGroup( - mainLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(viewerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()); - mainLayout.setVerticalGroup( - mainLayout.createSequentialGroup() - .addContainerGap() - .addComponent(viewerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addContainerGap()); - - pack(); - setLocationRelativeTo(frame); - } - - private JPanel createViewerPanel(ResourceBundle messages, HashDataInput hashData, HelpMouseListener helpListener) { - String mimeType = hashData.getMimeType(); - String encoding = hashData.getEncoding(); - - log.debug("display hashdata: " + mimeType + ";" + encoding); - - if (mimeType == null) { - mimeType = "text/plain"; - } - if (encoding == null) { - encoding = "UTF-8"; - } - - JEditorPane viewer = new JEditorPane(); - viewer.setEditable(false); - viewer.setContentType(mimeType); - if ("text/plain".equals(mimeType)) { - viewer.setFont(new Font(PLAINTEXT_FONT, viewer.getFont().getStyle(), viewer.getFont().getSize())); - } - - EditorKit editorKit = viewer.getEditorKit(); - Document document = editorKit.createDefaultDocument(); - - Reader reader; - try { - reader = new InputStreamReader(hashData.getHashDataInput(), encoding); - viewer.read(reader, document); - } catch (Exception ex) { - String p = messages.getString(BKUGUIFacade.ERR_DISPLAY_HASHDATA); - viewer.setText(MessageFormat.format(p, ex.getMessage())); - } - - JScrollPane scrollPane = new JScrollPane(viewer); -// scrollPane.setPreferredSize(new Dimension(400, 300)); - scrollPane.setPreferredSize(viewer.getPreferredSize()); - scrollPane.setAlignmentX(LEFT_ALIGNMENT); - - JLabel viewerTitle = new JLabel(); - viewerTitle.setText(messages.getString(BKUGUIFacade.TITLE_HASHDATA)); - viewerTitle.setFont(viewerTitle.getFont().deriveFont(viewerTitle.getFont().getStyle() | java.awt.Font.BOLD)); - viewerTitle.setLabelFor(viewer); - - JLabel helpLabel = new JLabel(); - helpListener.setHelpTopic(BKUGUIFacade.HELP_HASHDATAVIEWER); - helpLabel.setIcon(new ImageIcon(getClass().getResource(BKUGUIFacade.HELP_IMG))); - helpLabel.addMouseListener(helpListener); - helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - - JPanel viewerPanel = new JPanel(); - GroupLayout viewerPanelLayout = new GroupLayout(viewerPanel); - viewerPanel.setLayout(viewerPanelLayout); - - viewerPanelLayout.setHorizontalGroup( - viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(viewerPanelLayout.createSequentialGroup() - .addComponent(viewerTitle) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)) - .addComponent(scrollPane)); //, 0, 0, Short.MAX_VALUE)); - - viewerPanelLayout.setVerticalGroup( - viewerPanelLayout.createSequentialGroup() - .addGroup(viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(viewerTitle) - .addComponent(helpLabel)) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(scrollPane)); //, 0, 0, Short.MAX_VALUE)); - -// viewerPanel.setLayout(new BoxLayout(viewerPanel, BoxLayout.PAGE_AXIS)); -// JLabel title = new JLabel(messages.getString(BKUGUIFacade.TITLE_HASHDATA)); -// title.setLabelFor(viewer); -// viewerPanel.add(title); -// viewerPanel.add(Box.createRigidArea(new Dimension(0, 5))); -// viewerPanel.add(scrollPane); -// viewerPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); - - return viewerPanel; - } - - private JPanel createButtonPanel(ResourceBundle messages, ActionListener saveListener, String saveCommand) { - JButton closeButton = new JButton(); - closeButton.setText(messages.getString(BKUGUIFacade.BUTTON_CLOSE)); - closeButton.addActionListener(this); - - JButton saveButton = new JButton(); - saveButton.setText(messages.getString(BKUGUIFacade.BUTTON_SAVE)); - saveButton.setActionCommand(saveCommand); - saveButton.addActionListener(saveListener); - - int buttonSize = closeButton.getPreferredSize().width; - if (saveButton.getPreferredSize().width > buttonSize) { - buttonSize = saveButton.getPreferredSize().width; - } - - JPanel buttonPanel = new JPanel(); - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createSequentialGroup().addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(saveButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(closeButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(saveButton).addComponent(closeButton)); - - return buttonPanel; - } - - @Override - public void actionPerformed(ActionEvent e) { -// if ("close".equals(e.getActionCommand())) { - HashDataViewer.dialog.setVisible(false); -// HashDataViewer.dialog.dispose(); - } - - @Override - public void windowOpened(WindowEvent e) { - log.debug("WINDOW OPENED"); - } - - @Override - public void windowClosing(WindowEvent e) { - log.debug("WINDOW CLOSING"); - } - - @Override - public void windowClosed(WindowEvent e) { - log.debug("WINDOW CLOSED"); - } - - @Override - public void windowIconified(WindowEvent e) { - log.debug("WINDOW ICONIFIED"); - } - - @Override - public void windowDeiconified(WindowEvent e) { - } - - @Override - public void windowActivated(WindowEvent e) { - log.debug("WINDOW ACTIVATED"); - } - - @Override - public void windowDeactivated(WindowEvent e) { - log.debug("WINDOW DEACTIVATED"); - } - - - - - - - -} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperLinkRenderer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperLinkRenderer.java new file mode 100644 index 00000000..d9606177 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperLinkRenderer.java @@ -0,0 +1,47 @@ +/* + * 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.gui; + +import at.gv.egiz.stal.HashDataInput; +import java.awt.Color; +import java.awt.Component; +import javax.swing.JLabel; +import javax.swing.JTable; +import javax.swing.table.TableCellRenderer; + +/** + * + * @author Clemens Orthacker + */ +public class HyperLinkRenderer extends JLabel implements TableCellRenderer { + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + HashDataInput hdi = (HashDataInput) value; + setText(hdi.getReferenceId() + " (" + hdi.getMimeType() + ")"); + setBackground(Color.CYAN); + return this; + } + +// extends DefaultTableCellRenderer { +// +// @Override +// public void setValue(Object value) { +// HashDataInput hdi = (HashDataInput) value; +// setText(hdi.getReferenceId() + " (" + hdi.getMimeType() + ")"); +// } +} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java index 583dae0f..6250dd0e 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java @@ -83,7 +83,7 @@ public class SimpleGUI implements BKUGUIFacade { protected int buttonSize; - private static final int CHECKBOX_WIDTH = new JCheckBox().getPreferredSize().width; +// private static final int CHECKBOX_WIDTH = new JCheckBox().getPreferredSize().width; /** * @param contentPane @@ -924,16 +924,17 @@ public class SimpleGUI implements BKUGUIFacade { } } else { - final HashDataTableModel tableModel = new HashDataTableModel(signedReferences); - - ActionListener saveHashDataListener = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - showSaveHashDataInputDialog(tableModel.getSelectedHashData(), okListener, okCommand); - } - }; - showMultipleHashDataInputDialog(tableModel, okListener, okCommand, saveHashDataListener, "save"); + SimpleHashDataTableModel tableModel = new SimpleHashDataTableModel(signedReferences); +// final HashDataTableModel tableModel = new HashDataTableModel(signedReferences); +// +// ActionListener saveHashDataListener = new ActionListener() { +// +// @Override +// public void actionPerformed(ActionEvent e) { +// showSaveHashDataInputDialog(tableModel.getSelectedHashData(), okListener, okCommand); +// } +// }; + showMultipleHashDataInputDialog(tableModel, okListener, okCommand); } } @@ -953,7 +954,7 @@ public class SimpleGUI implements BKUGUIFacade { log.debug("show plaintext hashdatainput dialog"); - HashDataViewer.showDialog(contentPane, signedReferences, messages, saveListener, saveCommand, helpListener); + ViewerDialog.showHashDataInput(contentPane, signedReferences, messages, saveListener, saveCommand, helpListener); } }); } @@ -1052,7 +1053,8 @@ public class SimpleGUI implements BKUGUIFacade { }); } - private void showMultipleHashDataInputDialog(final TableModel signedReferences, final ActionListener cancelListener, final String cancelCommand, final ActionListener saveListener, final String saveCommand) { + private void showMultipleHashDataInputDialog(final TableModel signedReferences, final ActionListener cancelListener, final String cancelCommand) { +// , final ActionListener saveListener, final String saveCommand log.debug("scheduling multiple hashdatainput dialog"); @@ -1076,13 +1078,14 @@ public class SimpleGUI implements BKUGUIFacade { refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[]{signedReferences.getRowCount()})); JTable hashDataTable = new JTable(); + hashDataTable.setDefaultRenderer(HashDataInput.class, new HyperLinkRenderer()); hashDataTable.setModel(signedReferences); hashDataTable.setTableHeader(null); // hashDataTable.setShowVerticalLines(false); // hashDataTable.setRowSelectionAllowed(false); - TableColumn selectCol = hashDataTable.getColumnModel().getColumn(1); - selectCol.setMinWidth(CHECKBOX_WIDTH); - selectCol.setMaxWidth(CHECKBOX_WIDTH); +// TableColumn selectCol = hashDataTable.getColumnModel().getColumn(1); +// selectCol.setMinWidth(CHECKBOX_WIDTH); +// selectCol.setMaxWidth(CHECKBOX_WIDTH); // hashDataTable.setPreferredScrollableViewportSize(mainPanel.getPreferredSize()); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleHashDataTableModel.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleHashDataTableModel.java new file mode 100644 index 00000000..463dbe81 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SimpleHashDataTableModel.java @@ -0,0 +1,60 @@ +/* + * 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.gui; + +import at.gv.egiz.stal.HashDataInput; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.List; +import java.util.Vector; +import javax.swing.table.DefaultTableModel; + +/** + * + * @author clemens + */ +class SimpleHashDataTableModel extends DefaultTableModel { + + protected List signedReferences; + + protected Class[] types = new Class[]{ + java.lang.String.class + }; + + public SimpleHashDataTableModel(List signedReferences) { + super(0, 1); + this.signedReferences = signedReferences; + for (HashDataInput hashDataInput : signedReferences) { + +// String desc = hashDataInput.getReferenceId() + " (" + hashDataInput.getMimeType() + ")"; + addRow(new Object[]{hashDataInput}); + } + } + + @Override + public Class getColumnClass(int columnIndex) { + return types[columnIndex]; + } + + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + if (columnIndex == 1) + return true; + return false; + } +} \ No newline at end of file diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ViewerDialog.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ViewerDialog.java new file mode 100644 index 00000000..cd04ad98 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ViewerDialog.java @@ -0,0 +1,354 @@ +/* + * 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.gui; + +import at.gv.egiz.stal.HashDataInput; +import java.awt.Component; +import java.awt.Container; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Frame; +import java.awt.Point; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.URL; +import java.net.URLConnection; +import java.nio.charset.Charset; +import java.text.MessageFormat; +import java.util.List; +import java.util.ResourceBundle; +import javax.swing.GroupLayout; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JEditorPane; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.LayoutStyle; +import javax.swing.text.Document; +import javax.swing.text.EditorKit; +import javax.swing.text.html.HTMLDocument; +import javax.swing.text.html.HTMLEditorKit; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author Clemens Orthacker + */ +public class ViewerDialog extends JDialog + implements ActionListener { + + public static final String PLAINTEXT_FONT = "Monospaced"; + protected static final Log log = LogFactory.getLog(ViewerDialog.class); +// private ViewerDialog dialog; + + protected ResourceBundle messages; + + /** + * + * @param frameComp + * @param signedReferences currently, only one hashdata input (the first in the list) is displayed + * @param messages + * @param saveListener + * @param saveCommand + * @param helpListener + */ + public static void showHashDataInput(Component frameComp, + List hashDataInputs, + ResourceBundle messages, + ActionListener saveListener, + String saveCommand, + HelpMouseListener helpListener) { + + Frame frame = null; + if (frameComp != null) { + JOptionPane.getFrameForComponent(frameComp); + } + ViewerDialog viewer = new ViewerDialog(frame, + messages, + hashDataInputs, + saveListener, + saveCommand, + helpListener); + viewer.setVisible(true); + } + + public static void showHelp(Component frameComp, + String helpTopic, +// Reader helpDocument, + InputStream helpDocument, + String mimeType, + ResourceBundle messages) { + + Frame frame = null; + if (frameComp != null) { + JOptionPane.getFrameForComponent(frameComp); + } + ViewerDialog viewer = new ViewerDialog(frame, messages, helpTopic, helpDocument, mimeType); + viewer.setVisible(true); + } + + /** + * TODO make encoding aware! + * @param frame + * @param title + * @param messages + * @param hashDataInputs + * @param saveListener + * @param saveCommand + * @param helpListener + */ + private ViewerDialog(Frame frame, + ResourceBundle messages, + List hashDataInputs, + ActionListener saveListener, + String saveCommand, + HelpMouseListener helpListener) { + super(frame, messages.getString(BKUGUIFacade.WINDOWTITLE_VIEWER), true); + this.messages = messages; + + HashDataInput hashData = hashDataInputs.get(0); + +// Charset cs; +// if (hashData.getEncoding() == null) { +// cs = Charset.forName("UTF-8"); +// } else { +// try { +// cs = Charset.forName(hashData.getEncoding()); +// } catch (Exception ex) { +// log.debug("charset " + hashData.getEncoding() + " not supported, assuming UTF-8: " + ex.getMessage()); +// cs = Charset.forName("UTF-8"); +// } +// } + +// InputStreamReader isr = new InputStreamReader(hashData.getHashDataInput(), cs); +// Reader content = new BufferedReader(isr); + InputStream content = hashData.getHashDataInput(); + String mimeType = hashData.getMimeType(); + String encoding = hashData.getEncoding(); + + JPanel hashDataPanel = createViewerPanel(messages.getString(BKUGUIFacade.MESSAGE_HASHDATA), content, mimeType, encoding, helpListener); + JPanel buttonPanel = createButtonPanel(saveListener, saveCommand); + initContentPane(new Dimension(600, 400), hashDataPanel, buttonPanel); + + pack(); + if (frame != null) { + setLocationRelativeTo(frame); + } else { + setLocationByPlatform(true); + } + } + + private ViewerDialog(Frame frame, + ResourceBundle messages, + String helpTopic, +// Reader helpDocument, + InputStream helpDocument, + String mimeType) { + super(frame, messages.getString(BKUGUIFacade.WINDOWTITLE_HELP), true); + this.messages = messages; + + String p = messages.getString(BKUGUIFacade.MESSAGE_HELP); + String helpItem = messages.getString(helpTopic); + String viewerLabel = MessageFormat.format(p, new Object[] {helpItem}); + + JPanel helpPanel = createViewerPanel(viewerLabel, helpDocument, mimeType, null, null); + JPanel buttonPanel = createButtonPanel(); + + initContentPane(new Dimension(600, 400), helpPanel, buttonPanel); + pack(); + if (frame != null) { + setLocationRelativeTo(frame); + } else { + setLocationByPlatform(true); + } + } + + private void initContentPane(Dimension preferredSize, JPanel viewerPanel, JPanel buttonPanel) { + Container contentPane = getContentPane(); + contentPane.setPreferredSize(preferredSize); + + GroupLayout mainLayout = new GroupLayout(contentPane); + contentPane.setLayout(mainLayout); + + mainLayout.setHorizontalGroup( + mainLayout.createSequentialGroup().addContainerGap().addGroup( + mainLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(viewerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addContainerGap()); + mainLayout.setVerticalGroup( + mainLayout.createSequentialGroup() + .addContainerGap() + .addComponent(viewerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(buttonPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addContainerGap()); + } + + /** + * + * @param messages + * @param content + * @param mimeType defaults to text/plain if null + * @param encoding must be null if document contains charset declaration (e.g. HTML page), otherwise the parser crashes + * @param helpListener may be null + * @return + */ + private JPanel createViewerPanel(String viewerLabelText, InputStream content, String mimeType, String encoding, HelpMouseListener helpListener) { + log.debug("viewer dialog: " + mimeType); + + if (mimeType == null) { + mimeType = "text/plain"; + } else if ("application/xhtml+xml".equals(mimeType)) { + mimeType = "text/html"; + } + + JEditorPane viewer = new JEditorPane(); + viewer.setEditable(false); + viewer.setContentType(mimeType); + if ("text/plain".equals(mimeType)) { + viewer.setFont(new Font(PLAINTEXT_FONT, viewer.getFont().getStyle(), viewer.getFont().getSize())); + } + + EditorKit editorKit = viewer.getEditorKit(); + Document document = editorKit.createDefaultDocument(); +// document.putProperty("IgnoreCharsetDirective", new Boolean(true)); + + try { + if (encoding != null) { + BufferedReader contentReader = new BufferedReader(new InputStreamReader(content, encoding)); + viewer.read(contentReader, document); + contentReader.close(); + } else { + // charset declaration in content + viewer.read(content, document); + content.close(); + } + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + String p = messages.getString(BKUGUIFacade.ERR_VIEWER); + viewer.setText(MessageFormat.format(p, ex.getMessage())); + } + + JScrollPane scrollPane = new JScrollPane(viewer); + scrollPane.setPreferredSize(viewer.getPreferredSize()); + scrollPane.setAlignmentX(LEFT_ALIGNMENT); + viewer.setCaretPosition(0); + + JLabel viewerLabel = new JLabel(); + viewerLabel.setText(viewerLabelText); + viewerLabel.setFont(viewerLabel.getFont().deriveFont(viewerLabel.getFont().getStyle() | java.awt.Font.BOLD)); + viewerLabel.setLabelFor(viewer); + + JPanel viewerPanel = new JPanel(); + GroupLayout viewerPanelLayout = new GroupLayout(viewerPanel); + viewerPanel.setLayout(viewerPanelLayout); + + if (helpListener != null) { + JLabel helpLabel = new JLabel(); + helpListener.setHelpTopic(BKUGUIFacade.HELP_HASHDATAVIEWER); + helpLabel.setIcon(new ImageIcon(getClass().getResource(BKUGUIFacade.HELP_IMG))); + helpLabel.addMouseListener(helpListener); + helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + viewerPanelLayout.setHorizontalGroup( + viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(viewerPanelLayout.createSequentialGroup().addComponent(viewerLabel).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE).addComponent(helpLabel)).addComponent(scrollPane)); //, 0, 0, Short.MAX_VALUE)); + viewerPanelLayout.setVerticalGroup( + viewerPanelLayout.createSequentialGroup() + .addGroup(viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(viewerLabel) + .addComponent(helpLabel)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(scrollPane)); + } else { + viewerPanelLayout.setHorizontalGroup( + viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(viewerLabel) + .addComponent(scrollPane)); + viewerPanelLayout.setVerticalGroup( + viewerPanelLayout.createSequentialGroup() + .addComponent(viewerLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(scrollPane)); + + } + + return viewerPanel; + } + + private JPanel createButtonPanel() { + JButton closeButton = new JButton(); + closeButton.setText(messages.getString(BKUGUIFacade.BUTTON_CLOSE)); + closeButton.addActionListener(this); + + JPanel buttonPanel = new JPanel(); + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(closeButton)); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createSequentialGroup() + .addComponent(closeButton)); + return buttonPanel; + } + + private JPanel createButtonPanel(ActionListener saveListener, String saveCommand) { + JButton closeButton = new JButton(); + closeButton.setText(messages.getString(BKUGUIFacade.BUTTON_CLOSE)); + closeButton.addActionListener(this); + + JButton saveButton = new JButton(); + saveButton.setText(messages.getString(BKUGUIFacade.BUTTON_SAVE)); + saveButton.setActionCommand(saveCommand); + saveButton.addActionListener(saveListener); + + int buttonSize = closeButton.getPreferredSize().width; + if (saveButton.getPreferredSize().width > buttonSize) { + buttonSize = saveButton.getPreferredSize().width; + } + + JPanel buttonPanel = new JPanel(); + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createSequentialGroup().addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(saveButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(closeButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(saveButton).addComponent(closeButton)); + + return buttonPanel; + } + + @Override + public void actionPerformed(ActionEvent e) { +// if ("close".equals(e.getActionCommand())) { +// ViewerDialog.dialog.setVisible(false); +// HashDataViewer.dialog.dispose(); + this.setVisible(false); + } +} diff --git a/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages.properties b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages.properties index c47242b2..ba20471d 100644 --- a/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages.properties +++ b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages.properties @@ -26,14 +26,17 @@ windowtitle.save=Signaturdaten speichern windowtitle.savedir=Signaturdaten in Verzeichnis speichern windowtitle.overwrite=Datei \u00FCberschreiben? windowtitle.viewer=Signaturedaten +windowtitle.help=Hilfe message.wait=Bitte warten... message.insertcard=Bitte die B\u00FCrgerkarte in den Kartenleser stecken message.enterpin={0} eingeben message.hashdatalink=Signaturdaten anzeigen -message.hashdata=Signaturdaten: +message.hashdata=Dies ist eine Voransicht des zu signierenden Inhaltes. F\u00FCr Details siehe Hilfe. +#verwenden sie bitte die von ihrem System zur Verf\u00FCgung gestellte {0} Anwendung. message.hashdatalist={0} Signaturdaten: message.retries=Noch {0} Versuch(e) message.overwrite=M\u00F6chten Sie das existierende Dokument {0} \u00FCberschreiben? +message.help=Hilfe zu {0} label.pin={0}: label.pinsize=({0} stellig) button.ok=OK @@ -62,4 +65,17 @@ error.cardterminal=Es konnte kein Smartcard-Leser gefunden werden error.unknown=Leider trat ein Fehler auf: {0} error.test=Fehler1 {0} - Fehler2 {1} error.card.locked=B\u00FCrgerkarte ist gesperrt -error.card.notactivated=B\u00FCrgerkartenfunktion ist nicht aktiviert \ No newline at end of file +error.card.notactivated=B\u00FCrgerkartenfunktion ist nicht aktiviert +error.viewer=Der Inhalt kann nicht dargestellt werden: {0} + +# Help Topics +help.welcome=Startseite +help.wait=Bitte Warten Bildschirm +help.cardnotsupported=Nicht unterst\u00FCtzte B\u00FCrgerkarte +help.insertcard=Keine B\u00FCrgerkarte im Kartenleser +help.cardpin=Pineingabe +help.signpin=Signatur-Pineingabe +help.retry=Falscher Pin +help.hashdata=Signierte Inhalte +help.hashdatalist=Signierte Inhalte +help.hashdataviewer=Anzeige signierter Inhalte \ No newline at end of file diff --git a/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages_en.properties b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages_en.properties index c7cc9084..edc5371d 100644 --- a/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages_en.properties +++ b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages_en.properties @@ -26,6 +26,7 @@ windowtitle.save=Save signature data windowtitle.savedir=Save signature data to directory windowtitle.overwrite=Overwrite file? windowtitle.viewer=Signature data +windowtitle.help=Help message.wait=Please wait... message.insertcard=Please insert your citizen-card into the reader message.enterpin=Enter {0} @@ -34,6 +35,7 @@ message.hashdata=Signature data: message.hashdatalist={0} signature data objects: message.retries={0} tries left message.overwrite=Overwrite {0}? +message.help=Help topic {0} label.pin={0}: label.pinsize=({0} digits) button.ok=OK @@ -61,4 +63,17 @@ error.cardterminal=Could not find smartcard reader error.unknown=An error occured: {0} error.test=Error1 {0} - Error2 {1} error.card.locked=Citizen-card is locked -error.card.notactivated=Citizen-card not activated \ No newline at end of file +error.card.notactivated=Citizen-card not activated +error.viewer=Failed to display contents: {0} + +# Help Topics +help.welcome=Welcome page +help.wait=Wait screen +help.cardnotsupported=Unsupported citizen card +help.insertcard=No citizen card found +help.cardpin=Pin entry +help.signpin=Signature pin entry +help.retry=Wrong Pin +help.hashdata=Signed contents +help.hashdatalist=Signed contents +help.hashdataviewer=Display of signed contents \ No newline at end of file diff --git a/BKUCommonGUI/src/main/resources/images/help.png b/BKUCommonGUI/src/main/resources/images/help.png index 4ed65a97..5d6da3bf 100644 Binary files a/BKUCommonGUI/src/main/resources/images/help.png and b/BKUCommonGUI/src/main/resources/images/help.png differ diff --git a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java index c366cb76..af1368e5 100644 --- a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java +++ b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java @@ -176,7 +176,7 @@ public class BKUGUIWorker implements Runnable { // signedRefs.add(signedRef4); // signedRefs.add(signedRef4); // signedRefs = Collections.singletonList(signedRef1); - gui.showHashDataInputDialog(signedRefs, returnListener, "return"); + gui.showHashDataInputDialog(signedRefs, true, returnListener, "return"); } }; diff --git a/BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALServiceImpl.java b/BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALServiceImpl.java index 7faad548..05a3f5e5 100644 --- a/BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALServiceImpl.java +++ b/BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALServiceImpl.java @@ -64,10 +64,14 @@ public class STALServiceImpl implements STALPortType { protected static final Log log = LogFactory.getLog(STALServiceImpl.class); static { + if (log.isTraceEnabled()) { log.trace("enabling webservice communication dump"); System.setProperty("com.sun.xml.ws.transport.http.HttpAdapter.dump", "true"); + } else { + System.setProperty("com.sun.xml.ws.fault.SOAPFaultBuilder.disableCaptureStackTrace", "false"); } + } @Resource @@ -291,8 +295,8 @@ public class STALServiceImpl implements STALPortType { throw new GetHashDataInputFault(msg, faultInfo); } } else { - String msg = "Failed to get STAL for session " + sessionId; - log.error(msg); + String msg = "Session timeout"; //Failed to get STAL for session " + sessionId; + log.error(msg + " " + sessionId); GetHashDataInputFaultType faultInfo = new GetHashDataInputFaultType(); faultInfo.setErrorCode(1); faultInfo.setErrorMessage(msg); diff --git a/BKUOnline/src/test/java/at/gv/egiz/bku/online/conf/SSLConfigTest.java b/BKUOnline/src/test/java/at/gv/egiz/bku/online/conf/SSLConfigTest.java index 612480b2..eefaf5b6 100644 --- a/BKUOnline/src/test/java/at/gv/egiz/bku/online/conf/SSLConfigTest.java +++ b/BKUOnline/src/test/java/at/gv/egiz/bku/online/conf/SSLConfigTest.java @@ -11,6 +11,7 @@ import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; +@Ignore public class SSLConfigTest { private SpringConfigurator cfg; @@ -21,7 +22,7 @@ public class SSLConfigTest { ctx = new ClassPathXmlApplicationContext("applicationContext.xml"); } - + @Ignore @Test public void testConnect() throws Exception { diff --git a/STALService/pom.xml b/STALService/pom.xml index e9c573f1..db126b3c 100644 --- a/STALService/pom.xml +++ b/STALService/pom.xml @@ -18,10 +18,10 @@ STAL 1.0-SNAPSHOT - + \ No newline at end of file diff --git a/STALService/src/main/java/at/gv/egiz/stal/util/HashDataInputProxy.java b/STALService/src/main/java/at/gv/egiz/stal/util/HashDataInputProxy.java deleted file mode 100644 index 01d207d2..00000000 --- a/STALService/src/main/java/at/gv/egiz/stal/util/HashDataInputProxy.java +++ /dev/null @@ -1,67 +0,0 @@ -package at.gv.egiz.stal.util; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import at.gv.egiz.bku.utils.StreamUtil; -import at.gv.egiz.stal.HashDataInput; - -/** - * Enables multiple read requests. - * @deprecated use at.gv.egiz.stal.impl.ByteArrayHashDataInput - */ -public class HashDataInputProxy implements HashDataInput { - - private static Log log = LogFactory.getLog(HashDataInputProxy.class); - - private HashDataInput delegate; - private byte[] hashInput; - - /** - * - * @param delegate - * != null - */ - public HashDataInputProxy(HashDataInput delegate) { - if (delegate == null) { - throw new NullPointerException("Constructor argument must not be null"); - } - this.delegate = delegate; - } - - @Override - public String getEncoding() { - return delegate.getEncoding(); - } - - @Override - public InputStream getHashDataInput() { - if (hashInput == null) { - ByteArrayOutputStream os = new ByteArrayOutputStream(); - try { - StreamUtil.copyStream(delegate.getHashDataInput(), os); - hashInput = os.toByteArray(); - } catch (IOException e) { - log.error("Cannot access hashdatainput stream", e); - hashInput = new byte[0]; - } - } - return new ByteArrayInputStream(hashInput); - } - - @Override - public String getMimeType() { - return delegate.getMimeType(); - } - - @Override - public String getReferenceId() { - return delegate.getReferenceId(); - } - -} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/HashDataInputDisplay.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/HashDataInputDisplay.java index f79a2027..59700d4a 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/HashDataInputDisplay.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/HashDataInputDisplay.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.smccstal; @@ -14,7 +26,11 @@ import java.util.List; */ public interface HashDataInputDisplay { + /** + * TODO: (see AbstractHelpListener) + * + * * Displays the hashdata inputs for all provided dsig:SignedReferences. * Implementations may verify the digest value if necessary. * (LocalSignRequestHandler operates on DataObjectHashDataInput, diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java index 6c30a68a..77ee45b6 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SignRequestHandler.java @@ -192,7 +192,7 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen - class STALPinProvider implements PINProvider, ActionListener { + class STALPinProvider implements PINProvider { protected SignedInfoType signedInfo; protected List hashDataInputs; @@ -230,10 +230,10 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen displayHashDataInputs(signedInfo.getReference()); } catch (DigestException ex) { log.error("Bad digest value: " + ex.getMessage()); - gui.showErrorDialog(BKUGUIFacade.ERR_INVALID_HASH, new Object[] {ex.getMessage()}); + gui.showErrorDialog(BKUGUIFacade.ERR_INVALID_HASH, new Object[] {ex.getMessage()}, SignRequestHandler.this, "error"); } catch (Exception ex) { log.error("Could not display hashdata inputs: " + ex.getMessage()); - gui.showErrorDialog(BKUGUIFacade.ERR_DISPLAY_HASHDATA, new Object[] {ex.getMessage()}, SignRequestHandler.this, "ok"); + gui.showErrorDialog(BKUGUIFacade.ERR_DISPLAY_HASHDATA, new Object[] {ex.getMessage()}, SignRequestHandler.this, "error"); } // OLD HASHDATA DISPLAY (in applet), @@ -261,13 +261,15 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen return new String(gui.getPin()); } else if (actionCommand.equals("ok")) { showSignaturePINDialog(spec, retries); + } else if (actionCommand.equals("error")) { + return null; } } while (true); } - @Override - public void actionPerformed(ActionEvent e) { - throw new UnsupportedOperationException("Not supported yet."); - } +// @Override +// public void actionPerformed(ActionEvent e) { +// throw new UnsupportedOperationException("Not supported yet."); +// } } } -- cgit v1.2.3 From 959130f29903568c6b7fe3d6538b33887b3b1aaf Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 27 Nov 2008 15:22:32 +0000 Subject: help viewer label removed git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@221 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/gui/AbstractHelpListener.java | 5 ++- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 7 ++-- .../at/gv/egiz/bku/gui/DefaultHelpListener.java | 8 ++-- .../main/java/at/gv/egiz/bku/gui/HelpViewer.java | 43 ++++++++++++---------- .../at/gv/egiz/bku/gui/Messages.properties | 2 +- .../at/gv/egiz/bku/gui/Messages_en.properties | 14 +++---- .../at/gv/egiz/bku/local/stal/BKUGuiProxy.java | 7 ---- 7 files changed, 42 insertions(+), 44 deletions(-) (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java index f46f5227..b871263e 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java @@ -30,6 +30,9 @@ import org.apache.commons.logging.LogFactory; * This class does not keep a GUI reference and subclasses should not interfere with the GUI. * Therefore, any errors occurring in showDocument() should be handled/displayed within * showDocument() and exceptions thrown from showDocument() are logged, not displayed in the GUI. + *
+ * The help URL is build as [baseURL]/[locale]/[helpTopic].html + * (note that no session information is contained). * * @author Clemens Orthacker */ @@ -41,7 +44,7 @@ public abstract class AbstractHelpListener implements ActionListener { protected ResourceBundle messages; public AbstractHelpListener(URL baseURL, Locale locale) { - if (baseURL == null || "".equals(baseURL)) { + if (baseURL == null || "".equals(baseURL.toString())) { throw new RuntimeException("no help URL provided"); } this.baseURL = baseURL; diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java index c786a291..d61c9a03 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java @@ -58,9 +58,6 @@ import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; -import javax.swing.table.TableCellRenderer; -import javax.swing.table.TableColumn; -import javax.swing.table.TableModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -117,7 +114,9 @@ public class BKUGUIImpl implements BKUGUIFacade { this.contentPane = contentPane; if (locale != null) { - messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, locale); + Locale lang = new Locale(locale.getLanguage().substring(0,2)); + log.debug("loading applet resources for language: " + lang.toString()); + messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, lang); } else { messages = ResourceBundle.getBundle(MESSAGES_BUNDLE); } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java index 3c8c7d6c..c8594fe1 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/DefaultHelpListener.java @@ -57,10 +57,10 @@ public class DefaultHelpListener extends AbstractHelpListener { /** * blocks until help viewer returns (is closed) * @param helpURL - * @param helpTopic + * @param helpTopic ignored */ @Override - public void showDocument(final URL helpURL, final String helpTopic) { + public void showDocument(final URL helpURL, final String helpTopic) { // try { log.debug("schedule help dialog"); @@ -72,9 +72,9 @@ public class DefaultHelpListener extends AbstractHelpListener { log.debug("show help dialog"); if (ctx == null) { - HelpViewer.showHelpDialog(helpURL, helpTopic, messages); + HelpViewer.showHelpDialog(helpURL, messages); // helpTopic, messages); } else { - HelpViewer.showHelpDialog(ctx, helpURL, helpTopic, messages); + HelpViewer.showHelpDialog(ctx, helpURL, messages); //helpTopic, messages); } } }); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java index 0fef3f75..364da6ec 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpViewer.java @@ -32,7 +32,6 @@ import javax.swing.GroupLayout; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JEditorPane; -import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; @@ -64,45 +63,44 @@ public class HelpViewer extends JDialog */ public static void showHelpDialog(AppletContext ctx, URL helpURL, - String helpTopic, +// String helpTopic, ResourceBundle messages) { - showHelpDialog(null, ctx, helpURL, helpTopic, messages); + showHelpDialog(null, ctx, helpURL, messages); //helpTopic, messages); } public static void showHelpDialog(URL helpURL, - String helpTopic, +// String helpTopic, ResourceBundle messages) { - showHelpDialog(null, null, helpURL, helpTopic, messages); + showHelpDialog(null, null, helpURL, messages); // helpTopic, messages); } public static void showHelpDialog(Component owner, AppletContext ctx, URL helpURL, - String helpTopic, +// String helpTopic, ResourceBundle messages) { Frame frame = null; if (owner != null) { JOptionPane.getFrameForComponent(owner); } - dialog = new HelpViewer(frame, messages, ctx, helpURL, helpTopic); + dialog = new HelpViewer(frame, messages, ctx, helpURL); //, helpTopic); dialog.setVisible(true); } private HelpViewer(Frame frame, ResourceBundle messages, AppletContext ctx, - URL helpURL, - String helpTopic) { + URL helpURL) { //, String helpTopic) { super(frame, messages.getString(BKUGUIFacade.WINDOWTITLE_HELP), true); this.messages = messages; this.ctx = ctx; - String p = messages.getString(BKUGUIFacade.MESSAGE_HELP); - String helpItem = messages.getString(helpTopic); - String viewerLabel = MessageFormat.format(p, new Object[]{helpItem}); +// String p = messages.getString(BKUGUIFacade.MESSAGE_HELP); +// String helpItem = messages.getString(helpTopic); +// String viewerLabel = MessageFormat.format(p, new Object[]{helpItem}); - JPanel helpPanel = createViewerPanel(viewerLabel, helpURL); + JPanel helpPanel = createViewerPanel(helpURL); //viewerLabel, helpURL); JPanel buttonPanel = createButtonPanel(); initContentPane(new Dimension(600, 600), helpPanel, buttonPanel); @@ -128,7 +126,7 @@ public class HelpViewer extends JDialog mainLayout.createSequentialGroup().addContainerGap().addComponent(viewerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(buttonPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addContainerGap()); } - private JPanel createViewerPanel(String viewerLabelText, URL helpURL) { + private JPanel createViewerPanel(URL helpURL) { //String viewerLabelText, log.debug("viewer dialog: " + helpURL.toString()); final JEditorPane viewer = new JEditorPane(); @@ -170,19 +168,24 @@ public class HelpViewer extends JDialog scrollPane.setAlignmentX(LEFT_ALIGNMENT); viewer.setCaretPosition(0); - JLabel viewerLabel = new JLabel(); - viewerLabel.setText(viewerLabelText); - viewerLabel.setFont(viewerLabel.getFont().deriveFont(viewerLabel.getFont().getStyle() | java.awt.Font.BOLD)); - viewerLabel.setLabelFor(viewer); +// JLabel viewerLabel = new JLabel(); +// viewerLabel.setText(viewerLabelText); +// viewerLabel.setFont(viewerLabel.getFont().deriveFont(viewerLabel.getFont().getStyle() | java.awt.Font.BOLD)); +// viewerLabel.setLabelFor(viewer); JPanel viewerPanel = new JPanel(); GroupLayout viewerPanelLayout = new GroupLayout(viewerPanel); viewerPanel.setLayout(viewerPanelLayout); viewerPanelLayout.setHorizontalGroup( - viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(viewerLabel).addComponent(scrollPane)); + viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addComponent(viewerLabel) + .addComponent(scrollPane)); viewerPanelLayout.setVerticalGroup( - viewerPanelLayout.createSequentialGroup().addComponent(viewerLabel).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(scrollPane)); + viewerPanelLayout.createSequentialGroup() +// .addComponent(viewerLabel) +// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(scrollPane)); return viewerPanel; } diff --git a/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages.properties b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages.properties index a7363421..e5315c8d 100644 --- a/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages.properties +++ b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages.properties @@ -27,7 +27,7 @@ windowtitle.save=Signaturdaten speichern windowtitle.savedir=Signaturdaten in Verzeichnis speichern windowtitle.overwrite=Datei \u00FCberschreiben? windowtitle.viewer=Signaturedaten -windowtitle.help=Hilfe +windowtitle.help=Hilfe zur B\u00FCrgerkarte message.wait=Bitte warten... message.insertcard=Bitte die B\u00FCrgerkarte in den Kartenleser stecken message.enterpin={0} eingeben diff --git a/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages_en.properties b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages_en.properties index 7aae8eae..96f99a8a 100644 --- a/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages_en.properties +++ b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/Messages_en.properties @@ -14,7 +14,7 @@ # limitations under the License. title.welcome=Welcome -title.insertcard=No citizencard found +title.insertcard=No citizen card found title.cardnotsupported=This card is not supported #title.cardpin=Enter {0} title.cardpin=Reading card @@ -27,9 +27,9 @@ windowtitle.save=Save signature data windowtitle.savedir=Save signature data to directory windowtitle.overwrite=Overwrite file? windowtitle.viewer=Signature data -windowtitle.help=Help +windowtitle.help=Citizen card help message.wait=Please wait... -message.insertcard=Please insert your citizencard into the reader +message.insertcard=Please insert your citizen card into the reader message.enterpin=Enter {0} message.hashdatalink=Display signature data #message.hashdata=Remark: This is a preview of the data to-be signed. For standards compliant display see help. @@ -65,16 +65,16 @@ error.pcsc=No PC/SC interface for smartcard access provided error.cardterminal=Could not find smartcard reader error.unknown=An error occured: {0} error.test=Error1 {0} - Error2 {1} -error.card.locked=Citizencard is locked -error.card.notactivated=Citizencard not activated +error.card.locked=Citizen card is locked +error.card.notactivated=Citizen card not activated error.viewer=Failed to display contents: {0} error.external.link=Externer Link {0} wird nicht ge\u00F6ffnet # Help Topics help.welcome=Welcome page help.wait=Wait screen -help.cardnotsupported=Unsupported citizencard -help.insertcard=No citizencard found +help.cardnotsupported=Unsupported citizen card +help.insertcard=No citizen card found help.cardpin=Pin entry help.signpin=Signature pin entry help.retry=Wrong Pin diff --git a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/BKUGuiProxy.java b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/BKUGuiProxy.java index eaa4d6ad..a28ee1eb 100644 --- a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/BKUGuiProxy.java +++ b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/BKUGuiProxy.java @@ -1,13 +1,6 @@ package at.gv.egiz.bku.local.stal; -import java.awt.Container; -import java.awt.EventQueue; -import java.awt.Toolkit; import java.awt.event.ActionListener; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.awt.event.WindowEvent; -import java.net.URL; import java.util.List; import java.util.Locale; -- cgit v1.2.3 From 145003155c05e915b900989a27cef1271398164b Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 26 Aug 2009 17:31:32 +0000 Subject: MOCCA TLS Server CA cert installation servlet removed help.jsp (and jsp dependencies in jetty) moved html pages to src/main/webapp (encoding problem?) switch to BASIC download protocol in BKUWebStart (no jnlpDownloadServlet required, see template.xml) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@474 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/gui/AbstractHelpListener.java | 17 +- BKUHelp/pom.xml | 9 +- BKULocal/pom.xml | 2 +- .../local/webapp/InstallCertificateServlet.java | 149 +++++++++++++++ BKULocal/src/main/webapp/WEB-INF/web.xml | 19 +- BKULocal/src/main/webapp/img/chip16.ico | Bin 0 -> 1150 bytes BKULocal/src/main/webapp/img/chip48.png | Bin 0 -> 2771 bytes BKULocal/src/main/webapp/index.html | 56 ++++-- BKUOnline/pom.xml | 7 +- BKUWebStart/pom.xml | 28 +-- .../java/at/gv/egiz/bku/webstart/Configurator.java | 2 +- .../java/at/gv/egiz/bku/webstart/Container.java | 210 +++++++++++++-------- .../java/at/gv/egiz/bku/webstart/Launcher.java | 7 +- .../java/at/gv/egiz/bku/webstart/TLSServerCA.java | 3 +- BKUWebStart/src/main/jnlp/resources/version.xml | 35 ---- BKUWebStart/src/main/jnlp/template.xml | 22 +-- 16 files changed, 387 insertions(+), 179 deletions(-) create mode 100644 BKULocal/src/main/java/at/gv/egiz/bku/local/webapp/InstallCertificateServlet.java create mode 100644 BKULocal/src/main/webapp/img/chip16.ico create mode 100644 BKULocal/src/main/webapp/img/chip48.png (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java index b871263e..6fd1ffea 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/AbstractHelpListener.java @@ -38,6 +38,11 @@ import org.apache.commons.logging.LogFactory; */ public abstract class AbstractHelpListener implements ActionListener { + /** + * any locale not in the list will be mapped to 'de' + */ + public static final String[] SUPPORTED_LANGUAGES = new String[] { "de" }; + protected final static Log log = LogFactory.getLog(AbstractHelpListener.class); protected URL baseURL; protected Locale locale; @@ -71,12 +76,14 @@ public abstract class AbstractHelpListener implements ActionListener { URL helpURL = baseURL; log.trace("constructing help URL: " + helpURL); try { - if (locale != null) { - helpURL = new URL(helpURL, locale.toString() + "/"); - log.trace("constructing help URL: " + helpURL); - } + // not localized for now + //check if locale.getLanguage() supported and add default if not +// if (locale != null) { +// helpURL = new URL(helpURL, locale.toString() + "/"); +// log.trace("constructing help URL: " + helpURL); +// } if (helpTopic != null && !"".equals(helpTopic)) { - helpURL = new URL(helpURL, helpTopic + ".html"); + helpURL = new URL(helpURL, "de/" + helpTopic + ".html"); log.trace("constructing help URL: " + helpURL); } } catch (MalformedURLException ex) { diff --git a/BKUHelp/pom.xml b/BKUHelp/pom.xml index ec2ad47d..6dbfd55f 100644 --- a/BKUHelp/pom.xml +++ b/BKUHelp/pom.xml @@ -7,6 +7,13 @@ at.gv.egiz BKUHelp - 1.1 + 1.2-SNAPSHOT BKU Help + + + + src/main/webapp + + + \ No newline at end of file diff --git a/BKULocal/pom.xml b/BKULocal/pom.xml index 523357f2..b3487f68 100644 --- a/BKULocal/pom.xml +++ b/BKULocal/pom.xml @@ -111,7 +111,7 @@ BKUHelp at.gv.egiz - 1.1 + 1.2-SNAPSHOT org.springframework diff --git a/BKULocal/src/main/java/at/gv/egiz/bku/local/webapp/InstallCertificateServlet.java b/BKULocal/src/main/java/at/gv/egiz/bku/local/webapp/InstallCertificateServlet.java new file mode 100644 index 00000000..0a9d001b --- /dev/null +++ b/BKULocal/src/main/java/at/gv/egiz/bku/local/webapp/InstallCertificateServlet.java @@ -0,0 +1,149 @@ +/* + * 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.local.webapp; + +import iaik.pkcs.PKCS7CertList; +import iaik.utils.Util; +import java.io.IOException; +import java.security.cert.Certificate; +import java.security.cert.CertificateException; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * @author Clemens Orthacker + */ +public class InstallCertificateServlet extends HttpServlet { + public static final String HTTPS_REDIRECT = "https://localhost:3496/"; + + public static final String SERVER_CA_CERTIFICATE_ATTRIBUTE = "mocca.tls.server.ca.certificate"; + protected PKCS7CertList p7c; + private static final Log log = LogFactory.getLog(InstallCertificateServlet.class); + + @Override + public void init() throws ServletException { + super.init(); + Certificate caCert = (Certificate) getServletContext().getAttribute(SERVER_CA_CERTIFICATE_ATTRIBUTE); + if (caCert != null) { + try { + p7c = new PKCS7CertList(); + p7c.setCertificateList(new iaik.x509.X509Certificate[] { Util.convertCertificate(caCert) }); + } catch (CertificateException ex) { + log.error("failed to import local ca certificate " + SERVER_CA_CERTIFICATE_ATTRIBUTE, ex); + } + } else { + log.error("failed to import local ca certificate " + SERVER_CA_CERTIFICATE_ATTRIBUTE); + } + } + + /** + * Processes requests for both HTTP GET and POST methods. + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + +// try { +// SSLContext sslCtx1 = SSLContext.getDefault(); +// log.debug("Default SSLContext (" + sslCtx1.getProtocol() + "): " + sslCtx1.getClass().getName()); +// } catch (NoSuchAlgorithmException ex) { +// log.debug("no sslContext: " + ex.getMessage(), ex); +// } +// +// try { +// SSLContext sslCtx2 = SSLContext.getInstance("TLS"); +// log.debug("TLS SSLContext: " + sslCtx2.getClass().getName()); +// +// SSLServerSocketFactory serverSocketFactory = sslCtx2.getServerSocketFactory(); +// SSLSessionContext serverSessionContext = sslCtx2.getServerSessionContext(); +// +// if (serverSocketFactory != null) { +// log.debug("SSL ServerSocketFactory: " + serverSocketFactory.getClass().getName()); +// } +// if (serverSessionContext != null) { +// log.debug("SSL ServerSessionContext: " + serverSessionContext.getClass().getName()); +// } +// } catch (NoSuchAlgorithmException ex) { +// log.debug("no sslContext: " + ex.getMessage(), ex); +// } +// +// try { +// SSLContext sslCtx3 = SSLContext.getInstance("SSLv3"); +// log.debug("TLS SSLContext: " + sslCtx3.getClass().getName()); +// } catch (NoSuchAlgorithmException ex) { +// log.debug("no sslContext: " + ex.getMessage(), ex); +// } + + + + + + if (p7c != null) { + log.debug("returning local ca certificate"); + response.setContentType("application/x-x509-ca-cert"); + p7c.writeTo(response.getOutputStream()); + response.getOutputStream().flush(); + } else { + log.debug("no local ca certificate, redirecting to " + HTTPS_REDIRECT); + response.sendRedirect(HTTPS_REDIRECT); + } + + } + + // + /** + * Handles the HTTP GET method. + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// +} diff --git a/BKULocal/src/main/webapp/WEB-INF/web.xml b/BKULocal/src/main/webapp/WEB-INF/web.xml index 83f33d9e..8768dbd8 100644 --- a/BKULocal/src/main/webapp/WEB-INF/web.xml +++ b/BKULocal/src/main/webapp/WEB-INF/web.xml @@ -1,5 +1,4 @@ - - + http-security-layer-request @@ -35,15 +34,15 @@ BKUServlet at.gv.egiz.bku.local.webapp.BKURequestHandler - - - help - /help.jsp PINManagementServlet at.gv.egiz.bku.local.webapp.PINManagementServlet + + InstallCertificateServlet + at.gv.egiz.bku.local.webapp.InstallCertificateServlet + BKUServlet /http-security-layer-request @@ -52,16 +51,16 @@ BKUServlet /https-security-layer-request - - help - /help/* - PINManagementServlet /PINManagement + + InstallCertificateServlet + /installCertificate + index.html index.htm diff --git a/BKULocal/src/main/webapp/img/chip16.ico b/BKULocal/src/main/webapp/img/chip16.ico new file mode 100644 index 00000000..42175127 Binary files /dev/null and b/BKULocal/src/main/webapp/img/chip16.ico differ diff --git a/BKULocal/src/main/webapp/img/chip48.png b/BKULocal/src/main/webapp/img/chip48.png new file mode 100644 index 00000000..491fbcac Binary files /dev/null and b/BKULocal/src/main/webapp/img/chip48.png differ diff --git a/BKULocal/src/main/webapp/index.html b/BKULocal/src/main/webapp/index.html index 537c154a..6aefe43c 100644 --- a/BKULocal/src/main/webapp/index.html +++ b/BKULocal/src/main/webapp/index.html @@ -14,21 +14,45 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - - BKU Web Start - Willkommen - - - - -

BKU Web Start - Willkommen

-
-

Diese Seite installiert das MOCCA Zertifikat in ihrem Browser. - In jedem weiteren Browser können sie dieses durch Aufruf dieser Seite ebenso installieren.

-
-
- PIN Verwaltung + + + + + Bürgerkarte - Willkommen + + + + + + +
+ +
+
+ Logo
- +

Um die Bürgerkartenumgebung zu verwenden installieren Sie bitte + zunächst das CA Zertifikat. +

+ +

Weiters können Sie

+ + +


+ +
+ +
+ + diff --git a/BKUOnline/pom.xml b/BKUOnline/pom.xml index f03bc792..9fc36d63 100644 --- a/BKUOnline/pom.xml +++ b/BKUOnline/pom.xml @@ -39,7 +39,7 @@ BKUHelp at.gv.egiz - 1.1 + 1.2-SNAPSHOT commons-logging @@ -302,12 +302,13 @@ - + webstart-maven-plugin @@ -98,8 +100,8 @@ false - - true + false + false true true @@ -190,9 +192,6 @@ false - true - - true @@ -212,7 +211,6 @@ template-local.xml mocca-local.jnlp - false @@ -221,6 +219,14 @@ + at.gv.egiz BKULocal @@ -259,12 +265,12 @@ + | org.mortbay.jetty jsp-2.1-jetty 6.1.19 - + org.slf4j slf4j-api diff --git a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Configurator.java b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Configurator.java index bef2246b..923a70d9 100644 --- a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Configurator.java +++ b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Configurator.java @@ -56,7 +56,7 @@ public class Configurator { * configurations with less than this (major) version will be backuped and updated * allowed: MAJOR[.MINOR[.X[-SNAPSHOT]]] */ - public static final String MIN_CONFIG_VERSION = "1.0.9"; + public static final String MIN_CONFIG_VERSION = "1.2.4-SNAPSHOT"; public static final String CONFIG_DIR = ".mocca/conf/"; public static final String CERTS_DIR = ".mocca/certs/"; public static final String VERSION_FILE = ".version"; diff --git a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Container.java b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Container.java index 08a0808a..3bf74d3c 100644 --- a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Container.java +++ b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Container.java @@ -2,9 +2,11 @@ package at.gv.egiz.bku.webstart; import at.gv.egiz.bku.utils.StreamUtil; import java.awt.AWTPermission; +import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FilePermission; @@ -15,8 +17,12 @@ import java.io.OutputStream; import java.lang.reflect.ReflectPermission; import java.net.NetPermission; import java.net.SocketPermission; +import java.security.AllPermission; +import java.security.KeyStore; import java.security.Permissions; import java.security.SecurityPermission; +import java.security.cert.Certificate; +import java.security.cert.CertificateException; import java.util.PropertyPermission; import javax.smartcardio.CardPermission; import org.apache.commons.logging.Log; @@ -32,8 +38,9 @@ public class Container { public static final String HTTP_PORT_PROPERTY = "mocca.http.port"; public static final String HTTPS_PORT_PROPERTY = "mocca.http.port"; - + public static final String SERVER_CA_CERTIFICATE_ATTRIBUTE = "mocca.tls.server.ca.certificate"; private static Log log = LogFactory.getLog(Container.class); + static { if (log.isDebugEnabled()) { //Jetty log INFO and WARN, include ignored exceptions @@ -43,7 +50,6 @@ public class Container { //System.setProperty("DEBUG", "true"); } } - private Server server; public void init() throws IOException { @@ -75,63 +81,98 @@ public class Container { } log.debug("loading MOCCA keystore from " + keystoreFile.getAbsolutePath()); sslConnector.setKeystore(keystoreFile.getAbsolutePath()); - File passwdFile = new File(configDir, Configurator.PASSWD_FILE); - BufferedReader reader = new BufferedReader(new FileReader(passwdFile)); - String pwd; - while ((pwd = reader.readLine()) != null) { - sslConnector.setPassword(pwd); - sslConnector.setKeyPassword(pwd); - } - reader.close(); - + String passwd = readPassword(new File(configDir, Configurator.PASSWD_FILE)); + sslConnector.setPassword(passwd); + sslConnector.setKeyPassword(passwd); + //avoid jetty's ClassCastException: iaik.security.ecc.ecdsa.ECPublicKey cannot be cast to java.security.interfaces.ECPublicKey - String[] RFC4492CipherSuites = new String[] { + String[] RFC4492CipherSuites = new String[]{ "TLS_ECDH_ECDSA_WITH_NULL_SHA", - "TLS_ECDH_ECDSA_WITH_RC4_128_SHA", - "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA", - "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA", - "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA", - - "TLS_ECDHE_ECDSA_WITH_NULL_SHA", - "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA", - "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA", - "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", - "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", - - "TLS_ECDH_RSA_WITH_NULL_SHA", - "TLS_ECDH_RSA_WITH_RC4_128_SHA", - "TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA", - "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA", - "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA", - - "TLS_ECDHE_RSA_WITH_NULL_SHA", - "TLS_ECDHE_RSA_WITH_RC4_128_SHA", - "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA", - "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", - "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", - - "TLS_ECDH_anon_WITH_NULL_SHA", - "TLS_ECDH_anon_WITH_RC4_128_SHA", - "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA", - "TLS_ECDH_anon_WITH_AES_128_CBC_SHA", - "TLS_ECDH_anon_WITH_AES_256_CBC_SHA" + "TLS_ECDH_ECDSA_WITH_RC4_128_SHA", + "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA", + "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA", + "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA", + "TLS_ECDHE_ECDSA_WITH_NULL_SHA", + "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA", + "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA", + "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", + "TLS_ECDH_RSA_WITH_NULL_SHA", + "TLS_ECDH_RSA_WITH_RC4_128_SHA", + "TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA", + "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA", + "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA", + "TLS_ECDHE_RSA_WITH_NULL_SHA", + "TLS_ECDHE_RSA_WITH_RC4_128_SHA", + "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", + "TLS_ECDH_anon_WITH_NULL_SHA", + "TLS_ECDH_anon_WITH_RC4_128_SHA", + "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA", + "TLS_ECDH_anon_WITH_AES_128_CBC_SHA", + "TLS_ECDH_anon_WITH_AES_256_CBC_SHA" }; sslConnector.setExcludeCipherSuites(RFC4492CipherSuites); - server.setConnectors(new Connector[] { connector, sslConnector }); - + server.setConnectors(new Connector[]{connector, sslConnector}); + WebAppContext webapp = new WebAppContext(); webapp.setLogUrlOnStart(true); webapp.setContextPath("/"); - webapp.setExtractWAR(true); + webapp.setExtractWAR(true); webapp.setParentLoaderPriority(false); + try { + // no way to get certificate from within the servlet (SSLEngine/Jetty SSLSocketConnector/SSLContext?) + if (log.isTraceEnabled()) { + log.trace("local ca certificate from " + keystoreFile + " in webapp context at " + SERVER_CA_CERTIFICATE_ATTRIBUTE); + } + BufferedInputStream bis = new BufferedInputStream(new FileInputStream(keystoreFile)); + KeyStore sslKeyStore = KeyStore.getInstance("JKS"); + sslKeyStore.load(bis, passwd.toCharArray()); + Certificate[] sslChain = sslKeyStore.getCertificateChain(TLSServerCA.MOCCA_TLS_SERVER_ALIAS); + webapp.setAttribute(SERVER_CA_CERTIFICATE_ATTRIBUTE, sslChain[sslChain.length - 1]); + bis.close(); + } catch (Exception ex) { + log.error("Failed to load local ca certificate", ex); + log.warn("automated web certificate installation will not be available"); + } + webapp.setWar(copyWebapp(webapp.getTempDirectory())); webapp.setPermissions(getPermissions(webapp.getTempDirectory())); - + server.setHandler(webapp); - server.setGracefulShutdown(1000*3); + server.setGracefulShutdown(1000 * 3); + } + + /** + * @return The first valid (not empty, no comment) line of the passwd file + * @throws IOException + */ + protected static String readPassword(File passwdFile) throws IOException { + if (passwdFile.exists() && passwdFile.canRead()) { + BufferedReader passwdReader = null; + try { + passwdReader = new BufferedReader(new FileReader(passwdFile)); + String passwd; + while ((passwd = passwdReader.readLine().trim()) != null) { + if (passwd.length() > 0 && !passwd.startsWith("#")) { + return passwd; + } + } + } catch (IOException ex) { + log.error("failed to read password from " + passwdFile, ex); + throw ex; + } finally { + try { + passwdReader.close(); + } catch (IOException ex) { + } + } + } + throw new IOException(passwdFile + " not readable"); } private String copyWebapp(File webappDir) throws IOException { @@ -146,43 +187,48 @@ public class Container { private Permissions getPermissions(File webappDir) { Permissions perms = new Permissions(); + perms.add(new AllPermission()); + + + if (false) { + + // jetty-webstart (spring?) + perms.add(new RuntimePermission("getClassLoader")); + + // standard permissions + perms.add(new PropertyPermission("*", "read,write")); + perms.add(new RuntimePermission("accessDeclaredMembers")); + perms.add(new RuntimePermission("accessClassInPackage.*")); + perms.add(new RuntimePermission("defineClassInPackage.*")); + perms.add(new RuntimePermission("setFactory")); + perms.add(new RuntimePermission("getProtectionDomain")); + perms.add(new RuntimePermission("modifyThread")); + perms.add(new RuntimePermission("modifyThreadGroup")); + perms.add(new RuntimePermission("setFactory")); + perms.add(new ReflectPermission("suppressAccessChecks")); + + // MOCCA specific + perms.add(new SocketPermission("*", "connect,resolve")); + perms.add(new NetPermission("specifyStreamHandler")); + perms.add(new SecurityPermission("insertProvider.*")); + perms.add(new SecurityPermission("putProviderProperty.*")); + perms.add(new SecurityPermission("removeProvider.*")); + perms.add(new CardPermission("*", "*")); + perms.add(new AWTPermission("*")); + + perms.add(new FilePermission(webappDir.getAbsolutePath() + "/-", "read")); + perms.add(new FilePermission(new File(System.getProperty("java.home") + "/lib/xalan.properties").getAbsolutePath(), "read")); + perms.add(new FilePermission(new File(System.getProperty("java.home") + "/lib/xerces.properties").getAbsolutePath(), "read")); + perms.add(new FilePermission(new File(System.getProperty("user.home")).getAbsolutePath(), "read, write")); + perms.add(new FilePermission(new File(System.getProperty("user.home") + "/-").getAbsolutePath(), "read, write")); + perms.add(new FilePermission(new File(System.getProperty("user.home") + "/.mocca/logs/*").getAbsolutePath(), "read, write,delete")); + perms.add(new FilePermission(new File(System.getProperty("user.home") + "/.mocca/certs/-").getAbsolutePath(), "read, write,delete")); + + //TODO +// log.trace("granting file read/write permission to MOCCA local"); +// perms.add(new FilePermission("<>", "read, write")); - // jetty-webstart (spring?) - perms.add(new RuntimePermission("getClassLoader")); - - // standard permissions - perms.add(new PropertyPermission("*", "read,write")); - perms.add(new RuntimePermission("accessDeclaredMembers")); - perms.add(new RuntimePermission("accessClassInPackage.*")); - perms.add(new RuntimePermission("defineClassInPackage.*")); - perms.add(new RuntimePermission("setFactory")); - perms.add(new RuntimePermission("getProtectionDomain")); - perms.add(new RuntimePermission("modifyThread")); - perms.add(new RuntimePermission("modifyThreadGroup")); - perms.add(new RuntimePermission("setFactory")); - perms.add(new ReflectPermission("suppressAccessChecks")); - - // MOCCA specific - perms.add(new SocketPermission("*", "connect,resolve")); - perms.add(new NetPermission("specifyStreamHandler")); - perms.add(new SecurityPermission("insertProvider.*")); - perms.add(new SecurityPermission("putProviderProperty.*")); - perms.add(new SecurityPermission("removeProvider.*")); - perms.add(new CardPermission("*", "*")); - perms.add(new AWTPermission("*")); - - perms.add(new FilePermission(webappDir.getAbsolutePath() + "/-", "read")); - perms.add(new FilePermission(new File(System.getProperty("java.home") + "/lib/xalan.properties").getAbsolutePath(), "read")); - perms.add(new FilePermission(new File(System.getProperty("java.home") + "/lib/xerces.properties").getAbsolutePath(), "read")); - perms.add(new FilePermission(new File(System.getProperty("user.home")).getAbsolutePath(), "read, write")); - perms.add(new FilePermission(new File(System.getProperty("user.home") + "/-").getAbsolutePath(), "read, write")); - perms.add(new FilePermission(new File(System.getProperty("user.home") + "/.mocca/logs/*").getAbsolutePath(), "read, write,delete")); - perms.add(new FilePermission(new File(System.getProperty("user.home") + "/.mocca/certs/-").getAbsolutePath(), "read, write,delete")); - - //TODO - log.trace("granting file read/write permission to MOCCA local"); - perms.add(new FilePermission("<>", "read, write")); - + } return perms; } @@ -205,4 +251,4 @@ public class Container { public void join() throws InterruptedException { server.join(); } -} \ No newline at end of file +} diff --git a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Launcher.java b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Launcher.java index 0cfc14e5..0106de62 100644 --- a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Launcher.java +++ b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Launcher.java @@ -27,6 +27,7 @@ import java.awt.event.WindowAdapter; import java.net.BindException; import java.net.HttpURLConnection; import java.net.MalformedURLException; +import java.net.URI; import java.net.URL; import java.security.GeneralSecurityException; import java.util.jar.Attributes; @@ -73,21 +74,25 @@ public class Launcher implements BKUControllerInterface, ActionListener { /** local bku uri */ public static final URL HTTP_SECURITY_LAYER_URL; public static final URL HTTPS_SECURITY_LAYER_URL; + public static final URL INSTALL_CERT_URL; public static final URL PIN_MANAGEMENT_URL; static { URL http = null; URL https = null; URL pin = null; + URL cert = null; try { http = new URL("http://localhost:" + Integer.getInteger(Container.HTTPS_PORT_PROPERTY, 3495).intValue()); https = new URL("https://localhost:" + Integer.getInteger(Container.HTTPS_PORT_PROPERTY, 3496).intValue()); pin = new URL(http, "/PINManagement"); + cert = new URL(http, "/installCertificate"); } catch (MalformedURLException ex) { log.error(ex); } finally { HTTP_SECURITY_LAYER_URL = http; HTTPS_SECURITY_LAYER_URL = https; PIN_MANAGEMENT_URL = pin; + INSTALL_CERT_URL = cert; } } public static final String version; @@ -273,7 +278,7 @@ public class Launcher implements BKUControllerInterface, ActionListener { Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.BROWSE)) { try { - desktop.browse(HTTPS_SECURITY_LAYER_URL.toURI()); + desktop.browse(HTTP_SECURITY_LAYER_URL.toURI()); } catch (Exception ex) { log.error("failed to open system browser, install TLS certificate manually: " + HTTPS_SECURITY_LAYER_URL, ex); } diff --git a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/TLSServerCA.java b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/TLSServerCA.java index 97ca716b..fd94958e 100644 --- a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/TLSServerCA.java +++ b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/TLSServerCA.java @@ -32,6 +32,7 @@ import org.apache.commons.logging.LogFactory; public class TLSServerCA { public static final int CA_VALIDITY_Y = 3; + public static final String MOCCA_TLS_SERVER_ALIAS = "server"; public static final int SERVER_VALIDITY_Y = 3; private final static Log log = LogFactory.getLog(TLSServerCA.class); @@ -127,7 +128,7 @@ public class TLSServerCA { generateServerCert(); KeyStore ks = KeyStore.getInstance("JKS"); ks.load(null, null); - ks.setKeyEntry("server", serverKeyPair.getPrivate(), password, new X509Certificate[]{serverCert, caCert}); + ks.setKeyEntry(MOCCA_TLS_SERVER_ALIAS, serverKeyPair.getPrivate(), password, new X509Certificate[]{serverCert, caCert}); return ks; // } catch (Exception e) { // log.error("Cannot generate certificate", e); diff --git a/BKUWebStart/src/main/jnlp/resources/version.xml b/BKUWebStart/src/main/jnlp/resources/version.xml index 451fe038..5e504b68 100644 --- a/BKUWebStart/src/main/jnlp/resources/version.xml +++ b/BKUWebStart/src/main/jnlp/resources/version.xml @@ -89,41 +89,6 @@ servlet-api-2.5-20081211.jar - - - jsp-2.1-jetty-6.1.19.jar - 6.1.19 - - jsp-2.1-jetty-6.1.19.jar - - - - jsp-2.1-glassfish-9.1.1.B60.25.p0.jar - 9.1.1.B60.25.p0 - - jsp-2.1-glassfish-9.1.1.B60.25.p0.jar - - - - jsp-api-2.1-glassfish-9.1.1.B60.25.p0.jar - 9.1.1.B60.25.p0 - - jsp-api-2.1-glassfish-9.1.1.B60.25.p0.jar - - - - ant-1.6.5.jar - 1.6.5 - - ant-1.6.5.jar - - - - core-3.1.1.jar - 3.1.1 - - core-3.1.1.jar - slf4j-api-1.5.8.jar diff --git a/BKUWebStart/src/main/jnlp/template.xml b/BKUWebStart/src/main/jnlp/template.xml index a8ee0341..8181bc31 100644 --- a/BKUWebStart/src/main/jnlp/template.xml +++ b/BKUWebStart/src/main/jnlp/template.xml @@ -1,5 +1,5 @@ - + @@ -9,15 +9,15 @@ $project.Description (BKU) MOCCA Web Start $project.Description - - - - - - - - - + + + + + + + + + @@ -39,13 +39,11 @@ - $dependencies - $dependencies -- cgit v1.2.3