From 32d17447a258188b2d534bcb0bf65a659ba7b7d0 Mon Sep 17 00:00:00 2001 From: mcentner Date: Fri, 29 Aug 2008 12:11:34 +0000 Subject: Initial import. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@1 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../test/java/at/gv/egiz/bku/gui/BKUGUITest.java | 53 ++++++++ .../test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java | 136 +++++++++++++++++++++ 2 files changed, 189 insertions(+) create mode 100644 BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java create mode 100644 BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java (limited to 'BKUCommonGUI/src/test/java') diff --git a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java new file mode 100644 index 00000000..4dc1f8b3 --- /dev/null +++ b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java @@ -0,0 +1,53 @@ +/* +* Copyright 2008 Federal Chancellery Austria and +* Graz University of Technology +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package at.gv.egiz.bku.gui; + +import javax.swing.JFrame; +import org.junit.Ignore; +import org.junit.Test; + + +/** + * + * @author clemens + */ +public class BKUGUITest { + + @Ignore + public void testBKUGUI() { + JFrame testFrame = new JFrame("BKUGUITest"); + BKUGUI gui = new BKUGUI(); + gui.init(testFrame.getContentPane(), null); + BKUGUIWorker worker = new BKUGUIWorker(); + worker.init(gui); + testFrame.pack(); + testFrame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + testFrame.setVisible(true); + new Thread(worker).start(); + + while(true) ; + } + + @Test + public void dummyTest() { + } +} 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 new file mode 100644 index 00000000..50771216 --- /dev/null +++ b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java @@ -0,0 +1,136 @@ +/* +* Copyright 2008 Federal Chancellery Austria and +* Graz University of Technology +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package at.gv.egiz.bku.gui; + +import at.gv.egiz.smcc.PINSpec; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.Collections; + +/** + * + * @author clemens + */ +public class BKUGUIWorker implements Runnable { + + BKUGUIFacade gui; + + public void init(BKUGUIFacade gui) { + this.gui = gui; + } + + @Override + public void run() { + try { + + final PINSpec signPinSpec = new PINSpec(6, 10, "[0-9]", "Signatur-PIN"); + + + final ActionListener cancelListener = new ActionListener() { + + public void actionPerformed(ActionEvent e) { + System.out.println("CANCEL EVENT OCCURED: " + e); + } + }; + ActionListener okListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + System.out.println("OK EVENT OCCURED: " + e); + } + }; + final ActionListener signListener = new ActionListener() { + + public void actionPerformed(ActionEvent e) { + System.out.println("SIGN EVENT OCCURED: " + e); + } + }; + ActionListener hashdataListener = new ActionListener() { + + public void actionPerformed(ActionEvent e) { + System.out.println("HASHDATA EVENT OCCURED: " + e); + ActionListener returnListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + gui.showSignaturePINDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", null, "hashdata"); + } + }; + HashDataInput signedRef = new HashDataInput() { + + @Override + public InputStream getHashDataInput() { + return new ByteArrayInputStream("HashDataInput_002".getBytes()); + } + + @Override + public String getMimeType() { + return "text/xml"; + } + }; + gui.showHashDataInputDialog(Collections.singletonList(signedRef), returnListener, "return"); + } + }; + + + +// gui.showWelcomeDialog(); +// +// Thread.sleep(2000); + + gui.showInsertCardDialog(cancelListener, "cancel"); + + Thread.sleep(2000); + + gui.showCardNotSupportedDialog(cancelListener, "cancel"); + + Thread.sleep(2000); + +// PINSpec cardPinSpec = new PINSpec(4, 4, "[0-9]", "Karten-PIN"); +// +// gui.showCardPINDialog(cardPinSpec, okListener, "ok", cancelListener, "cancel"); +// +// Thread.sleep(2000); +// + +// gui.showSignaturePINDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); +// +// Thread.sleep(2000); +// +// gui.showSignaturePINRetryDialog(signPinSpec, 2, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); +// +// Thread.sleep(2000); +//// +// gui.showErrorDialog("Testfehler occured", null, null); +// +// Thread.sleep(2000); +// +// gui.showErrorDialog("Testfehler occured"); + + } catch (InterruptedException ex) { + ex.printStackTrace(); + } + } +} -- cgit v1.2.3 From 3808a5b4ec9d13c8cbb1b7fd95afa62c133342fd Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 5 Sep 2008 13:39:14 +0000 Subject: HashDataInput git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@21 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUCommonGUI/pom.xml | 32 +- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 432 +++++++++++---------- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 17 +- .../java/at/gv/egiz/bku/gui/HashDataInput.java | 36 -- .../at/gv/egiz/bku/gui/Messages.properties | 8 +- .../test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java | 8 +- 6 files changed, 258 insertions(+), 275 deletions(-) delete mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataInput.java (limited to 'BKUCommonGUI/src/test/java') diff --git a/BKUCommonGUI/pom.xml b/BKUCommonGUI/pom.xml index bd579c51..8c08ba6e 100644 --- a/BKUCommonGUI/pom.xml +++ b/BKUCommonGUI/pom.xml @@ -1,6 +1,5 @@ - + bku at.gv.egiz @@ -11,23 +10,28 @@ BKUCommonGUI BKU Common GUI 1.0-SNAPSHOT - at.gv.egiz smcc 1.0-SNAPSHOT + + at.gv.egiz + STAL + 1.0-SNAPSHOT + compile + - - \ No newline at end of file + diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 87b4eab4..0ad09c70 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -1,19 +1,19 @@ /* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /* * To change this template, choose Tools | Templates * and open the template in the editor. @@ -21,6 +21,7 @@ package at.gv.egiz.bku.gui; import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.stal.HashDataInput; import java.awt.Color; import java.awt.Container; import java.awt.Cursor; @@ -30,7 +31,6 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.BufferedOutputStream; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -38,16 +38,14 @@ import java.text.MessageFormat; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.GroupLayout; import javax.swing.ImageIcon; import javax.swing.JButton; -import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JLabel; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.LayoutStyle; @@ -56,22 +54,23 @@ import javax.swing.filechooser.FileFilter; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; import javax.swing.text.PlainDocument; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** * * @author clemens */ public class BKUGUI implements BKUGUIFacade { - + + private static final Log log = LogFactory.getLog(BKUGUI.class); public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; public static final String LOGO_RESOURCE = "/images/logo.png"; - public static final int MAIN_PANEL_WIDTH = 100; // public static final int MAIN_PANEL_HEIGHT = 20; public static final int PREF_SIZE_PINFIELD = 118; public static final Color ERROR_COLOR = Color.RED; public static final Color HYPERLINK_COLOR = Color.BLUE; - private static final String TITLE_WELCOME = "title.welcome"; private static final String TITLE_INSERTCARD = "title.insertcard"; private static final String TITLE_CARD_NOT_SUPPORTED = "title.cardnotsupported"; @@ -79,30 +78,32 @@ public class BKUGUI implements BKUGUIFacade { private static final String TITLE_SIGN = "title.sign"; private static final String TITLE_ERROR = "title.error"; private static final String TITLE_RETRY = "title.retry"; + private static final String TITLE_WAIT = "title.wait"; + private static final String TITLE_HASHDATA = "title.hashdata"; private static final String WINDOWTITLE_SAVE = "windowtitle.save"; - - private static final String MESSAGE_WAIT="message.wait"; - private static final String MESSAGE_INSERTCARD="message.insertcard"; - private static final String MESSAGE_HASHDATALINK="message.hashdatalink"; - private static final String MESSAGE_RETRIES="message.retries"; - private static final String LABEL_PIN="label.pin"; - private static final String LABEL_PINSIZE="label.pinsize"; + private static final String WINDOWTITLE_OVERWRITE = "windowtitle.overwrite"; + private static final String MESSAGE_WAIT = "message.wait"; + private static final String MESSAGE_INSERTCARD = "message.insertcard"; + private static final String MESSAGE_HASHDATALINK = "message.hashdatalink"; + private static final String MESSAGE_HASHDATA = "message.hashdata"; + private static final String MESSAGE_RETRIES = "message.retries"; + private static final String MESSAGE_OVERWRITE = "message.overwrite"; + private static final String LABEL_PIN = "label.pin"; + private static final String LABEL_PINSIZE = "label.pinsize"; // private static final String LABEL_CARDPINSIZE="label.cardpinsize"; // private static final String LABEL_SIGNPIN="label.signpin"; // private static final String LABEL_SIGNPINSIZE="label.signpinsize"; private static final String BUTTON_OK = "button.ok"; private static final String BUTTON_CANCEL = "button.cancel"; private static final String BUTTON_SIGN = "button.sign"; - + private static final String BUTTON_SAVE = "button.save"; private static final String MIMETYPE_DESC_XML = "mimetype.desc.xml"; private static final String MIMETYPE_DESC_TXT = "mimetype.desc.txt"; private static final String MIMETYPE_DESC_PDF = "mimetype.desc.pdf"; private static final String MIMETYPE_DESC_BIN = "mimetype.desc.bin"; private static final String SAVE_HASHDATAINPUT_PREFIX = "save.hashdatainput.prefix"; - protected Container contentPane; protected ResourceBundle messages; - /** left and right side main panels */ protected JPanel iconPanel; protected JPanel contentPanel; @@ -121,7 +122,7 @@ public class BKUGUI implements BKUGUIFacade { */ @Override public void init(final Container contentPane, String localeString) { - + if (localeString != null) { messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, new Locale(localeString)); } else { @@ -174,18 +175,17 @@ public class BKUGUI implements BKUGUIFacade { // headerPanel.setBorder(new TitledBorder("header")); // mainPanel.setBorder(new TitledBorder("main")); // buttonPanel.setBorder(new TitledBorder("button")); - + titleLabel = new JLabel(); - titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | - java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); + titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | + java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); // titleLabel.setForeground(defaultForground); - + GroupLayout headerPanelLayout = new GroupLayout(headerPanel); headerPanel.setLayout(headerPanelLayout); - + headerPanelLayout.setHorizontalGroup( - headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(titleLabel, GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)); + headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(titleLabel, GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)); headerPanelLayout.setVerticalGroup( headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(titleLabel)); @@ -194,25 +194,12 @@ public class BKUGUI implements BKUGUIFacade { GroupLayout contentPanelLayout = new GroupLayout(contentPanel); contentPanel.setLayout(contentPanelLayout); contentPanelLayout.setHorizontalGroup( - contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(contentPanelLayout.createSequentialGroup() - .addContainerGap() - .addGroup(contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(headerPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(mainPanel, GroupLayout.DEFAULT_SIZE, MAIN_PANEL_WIDTH, Short.MAX_VALUE) - .addComponent(buttonPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))); + contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(contentPanelLayout.createSequentialGroup().addContainerGap().addGroup(contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(headerPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(mainPanel, GroupLayout.DEFAULT_SIZE, MAIN_PANEL_WIDTH, Short.MAX_VALUE).addComponent(buttonPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))); contentPanelLayout.setVerticalGroup( - contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(contentPanelLayout.createSequentialGroup() - .addContainerGap() - .addComponent(headerPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(mainPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) //79, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addContainerGap())); + contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(contentPanelLayout.createSequentialGroup().addContainerGap().addComponent(headerPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(mainPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) //79, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(buttonPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addContainerGap())); } - + @Override public void showLoginDialog(ActionListener loginListener, String actionCommand) { SwingUtilities.invokeLater(new Runnable() { @@ -220,13 +207,13 @@ public class BKUGUI implements BKUGUIFacade { public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); - + titleLabel.setText(messages.getString(TITLE_ERROR)); // titleLabel.setForeground(defaultForground); - + JLabel waitMsgLabel = new JLabel(); waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - waitMsgLabel.setText("LoginDialog not supported yet."); + waitMsgLabel.setText("LoginDialog not supported yet."); waitMsgLabel.setForeground(ERROR_COLOR); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); @@ -236,12 +223,12 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel)); - + contentPanel.validate(); } }); } - + @Override public void showWelcomeDialog() { SwingUtilities.invokeLater(new Runnable() { @@ -249,13 +236,13 @@ public class BKUGUI implements BKUGUIFacade { public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); - - titleLabel.setText(messages.getString(TITLE_WELCOME)); + + titleLabel.setText(messages.getString(TITLE_WELCOME)); // titleLabel.setForeground(defaultForground); - + JLabel waitMsgLabel = new JLabel(); waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - waitMsgLabel.setText(messages.getString(MESSAGE_WAIT)); + waitMsgLabel.setText(messages.getString(MESSAGE_WAIT)); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); @@ -264,9 +251,9 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel)); - + contentPanel.validate(); - + } }); } @@ -278,13 +265,13 @@ public class BKUGUI implements BKUGUIFacade { public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); - - titleLabel.setText(messages.getString(TITLE_INSERTCARD)); + + titleLabel.setText(messages.getString(TITLE_INSERTCARD)); // titleLabel.setForeground(defaultForground); - + JButton cancelButton = new JButton(); cancelButton.setFont(cancelButton.getFont()); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); cancelButton.addActionListener(cancelListener); cancelButton.setActionCommand(cancelCommand); @@ -292,15 +279,10 @@ public class BKUGUI implements BKUGUIFacade { buttonPanel.setLayout(buttonPanelLayout); buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(cancelButton) - .addContainerGap())); + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(cancelButton).addContainerGap())); buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(cancelButton)); - + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(cancelButton)); + contentPanel.validate(); } }); @@ -313,19 +295,19 @@ public class BKUGUI implements BKUGUIFacade { public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); - + titleLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); // titleLabel.setForeground(defaultForground); - + JButton cancelButton = new JButton(); cancelButton.setFont(cancelButton.getFont()); cancelButton.setText(messages.getString(BUTTON_CANCEL)); cancelButton.addActionListener(cancelListener); cancelButton.setActionCommand(cancelCommand); - + JLabel errorMsgLabel = new JLabel(); errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); + errorMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); @@ -334,21 +316,16 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel)); - - + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(cancelButton) - .addContainerGap())); + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(cancelButton).addContainerGap())); buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(cancelButton)); - + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(cancelButton)); + contentPanel.validate(); } }); @@ -361,10 +338,10 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - + if (numRetries < 0) { String cardpinTitle = messages.getString(TITLE_CARDPIN); - titleLabel.setText(MessageFormat.format(cardpinTitle, new Object[] {pinSpec.getLocalizedName()})); + titleLabel.setText(MessageFormat.format(cardpinTitle, new Object[]{pinSpec.getLocalizedName()})); } else { titleLabel.setText(messages.getString(TITLE_RETRY)); } @@ -381,11 +358,11 @@ public class BKUGUI implements BKUGUIFacade { okButton.setText(messages.getString(BUTTON_OK)); okButton.setActionCommand(okCommand); okButton.addActionListener(okListener); - + JLabel cardPinLabel = new JLabel(); cardPinLabel.setFont(cardPinLabel.getFont().deriveFont(cardPinLabel.getFont().getStyle() | java.awt.Font.BOLD)); - String pinLabel = messages.getString(LABEL_PIN); - cardPinLabel.setText(MessageFormat.format(pinLabel, new Object[] {pinSpec.getLocalizedName()})); + String pinLabel = messages.getString(LABEL_PIN); + cardPinLabel.setText(MessageFormat.format(pinLabel, new Object[]{pinSpec.getLocalizedName()})); // JPasswordField cardPINField = new JPasswordField(); pinField = new JPasswordField(); @@ -410,9 +387,9 @@ public class BKUGUI implements BKUGUIFacade { if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { pinSize += "-" + pinSpec.getMaxLength(); } - infoLabel.setText(MessageFormat.format(pinsizePattern, new Object[] {pinSize})); - } else { - infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[] {String.valueOf(numRetries)})); + infoLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); + } else { + infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); infoLabel.setForeground(ERROR_COLOR); } @@ -422,7 +399,7 @@ public class BKUGUI implements BKUGUIFacade { // GroupLayout.ParallelGroup mainGroup = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); // mainGroup.addComponent(pinSizeLabel) //, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE) // .addComponent(pinField, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE); - + mainPanelLayout.setHorizontalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup() // .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) // .addComponent(hashDataLabel) @@ -434,9 +411,7 @@ public class BKUGUI implements BKUGUIFacade { .addContainerGap())); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() - .addContainerGap() // .addComponent(hashDataLabel).addGap(14, 14, 14) + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addContainerGap() // .addComponent(hashDataLabel).addGap(14, 14, 14) .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) //, false) .addComponent(cardPinLabel) //, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) .addComponent(pinField)) //, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) @@ -446,18 +421,13 @@ public class BKUGUI implements BKUGUIFacade { buttonPanel.setLayout(buttonPanelLayout); buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() - .addContainerGap(15, Short.MAX_VALUE) - .addComponent(okButton) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cancelButton).addContainerGap())); + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(okButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); buttonPanelLayout.setVerticalGroup( buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(okButton).addComponent(cancelButton))); - + pinField.requestFocusInWindow(); contentPanel.validate(); - + } }); } @@ -471,7 +441,7 @@ public class BKUGUI implements BKUGUIFacade { public void showCardPINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand) { showCardPINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand); } - + @Override public void showSignaturePINDialog(PINSpec pinSpec, ActionListener signListener, String signCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand) { showSignaturePINDialog(pinSpec, -1, signListener, signCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); @@ -482,15 +452,13 @@ public class BKUGUI implements BKUGUIFacade { showSignaturePINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); } - - private void showSignaturePINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener signListener, final String signCommand, final ActionListener cancelListener, final String cancelCommand, final ActionListener hashdataListener, final String hashdataCommand) { SwingUtilities.invokeLater(new Runnable() { public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); - + if (numRetries < 0) { titleLabel.setText(messages.getString(TITLE_SIGN)); } else { @@ -512,8 +480,8 @@ public class BKUGUI implements BKUGUIFacade { JLabel signPinLabel = new JLabel(); signPinLabel.setFont(signPinLabel.getFont().deriveFont(signPinLabel.getFont().getStyle() | java.awt.Font.BOLD)); - String pinLabel = messages.getString(LABEL_PIN); - signPinLabel.setText(MessageFormat.format(pinLabel, new Object[] {pinSpec.getLocalizedName()})); + String pinLabel = messages.getString(LABEL_PIN); + signPinLabel.setText(MessageFormat.format(pinLabel, new Object[]{pinSpec.getLocalizedName()})); pinField = new JPasswordField(); pinField.setText(""); @@ -538,25 +506,26 @@ public class BKUGUI implements BKUGUIFacade { if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { pinSize += "-" + pinSpec.getMaxLength(); } - infoLabel.setText(MessageFormat.format(pinsizePattern, new Object[] {pinSize})); + infoLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); } else { - infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[] {String.valueOf(numRetries)})); + infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); infoLabel.setForeground(ERROR_COLOR); } - + JLabel hashDataLabel = new JLabel(); hashDataLabel.setFont(hashDataLabel.getFont().deriveFont(hashDataLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); hashDataLabel.setText(messages.getString(MESSAGE_HASHDATALINK)); hashDataLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); hashDataLabel.setForeground(HYPERLINK_COLOR); hashDataLabel.addMouseListener(new MouseAdapter() { + @Override - public void mouseClicked(MouseEvent me) { + public void mouseClicked(MouseEvent me) { ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, hashdataCommand); hashdataListener.actionPerformed(e); } }); - + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); @@ -580,10 +549,8 @@ public class BKUGUI implements BKUGUIFacade { pinField.requestFocusInWindow(); contentPanel.validate(); - - } -// private ParallelGroup createMainGroup(GroupLayout mainPanelLayout, JLabel hashDataLabel, JLabel signPinLabel, JLabel pinSizeLabel, JLabel errorLabel) { + }// private ParallelGroup createMainGroup(GroupLayout mainPanelLayout, JLabel hashDataLabel, JLabel signPinLabel, JLabel pinSizeLabel, JLabel errorLabel) { // ParallelGroup mainGroup = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); // mainGroup.addComponent(hashDataLabel); // if (errorLabel != null) { @@ -597,7 +564,6 @@ public class BKUGUI implements BKUGUIFacade { // .addComponent(pinField, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE))); // return mainGroup; // } - // private GroupLayout.SequentialGroup createVerticalMainGroup(GroupLayout mainPanelLayout, JLabel hashDataLabel, JLabel signPinLabel, JLabel pinSizeLabel, JLabel errorLabel) { // GroupLayout.SequentialGroup mainGroup = mainPanelLayout.createSequentialGroup(); // mainGroup.addComponent(hashDataLabel) @@ -637,8 +603,8 @@ public class BKUGUI implements BKUGUIFacade { public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); - - titleLabel.setText(messages.getString(TITLE_ERROR)); + + titleLabel.setText(messages.getString(TITLE_ERROR)); // titleLabel.setForeground(defaultForground); JLabel errorMsgLabel = new JLabel(); @@ -653,7 +619,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel)); - + JButton okButton = new JButton(); okButton.setFont(okButton.getFont()); okButton.setText(messages.getString(BUTTON_OK)); @@ -664,15 +630,10 @@ public class BKUGUI implements BKUGUIFacade { buttonPanel.setLayout(buttonPanelLayout); buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(okButton) - .addContainerGap())); + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(okButton).addContainerGap())); buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(okButton)); - + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(okButton)); + contentPanel.validate(); } }); @@ -685,13 +646,13 @@ public class BKUGUI implements BKUGUIFacade { public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); - - titleLabel.setText(messages.getString(TITLE_ERROR)); + + titleLabel.setText(messages.getString(TITLE_ERROR)); // titleLabel.setForeground(defaultForground); JLabel errorMsgLabel = new JLabel(); errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText("" + errorMsg + ""); + errorMsgLabel.setText("" + errorMsg + ""); errorMsgLabel.setForeground(ERROR_COLOR); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); @@ -701,69 +662,37 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel)); - + contentPanel.validate(); } }); } - + @Override public void showHashDataInputDialog(final List signedReferences, final ActionListener okListener, final String okCommand) { SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { - + if (signedReferences != null && signedReferences.size() == 1) { - FileOutputStream fos = null; - try { - HashDataInput signedRef = signedReferences.get(0); - final String mimeType = signedRef.getMimeType(); - String dir = System.getProperty("user.home"); - JFileChooser fileDialog = new JFileChooser(dir); - fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY); - fileDialog.setMultiSelectionEnabled(false); - fileDialog.setDialogTitle(messages.getString(WINDOWTITLE_SAVE)); - fileDialog.setDialogType(JFileChooser.SAVE_DIALOG); - fileDialog.setFileHidingEnabled(true); - MimeFilter mimeFilter = new MimeFilter(mimeType); - fileDialog.setFileFilter(mimeFilter); - String filename = messages.getString(SAVE_HASHDATAINPUT_PREFIX) + mimeFilter.getExtension(); - fileDialog.setSelectedFile(new File(dir, filename)); - switch (fileDialog.showSaveDialog(contentPane)) { - case JFileChooser.APPROVE_OPTION: - File f = fileDialog.getSelectedFile(); -// if (f.exists()) { -// //TODO -// } - - fos = new FileOutputStream(f); - BufferedOutputStream bos = new BufferedOutputStream(fos); - InputStream hdi = signedRef.getHashDataInput(); - int b; - while ((b = hdi.read()) != -1) { - bos.write(b); - } - bos.flush(); - bos.close(); - } - } catch (IOException ex) { - showErrorDialog("Failed to write signed reference to file: " + ex.getMessage(), null, null); - ex.printStackTrace(); - } finally { - try { - fos.close(); - } catch (IOException ex) {} - } + + HashDataInput signedRef = signedReferences.get(0); +// if ("text/plain".equals(signedRef.getMimeType())) { +// } else { + showSaveHashDataInputDialog(signedRef, okListener, okCommand); +// } + } else { mainPanel.removeAll(); buttonPanel.removeAll(); - titleLabel.setText(messages.getString(TITLE_ERROR)); - // titleLabel.setForeground(defaultForground); + titleLabel.setText(messages.getString(TITLE_ERROR)); + // titleLabel.setForeground(defaultForground); JLabel errorMsgLabel = new JLabel(); errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText("HashDataInputDialog not supported yet."); + errorMsgLabel.setText("HashDataInputDialog not supported yet."); errorMsgLabel.setForeground(ERROR_COLOR); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); @@ -784,14 +713,9 @@ public class BKUGUI implements BKUGUIFacade { buttonPanel.setLayout(buttonPanelLayout); buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(okButton) - .addContainerGap())); + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(okButton).addContainerGap())); buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(okButton)); + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(okButton)); contentPanel.validate(); } @@ -799,13 +723,100 @@ public class BKUGUI implements BKUGUIFacade { }); } + + + private void showSaveHashDataInputDialog(HashDataInput signedRef, ActionListener okListener, String okCommand) { + String dir = System.getProperty("user.home"); + JFileChooser fileDialog = new JFileChooser(dir); + fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY); + fileDialog.setMultiSelectionEnabled(false); + fileDialog.setDialogTitle(messages.getString(WINDOWTITLE_SAVE)); + fileDialog.setDialogType(JFileChooser.SAVE_DIALOG); + fileDialog.setFileHidingEnabled(true); + MimeFilter mimeFilter = new MimeFilter(signedRef.getMimeType()); + fileDialog.setFileFilter(mimeFilter); + String filename = messages.getString(SAVE_HASHDATAINPUT_PREFIX) + mimeFilter.getExtension(); + fileDialog.setSelectedFile(new File(dir, filename)); + switch (fileDialog.showSaveDialog(contentPane)) { + case JFileChooser.APPROVE_OPTION: + File f = fileDialog.getSelectedFile(); + if (f.exists()) { +// log.debug("hashDataInput file exists, overwrite?"); + String ovrwrt = messages.getString(MESSAGE_OVERWRITE); + int overwrite = JOptionPane.showConfirmDialog(contentPane, MessageFormat.format(ovrwrt, filename), messages.getString(WINDOWTITLE_OVERWRITE), JOptionPane.OK_CANCEL_OPTION); + if (overwrite != JOptionPane.OK_OPTION) { +// log.debug("User canceled overwrite HashDataInput, returning to SignaturePin dialog"); + okListener.actionPerformed(new ActionEvent(fileDialog, ActionEvent.ACTION_PERFORMED, okCommand)); + return; + } + } + if (log.isDebugEnabled()) { + log.debug("Writing HashDataInput " + signedRef.getReferenceId() + " (" + signedRef.getMimeType() + ") to file " + f); + } + FileOutputStream fos = null; + try { + fos = new FileOutputStream(f); + BufferedOutputStream bos = new BufferedOutputStream(fos); + InputStream hdi = signedRef.getHashDataInput(); + int b; + while ((b = hdi.read()) != -1) { + bos.write(b); + } + bos.flush(); + bos.close(); + } catch (IOException ex) { + log.error("Failed to write HashDataInput to file " + f + ": " + ex.getMessage()); + showErrorDialog("Failed to write signed reference to file: " + ex.getMessage(), null, null); + ex.printStackTrace(); + } finally { + try { + fos.close(); + } catch (IOException ex) { + } + } + } + okListener.actionPerformed(new ActionEvent(fileDialog, ActionEvent.ACTION_PERFORMED, okCommand)); + } + + @Override + public void showWaitDialog(final String waitMessage) { + SwingUtilities.invokeLater(new Runnable() { + + public void run() { + mainPanel.removeAll(); + buttonPanel.removeAll(); + + titleLabel.setText(messages.getString(TITLE_WAIT)); + + JLabel waitMsgLabel = new JLabel(); + waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + if (waitMessage != null) { + waitMsgLabel.setText("" + waitMessage + ""); + } else { + waitMsgLabel.setText("" + messages.getString(MESSAGE_WAIT) + ""); + } + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel)); + + contentPanel.validate(); + } + }); + } + @Override public char[] getPin() { - if (pinField != null) + if (pinField != null) { return pinField.getPassword(); + } return null; } - + class PINDocument extends PlainDocument { private PINSpec pinSpec; @@ -827,7 +838,7 @@ public class BKUGUI implements BKUGUIFacade { if (pinSpec.getMaxLength() >= (getLength() + str.length())) { boolean matches = true; for (int i = 0; i < str.length(); i++) { - Matcher m = pinPattern.matcher(str.substring(i, i+1)); + Matcher m = pinPattern.matcher(str.substring(i, i + 1)); if (!m.matches()) { matches = false; } @@ -845,7 +856,7 @@ public class BKUGUI implements BKUGUIFacade { enterButton.setEnabled(getLength() >= pinSpec.getMinLength()); } } - + class MimeFilter extends FileFilter { protected String mimeType; @@ -853,20 +864,23 @@ public class BKUGUI implements BKUGUIFacade { public MimeFilter(String mimeType) { this.mimeType = mimeType; } - + @Override public boolean accept(File f) { if (f.isDirectory()) { return true; - } else if ("text/xml".equals(mimeType)) { - return "xml".equals(getExtension(f)); + } + + String ext = getExtension(f); + if ("text/xml".equals(mimeType)) { + return "xml".equals(ext); } else if ("text/plain".equals(mimeType)) { - return "txt".equals(getExtension(f)); + return "txt".equals(ext); } else if ("application/pdf".equals(mimeType)) { - return "pdf".equals(getExtension(f)); + return "pdf".equals(ext); } else { - return "bin".equals(getExtension(f)); + return "bin".equals(ext); } } @@ -875,8 +889,8 @@ public class BKUGUI implements BKUGUIFacade { String s = f.getName(); int i = s.lastIndexOf('.'); - if (i > 0 && i < s.length() - 1) { - ext = s.substring(i+1).toLowerCase(); + if (i > 0 && i < s.length() - 1) { + ext = s.substring(i + 1).toLowerCase(); } return ext; } @@ -893,7 +907,7 @@ public class BKUGUI implements BKUGUIFacade { return messages.getString(MIMETYPE_DESC_BIN); } } - + public String getExtension() { if ("text/xml".equals(mimeType)) { return ".xml"; 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 3766e905..f8b80556 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 @@ -14,23 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ package at.gv.egiz.bku.gui; -//import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.stal.HashDataInput; import at.gv.egiz.smcc.PINSpec; import java.awt.Container; import java.awt.event.ActionListener; import java.util.List; -import javax.swing.JPasswordField; -/** - * - * @author clemens - */ public interface BKUGUIFacade { public void init(Container contentPane, String localeString); @@ -42,7 +33,10 @@ public interface BKUGUIFacade { * @param loginListener */ public void showLoginDialog(ActionListener loginListener, String actionCommand); - + + /** optional wait message */ + public void showWaitDialog(String waitMessage); + public void showInsertCardDialog(ActionListener cancelListener, String actionCommand); public void showCardNotSupportedDialog(ActionListener cancelListener, String actionCommand); @@ -62,5 +56,4 @@ public interface BKUGUIFacade { public void showErrorDialog(String errorMsg, ActionListener okListener, String actionCommand); public void showErrorDialog(String errorMsg); - } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataInput.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataInput.java deleted file mode 100644 index d916e81c..00000000 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataInput.java +++ /dev/null @@ -1,36 +0,0 @@ -/* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package at.gv.egiz.bku.gui; - -import java.io.InputStream; - -/** - * - * @author clemens - */ -public interface HashDataInput { - - public InputStream getHashDataInput(); - - public String getMimeType(); - -} 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 62c5a670..21a6bd1b 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 @@ -13,8 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -# To change this template, choose Tools | Templates -# and open the template in the editor. title.welcome=Willkommen title.insertcard=Bitte B\u00FCrgerkarte in den Kartenleser stecken title.cardnotsupported=Die Karte wird nicht unterst\u00FCtzt @@ -22,16 +20,22 @@ title.cardpin={0} eingeben title.sign=Signatur erstellen title.error=Ein Fehler trat auf title.retry=Falscher PIN +title.wait=Bitte warten +title.hashdata=Signaturdaten windowtitle.save=Signaturdaten speichern +windowtitle.overwrite=Datei \u00FCberschreiben? message.wait=Bitte warten... message.insertcard=Bitte B\u00FCrgerkarte in den Kartenleser stecken. message.hashdatalink=Signaturdaten anzeigen... +message.hashdata=Referenz Id: {0} message.retries=Noch {0} Versuche +message.overwrite=M\u00F6chten Sie das existierende Dokument {0} \u00FCberschreiben? label.pin={0}: label.pinsize=({0} stellig) button.ok=OK button.cancel=Abbrechen button.sign=Signieren +button.save=Speichern... mimetype.desc.xml=XML-Dateien (*.xml) mimetype.desc.txt=Textdateien (*.txt) mimetype.desc.pdf=Adobe PDF-Dateien (*.pdf) 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 50771216..a251be55 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 @@ -21,10 +21,9 @@ package at.gv.egiz.bku.gui; import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.stal.HashDataInput; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.util.Collections; @@ -89,6 +88,11 @@ public class BKUGUIWorker implements Runnable { public String getMimeType() { return "text/xml"; } + + @Override + public String getReferenceId() { + return "ref123"; + } }; gui.showHashDataInputDialog(Collections.singletonList(signedRef), returnListener, "return"); } -- cgit v1.2.3 From d3698ed2a4f129e5af970f072bc79bb8226d7765 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 5 Sep 2008 15:41:19 +0000 Subject: Text HashDataInput git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@24 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 111 ++++++++++++++++++++- .../test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java | 34 ++++--- .../stal/service/impl/STALRequestBrokerImpl.java | 2 +- .../gv/egiz/stal/service/impl/STALServiceImpl.java | 2 +- .../gv/egiz/bku/smccstal/SignRequestHandler.java | 2 +- 5 files changed, 128 insertions(+), 23 deletions(-) (limited to 'BKUCommonGUI/src/test/java') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 0ad09c70..5175b45f 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -29,15 +29,22 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.io.BufferedInputStream; import java.io.BufferedOutputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; import java.text.MessageFormat; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.GroupLayout; @@ -48,6 +55,8 @@ import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPasswordField; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; import javax.swing.LayoutStyle; import javax.swing.SwingUtilities; import javax.swing.filechooser.FileFilter; @@ -677,11 +686,44 @@ public class BKUGUI implements BKUGUIFacade { if (signedReferences != null && signedReferences.size() == 1) { - HashDataInput signedRef = signedReferences.get(0); -// if ("text/plain".equals(signedRef.getMimeType())) { -// } else { + final HashDataInput signedRef = signedReferences.get(0); + if ("text/plain".equals(signedRef.getMimeType())) { + //TODO get encoding from mimetype + //read directly to byte[] since hashDataIS is backed by byte[] ? + ByteArrayOutputStream baos = null; + try { + String refId = signedRef.getReferenceId(); + InputStream hashDataIS = signedRef.getHashDataInput(); + if (hashDataIS == null) { + showErrorDialog("Failed to obtain HashDataInput for reference " + refId, okListener, okCommand); + } else { + baos = new ByteArrayOutputStream(hashDataIS.available()); + int c; + while ((c = hashDataIS.read()) != -1) { + baos.write(c); + } + String text = baos.toString("UTF-8"); + + ActionListener al = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + showSaveHashDataInputDialog(signedRef, okListener, okCommand); + } + }; + showPlainTextHashDataInputDialog(text, refId, okListener, okCommand, al, "save"); + } + } catch (IOException ex) { + showErrorDialog("Failed to read HashDataInput for reference " + signedRef.getReferenceId() + ": " + ex.getMessage(), okListener, okCommand); + } finally { + try { + baos.close(); + } catch (IOException ex) { + } + } + } else { showSaveHashDataInputDialog(signedRef, okListener, okCommand); -// } + } } else { mainPanel.removeAll(); @@ -723,7 +765,66 @@ public class BKUGUI implements BKUGUIFacade { }); } - + private void showPlainTextHashDataInputDialog(String text, String refId, ActionListener cancelListener, String cancelCommand, ActionListener saveListener, String saveCommand) { + mainPanel.removeAll(); + buttonPanel.removeAll(); + + titleLabel.setText(messages.getString(TITLE_HASHDATA)); + + JLabel refIdLabel = new JLabel(); + refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + String refIdLabelPattern = messages.getString(MESSAGE_HASHDATA); + refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[] {refId} )); + + JScrollPane hashDataScrollPane = new JScrollPane(); + JTextArea hashDataTextArea = new JTextArea(text); + hashDataTextArea.setEditable(false); + hashDataTextArea.setColumns(20); + hashDataTextArea.setRows(3); + hashDataScrollPane.setViewportView(hashDataTextArea); + + + JButton cancelButton = new JButton(); + cancelButton.setFont(cancelButton.getFont()); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.setActionCommand(cancelCommand); + cancelButton.addActionListener(cancelListener); + + JButton saveButton = new JButton(); + saveButton.setFont(saveButton.getFont()); + saveButton.setText(messages.getString(BUTTON_SAVE)); + saveButton.setActionCommand(saveCommand); + saveButton.addActionListener(saveListener); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(mainPanelLayout.createSequentialGroup() + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(refIdLabel) + .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)) + .addContainerGap())); + + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(refIdLabel) + .addGap(refIdLabel.getFont().getSize()) + .addComponent(hashDataScrollPane) + .addGap(refIdLabel.getFont().getSize()))); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(saveButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(saveButton).addComponent(cancelButton))); + + contentPanel.validate(); + } private void showSaveHashDataInputDialog(HashDataInput signedRef, ActionListener okListener, String okCommand) { String dir = System.getProperty("user.home"); 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 a251be55..e2f478c9 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 @@ -86,7 +86,7 @@ public class BKUGUIWorker implements Runnable { @Override public String getMimeType() { - return "text/xml"; + return "text/plain"; } @Override @@ -104,13 +104,13 @@ public class BKUGUIWorker implements Runnable { // // Thread.sleep(2000); - gui.showInsertCardDialog(cancelListener, "cancel"); - - Thread.sleep(2000); - - gui.showCardNotSupportedDialog(cancelListener, "cancel"); - - Thread.sleep(2000); +// gui.showInsertCardDialog(cancelListener, "cancel"); +// +// Thread.sleep(2000); +// +// gui.showCardNotSupportedDialog(cancelListener, "cancel"); +// +// Thread.sleep(2000); // PINSpec cardPinSpec = new PINSpec(4, 4, "[0-9]", "Karten-PIN"); // @@ -119,19 +119,23 @@ public class BKUGUIWorker implements Runnable { // Thread.sleep(2000); // -// gui.showSignaturePINDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); -// -// Thread.sleep(2000); -// -// gui.showSignaturePINRetryDialog(signPinSpec, 2, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); -// -// Thread.sleep(2000); + gui.showSignaturePINDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); + + Thread.sleep(2000); + + gui.showSignaturePINRetryDialog(signPinSpec, 2, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); + + Thread.sleep(2000); //// // gui.showErrorDialog("Testfehler occured", null, null); // // Thread.sleep(2000); // // gui.showErrorDialog("Testfehler occured"); + + +// gui.showTextPlainHashDataInput("hallo,\n welt!", "12345", null, "cancel", null, "save"); +// Thread.sleep(2000); } catch (InterruptedException ex) { ex.printStackTrace(); diff --git a/BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALRequestBrokerImpl.java b/BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALRequestBrokerImpl.java index 9601d39c..d206913d 100644 --- a/BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALRequestBrokerImpl.java +++ b/BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALRequestBrokerImpl.java @@ -95,7 +95,7 @@ public class STALRequestBrokerImpl implements STALRequestBroker { currentHashDataInput = null; for (STALRequest request : requests) { if (request instanceof SignRequest) { - log.trace("Received SignRequest, keep HashDataInput callback."); + log.trace("Received SignRequest, keep HashDataInput."); currentHashDataInput = ((SignRequest) request).getHashDataInput(); break; } else if (request instanceof QuitRequest) { 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 f0df22ea..f4cdc7d2 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 @@ -1,4 +1,4 @@ -/* + /* * Copyright 2008 Federal Chancellery Austria and * Graz University of Technology * 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 2fe77c5d..1f84300a 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 @@ -146,7 +146,7 @@ public class SignRequestHandler extends AbstractRequestHandler implements if (signedInfo != null) { try { gui.showWaitDialog(null); - if (hashDataInputs == null) { + if (hashDataInputs == null || hashDataInputs.size() == 0) { hashDataInputs = getHashDataInputs(signedInfo.getReference()); } gui.showHashDataInputDialog(hashDataInputs, this, "ok"); -- cgit v1.2.3 From 84e214e4d708f13c8f09c68273541e535c560296 Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 10 Sep 2008 16:54:04 +0000 Subject: gui final 0.1b git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@30 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 620 ++++++++++++++++----- .../at/gv/egiz/bku/gui/Messages.properties | 10 +- .../test/java/at/gv/egiz/bku/gui/BKUGUITest.java | 10 +- .../test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java | 90 ++- .../src/test/resources/commons-logging.properties | 1 + BKUCommonGUI/src/test/resources/log4j.properties | 19 + 6 files changed, 579 insertions(+), 171 deletions(-) create mode 100644 BKUCommonGUI/src/test/resources/commons-logging.properties create mode 100644 BKUCommonGUI/src/test/resources/log4j.properties (limited to 'BKUCommonGUI/src/test/java') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 5175b45f..044e6927 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -23,43 +23,47 @@ package at.gv.egiz.bku.gui; import at.gv.egiz.smcc.PINSpec; import at.gv.egiz.stal.HashDataInput; import java.awt.Color; +import java.awt.Component; import java.awt.Container; import java.awt.Cursor; +import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.io.BufferedInputStream; import java.io.BufferedOutputStream; -import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; import java.text.MessageFormat; +import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; -import java.util.logging.Level; -import java.util.logging.Logger; +import java.util.Vector; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.GroupLayout; import javax.swing.ImageIcon; import javax.swing.JButton; +import javax.swing.JCheckBox; import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JScrollPane; +import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.LayoutStyle; import javax.swing.SwingUtilities; +import javax.swing.border.TitledBorder; import javax.swing.filechooser.FileFilter; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableColumn; +import javax.swing.table.TableModel; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; import javax.swing.text.PlainDocument; @@ -75,9 +79,9 @@ public class BKUGUI implements BKUGUIFacade { private static final Log log = LogFactory.getLog(BKUGUI.class); public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; public static final String LOGO_RESOURCE = "/images/logo.png"; - public static final int MAIN_PANEL_WIDTH = 100; +// public static final int MAIN_PANEL_WIDTH = 100; // public static final int MAIN_PANEL_HEIGHT = 20; - public static final int PREF_SIZE_PINFIELD = 118; +// public static final int PREF_SIZE_PINFIELD = 118; public static final Color ERROR_COLOR = Color.RED; public static final Color HYPERLINK_COLOR = Color.BLUE; private static final String TITLE_WELCOME = "title.welcome"; @@ -95,18 +99,21 @@ public class BKUGUI implements BKUGUIFacade { private static final String MESSAGE_INSERTCARD = "message.insertcard"; private static final String MESSAGE_HASHDATALINK = "message.hashdatalink"; private static final String MESSAGE_HASHDATA = "message.hashdata"; + private static final String MESSAGE_HASHDATALIST = "message.hashdatalist"; private static final String MESSAGE_RETRIES = "message.retries"; private static final String MESSAGE_OVERWRITE = "message.overwrite"; private static final String LABEL_PIN = "label.pin"; private static final String LABEL_PINSIZE = "label.pinsize"; -// private static final String LABEL_CARDPINSIZE="label.cardpinsize"; -// private static final String LABEL_SIGNPIN="label.signpin"; -// private static final String LABEL_SIGNPINSIZE="label.signpinsize"; + private static final String ERROR_HASHDATA = "error.hashdata"; + private static final String BUTTON_OK = "button.ok"; private static final String BUTTON_CANCEL = "button.cancel"; + private static final String BUTTON_BACK = "button.back"; private static final String BUTTON_SIGN = "button.sign"; private static final String BUTTON_SAVE = "button.save"; private static final String MIMETYPE_DESC_XML = "mimetype.desc.xml"; + private static final String MIMETYPE_DESC_HTML = "mimetype.desc.html"; + private static final String MIMETYPE_DESC_XHTML = "mimetype.desc.xhtml"; private static final String MIMETYPE_DESC_TXT = "mimetype.desc.txt"; private static final String MIMETYPE_DESC_PDF = "mimetype.desc.pdf"; private static final String MIMETYPE_DESC_BIN = "mimetype.desc.bin"; @@ -125,6 +132,15 @@ public class BKUGUI implements BKUGUIFacade { /** remember the pinfield to return to worker */ protected JPasswordField pinField; + protected JButton okButton; + protected JButton cancelButton; + protected JButton signButton; + protected JButton saveButton; + protected JButton backButton; + protected int buttonSize; + + private static final int CHECKBOX_WIDTH = new JCheckBox().getPreferredSize().width; + /** * @param contentPane * @param localeString may be null @@ -168,9 +184,19 @@ public class BKUGUI implements BKUGUIFacade { GroupLayout iconPanelLayout = new GroupLayout(iconPanel); iconPanel.setLayout(iconPanelLayout); iconPanelLayout.setHorizontalGroup( - iconPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(iconPanelLayout.createSequentialGroup().addContainerGap().addComponent(iconLabel).addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); + iconPanelLayout.createSequentialGroup() +// iconPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(iconPanelLayout.createSequentialGroup() + .addContainerGap() + .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, iconLabel.getPreferredSize().width, GroupLayout.PREFERRED_SIZE) + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); iconPanelLayout.setVerticalGroup( - iconPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(iconPanelLayout.createSequentialGroup().addContainerGap().addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, 105, GroupLayout.PREFERRED_SIZE).addContainerGap(41, Short.MAX_VALUE))); + iconPanelLayout.createSequentialGroup() +// iconPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(iconPanelLayout.createSequentialGroup() + .addContainerGap() + .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, iconLabel.getPreferredSize().height, GroupLayout.PREFERRED_SIZE) + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); } protected void initContentPanel() { @@ -190,23 +216,60 @@ public class BKUGUI implements BKUGUIFacade { java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); // titleLabel.setForeground(defaultForground); + okButton = new JButton(); + okButton.setText(messages.getString(BUTTON_OK)); + cancelButton = new JButton(); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); + signButton = new JButton(); + signButton.setText(messages.getString(BUTTON_SIGN)); + backButton = new JButton(); + backButton.setText(messages.getString(BUTTON_BACK)); + saveButton = new JButton(); + saveButton.setText(messages.getString(BUTTON_SAVE)); +// contentPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); + + if (okButton.getPreferredSize().width > buttonSize) + buttonSize = okButton.getPreferredSize().width; + if (cancelButton.getPreferredSize().width > buttonSize) + buttonSize = cancelButton.getPreferredSize().width; + if (signButton.getPreferredSize().width > buttonSize) + buttonSize = signButton.getPreferredSize().width; + if (backButton.getPreferredSize().width > buttonSize) + buttonSize = backButton.getPreferredSize().width; + if (saveButton.getPreferredSize().width > buttonSize) + buttonSize = saveButton.getPreferredSize().width; + + GroupLayout headerPanelLayout = new GroupLayout(headerPanel); headerPanel.setLayout(headerPanelLayout); headerPanelLayout.setHorizontalGroup( - headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(titleLabel, GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)); + headerPanelLayout.createSequentialGroup() +// headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); headerPanelLayout.setVerticalGroup( - headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(titleLabel)); + headerPanelLayout.createSequentialGroup() +// headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); // mainPanel.setPreferredSize(new Dimension(MAIN_PANEL_WIDTH, MAIN_PANEL_HEIGHT)); GroupLayout contentPanelLayout = new GroupLayout(contentPanel); contentPanel.setLayout(contentPanelLayout); contentPanelLayout.setHorizontalGroup( - contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(contentPanelLayout.createSequentialGroup().addContainerGap().addGroup(contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(headerPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(mainPanel, GroupLayout.DEFAULT_SIZE, MAIN_PANEL_WIDTH, Short.MAX_VALUE).addComponent(buttonPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))); + contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //)); contentPanelLayout.setVerticalGroup( - contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(contentPanelLayout.createSequentialGroup().addContainerGap().addComponent(headerPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(mainPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) //79, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(buttonPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addContainerGap())); + contentPanelLayout.createSequentialGroup() + .addContainerGap() + .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) //, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addContainerGap()); //); } @Override @@ -229,9 +292,13 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel) + .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel)); + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel)); contentPanel.validate(); } @@ -257,9 +324,14 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel) + .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel)); + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel)); contentPanel.validate(); @@ -276,21 +348,25 @@ public class BKUGUI implements BKUGUIFacade { buttonPanel.removeAll(); titleLabel.setText(messages.getString(TITLE_INSERTCARD)); -// titleLabel.setForeground(defaultForground); - JButton cancelButton = new JButton(); - cancelButton.setFont(cancelButton.getFont()); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); cancelButton.addActionListener(cancelListener); cancelButton.setActionCommand(cancelCommand); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); +// buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(cancelButton).addContainerGap())); + buttonPanelLayout.createSequentialGroup() +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + .addContainerGap()); //); buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(cancelButton)); + buttonPanelLayout.createSequentialGroup() +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(cancelButton)); contentPanel.validate(); } @@ -308,12 +384,6 @@ public class BKUGUI implements BKUGUIFacade { titleLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); // titleLabel.setForeground(defaultForground); - JButton cancelButton = new JButton(); - cancelButton.setFont(cancelButton.getFont()); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); - cancelButton.addActionListener(cancelListener); - cancelButton.setActionCommand(cancelCommand); - JLabel errorMsgLabel = new JLabel(); errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); errorMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); @@ -322,19 +392,33 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorMsgLabel)); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel)); + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorMsgLabel)); + cancelButton.addActionListener(cancelListener); + cancelButton.setActionCommand(cancelCommand); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); +// buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(cancelButton).addContainerGap())); + buttonPanelLayout.createSequentialGroup() +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + .addContainerGap()); //); buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(cancelButton)); - + buttonPanelLayout.createSequentialGroup() +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(cancelButton)); + contentPanel.validate(); } }); @@ -355,16 +439,10 @@ public class BKUGUI implements BKUGUIFacade { titleLabel.setText(messages.getString(TITLE_RETRY)); } - JButton cancelButton = new JButton(); - cancelButton.setFont(cancelButton.getFont()); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); cancelButton.setActionCommand(cancelCommand); cancelButton.addActionListener(cancelListener); - JButton okButton = new JButton(); okButton.setEnabled(false); - okButton.setFont(okButton.getFont()); - okButton.setText(messages.getString(BUTTON_OK)); okButton.setActionCommand(okCommand); okButton.addActionListener(okListener); @@ -402,37 +480,77 @@ public class BKUGUI implements BKUGUIFacade { infoLabel.setForeground(ERROR_COLOR); } +// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); +// mainPanel.setLayout(mainPanelLayout); +// +// mainPanelLayout.setHorizontalGroup( +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(mainPanelLayout.createSequentialGroup() // .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// // .addComponent(hashDataLabel) +// // .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() +// .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) //RELATED) +// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) //TRAILING) +// .addComponent(infoLabel) //, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE) +// .addComponent(pinField, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)) //)) +// .addContainerGap())); +// +// mainPanelLayout.setVerticalGroup( +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addContainerGap() // .addComponent(hashDataLabel).addGap(14, 14, 14) +// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) //, false) +// .addComponent(cardPinLabel) //, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) +// .addComponent(pinField)) //, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) +// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(infoLabel).addGap(cardPinLabel.getFont().getSize()))); //10, 10, 10))); +// +// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); +// buttonPanel.setLayout(buttonPanelLayout); +// +// buttonPanelLayout.setHorizontalGroup( +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(okButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); +// buttonPanelLayout.setVerticalGroup( +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(okButton).addComponent(cancelButton))); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); -// GroupLayout.ParallelGroup mainGroup = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); -// mainGroup.addComponent(pinSizeLabel) //, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE) -// .addComponent(pinField, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE); - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup() // .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - // .addComponent(hashDataLabel) - // .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() - .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) //RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) //TRAILING) - .addComponent(infoLabel) //, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE) - .addComponent(pinField, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)) //)) - .addContainerGap())); + mainPanelLayout.createSequentialGroup() +// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addComponent(hashDataLabel) +// .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() + .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) //)) + .addComponent(infoLabel)) + .addContainerGap()); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addContainerGap() // .addComponent(hashDataLabel).addGap(14, 14, 14) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) //, false) - .addComponent(cardPinLabel) //, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) - .addComponent(pinField)) //, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(infoLabel).addGap(cardPinLabel.getFont().getSize()))); //10, 10, 10))); + mainPanelLayout.createSequentialGroup() +// .addComponent(hashDataLabel) +// .addGap(hashDataLabel.getFont().getSize()) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(cardPinLabel) + .addComponent(pinField)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(infoLabel)); +// .addGap(signPinLabel.getFont().getSize())); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); +// buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(okButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); + buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + .addContainerGap());//); buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(okButton).addComponent(cancelButton))); + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(okButton) + .addComponent(cancelButton)); pinField.requestFocusInWindow(); contentPanel.validate(); @@ -474,16 +592,10 @@ public class BKUGUI implements BKUGUIFacade { titleLabel.setText(messages.getString(TITLE_RETRY)); } - JButton cancelButton = new JButton(); - cancelButton.setFont(cancelButton.getFont()); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); cancelButton.setActionCommand(cancelCommand); cancelButton.addActionListener(cancelListener); - JButton signButton = new JButton(); signButton.setEnabled(false); - signButton.setFont(signButton.getFont()); - signButton.setText(messages.getString(BUTTON_SIGN)); signButton.setActionCommand(signCommand); signButton.addActionListener(signListener); @@ -539,22 +651,43 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(hashDataLabel).addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup().addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING).addComponent(infoLabel) //, GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE) - .addComponent(pinField, GroupLayout.DEFAULT_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)))).addContainerGap())); + mainPanelLayout.createSequentialGroup() + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(hashDataLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() + .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(infoLabel)))) + .addContainerGap()); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addComponent(hashDataLabel).addGap(hashDataLabel.getFont().getSize()) //14, 14, 14) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE, false).addComponent(signPinLabel) //, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) - .addComponent(pinField)) //, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(infoLabel).addGap(signPinLabel.getFont().getSize()))); //10, 10, 10))); + mainPanelLayout.createSequentialGroup() + .addComponent(hashDataLabel) + .addGap(hashDataLabel.getFont().getSize()) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(signPinLabel) + .addComponent(pinField)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(infoLabel)); +// .addGap(signPinLabel.getFont().getSize())); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); +// buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(signButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); + buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(signButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + .addContainerGap());//); buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(signButton).addComponent(cancelButton))); + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(signButton) + .addComponent(cancelButton)); pinField.requestFocusInWindow(); contentPanel.validate(); @@ -625,23 +758,30 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel)); + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorMsgLabel)); - JButton okButton = new JButton(); - okButton.setFont(okButton.getFont()); - okButton.setText(messages.getString(BUTTON_OK)); okButton.setActionCommand(okCommand); okButton.addActionListener(okListener); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); +// buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(okButton).addContainerGap())); + buttonPanelLayout.createSequentialGroup() +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + .addContainerGap()); //); buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(okButton)); + buttonPanelLayout.createSequentialGroup() +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(okButton)); contentPanel.validate(); } @@ -668,9 +808,13 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorMsgLabel) + .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel)); + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorMsgLabel)); contentPanel.validate(); } @@ -725,41 +869,26 @@ public class BKUGUI implements BKUGUIFacade { showSaveHashDataInputDialog(signedRef, okListener, okCommand); } - } else { - mainPanel.removeAll(); - buttonPanel.removeAll(); - - titleLabel.setText(messages.getString(TITLE_ERROR)); - // titleLabel.setForeground(defaultForground); + } else if (signedReferences != null && signedReferences.size() > 1) { + final HashDataTableModel tableModel = new HashDataTableModel(signedReferences); - JLabel errorMsgLabel = new JLabel(); - errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText("HashDataInputDialog not supported yet."); - errorMsgLabel.setForeground(ERROR_COLOR); + ActionListener al = new ActionListener() { - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(errorMsgLabel)); - - JButton okButton = new JButton(); - okButton.setFont(okButton.getFont()); - okButton.setText(messages.getString(BUTTON_OK)); - okButton.setActionCommand(okCommand); - okButton.addActionListener(okListener); - - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(okButton).addContainerGap())); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(okButton)); - - contentPanel.validate(); + @Override + public void actionPerformed(ActionEvent e) { + List selection = tableModel.getSelectedReferenceIds(); + StringBuilder sb = new StringBuilder("Not implemented yet. \n"); + for (String string : selection) { + sb.append(string); + sb.append('\n'); + } + showErrorDialog(sb.toString(), okListener, okCommand); +// showSaveHashDataInputDialog(signedRef, okListener, okCommand); + } + }; + showMultipleHashDataInputDialog(tableModel, okListener, okCommand, al, "save"); + } else { + showErrorDialog(messages.getString(ERROR_HASHDATA), okListener, okCommand); } } }); @@ -774,54 +903,193 @@ public class BKUGUI implements BKUGUIFacade { JLabel refIdLabel = new JLabel(); refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); String refIdLabelPattern = messages.getString(MESSAGE_HASHDATA); - refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[] {refId} )); + refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[]{refId})); JScrollPane hashDataScrollPane = new JScrollPane(); JTextArea hashDataTextArea = new JTextArea(text); hashDataTextArea.setEditable(false); - hashDataTextArea.setColumns(20); - hashDataTextArea.setRows(3); + hashDataTextArea.setColumns(1); + hashDataTextArea.setRows(1); hashDataScrollPane.setViewportView(hashDataTextArea); + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createSequentialGroup() + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(refIdLabel) + .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()); + + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() + .addComponent(refIdLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(hashDataScrollPane, 0, GroupLayout.PREFERRED_SIZE, hashDataTextArea.getPreferredSize().height+3)); + - JButton cancelButton = new JButton(); - cancelButton.setFont(cancelButton.getFont()); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); - cancelButton.setActionCommand(cancelCommand); - cancelButton.addActionListener(cancelListener); + +// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); +// mainPanel.setLayout(mainPanelLayout); +// +// mainPanelLayout.setHorizontalGroup( +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(refIdLabel).addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)).addContainerGap())); +// +// mainPanelLayout.setVerticalGroup( +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addComponent(refIdLabel).addGap(refIdLabel.getFont().getSize()).addComponent(hashDataScrollPane).addGap(refIdLabel.getFont().getSize()))); + + backButton.setActionCommand(cancelCommand); + backButton.addActionListener(cancelListener); - JButton saveButton = new JButton(); - saveButton.setFont(saveButton.getFont()); - saveButton.setText(messages.getString(BUTTON_SAVE)); saveButton.setActionCommand(saveCommand); saveButton.addActionListener(saveListener); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + +// buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); + 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(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + .addContainerGap()); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(saveButton) + .addComponent(backButton)); + + +// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); +// buttonPanel.setLayout(buttonPanelLayout); +// +// buttonPanelLayout.setHorizontalGroup( +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(saveButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); +// buttonPanelLayout.setVerticalGroup( +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(saveButton).addComponent(cancelButton))); + + contentPanel.validate(); + } + + private void showMultipleHashDataInputDialog(final TableModel signedReferences, final ActionListener cancelListener, final String cancelCommand, ActionListener saveListener, String saveCommand) { + mainPanel.removeAll(); + buttonPanel.removeAll(); + + titleLabel.setText(messages.getString(TITLE_HASHDATA)); + JLabel refIdLabel = new JLabel(); + refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + String refIdLabelPattern = messages.getString(MESSAGE_HASHDATALIST); + refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[]{signedReferences.getRowCount()})); + + JTable hashDataTable = new JTable(); + 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); + + + hashDataTable.setPreferredScrollableViewportSize(mainPanel.getPreferredSize()); + + JScrollPane hashDataScrollPane = new JScrollPane(hashDataTable); + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(refIdLabel) - .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)) - .addContainerGap())); - + mainPanelLayout.createSequentialGroup() + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(refIdLabel) + .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()); + mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(refIdLabel) - .addGap(refIdLabel.getFont().getSize()) - .addComponent(hashDataScrollPane) - .addGap(refIdLabel.getFont().getSize()))); - + mainPanelLayout.createSequentialGroup() + .addComponent(refIdLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(hashDataScrollPane, 0, GroupLayout.PREFERRED_SIZE, hashDataTable.getPreferredSize().height+3)); +// .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)); + + + +// +// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); +// mainPanel.setLayout(mainPanelLayout); +// +// mainPanelLayout.setHorizontalGroup( +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(mainPanelLayout.createSequentialGroup() +// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addComponent(refIdLabel) +// .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)) +// .addContainerGap())); +// +// mainPanelLayout.setVerticalGroup( +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(mainPanelLayout.createSequentialGroup() +// .addComponent(refIdLabel) +// .addGap(refIdLabel.getFont().getSize()) +// .addComponent(hashDataScrollPane) +// .addGap(refIdLabel.getFont().getSize()))); + + + + + + + + + + + + +// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); +// buttonPanel.setLayout(buttonPanelLayout); +// +// buttonPanelLayout.setHorizontalGroup( +// buttonPanelLayout.createSequentialGroup() +//// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +//// .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() +// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) +// .addComponent(saveButton) +// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) +// .addComponent(cancelButton) +// .addContainerGap()); //); +// buttonPanelLayout.setVerticalGroup( +// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() +// .addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) +// .addComponent(saveButton) +// .addComponent(cancelButton)) +// .addContainerGap())); + + + backButton.setActionCommand(cancelCommand); + backButton.addActionListener(cancelListener); + + saveButton.setActionCommand(saveCommand); + saveButton.addActionListener(saveListener); + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); +// buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(saveButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); + buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(saveButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + .addContainerGap());//); buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(saveButton).addComponent(cancelButton))); + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(saveButton) + .addComponent(backButton)); contentPanel.validate(); } @@ -901,9 +1169,13 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel) + .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(waitMsgLabel)); + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel)); contentPanel.validate(); } @@ -975,13 +1247,17 @@ public class BKUGUI implements BKUGUIFacade { String ext = getExtension(f); if ("text/xml".equals(mimeType)) { - return "xml".equals(ext); + return "xml".equalsIgnoreCase(ext); + } else if ("text/html".equals(mimeType)) { + return "html".equalsIgnoreCase(ext) || "htm".equalsIgnoreCase(ext); + } else if ("application/xhtml+xml".equals(mimeType)) { + return "xhtml".equalsIgnoreCase(ext); } else if ("text/plain".equals(mimeType)) { - return "txt".equals(ext); + return "txt".equalsIgnoreCase(ext); } else if ("application/pdf".equals(mimeType)) { - return "pdf".equals(ext); + return "pdf".equalsIgnoreCase(ext); } else { - return "bin".equals(ext); + return true; } } @@ -1000,6 +1276,10 @@ public class BKUGUI implements BKUGUIFacade { public String getDescription() { if ("text/xml".equals(mimeType)) { return messages.getString(MIMETYPE_DESC_XML); + } else if ("text/html".equals(mimeType)) { + return messages.getString(MIMETYPE_DESC_HTML); + } else if ("application/xhtml+xml".equals(mimeType)) { + return messages.getString(MIMETYPE_DESC_XHTML); } else if ("text/plain".equals(mimeType)) { return messages.getString(MIMETYPE_DESC_TXT); } else if ("application/pdf".equals(mimeType)) { @@ -1012,6 +1292,10 @@ public class BKUGUI implements BKUGUIFacade { public String getExtension() { if ("text/xml".equals(mimeType)) { return ".xml"; + } else if ("text/html".equals(mimeType)) { + return ".html"; + } else if ("application/xhtml+xml".equals(mimeType)) { + return ".xhtml"; } else if ("text/plain".equals(mimeType)) { return ".txt"; } else if ("application/pdf".equals(mimeType)) { @@ -1021,4 +1305,34 @@ public class BKUGUI implements BKUGUIFacade { } } } + + class HashDataTableModel extends DefaultTableModel { + + Class[] types = new Class[]{ + java.lang.String.class, java.lang.Boolean.class + }; + + public HashDataTableModel(List signedReferences) { + super(0, 2); + for (HashDataInput hashDataInput : signedReferences) { + addRow(new Object[]{hashDataInput.getReferenceId(), new Boolean(true)}); + } + } + + @Override + public Class getColumnClass(int columnIndex) { + return types [columnIndex]; + } + + 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; + } + + } } 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 21a6bd1b..b651fa8d 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 @@ -25,18 +25,24 @@ title.hashdata=Signaturdaten windowtitle.save=Signaturdaten speichern windowtitle.overwrite=Datei \u00FCberschreiben? message.wait=Bitte warten... -message.insertcard=Bitte B\u00FCrgerkarte in den Kartenleser stecken. +message.insertcard=Bitte B\u00FCrgerkarte in den Kartenleser stecken message.hashdatalink=Signaturdaten anzeigen... -message.hashdata=Referenz Id: {0} +message.hashdata=Ein textuelles Signaturdatenobjekt: +#message.hashdata=Referenz Id: {0} +message.hashdatalist={0} Signaturdatenobjekte: message.retries=Noch {0} Versuche message.overwrite=M\u00F6chten Sie das existierende Dokument {0} \u00FCberschreiben? label.pin={0}: label.pinsize=({0} stellig) +error.hashdata=Keine Signaturdaten verf\u00FCgbar button.ok=OK button.cancel=Abbrechen +button.back=Zur\u00FCck button.sign=Signieren button.save=Speichern... mimetype.desc.xml=XML-Dateien (*.xml) +mimetype.desc.html=HTML-Dateien (*.html, *.htm) +mimetype.desc.xhtml=XHTML-Dateien (*.xhtml) mimetype.desc.txt=Textdateien (*.txt) mimetype.desc.pdf=Adobe PDF-Dateien (*.pdf) mimetype.desc.bin=Bin\u00E4rdateien (*.bin) diff --git a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java index 4dc1f8b3..a9c21a00 100644 --- a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java +++ b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java @@ -21,6 +21,8 @@ package at.gv.egiz.bku.gui; +import java.awt.Container; +import java.awt.Dimension; import javax.swing.JFrame; import org.junit.Ignore; import org.junit.Test; @@ -36,7 +38,9 @@ public class BKUGUITest { public void testBKUGUI() { JFrame testFrame = new JFrame("BKUGUITest"); BKUGUI gui = new BKUGUI(); - gui.init(testFrame.getContentPane(), null); + Container contentPane = testFrame.getContentPane(); + contentPane.setPreferredSize(new Dimension(500, 200)); + gui.init(contentPane, null); BKUGUIWorker worker = new BKUGUIWorker(); worker.init(gui); testFrame.pack(); @@ -50,4 +54,8 @@ public class BKUGUITest { @Test public void dummyTest() { } + +// public static void main(String[] args) { +// new BKUGUITest().testBKUGUI(); +// } } 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 e2f478c9..4367f642 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 @@ -26,7 +26,8 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.ByteArrayInputStream; import java.io.InputStream; -import java.util.Collections; +import java.util.ArrayList; +import java.util.List; /** * @@ -42,7 +43,7 @@ public class BKUGUIWorker implements Runnable { @Override public void run() { - try { +// try { final PINSpec signPinSpec = new PINSpec(6, 10, "[0-9]", "Signatur-PIN"); @@ -77,11 +78,11 @@ public class BKUGUIWorker implements Runnable { gui.showSignaturePINDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", null, "hashdata"); } }; - HashDataInput signedRef = new HashDataInput() { + HashDataInput signedRef1 = new HashDataInput() { @Override public InputStream getHashDataInput() { - return new ByteArrayInputStream("HashDataInput_002".getBytes()); + return new ByteArrayInputStream("HashDataInput_001\n12345\n\tHello, world!\n12345\n\n12345\n6789\nblabla".getBytes()); } @Override @@ -91,10 +92,69 @@ public class BKUGUIWorker implements Runnable { @Override public String getReferenceId() { - return "ref123"; + return "Reference-ref1-00000000000000000000001"; } }; - gui.showHashDataInputDialog(Collections.singletonList(signedRef), returnListener, "return"); + HashDataInput signedRef2 = new HashDataInput() { + + @Override + public InputStream getHashDataInput() { + return new ByteArrayInputStream("HashDataInput_002".getBytes()); + } + + @Override + public String getMimeType() { + return "text/xml"; + } + + @Override + public String getReferenceId() { + return "Reference-ref2-00000000000000000000002"; + } + }; + HashDataInput signedRef3 = new HashDataInput() { + + @Override + public InputStream getHashDataInput() { + return new ByteArrayInputStream("HashDataInput_003".getBytes()); + } + + @Override + public String getMimeType() { + return "text/xml"; + } + + @Override + public String getReferenceId() { + return "Reference-ref3-00000000000000000000003"; + } + }; + HashDataInput signedRef4 = new HashDataInput() { + + @Override + public InputStream getHashDataInput() { + return new ByteArrayInputStream("HashDataInput_004".getBytes()); + } + + @Override + public String getMimeType() { + return "text/xml"; + } + + @Override + public String getReferenceId() { + return "ref4"; + } + }; + + // + List signedRefs = new ArrayList(); + signedRefs.add(signedRef1); + signedRefs.add(signedRef2); + signedRefs.add(signedRef3); + signedRefs.add(signedRef4); +// signedRefs = Collections.singletonList(signedRef1); + gui.showHashDataInputDialog(signedRefs, returnListener, "return"); } }; @@ -105,7 +165,7 @@ public class BKUGUIWorker implements Runnable { // Thread.sleep(2000); // gui.showInsertCardDialog(cancelListener, "cancel"); -// + // Thread.sleep(2000); // // gui.showCardNotSupportedDialog(cancelListener, "cancel"); @@ -113,7 +173,7 @@ public class BKUGUIWorker implements Runnable { // Thread.sleep(2000); // PINSpec cardPinSpec = new PINSpec(4, 4, "[0-9]", "Karten-PIN"); -// +//// // gui.showCardPINDialog(cardPinSpec, okListener, "ok", cancelListener, "cancel"); // // Thread.sleep(2000); @@ -121,11 +181,11 @@ public class BKUGUIWorker implements Runnable { gui.showSignaturePINDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); - Thread.sleep(2000); +// Thread.sleep(2000); - gui.showSignaturePINRetryDialog(signPinSpec, 2, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); - - Thread.sleep(2000); +// gui.showSignaturePINRetryDialog(signPinSpec, 2, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); +// +// Thread.sleep(2000); //// // gui.showErrorDialog("Testfehler occured", null, null); // @@ -137,8 +197,8 @@ public class BKUGUIWorker implements Runnable { // gui.showTextPlainHashDataInput("hallo,\n welt!", "12345", null, "cancel", null, "save"); // Thread.sleep(2000); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } +// } catch (InterruptedException ex) { +// ex.printStackTrace(); +// } } } diff --git a/BKUCommonGUI/src/test/resources/commons-logging.properties b/BKUCommonGUI/src/test/resources/commons-logging.properties new file mode 100644 index 00000000..29292562 --- /dev/null +++ b/BKUCommonGUI/src/test/resources/commons-logging.properties @@ -0,0 +1 @@ +org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger diff --git a/BKUCommonGUI/src/test/resources/log4j.properties b/BKUCommonGUI/src/test/resources/log4j.properties new file mode 100644 index 00000000..053eac17 --- /dev/null +++ b/BKUCommonGUI/src/test/resources/log4j.properties @@ -0,0 +1,19 @@ +# loglever DEBUG, appender STDOUT +log4j.rootLogger=TRACE, STDOUT +#log4j.logger.at.gv.egiz.slbinding.RedirectEventFilter=DEBUG, STDOUT + +# STDOUT appender +log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender +log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout +#log4j.appender.STDOUT.layout.ConversionPattern=%5p | %d{dd HH:mm:ss,SSS} | %20c | %10t | %m%n +#log4j.appender.STDOUT.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n +log4j.appender.STDOUT.layout.ConversionPattern=%-5p |%d | %t | %c %x- %m%n + +### FILE appender +#log4j.appender.file=org.apache.log4j.RollingFileAppender +#log4j.appender.file.maxFileSize=100KB +#log4j.appender.file.maxBackupIndex=9 +#log4j.appender.file.File=egovbus_ca.log +#log4j.appender.file.threshold=info +#log4j.appender.file.layout=org.apache.log4j.PatternLayout +#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n \ No newline at end of file -- cgit v1.2.3 From 3794536434fdbb06067eddcfd248898ce85f85a1 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 12 Sep 2008 13:06:34 +0000 Subject: gui 0.2 git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@34 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 102 ++- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 885 ++++++++++----------- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 2 + .../at/gv/egiz/bku/gui/HashDataTableModel.java | 71 ++ .../main/java/at/gv/egiz/bku/gui/MimeFilter.java | 98 +++ .../main/java/at/gv/egiz/bku/gui/PinDocument.java | 58 ++ .../at/gv/egiz/bku/gui/Messages.properties | 15 +- .../test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java | 276 +++---- BKUOnline/pom.xml | 13 +- .../gv/egiz/bku/smccstal/SignRequestHandler.java | 6 +- 10 files changed, 840 insertions(+), 686 deletions(-) create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/MimeFilter.java create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java (limited to 'BKUCommonGUI/src/test/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 8289f30b..c7df0871 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -34,63 +34,59 @@ import at.gv.egiz.bku.gui.BKUGUIFactory; */ public class BKUApplet extends JApplet { - private static Log log = LogFactory.getLog(BKUApplet.class); + private static Log log = LogFactory.getLog(BKUApplet.class); + public final static String RESOURCE_BUNDLE_BASE = "at/gv/egiz/bku/online/applet/Messages"; + public final static String LOCALE_PARAM_KEY = "Locale"; + public final static String LOGO_URL_KEY = "LogoURL"; + public final static String WSDL_URL = "WSDL_URL"; + public final static String SESSION_ID = "SessionID"; + protected ResourceBundle resourceBundle; + protected BKUWorker worker; + protected Thread workerThread; - public final static String RESOURCE_BUNDLE_BASE = "at/gv/egiz/bku/online/applet/Messages"; + public BKUApplet() { + } - public final static String LOCALE_PARAM_KEY = "Locale"; - public final static String LOGO_URL_KEY = "LogoURL"; - public final static String WSDL_URL = "WSDL_URL"; - public final static String SESSION_ID = "SessionID"; + public void init() { + log.debug("Called init()"); + HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getInstance()); + String localeString = getMyAppletParameter(LOCALE_PARAM_KEY); + if (localeString != null) { + resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE, + new Locale(localeString)); + } else { + resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE); + } + BKUGUIFacade gui = BKUGUIFactory.createGUI(); + gui.init(getContentPane(), localeString); + worker = new BKUWorker(gui, this, resourceBundle); + } - protected ResourceBundle resourceBundle; - protected BKUWorker worker; - protected Thread workerThread; + public void start() { + log.debug("Called start()"); + workerThread = new Thread(worker); + workerThread.start(); + } - public BKUApplet() { - } + public void stop() { + log.debug("Called stop()"); + if ((workerThread != null) && (workerThread.isAlive())) { + workerThread.interrupt(); + } + } - public void init() { - log.debug("Called init()"); - HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory - .getInstance()); - String localeString = getMyAppletParameter(LOCALE_PARAM_KEY); - if (localeString != null) { - resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE, - new Locale(localeString)); - } else { - resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE); - } - BKUGUIFacade gui = BKUGUIFactory.createGUI(); - gui.init(getContentPane(), localeString); - worker = new BKUWorker(gui, this, resourceBundle); - } + public void destroy() { + log.debug("Called destroy()"); + } - public void start() { - log.debug("Called start()"); - workerThread = new Thread(worker); - workerThread.start(); - } - - public void stop() { - log.debug("Called stop()"); - if ((workerThread != null) && (workerThread.isAlive())) { - workerThread.interrupt(); - } - } - - public void destroy() { - log.debug("Called destroy()"); - } - - /** - * Applet configuration parameters - * - * @param paramKey - * @return - */ - public String getMyAppletParameter(String paramKey) { - log.info("Getting parameter: " + paramKey + ": " + getParameter(paramKey)); - return getParameter(paramKey); - } + /** + * Applet configuration parameters + * + * @param paramKey + * @return + */ + public String getMyAppletParameter(String paramKey) { + log.info("Getting parameter: " + paramKey + ": " + getParameter(paramKey)); + return getParameter(paramKey); + } } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 044e6927..584dba1a 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -27,6 +27,7 @@ import java.awt.Component; import java.awt.Container; import java.awt.Cursor; import java.awt.Dimension; +import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; @@ -75,13 +76,11 @@ import org.apache.commons.logging.LogFactory; * @author clemens */ public class BKUGUI implements BKUGUIFacade { - + private static final Log log = LogFactory.getLog(BKUGUI.class); public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; public static final String LOGO_RESOURCE = "/images/logo.png"; -// public static final int MAIN_PANEL_WIDTH = 100; -// public static final int MAIN_PANEL_HEIGHT = 20; -// public static final int PREF_SIZE_PINFIELD = 118; + public static final String HASHDATA_FONT = "Monospaced"; public static final Color ERROR_COLOR = Color.RED; public static final Color HYPERLINK_COLOR = Color.BLUE; private static final String TITLE_WELCOME = "title.welcome"; @@ -94,6 +93,7 @@ public class BKUGUI implements BKUGUIFacade { private static final String TITLE_WAIT = "title.wait"; private static final String TITLE_HASHDATA = "title.hashdata"; private static final String WINDOWTITLE_SAVE = "windowtitle.save"; + private static final String WINDOWTITLE_SAVEDIR = "windowtitle.savedir"; private static final String WINDOWTITLE_OVERWRITE = "windowtitle.overwrite"; private static final String MESSAGE_WAIT = "message.wait"; private static final String MESSAGE_INSERTCARD = "message.insertcard"; @@ -104,19 +104,13 @@ public class BKUGUI implements BKUGUIFacade { private static final String MESSAGE_OVERWRITE = "message.overwrite"; private static final String LABEL_PIN = "label.pin"; private static final String LABEL_PINSIZE = "label.pinsize"; - private static final String ERROR_HASHDATA = "error.hashdata"; + private static final String ERROR_NO_HASHDATA = "error.no.hashdata"; private static final String BUTTON_OK = "button.ok"; private static final String BUTTON_CANCEL = "button.cancel"; private static final String BUTTON_BACK = "button.back"; private static final String BUTTON_SIGN = "button.sign"; private static final String BUTTON_SAVE = "button.save"; - private static final String MIMETYPE_DESC_XML = "mimetype.desc.xml"; - private static final String MIMETYPE_DESC_HTML = "mimetype.desc.html"; - private static final String MIMETYPE_DESC_XHTML = "mimetype.desc.xhtml"; - private static final String MIMETYPE_DESC_TXT = "mimetype.desc.txt"; - private static final String MIMETYPE_DESC_PDF = "mimetype.desc.pdf"; - private static final String MIMETYPE_DESC_BIN = "mimetype.desc.bin"; private static final String SAVE_HASHDATAINPUT_PREFIX = "save.hashdatainput.prefix"; protected Container contentPane; protected ResourceBundle messages; @@ -132,11 +126,11 @@ public class BKUGUI implements BKUGUIFacade { /** remember the pinfield to return to worker */ protected JPasswordField pinField; - protected JButton okButton; - protected JButton cancelButton; - protected JButton signButton; - protected JButton saveButton; - protected JButton backButton; +// protected JButton okButton; +// protected JButton cancelButton; +// protected JButton signButton; +// protected JButton saveButton; +// protected JButton backButton; protected int buttonSize; private static final int CHECKBOX_WIDTH = new JCheckBox().getPreferredSize().width; @@ -216,28 +210,43 @@ public class BKUGUI implements BKUGUIFacade { java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); // titleLabel.setForeground(defaultForground); - okButton = new JButton(); - okButton.setText(messages.getString(BUTTON_OK)); - cancelButton = new JButton(); - cancelButton.setText(messages.getString(BUTTON_CANCEL)); - signButton = new JButton(); - signButton.setText(messages.getString(BUTTON_SIGN)); - backButton = new JButton(); - backButton.setText(messages.getString(BUTTON_BACK)); - saveButton = new JButton(); - saveButton.setText(messages.getString(BUTTON_SAVE)); +// okButton = new JButton(); +// okButton.setText(messages.getString(BUTTON_OK)); +// cancelButton = new JButton(); +// cancelButton.setText(messages.getString(BUTTON_CANCEL)); +// signButton = new JButton(); +// signButton.setText(messages.getString(BUTTON_SIGN)); +// backButton = new JButton(); +// backButton.setText(messages.getString(BUTTON_BACK)); +// saveButton = new JButton(); +// saveButton.setText(messages.getString(BUTTON_SAVE)); // contentPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); - if (okButton.getPreferredSize().width > buttonSize) - buttonSize = okButton.getPreferredSize().width; - if (cancelButton.getPreferredSize().width > buttonSize) - buttonSize = cancelButton.getPreferredSize().width; - if (signButton.getPreferredSize().width > buttonSize) - buttonSize = signButton.getPreferredSize().width; - if (backButton.getPreferredSize().width > buttonSize) - buttonSize = backButton.getPreferredSize().width; - if (saveButton.getPreferredSize().width > buttonSize) - buttonSize = saveButton.getPreferredSize().width; + JButton b = new JButton(); + b.setText(messages.getString(BUTTON_CANCEL)); + if (b.getPreferredSize().width > buttonSize) + buttonSize = b.getPreferredSize().width; + b.setText(messages.getString(BUTTON_OK)); + if (b.getPreferredSize().width > buttonSize) + buttonSize = b.getPreferredSize().width; + b.setText(messages.getString(BUTTON_SIGN)); + if (b.getPreferredSize().width > buttonSize) + buttonSize = b.getPreferredSize().width; + b.setText(messages.getString(BUTTON_BACK)); + if (b.getPreferredSize().width > buttonSize) + buttonSize = b.getPreferredSize().width; + b.setText(messages.getString(BUTTON_SAVE)); + if (b.getPreferredSize().width > buttonSize) + buttonSize = b.getPreferredSize().width; + +// if (cancelButton.getPreferredSize().width > buttonSize) +// buttonSize = cancelButton.getPreferredSize().width; +// if (signButton.getPreferredSize().width > buttonSize) +// buttonSize = signButton.getPreferredSize().width; +// if (backButton.getPreferredSize().width > buttonSize) +// buttonSize = backButton.getPreferredSize().width; +// if (saveButton.getPreferredSize().width > buttonSize) +// buttonSize = saveButton.getPreferredSize().width; GroupLayout headerPanelLayout = new GroupLayout(headerPanel); @@ -349,6 +358,8 @@ public class BKUGUI implements BKUGUIFacade { titleLabel.setText(messages.getString(TITLE_INSERTCARD)); + JButton cancelButton = new JButton(); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); cancelButton.addActionListener(cancelListener); cancelButton.setActionCommand(cancelCommand); @@ -400,6 +411,8 @@ public class BKUGUI implements BKUGUIFacade { // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(errorMsgLabel)); + JButton cancelButton = new JButton(); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); cancelButton.addActionListener(cancelListener); cancelButton.setActionCommand(cancelCommand); @@ -439,9 +452,13 @@ public class BKUGUI implements BKUGUIFacade { titleLabel.setText(messages.getString(TITLE_RETRY)); } + JButton cancelButton = new JButton(); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); cancelButton.setActionCommand(cancelCommand); cancelButton.addActionListener(cancelListener); + JButton okButton = new JButton(); + okButton.setText(messages.getString(BUTTON_OK)); okButton.setEnabled(false); okButton.setActionCommand(okCommand); okButton.addActionListener(okListener); @@ -592,9 +609,13 @@ public class BKUGUI implements BKUGUIFacade { titleLabel.setText(messages.getString(TITLE_RETRY)); } + JButton cancelButton = new JButton(); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); cancelButton.setActionCommand(cancelCommand); cancelButton.addActionListener(cancelListener); + JButton signButton = new JButton(); + signButton.setText(messages.getString(BUTTON_SIGN)); signButton.setEnabled(false); signButton.setActionCommand(signCommand); signButton.addActionListener(signListener); @@ -764,6 +785,8 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(errorMsgLabel)); + JButton okButton = new JButton(); + okButton.setText(messages.getString(BUTTON_OK)); okButton.setActionCommand(okCommand); okButton.addActionListener(okListener); @@ -790,343 +813,386 @@ public class BKUGUI implements BKUGUIFacade { @Override public void showErrorDialog(final String errorMsg) { - SwingUtilities.invokeLater(new Runnable() { + SwingUtilities.invokeLater(new Runnable() { - public void run() { - mainPanel.removeAll(); - buttonPanel.removeAll(); + @Override + public void run() { + mainPanel.removeAll(); + buttonPanel.removeAll(); - titleLabel.setText(messages.getString(TITLE_ERROR)); + titleLabel.setText(messages.getString(TITLE_ERROR)); // titleLabel.setForeground(defaultForground); - JLabel errorMsgLabel = new JLabel(); - errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText("" + errorMsg + ""); - errorMsgLabel.setForeground(ERROR_COLOR); + JLabel errorMsgLabel = new JLabel(); + errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + errorMsgLabel.setText("" + errorMsg + ""); + errorMsgLabel.setForeground(ERROR_COLOR); - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(errorMsgLabel) - .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(errorMsgLabel)); + .addComponent(errorMsgLabel) + .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorMsgLabel)); - contentPanel.validate(); - } - }); + contentPanel.validate(); + } + }); } @Override public void showHashDataInputDialog(final List signedReferences, final ActionListener okListener, final String okCommand) { - SwingUtilities.invokeLater(new Runnable() { + + if (signedReferences == null) { + showErrorDialog(messages.getString(ERROR_NO_HASHDATA), okListener, okCommand); + } + + if (signedReferences.size() == 1) { + +// final HashDataInput signedRef = signedReferences.get(0); + + if ("text/plain".equals(signedReferences.get(0).getMimeType())) { + + ActionListener saveHashDataListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + showSaveHashDataInputDialog(signedReferences, okListener, okCommand); + } + }; + String hashDataText = getText(signedReferences.get(0)); + if (hashDataText != null) { + showPlainTextHashDataInputDialog(hashDataText, saveHashDataListener, "save", okListener, okCommand); + } else { + showErrorDialog(messages.getString(ERROR_NO_HASHDATA), okListener, okCommand); + } + + } else { + showSaveHashDataInputDialog(signedReferences, okListener, okCommand); + } + + } else { - @Override - public void run() { + final HashDataTableModel tableModel = new HashDataTableModel(signedReferences); - if (signedReferences != null && signedReferences.size() == 1) { - - final HashDataInput signedRef = signedReferences.get(0); - if ("text/plain".equals(signedRef.getMimeType())) { - //TODO get encoding from mimetype - //read directly to byte[] since hashDataIS is backed by byte[] ? - ByteArrayOutputStream baos = null; - try { - String refId = signedRef.getReferenceId(); - InputStream hashDataIS = signedRef.getHashDataInput(); - if (hashDataIS == null) { - showErrorDialog("Failed to obtain HashDataInput for reference " + refId, okListener, okCommand); - } else { - baos = new ByteArrayOutputStream(hashDataIS.available()); - int c; - while ((c = hashDataIS.read()) != -1) { - baos.write(c); - } - String text = baos.toString("UTF-8"); - - ActionListener al = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - showSaveHashDataInputDialog(signedRef, okListener, okCommand); - } - }; - showPlainTextHashDataInputDialog(text, refId, okListener, okCommand, al, "save"); - } - } catch (IOException ex) { - showErrorDialog("Failed to read HashDataInput for reference " + signedRef.getReferenceId() + ": " + ex.getMessage(), okListener, okCommand); - } finally { - try { - baos.close(); - } catch (IOException ex) { - } - } - } else { - showSaveHashDataInputDialog(signedRef, okListener, okCommand); - } + ActionListener saveHashDataListener = new ActionListener() { - } else if (signedReferences != null && signedReferences.size() > 1) { - final HashDataTableModel tableModel = new HashDataTableModel(signedReferences); - - ActionListener al = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - List selection = tableModel.getSelectedReferenceIds(); - StringBuilder sb = new StringBuilder("Not implemented yet. \n"); - for (String string : selection) { - sb.append(string); - sb.append('\n'); - } - showErrorDialog(sb.toString(), okListener, okCommand); -// showSaveHashDataInputDialog(signedRef, okListener, okCommand); - } - }; - showMultipleHashDataInputDialog(tableModel, okListener, okCommand, al, "save"); - } else { - showErrorDialog(messages.getString(ERROR_HASHDATA), okListener, okCommand); - } + @Override + public void actionPerformed(ActionEvent e) { + showSaveHashDataInputDialog(tableModel.getSelectedHashData(), okListener, okCommand); } - }); + }; + showMultipleHashDataInputDialog(tableModel, okListener, okCommand, saveHashDataListener, "save"); + } + } + + private static String getText(HashDataInput hdi) { + ByteArrayOutputStream baos = null; + try { + InputStream hashDataIS = hdi.getHashDataInput(); + if (hashDataIS == null) { + log.error("No HashDataInput stream for reference " + hdi.getReferenceId()); + return null; + } else { + baos = new ByteArrayOutputStream(hashDataIS.available()); + int c; + while ((c = hashDataIS.read()) != -1) { + baos.write(c); + } + return baos.toString("UTF-8"); + } + } catch (IOException ex) { + log.error("Failed to read HashDataInput for reference " + hdi.getReferenceId() + ": " + ex.getMessage()); + return null; + } finally { + try { + baos.close(); + } catch (IOException ex) { + } + } } - private void showPlainTextHashDataInputDialog(String text, String refId, ActionListener cancelListener, String cancelCommand, ActionListener saveListener, String saveCommand) { - mainPanel.removeAll(); - buttonPanel.removeAll(); + private void showPlainTextHashDataInputDialog(final String hashDataText, final ActionListener saveListener, final String saveCommand, final ActionListener cancelListener, final String cancelCommand) { + SwingUtilities.invokeLater(new Runnable() { - titleLabel.setText(messages.getString(TITLE_HASHDATA)); + @Override + public void run() { + mainPanel.removeAll(); + buttonPanel.removeAll(); + + titleLabel.setText(messages.getString(TITLE_HASHDATA)); + + JLabel refIdLabel = new JLabel(); + refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + refIdLabel.setText(messages.getString(MESSAGE_HASHDATA)); //MessageFormat.format(refIdLabelPattern, new Object[]{refId})); + + JScrollPane hashDataScrollPane = new JScrollPane(); + JTextArea hashDataTextArea = new JTextArea(hashDataText); + hashDataTextArea.setEditable(false); + hashDataTextArea.setColumns(1); + hashDataTextArea.setRows(1); + hashDataTextArea.setFont(new Font(HASHDATA_FONT, hashDataTextArea.getFont().getStyle(), hashDataTextArea.getFont().getSize())); + hashDataScrollPane.setViewportView(hashDataTextArea); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createSequentialGroup() + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(refIdLabel) + .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()); + + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() + .addComponent(refIdLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(hashDataScrollPane, 0, GroupLayout.PREFERRED_SIZE, hashDataTextArea.getPreferredSize().height+3)); + + + + // GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + // mainPanel.setLayout(mainPanelLayout); + // + // mainPanelLayout.setHorizontalGroup( + // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(refIdLabel).addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)).addContainerGap())); + // + // mainPanelLayout.setVerticalGroup( + // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addComponent(refIdLabel).addGap(refIdLabel.getFont().getSize()).addComponent(hashDataScrollPane).addGap(refIdLabel.getFont().getSize()))); + + JButton backButton = new JButton(); + backButton.setText(messages.getString(BUTTON_BACK)); + backButton.setActionCommand(cancelCommand); + backButton.addActionListener(cancelListener); + + JButton saveButton = new JButton(); + saveButton.setText(messages.getString(BUTTON_SAVE)); + saveButton.setActionCommand(saveCommand); + saveButton.addActionListener(saveListener); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + // buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); + 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(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + .addContainerGap()); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(saveButton) + .addComponent(backButton)); + + + // GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + // buttonPanel.setLayout(buttonPanelLayout); + // + // buttonPanelLayout.setHorizontalGroup( + // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(saveButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); + // buttonPanelLayout.setVerticalGroup( + // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(saveButton).addComponent(cancelButton))); + + contentPanel.validate(); + } + }); + } - JLabel refIdLabel = new JLabel(); - refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - String refIdLabelPattern = messages.getString(MESSAGE_HASHDATA); - refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[]{refId})); + private void showMultipleHashDataInputDialog(final TableModel signedReferences, final ActionListener cancelListener, final String cancelCommand, final ActionListener saveListener, final String saveCommand) { + SwingUtilities.invokeLater(new Runnable() { - JScrollPane hashDataScrollPane = new JScrollPane(); - JTextArea hashDataTextArea = new JTextArea(text); - hashDataTextArea.setEditable(false); - hashDataTextArea.setColumns(1); - hashDataTextArea.setRows(1); - hashDataScrollPane.setViewportView(hashDataTextArea); + @Override + public void run() { + mainPanel.removeAll(); + buttonPanel.removeAll(); - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); + titleLabel.setText(messages.getString(TITLE_HASHDATA)); - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(refIdLabel) - .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()); + JLabel refIdLabel = new JLabel(); + refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + String refIdLabelPattern = messages.getString(MESSAGE_HASHDATALIST); + refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[]{signedReferences.getRowCount()})); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(refIdLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(hashDataScrollPane, 0, GroupLayout.PREFERRED_SIZE, hashDataTextArea.getPreferredSize().height+3)); + JTable hashDataTable = new JTable(); + 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); + + + hashDataTable.setPreferredScrollableViewportSize(mainPanel.getPreferredSize()); - - -// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); -// mainPanel.setLayout(mainPanelLayout); -// -// mainPanelLayout.setHorizontalGroup( -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(refIdLabel).addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)).addContainerGap())); -// -// mainPanelLayout.setVerticalGroup( -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addComponent(refIdLabel).addGap(refIdLabel.getFont().getSize()).addComponent(hashDataScrollPane).addGap(refIdLabel.getFont().getSize()))); + JScrollPane hashDataScrollPane = new JScrollPane(hashDataTable); - backButton.setActionCommand(cancelCommand); - backButton.addActionListener(cancelListener); + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); - saveButton.setActionCommand(saveCommand); - saveButton.addActionListener(saveListener); - - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - -// buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); - 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(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) - .addContainerGap()); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(saveButton) - .addComponent(backButton)); - - -// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); -// buttonPanel.setLayout(buttonPanelLayout); -// -// buttonPanelLayout.setHorizontalGroup( -// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE).addComponent(saveButton).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton).addContainerGap())); -// buttonPanelLayout.setVerticalGroup( -// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(saveButton).addComponent(cancelButton))); + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createSequentialGroup() + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(refIdLabel) + .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()); - contentPanel.validate(); - } + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() + .addComponent(refIdLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(hashDataScrollPane, 0, GroupLayout.PREFERRED_SIZE, hashDataTable.getPreferredSize().height+3)); + // .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)); - private void showMultipleHashDataInputDialog(final TableModel signedReferences, final ActionListener cancelListener, final String cancelCommand, ActionListener saveListener, String saveCommand) { - mainPanel.removeAll(); - buttonPanel.removeAll(); - - titleLabel.setText(messages.getString(TITLE_HASHDATA)); - - JLabel refIdLabel = new JLabel(); - refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - String refIdLabelPattern = messages.getString(MESSAGE_HASHDATALIST); - refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[]{signedReferences.getRowCount()})); - - JTable hashDataTable = new JTable(); - 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); - - - hashDataTable.setPreferredScrollableViewportSize(mainPanel.getPreferredSize()); - - JScrollPane hashDataScrollPane = new JScrollPane(hashDataTable); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(refIdLabel) - .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()); - - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(refIdLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(hashDataScrollPane, 0, GroupLayout.PREFERRED_SIZE, hashDataTable.getPreferredSize().height+3)); -// .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)); - - -// -// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); -// mainPanel.setLayout(mainPanelLayout); -// -// mainPanelLayout.setHorizontalGroup( -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addGroup(mainPanelLayout.createSequentialGroup() -// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addComponent(refIdLabel) -// .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)) -// .addContainerGap())); -// -// mainPanelLayout.setVerticalGroup( -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addGroup(mainPanelLayout.createSequentialGroup() -// .addComponent(refIdLabel) -// .addGap(refIdLabel.getFont().getSize()) -// .addComponent(hashDataScrollPane) -// .addGap(refIdLabel.getFont().getSize()))); - - - - - - - - - - - -// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); -// buttonPanel.setLayout(buttonPanelLayout); -// -// buttonPanelLayout.setHorizontalGroup( -// buttonPanelLayout.createSequentialGroup() -//// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -//// .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() -// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) -// .addComponent(saveButton) -// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) -// .addComponent(cancelButton) -// .addContainerGap()); //); -// buttonPanelLayout.setVerticalGroup( -// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() -// .addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) -// .addComponent(saveButton) -// .addComponent(cancelButton)) -// .addContainerGap())); + // + // GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + // mainPanel.setLayout(mainPanelLayout); + // + // mainPanelLayout.setHorizontalGroup( + // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + // .addGroup(mainPanelLayout.createSequentialGroup() + // .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + // .addComponent(refIdLabel) + // .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, PREF_SIZE_PINFIELD, Short.MAX_VALUE)) + // .addContainerGap())); + // + // mainPanelLayout.setVerticalGroup( + // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + // .addGroup(mainPanelLayout.createSequentialGroup() + // .addComponent(refIdLabel) + // .addGap(refIdLabel.getFont().getSize()) + // .addComponent(hashDataScrollPane) + // .addGap(refIdLabel.getFont().getSize()))); - - backButton.setActionCommand(cancelCommand); - backButton.addActionListener(cancelListener); - saveButton.setActionCommand(saveCommand); - saveButton.addActionListener(saveListener); - - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - -// buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); - 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(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) - .addContainerGap());//); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(saveButton) - .addComponent(backButton)); - - contentPanel.validate(); + + + + + + + + + + + // GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + // buttonPanel.setLayout(buttonPanelLayout); + // + // buttonPanelLayout.setHorizontalGroup( + // buttonPanelLayout.createSequentialGroup() + //// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + //// .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() + // .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + // .addComponent(saveButton) + // .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + // .addComponent(cancelButton) + // .addContainerGap()); //); + // buttonPanelLayout.setVerticalGroup( + // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + // .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() + // .addGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + // .addComponent(saveButton) + // .addComponent(cancelButton)) + // .addContainerGap())); + + + JButton backButton = new JButton(); + backButton.setText(messages.getString(BUTTON_BACK)); + backButton.setActionCommand(cancelCommand); + backButton.addActionListener(cancelListener); + + JButton saveButton = new JButton(); + saveButton.setText(messages.getString(BUTTON_SAVE)); + saveButton.setActionCommand(saveCommand); + saveButton.addActionListener(saveListener); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + // buttonPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); + 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(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) + .addContainerGap());//); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(saveButton) + .addComponent(backButton)); + + contentPanel.validate(); + } + }); } - private void showSaveHashDataInputDialog(HashDataInput signedRef, ActionListener okListener, String okCommand) { - String dir = System.getProperty("user.home"); - JFileChooser fileDialog = new JFileChooser(dir); - fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY); - fileDialog.setMultiSelectionEnabled(false); - fileDialog.setDialogTitle(messages.getString(WINDOWTITLE_SAVE)); - fileDialog.setDialogType(JFileChooser.SAVE_DIALOG); - fileDialog.setFileHidingEnabled(true); - MimeFilter mimeFilter = new MimeFilter(signedRef.getMimeType()); - fileDialog.setFileFilter(mimeFilter); - String filename = messages.getString(SAVE_HASHDATAINPUT_PREFIX) + mimeFilter.getExtension(); - fileDialog.setSelectedFile(new File(dir, filename)); - switch (fileDialog.showSaveDialog(contentPane)) { +// private DisposableFileChooser fileDialog; + + private void showSaveHashDataInputDialog(final List signedRefs, final ActionListener okListener, final String okCommand) { + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + String userHome = System.getProperty("user.home"); + + JFileChooser fileDialog = new JFileChooser(userHome); + fileDialog.setMultiSelectionEnabled(false); + fileDialog.setDialogType(JFileChooser.SAVE_DIALOG); + fileDialog.setFileHidingEnabled(true); + if (signedRefs.size() == 1) { + fileDialog.setDialogTitle(messages.getString(WINDOWTITLE_SAVE)); + fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY); + String mimeType = signedRefs.get(0).getMimeType(); + MimeFilter mimeFilter = new MimeFilter(mimeType, messages); + fileDialog.setFileFilter(mimeFilter); + String filename = messages.getString(SAVE_HASHDATAINPUT_PREFIX) + MimeFilter.getExtension(mimeType); + fileDialog.setSelectedFile(new File(userHome, filename)); + } else { + fileDialog.setDialogTitle(messages.getString(WINDOWTITLE_SAVEDIR)); + fileDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + } + + //parent contentPane -> placed over applet + switch (fileDialog.showSaveDialog(fileDialog)) { case JFileChooser.APPROVE_OPTION: - File f = fileDialog.getSelectedFile(); - if (f.exists()) { -// log.debug("hashDataInput file exists, overwrite?"); - String ovrwrt = messages.getString(MESSAGE_OVERWRITE); - int overwrite = JOptionPane.showConfirmDialog(contentPane, MessageFormat.format(ovrwrt, filename), messages.getString(WINDOWTITLE_OVERWRITE), JOptionPane.OK_CANCEL_OPTION); - if (overwrite != JOptionPane.OK_OPTION) { -// log.debug("User canceled overwrite HashDataInput, returning to SignaturePin dialog"); - okListener.actionPerformed(new ActionEvent(fileDialog, ActionEvent.ACTION_PERFORMED, okCommand)); - return; - } + File f = fileDialog.getSelectedFile(); + for (HashDataInput hashDataInput : signedRefs) { + String mimeType = hashDataInput.getMimeType(); + String id = hashDataInput.getReferenceId(); + File file; + if (f.isDirectory()) { + String filename = messages.getString(SAVE_HASHDATAINPUT_PREFIX) + '_' + id + MimeFilter.getExtension(mimeType); + file = new File(f, filename); + } else { + file = f; + } + if (file.exists()) { + String ovrwrt = messages.getString(MESSAGE_OVERWRITE); + int overwrite = JOptionPane.showConfirmDialog(fileDialog, MessageFormat.format(ovrwrt, file), messages.getString(WINDOWTITLE_OVERWRITE), JOptionPane.OK_CANCEL_OPTION); + if (overwrite != JOptionPane.OK_OPTION) { + continue; + } } if (log.isDebugEnabled()) { - log.debug("Writing HashDataInput " + signedRef.getReferenceId() + " (" + signedRef.getMimeType() + ") to file " + f); + log.debug("Writing HashDataInput " + id + " (" + mimeType + ") to file " + file); } FileOutputStream fos = null; try { - fos = new FileOutputStream(f); + fos = new FileOutputStream(file); BufferedOutputStream bos = new BufferedOutputStream(fos); - InputStream hdi = signedRef.getHashDataInput(); + InputStream hdi = hashDataInput.getHashDataInput(); int b; while ((b = hdi.read()) != -1) { bos.write(b); @@ -1134,7 +1200,7 @@ public class BKUGUI implements BKUGUIFacade { bos.flush(); bos.close(); } catch (IOException ex) { - log.error("Failed to write HashDataInput to file " + f + ": " + ex.getMessage()); + log.error("Failed to write HashDataInput to file " + file + ": " + ex.getMessage()); showErrorDialog("Failed to write signed reference to file: " + ex.getMessage(), null, null); ex.printStackTrace(); } finally { @@ -1142,11 +1208,15 @@ public class BKUGUI implements BKUGUIFacade { fos.close(); } catch (IOException ex) { } - } + } + } + } + log.debug("done saving hashdatainput"); + okListener.actionPerformed(new ActionEvent(fileDialog, ActionEvent.ACTION_PERFORMED, okCommand)); } - okListener.actionPerformed(new ActionEvent(fileDialog, ActionEvent.ACTION_PERFORMED, okCommand)); + }); } - + @Override public void showWaitDialog(final String waitMessage) { SwingUtilities.invokeLater(new Runnable() { @@ -1190,149 +1260,4 @@ public class BKUGUI implements BKUGUIFacade { return null; } - class PINDocument extends PlainDocument { - - private PINSpec pinSpec; - private Pattern pinPattern; - private JButton enterButton; - - public PINDocument(PINSpec pinSpec, JButton enterButton) { - this.pinSpec = pinSpec; - if (pinSpec.getRexepPattern() != null) { - pinPattern = Pattern.compile(pinSpec.getRexepPattern()); - } else { - pinPattern = Pattern.compile("."); - } - this.enterButton = enterButton; - } - - @Override - public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { - if (pinSpec.getMaxLength() >= (getLength() + str.length())) { - boolean matches = true; - for (int i = 0; i < str.length(); i++) { - Matcher m = pinPattern.matcher(str.substring(i, i + 1)); - if (!m.matches()) { - matches = false; - } - } - if (matches) { - super.insertString(offs, str, a); - } - } - enterButton.setEnabled(getLength() >= pinSpec.getMinLength()); - } - - @Override - public void remove(int offs, int len) throws BadLocationException { - super.remove(offs, len); - enterButton.setEnabled(getLength() >= pinSpec.getMinLength()); - } - } - - class MimeFilter extends FileFilter { - - protected String mimeType; - - public MimeFilter(String mimeType) { - this.mimeType = mimeType; - } - - @Override - public boolean accept(File f) { - - if (f.isDirectory()) { - return true; - } - - String ext = getExtension(f); - if ("text/xml".equals(mimeType)) { - return "xml".equalsIgnoreCase(ext); - } else if ("text/html".equals(mimeType)) { - return "html".equalsIgnoreCase(ext) || "htm".equalsIgnoreCase(ext); - } else if ("application/xhtml+xml".equals(mimeType)) { - return "xhtml".equalsIgnoreCase(ext); - } else if ("text/plain".equals(mimeType)) { - return "txt".equalsIgnoreCase(ext); - } else if ("application/pdf".equals(mimeType)) { - return "pdf".equalsIgnoreCase(ext); - } else { - return true; - } - } - - private String getExtension(File f) { - String ext = null; - String s = f.getName(); - int i = s.lastIndexOf('.'); - - if (i > 0 && i < s.length() - 1) { - ext = s.substring(i + 1).toLowerCase(); - } - return ext; - } - - @Override - public String getDescription() { - if ("text/xml".equals(mimeType)) { - return messages.getString(MIMETYPE_DESC_XML); - } else if ("text/html".equals(mimeType)) { - return messages.getString(MIMETYPE_DESC_HTML); - } else if ("application/xhtml+xml".equals(mimeType)) { - return messages.getString(MIMETYPE_DESC_XHTML); - } else if ("text/plain".equals(mimeType)) { - return messages.getString(MIMETYPE_DESC_TXT); - } else if ("application/pdf".equals(mimeType)) { - return messages.getString(MIMETYPE_DESC_PDF); - } else { - return messages.getString(MIMETYPE_DESC_BIN); - } - } - - public String getExtension() { - if ("text/xml".equals(mimeType)) { - return ".xml"; - } else if ("text/html".equals(mimeType)) { - return ".html"; - } else if ("application/xhtml+xml".equals(mimeType)) { - return ".xhtml"; - } else if ("text/plain".equals(mimeType)) { - return ".txt"; - } else if ("application/pdf".equals(mimeType)) { - return ".pdf"; - } else { - return ".bin"; - } - } - } - - class HashDataTableModel extends DefaultTableModel { - - Class[] types = new Class[]{ - java.lang.String.class, java.lang.Boolean.class - }; - - public HashDataTableModel(List signedReferences) { - super(0, 2); - for (HashDataInput hashDataInput : signedReferences) { - addRow(new Object[]{hashDataInput.getReferenceId(), new Boolean(true)}); - } - } - - @Override - public Class getColumnClass(int columnIndex) { - return types [columnIndex]; - } - - 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; - } - - } } 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 f8b80556..f4b6325d 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 @@ -53,6 +53,8 @@ public interface BKUGUIFacade { public void showHashDataInputDialog(List signedReferences, ActionListener okListener, String actionCommand); +// public void showPlainTextHashDataInputDialog(String text, ActionListener saveListener, String saveCommand, ActionListener cancelListener, String cancelCommand); + public void showErrorDialog(String errorMsg, ActionListener okListener, String actionCommand); public void showErrorDialog(String errorMsg); 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 new file mode 100644 index 00000000..061a2849 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataTableModel.java @@ -0,0 +1,71 @@ +/* +* 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.util.ArrayList; +import java.util.List; +import java.util.Vector; +import javax.swing.table.DefaultTableModel; + +/** + * + * @author clemens + */ +class HashDataTableModel extends DefaultTableModel { + + protected List signedReferences; + + Class[] types = new Class[]{ + java.lang.String.class, java.lang.Boolean.class + }; + + public HashDataTableModel(List signedReferences) { + super(0, 2); + this.signedReferences = signedReferences; + for (HashDataInput hashDataInput : signedReferences) { + String desc = hashDataInput.getReferenceId() + " (" + hashDataInput.getMimeType() + ")"; + addRow(new Object[]{desc, new Boolean(true)}); + } + } + + @Override + public Class getColumnClass(int columnIndex) { + return types [columnIndex]; + } + + public List getSelectedHashData() { + ArrayList selection = new ArrayList(); + for (int i = 0; i < dataVector.size(); i++) { + if ((Boolean) ((Vector) dataVector.get(i)).elementAt(1)) { + selection.add(signedReferences.get(i)); + } + } + 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/MimeFilter.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/MimeFilter.java new file mode 100644 index 00000000..6ee61a82 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/MimeFilter.java @@ -0,0 +1,98 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package at.gv.egiz.bku.gui; + +import java.io.File; +import java.util.ResourceBundle; +import javax.swing.filechooser.FileFilter; + +/** + * + * @author clemens + */ +class MimeFilter extends FileFilter { + + private static final String MIMETYPE_DESC_XML = "mimetype.desc.xml"; + private static final String MIMETYPE_DESC_HTML = "mimetype.desc.html"; + private static final String MIMETYPE_DESC_XHTML = "mimetype.desc.xhtml"; + private static final String MIMETYPE_DESC_TXT = "mimetype.desc.txt"; + private static final String MIMETYPE_DESC_PDF = "mimetype.desc.pdf"; + private static final String MIMETYPE_DESC_BIN = "mimetype.desc.bin"; + + protected String mimeType; + protected ResourceBundle messages; + + public MimeFilter(String mimeType, ResourceBundle messages) { + this.mimeType = mimeType; + this.messages = messages; + } + + @Override + public boolean accept(File f) { + + if (f.isDirectory()) { + return true; + } + + String ext = getExtension(f); + if ("text/xml".equals(mimeType)) { + return "xml".equalsIgnoreCase(ext); + } else if ("text/html".equals(mimeType)) { + return "html".equalsIgnoreCase(ext) || "htm".equalsIgnoreCase(ext); + } else if ("application/xhtml+xml".equals(mimeType)) { + return "xhtml".equalsIgnoreCase(ext); + } else if ("text/plain".equals(mimeType)) { + return "txt".equalsIgnoreCase(ext); + } else if ("application/pdf".equals(mimeType)) { + return "pdf".equalsIgnoreCase(ext); + } else { + return true; + } + } + + private String getExtension(File f) { + String ext = null; + String s = f.getName(); + int i = s.lastIndexOf('.'); + + if (i > 0 && i < s.length() - 1) { + ext = s.substring(i + 1).toLowerCase(); + } + return ext; + } + + @Override + public String getDescription() { + if ("text/xml".equals(mimeType)) { + return messages.getString(MIMETYPE_DESC_XML); + } else if ("text/html".equals(mimeType)) { + return messages.getString(MIMETYPE_DESC_HTML); + } else if ("application/xhtml+xml".equals(mimeType)) { + return messages.getString(MIMETYPE_DESC_XHTML); + } else if ("text/plain".equals(mimeType)) { + return messages.getString(MIMETYPE_DESC_TXT); + } else if ("application/pdf".equals(mimeType)) { + return messages.getString(MIMETYPE_DESC_PDF); + } else { + return messages.getString(MIMETYPE_DESC_BIN); + } + } + + public static String getExtension(String mimeType) { + if ("text/xml".equals(mimeType)) { + return ".xml"; + } else if ("text/html".equals(mimeType)) { + return ".html"; + } else if ("application/xhtml+xml".equals(mimeType)) { + return ".xhtml"; + } else if ("text/plain".equals(mimeType)) { + return ".txt"; + } else if ("application/pdf".equals(mimeType)) { + return ".pdf"; + } else { + return ".bin"; + } + } +} \ No newline at end of file diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java new file mode 100644 index 00000000..e8572742 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java @@ -0,0 +1,58 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package at.gv.egiz.bku.gui; + +import at.gv.egiz.smcc.PINSpec; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import javax.swing.JButton; +import javax.swing.text.AttributeSet; +import javax.swing.text.BadLocationException; +import javax.swing.text.PlainDocument; + +/** + * + * @author clemens + */ +class PINDocument extends PlainDocument { + + private PINSpec pinSpec; + private Pattern pinPattern; + private JButton enterButton; + + public PINDocument(PINSpec pinSpec, JButton enterButton) { + this.pinSpec = pinSpec; + if (pinSpec.getRexepPattern() != null) { + pinPattern = Pattern.compile(pinSpec.getRexepPattern()); + } else { + pinPattern = Pattern.compile("."); + } + this.enterButton = enterButton; + } + + @Override + public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { + if (pinSpec.getMaxLength() >= (getLength() + str.length())) { + boolean matches = true; + for (int i = 0; i < str.length(); i++) { + Matcher m = pinPattern.matcher(str.substring(i, i + 1)); + if (!m.matches()) { + matches = false; + } + } + if (matches) { + super.insertString(offs, str, a); + } + } + enterButton.setEnabled(getLength() >= pinSpec.getMinLength()); + } + + @Override + public void remove(int offs, int len) throws BadLocationException { + super.remove(offs, len); + enterButton.setEnabled(getLength() >= pinSpec.getMinLength()); + } + } \ No newline at end of file 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 b651fa8d..a329ba86 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 @@ -23,6 +23,7 @@ title.retry=Falscher PIN title.wait=Bitte warten title.hashdata=Signaturdaten windowtitle.save=Signaturdaten speichern +windowtitle.savedir=Signaturdaten in Verzeichnis speichern windowtitle.overwrite=Datei \u00FCberschreiben? message.wait=Bitte warten... message.insertcard=Bitte B\u00FCrgerkarte in den Kartenleser stecken @@ -34,16 +35,16 @@ message.retries=Noch {0} Versuche message.overwrite=M\u00F6chten Sie das existierende Dokument {0} \u00FCberschreiben? label.pin={0}: label.pinsize=({0} stellig) -error.hashdata=Keine Signaturdaten verf\u00FCgbar +error.no.hashdata=Keine Signaturdaten verf\u00FCgbar button.ok=OK button.cancel=Abbrechen button.back=Zur\u00FCck button.sign=Signieren button.save=Speichern... -mimetype.desc.xml=XML-Dateien (*.xml) -mimetype.desc.html=HTML-Dateien (*.html, *.htm) -mimetype.desc.xhtml=XHTML-Dateien (*.xhtml) -mimetype.desc.txt=Textdateien (*.txt) -mimetype.desc.pdf=Adobe PDF-Dateien (*.pdf) -mimetype.desc.bin=Bin\u00E4rdateien (*.bin) +mimetype.desc.xml=XML-Dateien (.xml) +mimetype.desc.html=HTML-Dateien (.html, .htm) +mimetype.desc.xhtml=XHTML-Dateien (.xhtml) +mimetype.desc.txt=Textdateien (.txt) +mimetype.desc.pdf=Adobe PDF-Dateien (.pdf) +mimetype.desc.bin=Bin\u00E4rdateien (.bin) save.hashdatainput.prefix=Signaturdaten 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 4367f642..85f05435 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 @@ -1,19 +1,19 @@ /* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /* * To change this template, choose Tools | Templates * and open the template in the editor. @@ -35,137 +35,137 @@ import java.util.List; */ public class BKUGUIWorker implements Runnable { - BKUGUIFacade gui; + BKUGUIFacade gui; - public void init(BKUGUIFacade gui) { - this.gui = gui; - } + public void init(BKUGUIFacade gui) { + this.gui = gui; + } - @Override - public void run() { + @Override + public void run() { // try { - final PINSpec signPinSpec = new PINSpec(6, 10, "[0-9]", "Signatur-PIN"); - - - final ActionListener cancelListener = new ActionListener() { - - public void actionPerformed(ActionEvent e) { - System.out.println("CANCEL EVENT OCCURED: " + e); - } - }; - ActionListener okListener = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - System.out.println("OK EVENT OCCURED: " + e); - } - }; - final ActionListener signListener = new ActionListener() { - - public void actionPerformed(ActionEvent e) { - System.out.println("SIGN EVENT OCCURED: " + e); - } - }; - ActionListener hashdataListener = new ActionListener() { - - public void actionPerformed(ActionEvent e) { - System.out.println("HASHDATA EVENT OCCURED: " + e); - ActionListener returnListener = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - gui.showSignaturePINDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", null, "hashdata"); - } - }; - HashDataInput signedRef1 = new HashDataInput() { - - @Override - public InputStream getHashDataInput() { - return new ByteArrayInputStream("HashDataInput_001\n12345\n\tHello, world!\n12345\n\n12345\n6789\nblabla".getBytes()); - } - - @Override - public String getMimeType() { - return "text/plain"; - } - - @Override - public String getReferenceId() { - return "Reference-ref1-00000000000000000000001"; - } - }; - HashDataInput signedRef2 = new HashDataInput() { - - @Override - public InputStream getHashDataInput() { - return new ByteArrayInputStream("HashDataInput_002".getBytes()); - } - - @Override - public String getMimeType() { - return "text/xml"; - } - - @Override - public String getReferenceId() { - return "Reference-ref2-00000000000000000000002"; - } - }; - HashDataInput signedRef3 = new HashDataInput() { - - @Override - public InputStream getHashDataInput() { - return new ByteArrayInputStream("HashDataInput_003".getBytes()); - } - - @Override - public String getMimeType() { - return "text/xml"; - } - - @Override - public String getReferenceId() { - return "Reference-ref3-00000000000000000000003"; - } - }; - HashDataInput signedRef4 = new HashDataInput() { - - @Override - public InputStream getHashDataInput() { - return new ByteArrayInputStream("HashDataInput_004".getBytes()); - } - - @Override - public String getMimeType() { - return "text/xml"; - } - - @Override - public String getReferenceId() { - return "ref4"; - } - }; - - // - List signedRefs = new ArrayList(); - signedRefs.add(signedRef1); + final PINSpec signPinSpec = new PINSpec(6, 10, "[0-9]", "Signatur-PIN"); + + + final ActionListener cancelListener = new ActionListener() { + + public void actionPerformed(ActionEvent e) { + System.out.println("CANCEL EVENT OCCURED: " + e); + } + }; + ActionListener okListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + System.out.println("OK EVENT OCCURED: " + e); + } + }; + final ActionListener signListener = new ActionListener() { + + public void actionPerformed(ActionEvent e) { + System.out.println("SIGN EVENT OCCURED: " + e); + } + }; + ActionListener hashdataListener = new ActionListener() { + + public void actionPerformed(ActionEvent e) { + System.out.println("HASHDATA EVENT OCCURED: " + e); + ActionListener returnListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + gui.showSignaturePINDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", null, "hashdata"); + } + }; + HashDataInput signedRef1 = new HashDataInput() { + + @Override + public InputStream getHashDataInput() { + return new ByteArrayInputStream("oialfx HashDataInput_001\n12345\n\tHello, world!\n12345\n\n12345\n6789\nblabla".getBytes()); + } + + @Override + public String getMimeType() { + return "text/plain"; + } + + @Override + public String getReferenceId() { + return "Reference-ref1-00000000000000000000001"; + } + }; + HashDataInput signedRef2 = new HashDataInput() { + + @Override + public InputStream getHashDataInput() { + return new ByteArrayInputStream("HashDataInput_002".getBytes()); + } + + @Override + public String getMimeType() { + return "text/xml"; + } + + @Override + public String getReferenceId() { + return "Reference-ref2-00000000000000000000002"; + } + }; + HashDataInput signedRef3 = new HashDataInput() { + + @Override + public InputStream getHashDataInput() { + return new ByteArrayInputStream("HashDataInput_003".getBytes()); + } + + @Override + public String getMimeType() { + return "text/xml"; + } + + @Override + public String getReferenceId() { + return "Reference-ref3-00000000000000000000003"; + } + }; + HashDataInput signedRef4 = new HashDataInput() { + + @Override + public InputStream getHashDataInput() { + return new ByteArrayInputStream("HashDataInput_004".getBytes()); + } + + @Override + public String getMimeType() { + return "text/xml"; + } + + @Override + public String getReferenceId() { + return "ref4"; + } + }; + + // + List signedRefs = new ArrayList(); + signedRefs.add(signedRef1); signedRefs.add(signedRef2); signedRefs.add(signedRef3); signedRefs.add(signedRef4); // signedRefs = Collections.singletonList(signedRef1); - gui.showHashDataInputDialog(signedRefs, returnListener, "return"); - } - }; - + gui.showHashDataInputDialog(signedRefs, returnListener, "return"); + } + }; + // gui.showWelcomeDialog(); // // Thread.sleep(2000); - + // gui.showInsertCardDialog(cancelListener, "cancel"); - + // Thread.sleep(2000); // // gui.showCardNotSupportedDialog(cancelListener, "cancel"); @@ -178,11 +178,11 @@ public class BKUGUIWorker implements Runnable { // // Thread.sleep(2000); // - - gui.showSignaturePINDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); + + gui.showSignaturePINDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); // Thread.sleep(2000); - + // gui.showSignaturePINRetryDialog(signPinSpec, 2, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); // // Thread.sleep(2000); @@ -192,13 +192,13 @@ public class BKUGUIWorker implements Runnable { // Thread.sleep(2000); // // gui.showErrorDialog("Testfehler occured"); - - + + // gui.showTextPlainHashDataInput("hallo,\n welt!", "12345", null, "cancel", null, "save"); // Thread.sleep(2000); // } catch (InterruptedException ex) { // ex.printStackTrace(); // } - } + } } diff --git a/BKUOnline/pom.xml b/BKUOnline/pom.xml index d31367a8..a50954cd 100644 --- a/BKUOnline/pom.xml +++ b/BKUOnline/pom.xml @@ -58,11 +58,13 @@ 1.0-SNAPSHOT compile - + + + at.gv.egiz + BKUApplet + 1.0-SNAPSHOT + provided + @@ -177,4 +179,5 @@ +>>>>>>> .r33 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 1f84300a..d37d0551 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 @@ -47,6 +47,8 @@ import at.gv.egiz.stal.signedinfo.ObjectFactory; import at.gv.egiz.stal.signedinfo.ReferenceType; import at.gv.egiz.stal.signedinfo.SignedInfoType; import at.gv.egiz.stal.util.JCEAlgorithmNames; +import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -150,9 +152,6 @@ public class SignRequestHandler extends AbstractRequestHandler implements hashDataInputs = getHashDataInputs(signedInfo.getReference()); } gui.showHashDataInputDialog(hashDataInputs, this, "ok"); - waitForAction(); - gui.showSignaturePINDialog(spec, this, "sign", this, "cancel", this, - "hashData"); } catch (Exception ex) { //FIXME localize messages log.error("Failed to obtain HashDataInputs: " + ex.getMessage()); @@ -178,6 +177,7 @@ public class SignRequestHandler extends AbstractRequestHandler implements /** * override by subclass + * @post-condition returned list != null * @return */ protected List getHashDataInputs(List signedReferences) throws Exception { -- cgit v1.2.3 From a288c99fa6955a2c9055b28dc1c805dacbe5fc93 Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 15 Sep 2008 18:02:18 +0000 Subject: encoding git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@40 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 262 ++++++++++++++------- .../at/gv/egiz/bku/gui/HashDataTableModel.java | 94 ++++---- .../main/java/at/gv/egiz/bku/gui/MimeFilter.java | 18 +- .../main/java/at/gv/egiz/bku/gui/PinDocument.java | 19 +- .../test/java/at/gv/egiz/bku/gui/BKUGUITest.java | 2 +- .../test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java | 24 +- 6 files changed, 275 insertions(+), 144 deletions(-) (limited to 'BKUCommonGUI/src/test/java') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 584dba1a..5fb67982 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -23,10 +23,8 @@ package at.gv.egiz.bku.gui; import at.gv.egiz.smcc.PINSpec; import at.gv.egiz.stal.HashDataInput; import java.awt.Color; -import java.awt.Component; import java.awt.Container; import java.awt.Cursor; -import java.awt.Dimension; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -39,13 +37,10 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.text.MessageFormat; -import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; -import java.util.Vector; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import java.util.StringTokenizer; import javax.swing.GroupLayout; import javax.swing.ImageIcon; import javax.swing.JButton; @@ -59,15 +54,10 @@ import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.LayoutStyle; +import javax.swing.ScrollPaneConstants; import javax.swing.SwingUtilities; -import javax.swing.border.TitledBorder; -import javax.swing.filechooser.FileFilter; -import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; import javax.swing.table.TableModel; -import javax.swing.text.AttributeSet; -import javax.swing.text.BadLocationException; -import javax.swing.text.PlainDocument; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -154,6 +144,7 @@ public class BKUGUI implements BKUGUIFacade { SwingUtilities.invokeAndWait(new Runnable() { + @Override public void run() { initIconPanel(); @@ -285,6 +276,7 @@ public class BKUGUI implements BKUGUIFacade { public void showLoginDialog(ActionListener loginListener, String actionCommand) { SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); @@ -318,6 +310,7 @@ public class BKUGUI implements BKUGUIFacade { public void showWelcomeDialog() { SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); @@ -352,6 +345,7 @@ public class BKUGUI implements BKUGUIFacade { public void showInsertCardDialog(final ActionListener cancelListener, final String cancelCommand) { SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); @@ -388,6 +382,7 @@ public class BKUGUI implements BKUGUIFacade { public void showCardNotSupportedDialog(final ActionListener cancelListener, final String cancelCommand) { SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); @@ -440,6 +435,7 @@ public class BKUGUI implements BKUGUIFacade { private void showCardPINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener okListener, final String okCommand, final ActionListener cancelListener, final String cancelCommand) { SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { mainPanel.removeAll(); @@ -599,6 +595,7 @@ public class BKUGUI implements BKUGUIFacade { private void showSignaturePINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener signListener, final String signCommand, final ActionListener cancelListener, final String cancelCommand, final ActionListener hashdataListener, final String hashdataCommand) { SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); @@ -763,6 +760,7 @@ public class BKUGUI implements BKUGUIFacade { public void showErrorDialog(final String errorMsg, final ActionListener okListener, final String okCommand) { SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { mainPanel.removeAll(); buttonPanel.removeAll(); @@ -845,6 +843,50 @@ public class BKUGUI implements BKUGUIFacade { }); } + @Override + public void showWaitDialog(final String waitMessage) { + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + mainPanel.removeAll(); + buttonPanel.removeAll(); + + titleLabel.setText(messages.getString(TITLE_WAIT)); + + JLabel waitMsgLabel = new JLabel(); + waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + if (waitMessage != null) { + waitMsgLabel.setText("" + waitMessage + ""); + } else { + waitMsgLabel.setText("" + messages.getString(MESSAGE_WAIT) + ""); + } + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel) + .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel)); + + contentPanel.validate(); + } + }); + } + + @Override + public char[] getPin() { + if (pinField != null) { + return pinField.getPassword(); + } + return null; + } + @Override public void showHashDataInputDialog(final List signedReferences, final ActionListener okListener, final String okCommand) { @@ -891,32 +933,6 @@ public class BKUGUI implements BKUGUIFacade { } } - private static String getText(HashDataInput hdi) { - ByteArrayOutputStream baos = null; - try { - InputStream hashDataIS = hdi.getHashDataInput(); - if (hashDataIS == null) { - log.error("No HashDataInput stream for reference " + hdi.getReferenceId()); - return null; - } else { - baos = new ByteArrayOutputStream(hashDataIS.available()); - int c; - while ((c = hashDataIS.read()) != -1) { - baos.write(c); - } - return baos.toString("UTF-8"); - } - } catch (IOException ex) { - log.error("Failed to read HashDataInput for reference " + hdi.getReferenceId() + ": " + ex.getMessage()); - return null; - } finally { - try { - baos.close(); - } catch (IOException ex) { - } - } - } - private void showPlainTextHashDataInputDialog(final String hashDataText, final ActionListener saveListener, final String saveCommand, final ActionListener cancelListener, final String cancelCommand) { SwingUtilities.invokeLater(new Runnable() { @@ -931,13 +947,16 @@ public class BKUGUI implements BKUGUIFacade { refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); refIdLabel.setText(messages.getString(MESSAGE_HASHDATA)); //MessageFormat.format(refIdLabelPattern, new Object[]{refId})); - JScrollPane hashDataScrollPane = new JScrollPane(); JTextArea hashDataTextArea = new JTextArea(hashDataText); hashDataTextArea.setEditable(false); - hashDataTextArea.setColumns(1); - hashDataTextArea.setRows(1); +// hashDataTextArea.setColumns(1); +// hashDataTextArea.setRows(1); hashDataTextArea.setFont(new Font(HASHDATA_FONT, hashDataTextArea.getFont().getStyle(), hashDataTextArea.getFont().getSize())); - hashDataScrollPane.setViewportView(hashDataTextArea); +// hashDataScrollPane.setViewportView(hashDataTextArea); +// hashDataScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); //HORIZONTAL_SCROLLBAR_NEVER); + + + JScrollPane hashDataScrollPane = new JScrollPane(hashDataTextArea); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); @@ -946,16 +965,14 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.createSequentialGroup() .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(refIdLabel) - .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)) .addContainerGap()); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() .addComponent(refIdLabel) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(hashDataScrollPane, 0, GroupLayout.PREFERRED_SIZE, hashDataTextArea.getPreferredSize().height+3)); - - + .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); // GroupLayout mainPanelLayout = new GroupLayout(mainPanel); // mainPanel.setLayout(mainPanelLayout); @@ -1031,7 +1048,7 @@ public class BKUGUI implements BKUGUIFacade { selectCol.setMaxWidth(CHECKBOX_WIDTH); - hashDataTable.setPreferredScrollableViewportSize(mainPanel.getPreferredSize()); +// hashDataTable.setPreferredScrollableViewportSize(mainPanel.getPreferredSize()); JScrollPane hashDataScrollPane = new JScrollPane(hashDataTable); @@ -1042,14 +1059,14 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.createSequentialGroup() .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(refIdLabel) - .addComponent(hashDataScrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)) // GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap()); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() .addComponent(refIdLabel) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(hashDataScrollPane, 0, GroupLayout.PREFERRED_SIZE, hashDataTable.getPreferredSize().height+3)); + .addComponent(hashDataScrollPane, 0, 0, hashDataTable.getPreferredSize().height+3)); // .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)); @@ -1217,47 +1234,112 @@ public class BKUGUI implements BKUGUIFacade { }); } - @Override - public void showWaitDialog(final String waitMessage) { - SwingUtilities.invokeLater(new Runnable() { - - public void run() { - mainPanel.removeAll(); - buttonPanel.removeAll(); - - titleLabel.setText(messages.getString(TITLE_WAIT)); - - JLabel waitMsgLabel = new JLabel(); - waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - if (waitMessage != null) { - waitMsgLabel.setText("" + waitMessage + ""); - } else { - waitMsgLabel.setText("" + messages.getString(MESSAGE_WAIT) + ""); - } - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() -// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(waitMsgLabel) - .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(waitMsgLabel)); - - contentPanel.validate(); - } - }); - } - - @Override - public char[] getPin() { - if (pinField != null) { - return pinField.getPassword(); + private static String getText(HashDataInput hdi) { + ByteArrayOutputStream baos = null; + try { + InputStream hashDataIS = hdi.getHashDataInput(); + if (hashDataIS == null) { + log.error("No HashDataInput stream for reference " + hdi.getReferenceId()); + return null; + } else { + baos = new ByteArrayOutputStream(hashDataIS.available()); + int c; + while ((c = hashDataIS.read()) != -1) { + baos.write(c); + } + String encoding = hdi.getEncoding(); + if (encoding == null) { + //default for URL-encoded + encoding = "UTF-8"; + } + return baos.toString(encoding); } - return null; + } catch (IOException ex) { + log.error("Failed to read HashDataInput for reference " + hdi.getReferenceId() + ": " + ex.getMessage()); + return null; + } finally { + try { + baos.close(); + } catch (IOException ex) { + } + } } - + +// private String parseToken(final char[] terminators) { +// char ch; +// i1 = pos; +// i2 = pos; +// while (hasChar()) { +// ch = chars[pos]; +// if (isOneOf(ch, terminators)) { +// break; +// } +// i2++; +// pos++; +// } +// return getToken(false); +// } + +// private static String getCharset(String contentType) { +// +// StringTokenizer t = new StringTokenizer +// +// if (contentType == null) { +// return "UTF-8"; +// } +// +// int pos = 0; +// int len = contentType.length(); +// +// while (pos < len) { +// pos++; +// String paramName = parseToken(new char[] { +// '=', separator }); +// } +// +// HashMap params = new HashMap(); +// this.chars = chars; +// this.pos = offset; +// this.len = length; +// +// String paramName = null; +// String paramValue = null; +// while (hasChar()) { +// paramName = parseToken(new char[] { +// '=', separator }); +// paramValue = null; +// if (hasChar() && (chars[pos] == '=')) { +// pos++; // skip '=' +// paramValue = parseQuotedToken(new char[] { +// separator }); +// } +// if (hasChar() && (chars[pos] == separator)) { +// pos++; // skip separator +// } +// if ((paramName != null) && (paramName.length() > 0)) { +// if (this.lowerCaseNames) { +// paramName = paramName.toLowerCase(); +// } +// params.put(paramName, paramValue); +// } +// } +// return params; +// +// +// +// Parser +// ParameterParser pf = new ParameterParser(); +// pf.setLowerCaseNames(true); +// Map map = pf.parse(contentType, SEPERATOR); +// String retVal = (String) map.get(CHAR_SET); +// if ((retVal == null) && (replaceNullWithDefault)) { +// if (map.containsKey(APPLICATION_URL_ENCODED)) { +// // default charset for url encoded data +// return "UTF-8"; +// } +// retVal = getDefaultCharset(); +// } +// return retVal; +// } + } 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 061a2849..1a833f48 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 @@ -1,19 +1,19 @@ /* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package at.gv.egiz.bku.gui; import at.gv.egiz.stal.HashDataInput; @@ -28,37 +28,42 @@ import javax.swing.table.DefaultTableModel; */ class HashDataTableModel extends DefaultTableModel { - protected List signedReferences; - - Class[] types = new Class[]{ - java.lang.String.class, java.lang.Boolean.class - }; - - public HashDataTableModel(List signedReferences) { - super(0, 2); - this.signedReferences = signedReferences; - for (HashDataInput hashDataInput : signedReferences) { - String desc = hashDataInput.getReferenceId() + " (" + hashDataInput.getMimeType() + ")"; - addRow(new Object[]{desc, new Boolean(true)}); - } - } + protected List signedReferences; + + protected Class[] types = new Class[]{ + java.lang.String.class, java.lang.Boolean.class + }; - @Override - public Class getColumnClass(int columnIndex) { - return types [columnIndex]; - } + public HashDataTableModel(List signedReferences) { + super(0, 2); + this.signedReferences = signedReferences; + for (HashDataInput hashDataInput : signedReferences) { + String desc = hashDataInput.getReferenceId() + " (" + hashDataInput.getMimeType() + ")"; + addRow(new Object[]{desc, new Boolean(true)}); + } + } - public List getSelectedHashData() { - ArrayList selection = new ArrayList(); - for (int i = 0; i < dataVector.size(); i++) { - if ((Boolean) ((Vector) dataVector.get(i)).elementAt(1)) { - selection.add(signedReferences.get(i)); - } - } - return selection; - } + @Override + public Class getColumnClass(int columnIndex) { + return types[columnIndex]; + } -// public List getSelectedReferenceIds() { + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + if (columnIndex == 1) + return true; + return false; + } + + public List getSelectedHashData() { + ArrayList selection = new ArrayList(); + for (int i = 0; i < dataVector.size(); i++) { + if ((Boolean) ((Vector) dataVector.get(i)).elementAt(1)) { + selection.add(signedReferences.get(i)); + } + } + return selection; + }// public List getSelectedReferenceIds() { // ArrayList selection = new ArrayList(); // for (Object row : dataVector) { // if ((Boolean) ((Vector) row).elementAt(1)) { @@ -67,5 +72,4 @@ class HashDataTableModel extends DefaultTableModel { // } // return selection; // } - - } \ No newline at end of file +} \ No newline at end of file diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/MimeFilter.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/MimeFilter.java index 6ee61a82..4b48081a 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/MimeFilter.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/MimeFilter.java @@ -1,7 +1,19 @@ /* - * 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.gui; import java.io.File; diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java index e8572742..8ae9d7a3 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java @@ -1,8 +1,19 @@ /* - * 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.gui; import at.gv.egiz.smcc.PINSpec; diff --git a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java index a9c21a00..5f1bc8b2 100644 --- a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java +++ b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java @@ -39,7 +39,7 @@ public class BKUGUITest { JFrame testFrame = new JFrame("BKUGUITest"); BKUGUI gui = new BKUGUI(); Container contentPane = testFrame.getContentPane(); - contentPane.setPreferredSize(new Dimension(500, 200)); + contentPane.setPreferredSize(new Dimension(380, 150)); gui.init(contentPane, null); BKUGUIWorker worker = new BKUGUIWorker(); worker.init(gui); 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 85f05435..6cbc2cd1 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 @@ -82,7 +82,7 @@ public class BKUGUIWorker implements Runnable { @Override public InputStream getHashDataInput() { - return new ByteArrayInputStream("oialfx HashDataInput_001\n12345\n\tHello, world!\n12345\n\n12345\n6789\nblabla".getBytes()); + return new ByteArrayInputStream("Ich bin ein einfacher Text mit Umlauten: öäüßéç@€\n123\n456\n\tHello, world!\n\nlkjsd\nnksdjf".getBytes()); } @Override @@ -94,6 +94,10 @@ public class BKUGUIWorker implements Runnable { public String getReferenceId() { return "Reference-ref1-00000000000000000000001"; } + @Override + public String getEncoding() { + return "UTF-8"; + } }; HashDataInput signedRef2 = new HashDataInput() { @@ -111,6 +115,10 @@ public class BKUGUIWorker implements Runnable { public String getReferenceId() { return "Reference-ref2-00000000000000000000002"; } + @Override + public String getEncoding() { + return "UTF-8"; + } }; HashDataInput signedRef3 = new HashDataInput() { @@ -128,6 +136,11 @@ public class BKUGUIWorker implements Runnable { public String getReferenceId() { return "Reference-ref3-00000000000000000000003"; } + + @Override + public String getEncoding() { + return "UTF-8"; + } }; HashDataInput signedRef4 = new HashDataInput() { @@ -145,6 +158,11 @@ public class BKUGUIWorker implements Runnable { public String getReferenceId() { return "ref4"; } + + @Override + public String getEncoding() { + return "UTF-8"; + } }; // @@ -153,6 +171,10 @@ public class BKUGUIWorker implements Runnable { signedRefs.add(signedRef2); signedRefs.add(signedRef3); signedRefs.add(signedRef4); +// signedRefs.add(signedRef4); +// signedRefs.add(signedRef4); +// signedRefs.add(signedRef4); +// signedRefs.add(signedRef4); // signedRefs = Collections.singletonList(signedRef1); gui.showHashDataInputDialog(signedRefs, returnListener, "return"); } -- cgit v1.2.3 From 12d4f22e52fba1f867571afbd539b532e2afe1b5 Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 18 Sep 2008 09:48:56 +0000 Subject: wait message bug git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@47 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 8 +++--- .../test/java/at/gv/egiz/bku/gui/BKUGUITest.java | 2 +- .../test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java | 29 ++++++++++++++-------- 3 files changed, 24 insertions(+), 15 deletions(-) (limited to 'BKUCommonGUI/src/test/java') diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index be4aeded..449dfd61 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -835,7 +835,8 @@ public class BKUGUI implements BKUGUIFacade { .addComponent(errorMsgLabel) .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(errorMsgLabel)); contentPanel.validate(); @@ -859,7 +860,7 @@ public class BKUGUI implements BKUGUIFacade { if (waitMessage != null) { waitMsgLabel.setText("" + waitMessage + ""); } else { - waitMsgLabel.setText("" + messages.getString(MESSAGE_WAIT) + ""); + waitMsgLabel.setText(messages.getString(MESSAGE_WAIT)); } GroupLayout mainPanelLayout = new GroupLayout(mainPanel); @@ -873,8 +874,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(waitMsgLabel) - .addContainerGap()); + .addComponent(waitMsgLabel)); contentPanel.validate(); } diff --git a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java index 5f1bc8b2..2ea0c5a2 100644 --- a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java +++ b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java @@ -34,7 +34,7 @@ import org.junit.Test; */ public class BKUGUITest { - @Ignore + @Test public void testBKUGUI() { JFrame testFrame = new JFrame("BKUGUITest"); BKUGUI gui = new BKUGUI(); 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 6cbc2cd1..909da4ad 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 @@ -43,7 +43,7 @@ public class BKUGUIWorker implements Runnable { @Override public void run() { -// try { + try { final PINSpec signPinSpec = new PINSpec(6, 10, "[0-9]", "Signatur-PIN"); @@ -185,9 +185,18 @@ public class BKUGUIWorker implements Runnable { // gui.showWelcomeDialog(); // // Thread.sleep(2000); + + gui.showWaitDialog(null); + + Thread.sleep(1000); + + gui.showWaitDialog("test"); + + Thread.sleep(1000); + // gui.showInsertCardDialog(cancelListener, "cancel"); - +// // Thread.sleep(2000); // // gui.showCardNotSupportedDialog(cancelListener, "cancel"); @@ -201,7 +210,7 @@ public class BKUGUIWorker implements Runnable { // Thread.sleep(2000); // - gui.showSignaturePINDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); +// gui.showSignaturePINDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); // Thread.sleep(2000); @@ -209,18 +218,18 @@ public class BKUGUIWorker implements Runnable { // // Thread.sleep(2000); //// -// gui.showErrorDialog("Testfehler occured", null, null); -// -// Thread.sleep(2000); + gui.showErrorDialog("Testfehler occured", null, null); + + Thread.sleep(2000); // -// gui.showErrorDialog("Testfehler occured"); + gui.showErrorDialog("Testfehler occured"); // gui.showTextPlainHashDataInput("hallo,\n welt!", "12345", null, "cancel", null, "save"); // Thread.sleep(2000); -// } catch (InterruptedException ex) { -// ex.printStackTrace(); -// } + } catch (InterruptedException ex) { + ex.printStackTrace(); + } } } -- cgit v1.2.3 From 49dd625e2537b14b201d254ebef9745d9890a105 Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 18 Sep 2008 09:50:10 +0000 Subject: wait message bug git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@48 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'BKUCommonGUI/src/test/java') diff --git a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java index 2ea0c5a2..5f1bc8b2 100644 --- a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java +++ b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java @@ -34,7 +34,7 @@ import org.junit.Test; */ public class BKUGUITest { - @Test + @Ignore public void testBKUGUI() { JFrame testFrame = new JFrame("BKUGUITest"); BKUGUI gui = new BKUGUI(); -- cgit v1.2.3 From 8ccd9ab69dc74762567930f4c576a359502f1071 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 30 Sep 2008 16:37:59 +0000 Subject: showErrorDialog l10n git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@77 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/online/applet/BKUWorker.java | 10 +++--- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 41 +++++++++++++--------- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 14 ++++++-- .../at/gv/egiz/bku/gui/Messages.properties | 11 +++++- .../test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java | 33 +++++++++++------ .../at/gv/egiz/bku/local/stal/BKUGuiProxy.java | 8 ++--- .../gv/egiz/bku/smccstal/SignRequestHandler.java | 7 ++-- 7 files changed, 81 insertions(+), 43 deletions(-) (limited to 'BKUCommonGUI/src/test/java') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java index a87b04c4..12eb9d00 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUWorker.java @@ -126,7 +126,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, log.fatal("Failed to call STAL service.", e); actionCommandList.clear(); actionCommandList.add("ok"); - gui.showErrorDialog(errorMessages.getString("failed.WS")); + gui.showErrorDialog(BKUGUIFacade.ERR_SERVICE_UNREACHABLE, new Object[] {e.getMessage()}); try { waitForAction(); } catch (InterruptedException e1) { @@ -204,7 +204,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, log.info("Done " + Thread.currentThread().getName()); } catch (Exception ex) { log.error(ex.getMessage(), ex); - gui.showErrorDialog("Sorry, an internal error occured: " + ex.getMessage()); + gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, new Object[] {ex.getMessage()}); try { waitForAction(); } catch (InterruptedException e) { @@ -279,8 +279,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, case SMCCHelper.PC_SC_NOT_SUPPORTED: actionCommandList.clear(); actionCommandList.add("ok"); - gui.showErrorDialog(errorMessages.getString("nopcscsupport"), this, - "ok"); + gui.showErrorDialog(BKUGUIFacade.ERR_NO_PCSC, null, this, "ok"); try { waitForAction(); } catch (InterruptedException e) { @@ -290,8 +289,7 @@ public class BKUWorker extends AbstractSMCCSTAL implements Runnable, case SMCCHelper.TERMINAL_NOT_PRESENT: actionCommandList.clear(); actionCommandList.add("ok"); - gui.showErrorDialog(errorMessages.getString("nocardterminal"), this, - "ok"); + gui.showErrorDialog(BKUGUIFacade.ERR_NO_CARDTERMINAL,null,this,"ok"); try { waitForAction(); } catch (InterruptedException e) { diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 749207ee..b09669b8 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -41,6 +41,8 @@ import java.util.List; import java.util.Locale; import java.util.ResourceBundle; import java.util.StringTokenizer; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.swing.GroupLayout; import javax.swing.ImageIcon; import javax.swing.JButton; @@ -94,7 +96,7 @@ public class BKUGUI implements BKUGUIFacade { private static final String MESSAGE_OVERWRITE = "message.overwrite"; private static final String LABEL_PIN = "label.pin"; private static final String LABEL_PINSIZE = "label.pinsize"; - private static final String ERROR_NO_HASHDATA = "error.no.hashdata"; +// private static final String ERROR_NO_HASHDATA = "error.no.hashdata"; private static final String BUTTON_OK = "button.ok"; private static final String BUTTON_CANCEL = "button.cancel"; @@ -798,7 +800,7 @@ public class BKUGUI implements BKUGUIFacade { } @Override - public void showErrorDialog(final String errorMsg, final ActionListener okListener, final String okCommand) { + public void showErrorDialog(final String errorMsgKey, final Object[] errorMsgParams, final ActionListener okListener, final String okCommand) { log.debug("scheduling error dialog"); @@ -815,9 +817,12 @@ public class BKUGUI implements BKUGUIFacade { titleLabel.setText(messages.getString(TITLE_ERROR)); // titleLabel.setForeground(defaultForground); + String errorMsgPattern = messages.getString(errorMsgKey); + String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); + JLabel errorMsgLabel = new JLabel(); errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText("" + errorMsg + ""); + errorMsgLabel.setText(errorMsg); errorMsgLabel.setForeground(ERROR_COLOR); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); @@ -860,7 +865,7 @@ public class BKUGUI implements BKUGUIFacade { } @Override - public void showErrorDialog(final String errorMsg) { + public void showErrorDialog(final String errorMsgKey, final Object[] errorMsgParams) { log.debug("scheduling error dialog"); @@ -877,10 +882,13 @@ public class BKUGUI implements BKUGUIFacade { titleLabel.setText(messages.getString(TITLE_ERROR)); // titleLabel.setForeground(defaultForground); - JLabel errorMsgLabel = new JLabel(); - errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText("" + errorMsg + ""); - errorMsgLabel.setForeground(ERROR_COLOR); + String errorMsgPattern = messages.getString(errorMsgKey); + String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); + + JLabel errorMsgLabel = new JLabel(); + errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + errorMsgLabel.setText(errorMsg); + errorMsgLabel.setForeground(ERROR_COLOR); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); @@ -955,7 +963,7 @@ public class BKUGUI implements BKUGUIFacade { public void showHashDataInputDialog(final List signedReferences, final ActionListener okListener, final String okCommand) { if (signedReferences == null) { - showErrorDialog(messages.getString(ERROR_NO_HASHDATA), okListener, okCommand); + showErrorDialog(messages.getString(ERR_NO_HASHDATA), new Object[] {"No SignedReferences provided"}, okListener, okCommand); } if (signedReferences.size() == 1) { @@ -971,11 +979,12 @@ public class BKUGUI implements BKUGUIFacade { showSaveHashDataInputDialog(signedReferences, okListener, okCommand); } }; - String hashDataText = getText(signedReferences.get(0)); - if (hashDataText != null) { + + try { + String hashDataText = getText(signedReferences.get(0)); showPlainTextHashDataInputDialog(hashDataText, saveHashDataListener, "save", okListener, okCommand); - } else { - showErrorDialog(messages.getString(ERROR_NO_HASHDATA), okListener, okCommand); + } catch (IOException ex) { + showErrorDialog(messages.getString(ERR_NO_HASHDATA), new Object[] {ex.getMessage()}, okListener, okCommand); } } else { @@ -1300,7 +1309,7 @@ public class BKUGUI implements BKUGUIFacade { bos.close(); } catch (IOException ex) { log.error("Failed to write HashDataInput to file " + file + ": " + ex.getMessage()); - showErrorDialog("Failed to write signed reference to file: " + ex.getMessage(), null, null); + showErrorDialog(ERR_WRITE_HASHDATA, new Object[] {ex.getMessage()}, null, null); ex.printStackTrace(); } finally { try { @@ -1316,7 +1325,7 @@ public class BKUGUI implements BKUGUIFacade { }); } - private static String getText(HashDataInput hdi) { + private static String getText(HashDataInput hdi) throws IOException { ByteArrayOutputStream baos = null; try { InputStream hashDataIS = hdi.getHashDataInput(); @@ -1338,7 +1347,7 @@ public class BKUGUI implements BKUGUIFacade { } } catch (IOException ex) { log.error("Failed to read HashDataInput for reference " + hdi.getReferenceId() + ": " + ex.getMessage()); - return null; + throw ex; } finally { try { baos.close(); 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 f4b6325d..32eb4c3e 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 @@ -23,7 +23,15 @@ import java.awt.event.ActionListener; import java.util.List; 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"; + public static final String ERR_NO_CARDTERMINAL = "error.cardterminal"; + public static final String ERR_NO_HASHDATA = "error.no.hashdata"; + public static final String ERR_WRITE_HASHDATA = "error.write.hashdata"; + public static final String ERR_INVALID_HASH = "error.invalid.hash"; + public void init(Container contentPane, String localeString); public void showWelcomeDialog(); @@ -55,7 +63,7 @@ public interface BKUGUIFacade { // public void showPlainTextHashDataInputDialog(String text, ActionListener saveListener, String saveCommand, ActionListener cancelListener, String cancelCommand); - public void showErrorDialog(String errorMsg, ActionListener okListener, String actionCommand); + public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams, ActionListener okListener, String actionCommand); - public void showErrorDialog(String errorMsg); + public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams); } 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 a329ba86..79e23859 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 @@ -35,7 +35,6 @@ message.retries=Noch {0} Versuche message.overwrite=M\u00F6chten Sie das existierende Dokument {0} \u00FCberschreiben? label.pin={0}: label.pinsize=({0} stellig) -error.no.hashdata=Keine Signaturdaten verf\u00FCgbar button.ok=OK button.cancel=Abbrechen button.back=Zur\u00FCck @@ -48,3 +47,13 @@ mimetype.desc.txt=Textdateien (.txt) mimetype.desc.pdf=Adobe PDF-Dateien (.pdf) mimetype.desc.bin=Bin\u00E4rdateien (.bin) save.hashdatainput.prefix=Signaturdaten + +# Error Messages +error.no.hashdata=Keine Signaturdaten verf\u00FCgbar: {0} +error.write.hashdata=Die Signaturdaten konnten nicht gespeichert werden: {0} +error.invalid.hash=Die Signaturdaten sind ung\u00FCltig: {0} +error.ws.unreachable=Das Web-Service ist nicht erreichbar: {0} +error.pcsc=Java(TM) scheint keine PC/SC Schnittstelle f\u00FCr den Smartcard-Zugriff zur Verf\u00FCgung zu stellen. +error.cardterminal=Es konnte kein Smartcard-Leser gefunden werden.

Entweder ist kein Leser angeschlossen oder kein PC/SC Treiber installiert.

+error.unknown=Leider trat ein Fehler auf: {0} +error.test=Fehler1 {0} - Fehler2 {1} \ No newline at end of file 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 909da4ad..0641bf58 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 @@ -186,13 +186,13 @@ public class BKUGUIWorker implements Runnable { // // Thread.sleep(2000); - gui.showWaitDialog(null); - - Thread.sleep(1000); - - gui.showWaitDialog("test"); - - Thread.sleep(1000); +// gui.showWaitDialog(null); +// +// Thread.sleep(1000); +// +// gui.showWaitDialog("test"); +// +// Thread.sleep(1000); // gui.showInsertCardDialog(cancelListener, "cancel"); @@ -218,11 +218,24 @@ public class BKUGUIWorker implements Runnable { // // Thread.sleep(2000); //// - gui.showErrorDialog("Testfehler occured", null, null); - +// gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, new Object[] {"Testfehler"}, null, null); +// +// Thread.sleep(2000); +// + + gui.showErrorDialog("error.test", new Object[] {"Testfehler", "noch ein TestFehler"}); + Thread.sleep(2000); // - gui.showErrorDialog("Testfehler occured"); + gui.showErrorDialog("error.no.hashdata", null); + + Thread.sleep(2000); +// + gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, new Object[] {"Testfehler"}); + + Thread.sleep(2000); +// + gui.showErrorDialog("error.unknown", null); // gui.showTextPlainHashDataInput("hallo,\n welt!", "12345", null, "cancel", null, "save"); 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 c543c8ca..22ab1d6f 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 @@ -65,16 +65,16 @@ public class BKUGuiProxy implements BKUGUIFacade { } @Override - public void showErrorDialog(String errorMsg, ActionListener okListener, + public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams, ActionListener okListener, String actionCommand) { showDialog(); - delegate.showErrorDialog(errorMsg, okListener, actionCommand); + delegate.showErrorDialog(errorMsgKey, errorMsgParams, okListener, actionCommand); } @Override - public void showErrorDialog(String errorMsg) { + public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams) { showDialog(); - delegate.showErrorDialog(errorMsg); + delegate.showErrorDialog(errorMsgKey, errorMsgParams); } @Override 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 0b297283..7d994392 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 @@ -16,6 +16,7 @@ */ package at.gv.egiz.bku.smccstal; +import at.gv.egiz.bku.gui.BKUGUIFacade; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.security.MessageDigest; @@ -318,15 +319,15 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen gui.showHashDataInputDialog(hashDataInputs, SignRequestHandler.this, "ok"); } catch (DigestException ex) { log.error("Bad digest value: " + ex.getMessage()); - gui.showErrorDialog(ex.getMessage()); + gui.showErrorDialog(BKUGUIFacade.ERR_INVALID_HASH, new Object[] {ex.getMessage()}); } catch (Exception ex) { //FIXME localize messages log.error("Failed to obtain HashDataInputs: " + ex.getMessage()); - gui.showErrorDialog("Failed to obtain HashDataInputs: " + ex.getMessage(), SignRequestHandler.this, "ok"); + gui.showErrorDialog(BKUGUIFacade.ERR_NO_HASHDATA, new Object[] {ex.getMessage()}, SignRequestHandler.this, "ok"); } } else { //FIXME get all hashdatainputs - gui.showErrorDialog("Failed to obtain HashDataInputs: No dsig:SignedInfo provided.", SignRequestHandler.this, "ok"); + gui.showErrorDialog(BKUGUIFacade.ERR_NO_HASHDATA, new Object[] {"No dsig:SignedInfo provided"}, SignRequestHandler.this, "ok"); } } else if (actionCommand.equals("sign")) { return new String(gui.getPin()); -- cgit v1.2.3 From d7a3b8fdb62c881afb87838f2bb03b4c4b58e16d Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 8 Oct 2008 15:59:43 +0000 Subject: simpleGUI (header,chipperling removed) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@87 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUApplet/pom.xml | 30 +- BKUApplet/src/test/resources/appletTest.html | 29 ++ .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 295 ++++++----- .../test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java | 77 ++- BKULocalApp/pom.xml | 2 +- BKUOnline/src/main/webapp/appletPage.jsp | 16 +- .../finanzonline/FinanzOnlineLogin/award.gif | Bin 0 -> 8717 bytes .../finanzonline/FinanzOnlineLogin/bmf_01.gif | Bin 0 -> 2479 bytes .../finanzonline/FinanzOnlineLogin/bmf_02.gif | Bin 0 -> 5583 bytes .../finanzonline/FinanzOnlineLogin/browser.js | 165 ++++++ .../FinanzOnlineLogin/buergerkarte.gif | Bin 0 -> 1219 bytes .../finanzonline/FinanzOnlineLogin/eps-logo.gif | Bin 0 -> 4557 bytes .../finanzonline/FinanzOnlineLogin/epsa-award.jpg | Bin 0 -> 24106 bytes .../webapp/finanzonline/FinanzOnlineLogin/fon.css | 553 +++++++++++++++++++++ .../finanzonline/FinanzOnlineLogin/index.css | 101 ++++ BKUOnline/src/main/webapp/finanzonline/iframe.html | 22 + BKUOnline/src/main/webapp/finanzonline/index.html | 192 +++++++ BKUOnline/src/main/webapp/index.html | 2 + BKUOnline/src/test/resources/appletTest.html | 2 +- 19 files changed, 1279 insertions(+), 207 deletions(-) create mode 100644 BKUApplet/src/test/resources/appletTest.html create mode 100644 BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/award.gif create mode 100644 BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/bmf_01.gif create mode 100644 BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/bmf_02.gif create mode 100644 BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/browser.js create mode 100644 BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/buergerkarte.gif create mode 100644 BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/eps-logo.gif create mode 100644 BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/epsa-award.jpg create mode 100644 BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/fon.css create mode 100644 BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/index.css create mode 100644 BKUOnline/src/main/webapp/finanzonline/iframe.html create mode 100644 BKUOnline/src/main/webapp/finanzonline/index.html (limited to 'BKUCommonGUI/src/test/java') diff --git a/BKUApplet/pom.xml b/BKUApplet/pom.xml index 35672e51..130749c5 100644 --- a/BKUApplet/pom.xml +++ b/BKUApplet/pom.xml @@ -1,6 +1,5 @@ - + bku at.gv.egiz @@ -11,7 +10,6 @@ BKUApplet BKU Applet 1.0-SNAPSHOT - @@ -81,6 +79,30 @@ true + + maven-dependency-plugin + + + copytestlibs + + copy + + + + + commons-logging + commons-logging + + + iaik + iaik_jce_me4se + + + ${project.build.directory}/test-libs + + + + @@ -114,4 +136,4 @@ commons-logging - \ No newline at end of file + diff --git a/BKUApplet/src/test/resources/appletTest.html b/BKUApplet/src/test/resources/appletTest.html new file mode 100644 index 00000000..3b944a40 --- /dev/null +++ b/BKUApplet/src/test/resources/appletTest.html @@ -0,0 +1,29 @@ + + + +
+ + + + + +
+ + \ No newline at end of file diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index b09669b8..24cc2601 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -40,11 +40,7 @@ import java.text.MessageFormat; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; -import java.util.StringTokenizer; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.GroupLayout; -import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFileChooser; @@ -56,7 +52,6 @@ import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.LayoutStyle; -import javax.swing.ScrollPaneConstants; import javax.swing.SwingUtilities; import javax.swing.table.TableColumn; import javax.swing.table.TableModel; @@ -107,14 +102,14 @@ public class BKUGUI implements BKUGUIFacade { protected Container contentPane; protected ResourceBundle messages; /** left and right side main panels */ - protected JPanel iconPanel; +// protected JPanel iconPanel; protected JPanel contentPanel; /** right side content panels and layouts */ - protected JPanel headerPanel; +// protected JPanel headerPanel; protected JPanel mainPanel; protected JPanel buttonPanel; /** right side fixed labels */ - protected JLabel titleLabel; +// protected JLabel titleLabel; /** remember the pinfield to return to worker */ protected JPasswordField pinField; @@ -153,13 +148,21 @@ public class BKUGUI implements BKUGUIFacade { log.debug("initializing gui"); - initIconPanel(); +// initIconPanel(); initContentPanel(); GroupLayout layout = new GroupLayout(contentPane); contentPane.setLayout(layout); - layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(iconPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); - layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(iconPanel, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); + layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(contentPanel)); + layout.setVerticalGroup(layout.createSequentialGroup().addComponent(contentPanel)); +// layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(layout.createSequentialGroup() +// .addComponent(iconPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) +// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) +// .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); +// layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addComponent(iconPanel, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) +// .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); } }); } catch (Exception ex) { @@ -167,34 +170,30 @@ public class BKUGUI implements BKUGUIFacade { } } - protected void initIconPanel() { - iconPanel = new JPanel(); - JLabel iconLabel = new JLabel(); - iconLabel.setIcon(new ImageIcon(getClass().getResource(LOGO_RESOURCE))); // NOI18N - - GroupLayout iconPanelLayout = new GroupLayout(iconPanel); - iconPanel.setLayout(iconPanelLayout); - iconPanelLayout.setHorizontalGroup( - iconPanelLayout.createSequentialGroup() -// iconPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addGroup(iconPanelLayout.createSequentialGroup() - .addContainerGap() - .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, iconLabel.getPreferredSize().width, GroupLayout.PREFERRED_SIZE) - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); - iconPanelLayout.setVerticalGroup( - iconPanelLayout.createSequentialGroup() -// iconPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addGroup(iconPanelLayout.createSequentialGroup() - .addContainerGap() - .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, iconLabel.getPreferredSize().height, GroupLayout.PREFERRED_SIZE) - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); - } +// protected void initIconPanel() { +// iconPanel = new JPanel(); +// JLabel iconLabel = new JLabel(); +// iconLabel.setIcon(new ImageIcon(getClass().getResource(LOGO_RESOURCE))); // NOI18N +// +// GroupLayout iconPanelLayout = new GroupLayout(iconPanel); +// iconPanel.setLayout(iconPanelLayout); +// iconPanelLayout.setHorizontalGroup( +// iconPanelLayout.createSequentialGroup() +// .addContainerGap() +// .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, iconLabel.getPreferredSize().width, GroupLayout.PREFERRED_SIZE) +// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); +// iconPanelLayout.setVerticalGroup( +// iconPanelLayout.createSequentialGroup() +// .addContainerGap() +// .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, iconLabel.getPreferredSize().height, GroupLayout.PREFERRED_SIZE) +// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); +// } protected void initContentPanel() { contentPanel = new JPanel(); - headerPanel = new JPanel(); +// headerPanel = new JPanel(); mainPanel = new JPanel(); buttonPanel = new JPanel(); @@ -202,22 +201,9 @@ public class BKUGUI implements BKUGUIFacade { // mainPanel.setBorder(new TitledBorder("main")); // buttonPanel.setBorder(new TitledBorder("button")); - titleLabel = new JLabel(); - titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | - java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); -// titleLabel.setForeground(defaultForground); - -// okButton = new JButton(); -// okButton.setText(messages.getString(BUTTON_OK)); -// cancelButton = new JButton(); -// cancelButton.setText(messages.getString(BUTTON_CANCEL)); -// signButton = new JButton(); -// signButton.setText(messages.getString(BUTTON_SIGN)); -// backButton = new JButton(); -// backButton.setText(messages.getString(BUTTON_BACK)); -// saveButton = new JButton(); -// saveButton.setText(messages.getString(BUTTON_SAVE)); -// contentPanelLayout.linkSize(cancelButton, okButton, signButton, backButton, saveButton); +// titleLabel = new JLabel(); +// titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | +// java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); JButton b = new JButton(); b.setText(messages.getString(BUTTON_CANCEL)); @@ -246,33 +232,38 @@ public class BKUGUI implements BKUGUIFacade { // buttonSize = saveButton.getPreferredSize().width; - GroupLayout headerPanelLayout = new GroupLayout(headerPanel); - headerPanel.setLayout(headerPanelLayout); - - headerPanelLayout.setHorizontalGroup( - headerPanelLayout.createSequentialGroup() -// headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) - .addContainerGap()); - headerPanelLayout.setVerticalGroup( - headerPanelLayout.createSequentialGroup() -// headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); +// GroupLayout headerPanelLayout = new GroupLayout(headerPanel); +// headerPanel.setLayout(headerPanelLayout); +// +// headerPanelLayout.setHorizontalGroup( +// headerPanelLayout.createSequentialGroup() +// .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) +// .addContainerGap()); +// headerPanelLayout.setVerticalGroup( +// headerPanelLayout.createSequentialGroup() +// .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); -// mainPanel.setPreferredSize(new Dimension(MAIN_PANEL_WIDTH, MAIN_PANEL_HEIGHT)); GroupLayout contentPanelLayout = new GroupLayout(contentPanel); contentPanel.setLayout(contentPanelLayout); +// contentPanelLayout.setHorizontalGroup( +// contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) +// .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) +// .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //)); contentPanelLayout.setHorizontalGroup( - contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //)); + contentPanelLayout.createSequentialGroup() + .addContainerGap() + .addGroup( + contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()); contentPanelLayout.setVerticalGroup( contentPanelLayout.createSequentialGroup() .addContainerGap() - .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) +// .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) +// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) //, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) @@ -294,8 +285,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - titleLabel.setText(messages.getString(TITLE_ERROR)); -// titleLabel.setForeground(defaultForground); +// titleLabel.setText(messages.getString(TITLE_ERROR)); JLabel waitMsgLabel = new JLabel(); waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -308,8 +298,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(waitMsgLabel) - .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + .addComponent(waitMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(waitMsgLabel)); @@ -334,12 +323,11 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - titleLabel.setText(messages.getString(TITLE_WELCOME)); -// titleLabel.setForeground(defaultForground); +// titleLabel.setText(messages.getString(TITLE_WELCOME)); - JLabel waitMsgLabel = new JLabel(); - waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - waitMsgLabel.setText(messages.getString(MESSAGE_WAIT)); + JLabel welcomeMsgLabel = new JLabel(); + welcomeMsgLabel.setFont(welcomeMsgLabel.getFont().deriveFont(welcomeMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + welcomeMsgLabel.setText(messages.getString(TITLE_WELCOME)); //MESSAGE_WAIT)); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); @@ -347,12 +335,11 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(waitMsgLabel) - .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + .addComponent(welcomeMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(waitMsgLabel)); + .addComponent(welcomeMsgLabel)); contentPanel.validate(); @@ -375,8 +362,24 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - titleLabel.setText(messages.getString(TITLE_INSERTCARD)); +// titleLabel.setText(messages.getString(TITLE_INSERTCARD)); + JLabel insertCardMsgLabel = new JLabel(); + insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + insertCardMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(insertCardMsgLabel)); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(insertCardMsgLabel)); + JButton cancelButton = new JButton(); cancelButton.setText(messages.getString(BUTTON_CANCEL)); cancelButton.addActionListener(cancelListener); @@ -391,8 +394,7 @@ public class BKUGUI implements BKUGUIFacade { // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) // .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) - .addContainerGap()); //); + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); buttonPanelLayout.setVerticalGroup( buttonPanelLayout.createSequentialGroup() // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) @@ -403,6 +405,11 @@ public class BKUGUI implements BKUGUIFacade { }); } + /** + * only difference to showInsertCard: title text: card not supported + * @param cancelListener + * @param cancelCommand + */ @Override public void showCardNotSupportedDialog(final ActionListener cancelListener, final String cancelCommand) { @@ -418,12 +425,11 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - titleLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); -// titleLabel.setForeground(defaultForground); +// titleLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); - JLabel errorMsgLabel = new JLabel(); - errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); + JLabel insertCardMsgLabel = new JLabel(); + insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + insertCardMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); @@ -431,12 +437,11 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(errorMsgLabel) - .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + .addComponent(insertCardMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(errorMsgLabel)); + .addComponent(insertCardMsgLabel)); JButton cancelButton = new JButton(); cancelButton.setText(messages.getString(BUTTON_CANCEL)); @@ -452,8 +457,7 @@ public class BKUGUI implements BKUGUIFacade { // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) // .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) - .addContainerGap()); //); + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); buttonPanelLayout.setVerticalGroup( buttonPanelLayout.createSequentialGroup() // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) @@ -478,12 +482,12 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - if (numRetries < 0) { - String cardpinTitle = messages.getString(TITLE_CARDPIN); - titleLabel.setText(MessageFormat.format(cardpinTitle, new Object[]{pinSpec.getLocalizedName()})); - } else { - titleLabel.setText(messages.getString(TITLE_RETRY)); - } +// if (numRetries < 0) { +// String cardpinTitle = messages.getString(TITLE_CARDPIN); +// titleLabel.setText(MessageFormat.format(cardpinTitle, new Object[]{pinSpec.getLocalizedName()})); +// } else { +// titleLabel.setText(messages.getString(TITLE_RETRY)); +// } JButton cancelButton = new JButton(); cancelButton.setText(messages.getString(BUTTON_CANCEL)); @@ -572,8 +576,7 @@ public class BKUGUI implements BKUGUIFacade { .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) //)) - .addComponent(infoLabel)) - .addContainerGap()); + .addComponent(infoLabel))); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() @@ -595,8 +598,7 @@ public class BKUGUI implements BKUGUIFacade { .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) - .addContainerGap());//); + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); buttonPanelLayout.setVerticalGroup( buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(okButton) @@ -643,11 +645,11 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - if (numRetries < 0) { - titleLabel.setText(messages.getString(TITLE_SIGN)); - } else { - titleLabel.setText(messages.getString(TITLE_RETRY)); - } +// if (numRetries < 0) { +// titleLabel.setText(messages.getString(TITLE_SIGN)); +// } else { +// titleLabel.setText(messages.getString(TITLE_RETRY)); +// } JButton cancelButton = new JButton(); cancelButton.setText(messages.getString(BUTTON_CANCEL)); @@ -712,16 +714,14 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(hashDataLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() - .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(infoLabel)))) - .addContainerGap()); + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(hashDataLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addGroup(GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() + .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(infoLabel)))); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() @@ -743,8 +743,7 @@ public class BKUGUI implements BKUGUIFacade { .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(signButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) - .addContainerGap());//); + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); buttonPanelLayout.setVerticalGroup( buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(signButton) @@ -814,8 +813,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - titleLabel.setText(messages.getString(TITLE_ERROR)); -// titleLabel.setForeground(defaultForground); +// titleLabel.setText(messages.getString(TITLE_ERROR)); String errorMsgPattern = messages.getString(errorMsgKey); String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); @@ -831,8 +829,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(errorMsgLabel) //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); - .addContainerGap()); + .addComponent(errorMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) @@ -852,8 +849,7 @@ public class BKUGUI implements BKUGUIFacade { // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) // .addGroup(GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup() .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) - .addContainerGap()); //); + .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); buttonPanelLayout.setVerticalGroup( buttonPanelLayout.createSequentialGroup() // buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) @@ -879,16 +875,15 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - titleLabel.setText(messages.getString(TITLE_ERROR)); -// titleLabel.setForeground(defaultForground); +// titleLabel.setText(messages.getString(TITLE_ERROR)); String errorMsgPattern = messages.getString(errorMsgKey); - String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); - - JLabel errorMsgLabel = new JLabel(); - errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText(errorMsg); - errorMsgLabel.setForeground(ERROR_COLOR); + String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); + + JLabel errorMsgLabel = new JLabel(); + errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + errorMsgLabel.setText(errorMsg); + errorMsgLabel.setForeground(ERROR_COLOR); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); @@ -896,8 +891,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(errorMsgLabel) - .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + .addComponent(errorMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) @@ -923,7 +917,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - titleLabel.setText(messages.getString(TITLE_WAIT)); +// titleLabel.setText(messages.getString(TITLE_WAIT)); JLabel waitMsgLabel = new JLabel(); waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -939,8 +933,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanelLayout.setHorizontalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(waitMsgLabel) - .addContainerGap()); //, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); + .addComponent(waitMsgLabel)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) @@ -1020,7 +1013,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - titleLabel.setText(messages.getString(TITLE_HASHDATA)); +// titleLabel.setText(messages.getString(TITLE_HASHDATA)); JLabel refIdLabel = new JLabel(); refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -1042,11 +1035,9 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(refIdLabel) - .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)) - .addContainerGap()); + .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() @@ -1082,8 +1073,7 @@ public class BKUGUI implements BKUGUIFacade { .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(saveButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) - .addContainerGap()); + .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); buttonPanelLayout.setVerticalGroup( buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(saveButton) @@ -1117,7 +1107,7 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); - titleLabel.setText(messages.getString(TITLE_HASHDATA)); +// titleLabel.setText(messages.getString(TITLE_HASHDATA)); JLabel refIdLabel = new JLabel(); refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -1142,11 +1132,9 @@ public class BKUGUI implements BKUGUIFacade { mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(refIdLabel) - .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)) // GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()); + .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() @@ -1228,8 +1216,7 @@ public class BKUGUI implements BKUGUIFacade { .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(saveButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) - .addContainerGap());//); + .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); buttonPanelLayout.setVerticalGroup( buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(saveButton) 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 0641bf58..c366cb76 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 @@ -168,9 +168,9 @@ public class BKUGUIWorker implements Runnable { // List signedRefs = new ArrayList(); signedRefs.add(signedRef1); - signedRefs.add(signedRef2); - signedRefs.add(signedRef3); - signedRefs.add(signedRef4); +// signedRefs.add(signedRef2); +// signedRefs.add(signedRef3); +// signedRefs.add(signedRef4); // signedRefs.add(signedRef4); // signedRefs.add(signedRef4); // signedRefs.add(signedRef4); @@ -182,62 +182,61 @@ public class BKUGUIWorker implements Runnable { -// gui.showWelcomeDialog(); -// -// Thread.sleep(2000); + gui.showWelcomeDialog(); + + Thread.sleep(2000); + + gui.showWaitDialog(null); + + Thread.sleep(1000); -// gui.showWaitDialog(null); -// -// Thread.sleep(1000); -// -// gui.showWaitDialog("test"); -// -// Thread.sleep(1000); + gui.showWaitDialog("test"); + + Thread.sleep(1000); -// gui.showInsertCardDialog(cancelListener, "cancel"); -// -// Thread.sleep(2000); -// -// gui.showCardNotSupportedDialog(cancelListener, "cancel"); -// -// Thread.sleep(2000); + gui.showInsertCardDialog(cancelListener, "cancel"); -// PINSpec cardPinSpec = new PINSpec(4, 4, "[0-9]", "Karten-PIN"); -//// -// gui.showCardPINDialog(cardPinSpec, okListener, "ok", cancelListener, "cancel"); -// -// Thread.sleep(2000); -// + Thread.sleep(2000); + + gui.showCardNotSupportedDialog(cancelListener, "cancel"); + + Thread.sleep(2000); + + PINSpec cardPinSpec = new PINSpec(4, 4, "[0-9]", "Karten-PIN"); + + gui.showCardPINDialog(cardPinSpec, okListener, "ok", cancelListener, "cancel"); + + Thread.sleep(2000); -// gui.showSignaturePINDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); + gui.showSignaturePINDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); -// Thread.sleep(2000); + Thread.sleep(4000); -// gui.showSignaturePINRetryDialog(signPinSpec, 2, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); -// -// Thread.sleep(2000); -//// -// gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, new Object[] {"Testfehler"}, null, null); -// -// Thread.sleep(2000); -// + gui.showSignaturePINRetryDialog(signPinSpec, 2, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); + + Thread.sleep(2000); + + gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, new Object[] {"Testfehler"}, null, null); + + Thread.sleep(2000); gui.showErrorDialog("error.test", new Object[] {"Testfehler", "noch ein TestFehler"}); Thread.sleep(2000); -// + gui.showErrorDialog("error.no.hashdata", null); Thread.sleep(2000); -// + gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, new Object[] {"Testfehler"}); Thread.sleep(2000); -// + gui.showErrorDialog("error.unknown", null); +// gui.showTextPlainHashDataInput("hallo,\n welt!", "12345", null, "cancel", null, "save"); // gui.showTextPlainHashDataInput("hallo,\n welt!", "12345", null, "cancel", null, "save"); // Thread.sleep(2000); diff --git a/BKULocalApp/pom.xml b/BKULocalApp/pom.xml index 9ad6f50b..594f5af2 100644 --- a/BKULocalApp/pom.xml +++ b/BKULocalApp/pom.xml @@ -8,7 +8,7 @@ 4.0.0 at.gv.egiz.bku BKULocalApp - + BKU Local App 1.0-SNAPSHOT diff --git a/BKUOnline/src/main/webapp/appletPage.jsp b/BKUOnline/src/main/webapp/appletPage.jsp index 5f208a2a..b9225e56 100644 --- a/BKUOnline/src/main/webapp/appletPage.jsp +++ b/BKUOnline/src/main/webapp/appletPage.jsp @@ -19,12 +19,12 @@ - -MOCCA Appletpage - + + MOCCA Appletpage + + - -
+ diff --git a/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/award.gif b/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/award.gif new file mode 100644 index 00000000..8807fcf6 Binary files /dev/null and b/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/award.gif differ diff --git a/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/bmf_01.gif b/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/bmf_01.gif new file mode 100644 index 00000000..dd7697a4 Binary files /dev/null and b/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/bmf_01.gif differ diff --git a/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/bmf_02.gif b/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/bmf_02.gif new file mode 100644 index 00000000..961d511e Binary files /dev/null and b/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/bmf_02.gif differ diff --git a/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/browser.js b/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/browser.js new file mode 100644 index 00000000..6fbf74f0 --- /dev/null +++ b/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/browser.js @@ -0,0 +1,165 @@ +var BrowserDetect = { + init: function () { + this.browser = this.searchString(this.dataBrowser) || "An unknown browser"; + this.version = this.searchVersion(navigator.userAgent) + || this.searchVersion(navigator.appVersion) + || "an unknown version"; + this.OS = this.searchString(this.dataOS) || "an unknown OS"; + }, + searchString: function (data) { + for (var i=0;i
"); + document.write("Sehr geehrter FinanzOnline-Teilnehmer!

Die Menüführung in FinanzOnline wurde aus technischen Gründen geändert. Da Sie möglicherweise eine veraltete und nicht mehr dem letzten Sicherheitsstandard entsprechende Version Ihres Webbrowsers verwenden, besteht ab diesem Zeitpunkt die Möglichkeit, dass das Menü in FinanzOnline nicht richtig angezeigt werden kann.

Wir empfehlen daher bereits heute auch zu Ihrer Sicherheit, ein Update auf die aktuell gültige Browserversion durchzuführen. Die unterstützten Webbrowser finden Sie auf der BMF-Homepage unter 'E-Government'/'FinanzOnline'/'Browsereinstellungen'.

"); + + +/* document.write("Verwendeter Browser: " + BrowserDetect.browser + " " + BrowserDetect.version + " / " + BrowserDetect.OS); + if(BrowserDetect.browser.toLowerCase() == "explorer") { + if(eval(BrowserDetect.version) < 6) { + document.write(" *** nicht supported ***"); + } else { + //document.write(" *** supported ***"); + } + } + if(BrowserDetect.browser.toLowerCase() == "opera") { + if(eval(BrowserDetect.version) < 9) { + document.write(" *** nicht supported ***"); + } else { + //document.write(" *** supported ***"); + } + } + if(BrowserDetect.browser.toLowerCase() == "firefox") { + if(eval(BrowserDetect.version) < 1.5) { + document.write(" *** nicht supported ***"); + } else { + //document.write(" *** supported ***"); + } + } +// document.write("

Vorschlag für unterstütze Browser:
"); +// document.write("
  • Internet Explorer 6, PC
  • "); +// document.write("
  • Internet Explorer 7, PC
  • "); +// document.write("
  • Firefox (>= 1.5), PC + Mac + Linux
  • "); +// document.write("
  • Safari (>= 1.3+), Mac (<- WIE TESTEN??)
  • "); +// document.write("
  • Opera (>= 9), PC + Mac + Linux
  • "); +// document.write("
"); +*/ + document.write("
 "); + + } +} \ No newline at end of file diff --git a/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/buergerkarte.gif b/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/buergerkarte.gif new file mode 100644 index 00000000..99d5f37e Binary files /dev/null and b/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/buergerkarte.gif differ diff --git a/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/eps-logo.gif b/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/eps-logo.gif new file mode 100644 index 00000000..6f4ee65c Binary files /dev/null and b/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/eps-logo.gif differ diff --git a/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/epsa-award.jpg b/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/epsa-award.jpg new file mode 100644 index 00000000..0e68626d Binary files /dev/null and b/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/epsa-award.jpg differ diff --git a/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/fon.css b/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/fon.css new file mode 100644 index 00000000..f9b7b229 --- /dev/null +++ b/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/fon.css @@ -0,0 +1,553 @@ +BODY { + margin-left : 0px; + margin-right : 0px; + margin-top : 0px; + color : black; + background-color : #E8F4FE; + font-family : Verdana, Geneva, Arial, Helvetica, sans-serif, sans-serif; + font-size:13px; + font-weight: normal; +} +table.user { + background-color: #D6E6F9; + width: 100%; + font-family:Verdana,Arial,Helv; + font-size:13px; +} + +.BUT { + HEIGHT: 20px; + BORDER:1px solid #000000; + TEXT-DECORATION:none; + BACKGROUND-IMAGE:url(../graphics/butback.gif); +} + +A { + color : #000000; +} + + +TH.label { + padding: 10px; + margin-left: 10px; + font-size: 13px; + font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; + font-weight: bold; + color: #D6E6F9; + background-color: #006699; + vertical-align: top +} + +TH.label_hell { + padding : 5px; + margin-left : 10px; + font-size : 13px; + font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; + font-weight : bold; + color : #000000; + background-color : #D6E6F9; + vertical-align : top; + text-align : left; +} +TD.input { + padding : 5px; + margin-left : 10px; + font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; + color : #000000; + background-color : #D6E6F9; + vertical-align : middle; + text-align : right; + font-size: 13px; +} + +TD.input_links { + padding: 5px; + margin-left: 10px; + font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; + color: #000000; + background-color: #D6E6F9; + vertical-align: bottom; + text-align: left; + font-size: 13px; +} + +TD.input_center { + padding: 5px; + margin-left: 10px; + font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; + color: #000000; + background-color: #D6E6F9; + vertical-align: bottom; + text-align: center; + font-size: 13px; +} + +TD.input_mitte { + padding : 5px; + margin-left : 10px; + font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; + color : #000000; + background-color : #D6E6F9; + vertical-align : middle; + text-align : left; + font-size: 13px; +} + +TD.spacer { + padding : 5px; + margin-left : 10px; + background-color : #D6E6F9; + vertical-align : top; + font-size: 50%; +} +TD.erlaeut2 { + padding : 5px; + margin-left : 5px; + font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; + color : #000000; + background-color : #D6E6F9; + vertical-align : top; + font-size: 13px; +} +TD.erlaeut { + padding : 5px; + margin-left : 10px; + font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; + color : #000000; + background-color : #D6E6F9; + vertical-align : top; + font-size: 13px; +} +TD.erlaeut_white { + margin-left : 10px; + font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; + color : #000000; + background-color : #D6E5F8; + vertical-align : top; + font-size: 13px; +} +TD.login { + padding : 5px; + margin-left : 10px; + font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; + color : #000000; + vertical-align : top; + font-size: 13px; +} +.tabcap { + margin-left : 10px; + font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; + font-weight : bold; + color : #D6E6F9; + background-color : #6699CC; + font-size : 13px; + font-weight : bold; + padding : 5px; + padding-top:1px; + padding-bottom:1px; +} + +INPUT { + font-family : Verdana,Arial,Helv; + font-size : 8pt; + color : #000000; +} + +TD.erlaeut_fett { + padding : 5px; + margin-left : 10px; + font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; + color : #000000; + background-color : #D6E6F9; + vertical-align : top; + font-size : 13px; + font-weight : bold; +} + + +TABLE.normal { + width : 100%; +} +CAPTION.cap { + width : 100%; + padding : 10px; + font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; + color : black; + background-color : #E8FDFD; + font-size : 11pt; + font-weight : bold; +} + +H1{ + color : #D6E6F9; + text-align : center; + border-left-color: #996666; + padding-top: 0px; + padding-right: 0px; + padding-bottom: 0px; + padding-left: 10px; + ; + border-style: solid; + border-top-width: 0px; + border-right-width: 0px; + border-bottom-width: 0px; + border-left-width : 0px; + background-color : #006699; +} +H2{ + color : #006699; + text-align : center; + font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; + padding-top: 0px; + padding-right: 0px; + padding-bottom: 0px; + padding-left: 10px; + font-size : 25px; +} +H3{ + color : #006699;; + text-align : center; + border-left-color: #996666; + padding-top: 0px; + padding-right: 0px; + padding-bottom: 0px; + padding-left: 10px; + border-style: solid; + border-top-width: 0px; + border-right-width: 0px; + border-bottom-width: 0px; + border-left-width : 0px; +} +H3.info_center{ + color : #006699; + text-align : center; + padding-top: 0px; + padding-right: 0px; + padding-bottom: 0px; + padding-left: 10px; + border-style: solid; + border-top-width: 0px; + border-right-width: 0px; + border-bottom-width: 0px; + border-left-width : 0px; +} +.inv{ + color : #D6E6F9; + text-align : left; + background-color : #006699; + font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; + font-size : 13px; + width: 100%; +} +.inv2{ + color : #D6E6F9; + text-align : left; + background-color : #006699; + font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; + font-size : 13px; + width: 100%; + font-weight: bold; +} +H4{ + color : #006699; + text-align : center; + border-left-color: #996666; + padding-top: 0px; + padding-right: 0px; + padding-bottom: 0px; + padding-left: 10px; + border-style: solid; + border-top-width: 0px; + border-right-width: 0px; + border-bottom-width: 0px; + border-left-width : 0px; +} +H5{ + color : #006699; + text-align : center; + border-left-color: #996666; + padding-top: 0px; + padding-right: 0px; + padding-bottom: 0px; + padding-left: 10px; + border-style: solid; + border-top-width: 0px; + border-right-width: 0px; + border-bottom-width: 0px; + border-left-width : 0px; +} + +HR{ + height: 3px; +} +#erlauet{ + color : #006699; + text-align : left; + border-left-color: #996666; + padding: 5px 5px 5px 5px; + +} +#darkblock{ + background-color : #99CCFF; + text-align : left; + padding : 5px 5px 5px 5px; +font-size : 13px; +} +#lightblock{ + background-color : #D6E6F9; + text-align : left; + padding : 5px 5px 5px 5px; +font-size : 13px; +} +.versiontext { + font-family: Verdana, Arial, Helvetica, sans-serif; + font-size: 6pt; + color: #6b6b6b; + font-style: normal; + text-decoration: none; + text-align: right; + padding-right : 5px; +} +.navitext { + font-family: Verdana, Arial, Helvetica, sans-serif; + font-size: 7pt; + font-weight: bold; + color: #000000; + font-style: normal; + text-decoration: underline; +} +.navitext:hover { + font-family: Verdana, Arial, Helvetica, sans-serif; + font-size: 7pt; + font-weight: bold; + color: black; + font-style: normal; + text-decoration: underline; +} +a.pagelinks { + font-family: Verdana, Arial, Helvetica, sans-serif; + font-size: 9pt; + color: #000000; +} +a.pagelinks:hover { + color: gray; +} + +a.menulinks { + font-family: Verdana, Arial, Helvetica, sans-serif; + font-size: 10pt; + font-weight: normal; + color: #000000; + font-style: normal; + text-decoration: underline; +} +a.menulinks:hover { + text-decoration: underline; +} +.link_dbx +{ + font-family: Verdana, Arial, Helvetica, sans-serif; + font-weight: normal; + text-decoration: underline; + color: #000000; +} +.link_dbx:hover +{ + color: #000000; + text-decoration: underline; +} +.link_nav +{ + font-family: Verdana, Arial, Helvetica, sans-serif; + font-weight: normal; + text-decoration: underline; + color: #000000; +} + +.link_nav:hover +{ + color : gray; + text-decoration: underline; +} + +.link +{ + font-family: Verdana, Arial, Helvetica, sans-serif; + font-weight: bold; + text-decoration: underline; + color: #D6E5F8; +} + +.link:hover +{ + color: white; +} + +.link_fett +{ + font-family: Verdana, Arial, Helvetica, sans-serif; + font-weight: bold; + text-decoration: underline; + color: #D6E5F8; +} +.link_fett:hover +{ + color: #000000; + text-decoration: underline; +} +.header { font-family:Verdana,Arial,Helv; font-size:12px; margin-left:5px; font-weight:bold; text-decoration:none; color:#D6E5F8;} + +/* Definitionen für die Meldungen (hostmeld.inc) */ +.meld { +background-color: white; +color : black; +padding: 5px; +margin: 2px; +margin-bottom: 10px; +border: 6px solid; +} +.ok { +border-color: #199919; +} +.fehler { +border-color: #ff4c4c; +} +.hinweis { +border-color: #003399; +} +.fehlerfeld { +color: red; +font-weight: bolder; +} + +#tabheader { + color : #D6E6F9; + background-color : #6699CC; + font-size : 13px; + font-weight : bold; + padding : 5px; + padding-top:1px; + padding-bottom:1px; +} +#tab { + background-color : #D6E6F9; + margin-top: 2px; + padding : 5px; +} + + +/* ================================================================ +This copyright notice must be untouched at all times. + +The original version of this stylesheet and the associated (x)html +is available at http://www.cssplay.co.uk/menus/simple_vertical.html +Copyright (c) 2005-2007 Stu Nicholls. All rights reserved. +This stylesheet and the associated (x)html may be modified in any +way to fit your requirements. +=================================================================== */ + +/* Add a margin - for this demo only - and a relative position with a high z-index to make it appear over any element below */ +#menu_container {width:100%; height:22px; z-index:100; background-color: #cccccc;} + +/* Get rid of the margin, padding and bullets in the unordered lists */ +#pmenu, #pmenu ul {padding:0; margin:0; list-style-type: none;} + +/* Set up the link size, color and borders */ +#pmenu a, #pmenu a:visited {display:block; font-size:10pt; color:#000000; text-decoration:none; text-indent:5px; + border:1px solid; border-width:1px 0 1px 1px; border-bottom-color: gray; border-top-color: white; + border-left-color: white; border-right-color: gray; + min-height:20px; + line-height:20px; + height:20px; + height:auto !important; + } + +/* Breitenangaben mit child selector: funkt nicht mit IE < 7. */ +#pmenu > li > ul a {width:170px;} /* LVL 1 Diese Selektion haut im IE6 nicht hin */ +#pmenu > li > ul > li > ul a {width:200px;} /* LVL 2 Diese Selektion haut im IE6 nicht hin */ +/* Breitenangaben ohne child selector: für IE6 */ +#pmenu * a { width:100px; } +#pmenu * * a { width:200px; } + +/* Set up the sub level borders */ +#pmenu li ul li a, #pmenu li ul li a:visited {border-width:0 1px 1px 1px;} +#pmenu li a.enclose, #pmenu li a.enclose:visited {border-width:1px;} + +/* Set up the list items */ +#pmenu li {float:left; background:#cccccc;} /* orig: #7484ad;*/ + +/* For Non-IE browsers and IE7 */ +#pmenu li:hover {position:relative;} +/* Make the hovered list color persist */ +#pmenu li:hover > a {background:#006699; color:#ffffff;} /* orig: #dfd7ca;*/ +/* Set up the sublevel lists with a position absolute for flyouts and overrun padding. The transparent gif is for IE to work */ +#pmenu li ul {display:none;} +/* For Non-IE and IE7 make the sublevels visible on list hover. This is all it needs */ +#pmenu li:hover > ul {display:block; position:absolute; top:-11px; left:80px; padding:10px 30px 30px 30px; background:transparent url('../graphics/transparent.gif'); width:120px;} +/* Position the first sub level beneath the top level liinks */ +#pmenu > li:hover > ul {left:-30px; top:12px;} + +/* get rid of the table */ +#pmenu table {position:absolute; border-collapse:collapse; top:0; left:0; z-index:100; font-size:1em;} + +/* For IE5.5 and IE6 give the hovered links a position relative and a change of background and foreground color. This is needed to trigger IE to show the sub levels */ +* html #pmenu li a:hover {position:relative; background:#006699; color:#ffffff;} /* IE6: aktiv wenn Link hoovert */ + +/* For accessibility of the top level menu when tabbing */ +#pmenu li a:active, #pmenu li a:focus {background:#006699; color:#ffffff;} /* IE6: aktiv wenn Link hoovert */ + +/* Set up the pointers for the sub level indication */ +#pmenu li.fly {background:#cccccc url('../graphics/fly.gif') no-repeat right center;} /* orig: #7484ad;*/ +#pmenu li.drop {background:#cccccc url('../graphics/drop.gif') no-repeat right center;} /* orig: #7484ad;*/ + + +/* This lot is for IE5.5 and IE6 ONLY and is necessary to make the sublevels appear */ + +/* change the drop down levels from display:none; to visibility:hidden; */ +* html #pmenu li ul { visibility:hidden; display:block; position:absolute; top:-11px; left:80px; padding:10px 30px 30px 30px; background:transparent url('../graphics/transparent.gif');} + +/* keep the third level+ hidden when you hover on first level link */ +#pmenu li a:hover ul ul{ +visibility:hidden; +} +/* keep the fourth level+ hidden when you hover on second level link */ +#pmenu li a:hover ul a:hover ul ul{ +visibility:hidden; +} +/* keep the fifth level hidden when you hover on third level link */ +#pmenu li a:hover ul a:hover ul a:hover ul ul{ +visibility:hidden; +} +/* keep the sixth level hidden when you hover on fourth level link */ +#pmenu li a:hover ul a:hover ul a:hover ul a:hover ul ul { +visibility:hidden; +} + +/* make the second level visible when hover on first level link and position it */ +#pmenu li a:hover ul { +visibility:visible; left:-30px; top:14px; lef\t:-31px; to\p:15px; +} + +/* make the third level visible when you hover over second level link and position it and all further levels */ +#pmenu li a:hover ul a:hover ul{ +visibility:visible; top:-11px; left:80px; +} +/* make the fourth level visible when you hover over third level link */ +#pmenu li a:hover ul a:hover ul a:hover ul { +visibility:visible; +} +/* make the fifth level visible when you hover over fourth level link */ +#pmenu li a:hover ul a:hover ul a:hover ul a:hover ul { +visibility:visible; +} +/* make the sixth level visible when you hover over fifth level link */ +#pmenu li a:hover ul a:hover ul a:hover ul a:hover ul a:hover ul { +visibility:visible; +} +/* If you can see the pattern in the above IE5.5 and IE6 style then you can add as many sub levels as you like */ + +@media print { + #menu_container, #hd, #np {display: none;} + #div_teiln {min-width: 20%;} + h1, h2, h3, h4, h5 {color: black;} +} diff --git a/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/index.css b/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/index.css new file mode 100644 index 00000000..2b7cee82 --- /dev/null +++ b/BKUOnline/src/main/webapp/finanzonline/FinanzOnlineLogin/index.css @@ -0,0 +1,101 @@ + #leftcontent { + position: absolute; + left:10px; + top:120px; + width:210px; + border:0px solid #000; + } + #centercontent { + margin-left: 229px; + margin-right:229px; + margin-top: -2px; + /* + IE5x PC mis-implements the box model. Because of that we sometimes have + to perform a little CSS trickery to get pixel-perfect display across browsers. + The following bit of code was proposed by Tantek Celik, and it preys upon a CSS + parsing bug in IE5x PC that will prematurly close a style rule when it runs + into the string "\"}\"". After that string appears in a rule, then, we can override + previously set attribute values and only browsers without the parse bug will + recognize the new values. So any of the name-value pairs above this comment + that we need to override for browsers with correct box-model implementations + will be listed below. + + We use the voice-family property because it is likely to be used very infrequently, + and where it is used it will be set on the body tag. So the second voice-family value + of "inherit" will override our bogus "\"}\"" value and allow the proper value to + cascade down from the body tag. + + The style rule immediately following this rule offers another chance for CSS2 + aware browsers to pick up the values meant for correct box-model implementations. + It uses a CSS2 selector that will be ignored by IE5x PC. + + Read more at http://www.glish.com/css/hacks.asp + + + voice-family: "\"}\""; + voice-family: inherit; + margin-left: 201px; + margin-right:201px;*/ + } + html>body #centercontent { + margin-left: 231px; + margin-right:231px; + } + #rightcontent { + position: absolute; + right:10px; + top:120px; + width:210px; + } + #banner { + height:120px; + } + html>body #banner { + height:120px; + } + #rightcontent p { + font-size:10px + } + #tabheader { + color : #D6E6F9; + background-color : #6699CC; + font-size : 13px; + font-weight : bold; + padding : 5px; + padding-top:1px; + padding-bottom:1px; + } + #tab { + background-color : #D6E6F9; + margin-top: 2px; + padding : 5px; + } + #navlist { + padding: 0px; + margin: 0px; + width: 100%; + background-color: #6699cc; + } + #navlist li { + list-style: none; + margin: 0; + padding: 0.25em; + padding-top: 0.3em; + padding-bottom: 0.3em; + border-bottom: 1px solid white; + } + a.nb { + font-family:Verdana,Arial,Helv; + font-size:12px; + margin-left:5px; + font-weight:bold; + text-decoration:underline; + color:#D6E6F9; + } + a.nb:hover { + color:white; + } + + @media print { + #rightcontent {display: none;} + } diff --git a/BKUOnline/src/main/webapp/finanzonline/iframe.html b/BKUOnline/src/main/webapp/finanzonline/iframe.html new file mode 100644 index 00000000..ac2f6c93 --- /dev/null +++ b/BKUOnline/src/main/webapp/finanzonline/iframe.html @@ -0,0 +1,22 @@ + + + + bkuiframe + + + + + +
+ Logo + +
+ + +
+
+ + + diff --git a/BKUOnline/src/main/webapp/finanzonline/index.html b/BKUOnline/src/main/webapp/finanzonline/index.html new file mode 100644 index 00000000..d47e8e63 --- /dev/null +++ b/BKUOnline/src/main/webapp/finanzonline/index.html @@ -0,0 +1,192 @@ + + + + FinanzOnline Login + + + + + + + + + + + + + +
+
Login mit Bürgerkarte
+
+ +
+ +
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Login mit Zugangskennungen
+ +
+ +
+ +
+ + + + + + +
+ + Online-Erstanmeldung + + Erstanmeldung zu FinanzOnline für Nicht-Unternehmer (nur für Login mit Zugangskennungen nötig) +
+ PIN vergessen / gesperrt + + Online-Rücksetzen auf Start-PIN für Nicht-Unternehmer +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
Service
+ Anonyme Steuerberechnung + + Berechnung der Steuer ohne Anmeldung +
+ + DEMO Arbeitnehmerveranlagung + + + Animierte Anleitung zur Arbeitnehmerveranlagung +
+ + FinanzOnline Ratgeber + + + FinanzOnline in Frage und Antwort +
+ + FinanzOnline eLearning + + + Elektronisches Lernprogramm zur Handhabung von FinanzOnline und Durchführung der Arbeitnehmerveranlagung +
+
+ +
+ +
+ +
+ + + \ No newline at end of file diff --git a/BKUOnline/src/main/webapp/index.html b/BKUOnline/src/main/webapp/index.html index 8f1a338e..bf8b3ae0 100644 --- a/BKUOnline/src/main/webapp/index.html +++ b/BKUOnline/src/main/webapp/index.html @@ -49,6 +49,8 @@

TestRequest

Security Layer Request +

FinanzOnline

+FinanzOnline Demo Integration

STAL Service

STAL Service Endpoint Information

diff --git a/BKUOnline/src/test/resources/appletTest.html b/BKUOnline/src/test/resources/appletTest.html index bf24a2c9..71f09a93 100644 --- a/BKUOnline/src/test/resources/appletTest.html +++ b/BKUOnline/src/test/resources/appletTest.html @@ -22,7 +22,7 @@ width=380 height=160> - + -- cgit v1.2.3 From f993d336e51b9f7898aeeff2e5ae6785066d1e5b Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 9 Oct 2008 16:23:52 +0000 Subject: demo integration beta1 git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@94 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUApplet/hs_err_pid32072.log | 453 +++++++++++++++++++++ .../at/gv/egiz/bku/online/applet/BKUApplet.java | 17 +- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 7 +- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 3 +- .../main/java/at/gv/egiz/bku/gui/ImagePanel.java | 37 ++ .../main/java/at/gv/egiz/bku/gui/SimpleGUI.java | 38 +- .../at/gv/egiz/bku/gui/Messages.properties | 2 +- BKUCommonGUI/src/main/resources/images/mocca.png | Bin 0 -> 1450 bytes .../src/main/resources/images/mocca_default.png | Bin 0 -> 1287 bytes .../src/main/resources/images/mocca_tiny.png | Bin 0 -> 1025 bytes .../test/java/at/gv/egiz/bku/gui/BKUGUITest.java | 2 +- BKUOnline/src/main/webapp/META-INF/context.xml | 1 + BKUOnline/src/main/webapp/appletPage.jsp | 2 +- BKUOnline/src/main/webapp/index.html | 2 - 14 files changed, 542 insertions(+), 22 deletions(-) create mode 100644 BKUApplet/hs_err_pid32072.log create mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ImagePanel.java create mode 100644 BKUCommonGUI/src/main/resources/images/mocca.png create mode 100644 BKUCommonGUI/src/main/resources/images/mocca_default.png create mode 100644 BKUCommonGUI/src/main/resources/images/mocca_tiny.png (limited to 'BKUCommonGUI/src/test/java') diff --git a/BKUApplet/hs_err_pid32072.log b/BKUApplet/hs_err_pid32072.log new file mode 100644 index 00000000..cf86d1c5 --- /dev/null +++ b/BKUApplet/hs_err_pid32072.log @@ -0,0 +1,453 @@ +# +# An unexpected error has been detected by Java Runtime Environment: +# +# SIGBUS (0x7) at pc=0xb7bcbc53, pid=32072, tid=3033660304 +# +# Java VM: Java HotSpot(TM) Client VM (10.0-b22 mixed mode, sharing linux-x86) +# Problematic frame: +# C [libzip.so+0xbc53] +# +# If you would like to submit a bug report, please visit: +# http://java.sun.com/webapps/bugreport/crash.jsp +# The crash happened outside the Java Virtual Machine in native code. +# See problematic frame for where to report the bug. +# + +--------------- T H R E A D --------------- + +Current thread (0xb4faa400): JavaThread "Thread-2" [_thread_in_native, id=32091, stack(0xb4ccf000,0xb4d20000)] + +siginfo:si_signo=SIGBUS: si_errno=0, si_code=2 (BUS_ADRERR), si_addr=0xb5804fc0 + +Registers: +EAX=0x080576a8, EBX=0xb7bd07bc, ECX=0xb5803000, EDX=0x0002d000 +ESP=0xb4d1dc10, EBP=0xb4d1dc38, ESI=0xb5804fa3, EDI=0x0839b310 +EIP=0xb7bcbc53, CR2=0xb5804fc0, EFLAGS=0x00210286 + +Top of Stack: (sp=0xb4d1dc10) +0xb4d1dc10: 00000030 b4fa9370 b4fa9378 b4fa9764 +0xb4d1dc20: 08057568 08057568 b7bcbc0b b7bd07bc +0xb4d1dc30: 0828f3cc 00000000 b4d1dc68 b7bcc00b +0xb4d1dc40: 080576a8 0828f3cc 00000000 00000000 +0xb4d1dc50: b4faa400 00000004 87c67713 b7bd07bc +0xb4d1dc60: b4d1dcb0 b4faa4f4 b4d1e0d8 b7bc31b9 +0xb4d1dc70: 080576a8 b4d1dcb0 00000025 00000025 +0xb4d1dc80: b4d1dcb0 6c706d69 49554765 2e303124 + +Instructions: (pc=0xb7bcbc53) +0xb7bcbc43: 8b 70 04 8b 45 08 8b 48 10 8b 50 1c 01 ce 29 d6 +0xb7bcbc53: 0f b6 46 1d 0f b6 56 1c c1 e0 08 09 c2 89 55 f0 + +Stack: [0xb4ccf000,0xb4d20000], sp=0xb4d1dc10, free space=315k +Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) +C [libzip.so+0xbc53] +C [libzip.so+0xc00b] ZIP_GetEntry+0x10b +C [libzip.so+0x31b9] Java_java_util_zip_ZipFile_getEntry+0xc9 +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +J sun.misc.URLClassPath$JarLoader.getResource(Ljava/lang/String;Z)Lsun/misc/Resource; +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::StubRoutines (1) +V [libjvm.so+0x21c5cd] +V [libjvm.so+0x310748] +V [libjvm.so+0x21c460] +V [libjvm.so+0x272313] +C [libjava.so+0xaa5c] Java_java_security_AccessController_doPrivileged__Ljava_security_PrivilegedExceptionAction_2Ljava_security_AccessControlContext_2+0x3c +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::StubRoutines (1) +V [libjvm.so+0x21c5cd] +V [libjvm.so+0x310748] +V [libjvm.so+0x21c0f1] +V [libjvm.so+0x21c1da] +V [libjvm.so+0x375867] +V [libjvm.so+0x374305] +V [libjvm.so+0x373377] +V [libjvm.so+0x373082] +V [libjvm.so+0x1bc043] +V [libjvm.so+0x20c8e6] +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::StubRoutines (1) +V [libjvm.so+0x21c5cd] +V [libjvm.so+0x310748] +V [libjvm.so+0x21bee0] +V [libjvm.so+0x21bf6d] +V [libjvm.so+0x28c175] +V [libjvm.so+0x391f8d] +V [libjvm.so+0x3113f9] +C [libpthread.so.0+0x54fb] + +Java frames: (J=compiled Java code, j=interpreted, Vv=VM code) +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +J sun.misc.URLClassPath$JarLoader.getResource(Ljava/lang/String;Z)Lsun/misc/Resource; +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::StubRoutines (1) +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::StubRoutines (1) +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::Interpreter +v ~BufferBlob::StubRoutines (1) + +--------------- P R O C E S S --------------- + +Java Threads: ( => current thread ) + 0xb5702400 JavaThread "Thread-3" [_thread_blocked, id=32217, stack(0xb4c7e000,0xb4ccf000)] +=>0xb4faa400 JavaThread "Thread-2" [_thread_in_native, id=32091, stack(0xb4ccf000,0xb4d20000)] + 0x0828e400 JavaThread "AWT-EventQueue-1" [_thread_blocked, id=32089, stack(0xb4eaf000,0xb4f00000)] + 0xb57b9400 JavaThread "TimerQueue" daemon [_thread_blocked, id=32088, stack(0xb4dd5000,0xb4e26000)] + 0xb4f8a400 JavaThread "DestroyJavaVM" [_thread_blocked, id=32073, stack(0xb7c43000,0xb7c94000)] + 0xb57a1400 JavaThread "AWT-EventQueue-0" [_thread_blocked, id=32086, stack(0xb507f000,0xb50d0000)] + 0xb57a0800 JavaThread "AWT-Shutdown" [_thread_blocked, id=32085, stack(0xb50d0000,0xb5121000)] + 0xb5792000 JavaThread "AWT-XAWT" daemon [_thread_in_native, id=32082, stack(0xb520c000,0xb525d000)] + 0xb5751000 JavaThread "Java2D Disposer" daemon [_thread_blocked, id=32081, stack(0xb5285000,0xb52d6000)] + 0xb5700c00 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=32079, stack(0xb5823000,0xb5874000)] + 0x0808c000 JavaThread "CompilerThread0" daemon [_thread_blocked, id=32078, stack(0xb5874000,0xb58f5000)] + 0x0808ac00 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=32077, stack(0xb58f5000,0xb5946000)] + 0x08081c00 JavaThread "Finalizer" daemon [_thread_blocked, id=32076, stack(0xb598c000,0xb59dd000)] + 0x08080c00 JavaThread "Reference Handler" daemon [_thread_blocked, id=32075, stack(0xb59dd000,0xb5a2e000)] + +Other Threads: + 0x0807f400 VMThread [stack: 0xb5a2e000,0xb5aaf000] [id=32074] + 0xb570a400 WatcherThread [stack: 0xb567f000,0xb5700000] [id=32080] + +VM state:not at safepoint (normal execution) + +VM Mutex/Monitor currently owned by a thread: None + +Heap + def new generation total 960K, used 512K [0x8bfe0000, 0x8c0e0000, 0x8c4c0000) + eden space 896K, 50% used [0x8bfe0000, 0x8c050378, 0x8c0c0000) + from space 64K, 100% used [0x8c0d0000, 0x8c0e0000, 0x8c0e0000) + to space 64K, 0% used [0x8c0c0000, 0x8c0c0000, 0x8c0d0000) + tenured generation total 4096K, used 3837K [0x8c4c0000, 0x8c8c0000, 0x8ffe0000) + the space 4096K, 93% used [0x8c4c0000, 0x8c87f6a0, 0x8c87f800, 0x8c8c0000) + compacting perm gen total 12288K, used 6940K [0x8ffe0000, 0x90be0000, 0x93fe0000) + the space 12288K, 56% used [0x8ffe0000, 0x906a7308, 0x906a7400, 0x90be0000) + ro space 8192K, 73% used [0x93fe0000, 0x945c34a0, 0x945c3600, 0x947e0000) + rw space 12288K, 58% used [0x947e0000, 0x94ed8668, 0x94ed8800, 0x953e0000) + +Dynamic libraries: +06000000-0641b000 r-xp 00000000 08:02 1085428 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/client/libjvm.so +0641b000-06435000 rwxp 0041a000 08:02 1085428 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/client/libjvm.so +06435000-06855000 rwxp 06435000 00:00 0 +08048000-08052000 r-xp 00000000 08:02 1085534 /usr/lib/jvm/java-6-sun-1.6.0.06/bin/appletviewer +08052000-08053000 rwxp 00009000 08:02 1085534 /usr/lib/jvm/java-6-sun-1.6.0.06/bin/appletviewer +08053000-083f5000 rwxp 08053000 00:00 0 [heap] +8bfe0000-8c0e0000 rwxp 8bfe0000 00:00 0 +8c0e0000-8c4c0000 rwxp 8c0e0000 00:00 0 +8c4c0000-8c8c0000 rwxp 8c4c0000 00:00 0 +8c8c0000-8ffe0000 rwxp 8c8c0000 00:00 0 +8ffe0000-90be0000 rwxp 8ffe0000 00:00 0 +90be0000-93fe0000 rwxp 90be0000 00:00 0 +93fe0000-945c4000 r-xs 00001000 08:02 1081430 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/client/classes.jsa +945c4000-947e0000 rwxp 945c4000 00:00 0 +947e0000-94ed9000 rwxp 005e5000 08:02 1081430 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/client/classes.jsa +94ed9000-953e0000 rwxp 94ed9000 00:00 0 +953e0000-954b9000 rwxp 00cde000 08:02 1081430 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/client/classes.jsa +954b9000-957e0000 rwxp 954b9000 00:00 0 +957e0000-957e4000 r-xs 00db7000 08:02 1081430 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/client/classes.jsa +957e4000-95be0000 rwxp 957e4000 00:00 0 +b4c7e000-b4c81000 ---p b4c7e000 00:00 0 +b4c81000-b4ccf000 rwxp b4c81000 00:00 0 +b4ccf000-b4cd2000 ---p b4ccf000 00:00 0 +b4cd2000-b4d20000 rwxp b4cd2000 00:00 0 +b4d20000-b4d23000 r-xs 00000000 08:02 3560016 /var/cache/fontconfig/5e10083637a12ecd1bff191eb66bfa2f-x86.cache-2 +b4d23000-b4d29000 r-xs 00000000 08:02 3560014 /var/cache/fontconfig/945677eb7aeaf62f1d50efc3fb3ec7d8-x86.cache-2 +b4d29000-b4d2c000 r-xs 00000000 08:02 3560019 /var/cache/fontconfig/e383d7ea5fbe662a33d9b44caf393297-x86.cache-2 +b4d2c000-b4d31000 r-xs 00000000 08:02 3560011 /var/cache/fontconfig/bddabcf04192498a6a74911686fc6962-x86.cache-2 +b4d31000-b4d34000 r-xs 00000000 08:02 3556212 /var/cache/fontconfig/a46337af8a0b4c9b317ad981ec3bdf87-x86.cache-2 +b4d34000-b4d35000 r-xs 00000000 08:02 3560013 /var/cache/fontconfig/fd9505950c048a77dc4b710eb6a628ed-x86.cache-2 +b4d35000-b4d37000 r-xs 00000000 08:02 3560021 /var/cache/fontconfig/ddc79d3ea06a7c6ffa86ede85f3bb5df-x86.cache-2 +b4d37000-b4d38000 r-xs 00000000 08:02 3560164 /var/cache/fontconfig/e3fa16a14183b06aa45b3e009278fd14-x86.cache-2 +b4d38000-b4d39000 r-xs 00000000 08:02 3560125 /var/cache/fontconfig/e7071f4a29fa870f4323321c154eba04-x86.cache-2 +b4d39000-b4d3a000 r-xs 00000000 08:02 3560023 /var/cache/fontconfig/a2ab74764b07279e7c36ddb1d302cf26-x86.cache-2 +b4d3a000-b4d3e000 r-xs 00000000 08:02 3560003 /var/cache/fontconfig/921a30a17f0be15c70ac14043cb7a739-x86.cache-2 +b4d3e000-b4d3f000 r-xs 00000000 08:02 3560018 /var/cache/fontconfig/c69f04ab05004e31a6d5e715764f16d8-x86.cache-2 +b4d3f000-b4d40000 r-xs 00000000 08:02 3560008 /var/cache/fontconfig/4c73fe0c47614734b17d736dbde7580a-x86.cache-2 +b4d40000-b4d42000 r-xs 00000000 08:02 3560007 /var/cache/fontconfig/646addb8444faa74ee138aa00ab0b6a0-x86.cache-2 +b4d42000-b4d45000 r-xs 00000000 08:02 3560006 /var/cache/fontconfig/a755afe4a08bf5b97852ceb7400b47bc-x86.cache-2 +b4d45000-b4d47000 r-xs 00000000 08:02 3560015 /var/cache/fontconfig/20bd79ad97094406f7d1b9654bfbd926-x86.cache-2 +b4d47000-b4d49000 r-xs 00000000 08:02 3560009 /var/cache/fontconfig/9c0624108b9a2ae8552f664125be8356-x86.cache-2 +b4d49000-b4d50000 r-xs 00000000 08:02 3560004 /var/cache/fontconfig/6d41288fd70b0be22e8c3a91e032eec0-x86.cache-2 +b4d50000-b4d53000 r-xs 00000000 08:02 3560012 /var/cache/fontconfig/de156ccd2eddbdc19d37a45b8b2aac9c-x86.cache-2 +b4d53000-b4d55000 r-xs 00000000 08:02 3556204 /var/cache/fontconfig/da1bd5ca8443ffe22927a23ce431d198-x86.cache-2 +b4d55000-b4d5d000 r-xs 00000000 08:02 3560169 /var/cache/fontconfig/e3de0de479f42330eadf588a55fb5bf4-x86.cache-2 +b4d5d000-b4d65000 r-xs 00000000 08:02 2409868 /var/cache/fontconfig/0f34bcd4b6ee430af32735b75db7f02b-x86.cache-2 +b4d65000-b4d66000 r-xs 00000000 08:02 3560126 /var/cache/fontconfig/4794a0821666d79190d59a36cb4f44b5-x86.cache-2 +b4d66000-b4d88000 r-xs 00000000 08:02 1392718 /var/cache/fontconfig/365b55f210c0a22e9a19e35191240f32-x86.cache-2 +b4d88000-b4d8a000 r-xs 00000000 08:02 3560017 /var/cache/fontconfig/2c5ba8142dffc8bf0377700342b8ca1a-x86.cache-2 +b4d8a000-b4d8d000 r-xs 00000000 08:02 3560022 /var/cache/fontconfig/de9486f0b47a4d768a594cb4198cb1c6-x86.cache-2 +b4d8d000-b4d94000 r-xs 00000000 08:02 3556202 /var/cache/fontconfig/d52a8644073d54c13679302ca1180695-x86.cache-2 +b4d94000-b4d99000 r-xs 00000000 08:02 3558093 /var/cache/fontconfig/105b9c7e6f0a4f82d8c9b6e39c52c6f9-x86.cache-2 +b4d99000-b4d9c000 r-xs 00000000 08:02 3560677 /var/cache/fontconfig/6386b86020ecc1ef9690bb720a13964f-x86.cache-2 +b4d9c000-b4da7000 r-xs 00000000 08:02 3556115 /var/cache/fontconfig/089dead882dea3570ffc31a9898cfb69-x86.cache-2 +b4da7000-b4db4000 r-xs 00000000 08:02 2409873 /var/cache/fontconfig/e13b20fdb08344e0e664864cc2ede53d-x86.cache-2 +b4dd5000-b4dd8000 ---p b4dd5000 00:00 0 +b4dd8000-b4e26000 rwxp b4dd8000 00:00 0 +b4e3b000-b4e46000 rwxs 00000000 00:09 1831534605 /SYSV00000000 (deleted) +b4e46000-b4e47000 r--s 0000f000 00:11 751021 /var/run/pcscd/pcscd.pub +b4e47000-b4e48000 r--s 0000e000 00:11 751021 /var/run/pcscd/pcscd.pub +b4e48000-b4e49000 r--s 0000d000 00:11 751021 /var/run/pcscd/pcscd.pub +b4e49000-b4e4a000 r--s 0000c000 00:11 751021 /var/run/pcscd/pcscd.pub +b4e4a000-b4e4b000 r--s 0000b000 00:11 751021 /var/run/pcscd/pcscd.pub +b4e4b000-b4e4c000 r--s 0000a000 00:11 751021 /var/run/pcscd/pcscd.pub +b4e4c000-b4e4d000 r--s 00009000 00:11 751021 /var/run/pcscd/pcscd.pub +b4e4d000-b4e4e000 r--s 00008000 00:11 751021 /var/run/pcscd/pcscd.pub +b4e4e000-b4e4f000 r--s 00007000 00:11 751021 /var/run/pcscd/pcscd.pub +b4e4f000-b4e50000 r--s 00006000 00:11 751021 /var/run/pcscd/pcscd.pub +b4e50000-b4e51000 r--s 00005000 00:11 751021 /var/run/pcscd/pcscd.pub +b4e51000-b4e52000 r--s 00004000 00:11 751021 /var/run/pcscd/pcscd.pub +b4e52000-b4e5a000 r-xp 00000000 08:02 901283 /usr/lib/libpcsclite.so.1.0.0 +b4e5a000-b4e5b000 rwxp 00008000 08:02 901283 /usr/lib/libpcsclite.so.1.0.0 +b4e5b000-b4e5d000 r-xp 00000000 08:02 1085449 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/libj2pcsc.so +b4e5d000-b4e5e000 rwxp 00001000 08:02 1085449 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/libj2pcsc.so +b4e5e000-b4e61000 rwxp b4e5e000 00:00 0 +b4e61000-b4eaf000 rwxp b4e61000 00:00 0 +b4eaf000-b4eb2000 ---p b4eaf000 00:00 0 +b4eb2000-b4fd2000 rwxp b4eb2000 00:00 0 +b4fd2000-b5000000 ---p b4fd2000 00:00 0 +b5000000-b5001000 r--s 00003000 00:11 751021 /var/run/pcscd/pcscd.pub +b5001000-b5004000 r-xs 00027000 08:02 1086682 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/ext/sunjce_provider.jar +b5004000-b5036000 rwxp b5004000 00:00 0 +b5036000-b503a000 r-xs 00000000 08:02 3555788 /var/cache/fontconfig/4a195c91033ef4528a35b4a1ac51414e-x86.cache-2 +b503a000-b5048000 r-xs 00000000 08:02 3557818 /var/cache/fontconfig/865f88548240fee46819705c6468c165-x86.cache-2 +b5048000-b504f000 r-xs 00110000 08:02 1065527 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/resources.jar +b504f000-b5077000 rwxp b504f000 00:00 0 +b5077000-b507e000 r-xp 00000000 08:02 1085443 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/libnio.so +b507e000-b507f000 rwxp 00006000 08:02 1085443 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/libnio.so +b507f000-b5082000 ---p b507f000 00:00 0 +b5082000-b50d0000 rwxp b5082000 00:00 0 +b50d0000-b50d3000 ---p b50d0000 00:00 0 +b50d3000-b5121000 rwxp b50d3000 00:00 0 +b5121000-b5124000 r-xs 00000000 08:02 3560016 /var/cache/fontconfig/5e10083637a12ecd1bff191eb66bfa2f-x86.cache-2 +b5124000-b512a000 r-xs 00000000 08:02 3560014 /var/cache/fontconfig/945677eb7aeaf62f1d50efc3fb3ec7d8-x86.cache-2 +b512a000-b512d000 r-xs 00000000 08:02 3560019 /var/cache/fontconfig/e383d7ea5fbe662a33d9b44caf393297-x86.cache-2 +b512d000-b5132000 r-xs 00000000 08:02 3560011 /var/cache/fontconfig/bddabcf04192498a6a74911686fc6962-x86.cache-2 +b5132000-b5135000 r-xs 00000000 08:02 3556212 /var/cache/fontconfig/a46337af8a0b4c9b317ad981ec3bdf87-x86.cache-2 +b5135000-b5136000 r-xs 00000000 08:02 3560013 /var/cache/fontconfig/fd9505950c048a77dc4b710eb6a628ed-x86.cache-2 +b5136000-b5138000 r-xs 00000000 08:02 3560021 /var/cache/fontconfig/ddc79d3ea06a7c6ffa86ede85f3bb5df-x86.cache-2 +b5138000-b5139000 r-xs 00000000 08:02 3560164 /var/cache/fontconfig/e3fa16a14183b06aa45b3e009278fd14-x86.cache-2 +b5139000-b513a000 r-xs 00000000 08:02 3560125 /var/cache/fontconfig/e7071f4a29fa870f4323321c154eba04-x86.cache-2 +b513a000-b513b000 r-xs 00000000 08:02 3560023 /var/cache/fontconfig/a2ab74764b07279e7c36ddb1d302cf26-x86.cache-2 +b513b000-b513f000 r-xs 00000000 08:02 3560003 /var/cache/fontconfig/921a30a17f0be15c70ac14043cb7a739-x86.cache-2 +b513f000-b5140000 r-xs 00000000 08:02 3560018 /var/cache/fontconfig/c69f04ab05004e31a6d5e715764f16d8-x86.cache-2 +b5140000-b5141000 r-xs 00000000 08:02 3560008 /var/cache/fontconfig/4c73fe0c47614734b17d736dbde7580a-x86.cache-2 +b5141000-b5143000 r-xs 00000000 08:02 3560007 /var/cache/fontconfig/646addb8444faa74ee138aa00ab0b6a0-x86.cache-2 +b5143000-b5146000 r-xs 00000000 08:02 3560006 /var/cache/fontconfig/a755afe4a08bf5b97852ceb7400b47bc-x86.cache-2 +b5146000-b5148000 r-xs 00000000 08:02 3560015 /var/cache/fontconfig/20bd79ad97094406f7d1b9654bfbd926-x86.cache-2 +b5148000-b514a000 r-xs 00000000 08:02 3560009 /var/cache/fontconfig/9c0624108b9a2ae8552f664125be8356-x86.cache-2 +b514a000-b5151000 r-xs 00000000 08:02 3560004 /var/cache/fontconfig/6d41288fd70b0be22e8c3a91e032eec0-x86.cache-2 +b5151000-b5154000 r-xs 00000000 08:02 3560012 /var/cache/fontconfig/de156ccd2eddbdc19d37a45b8b2aac9c-x86.cache-2 +b5154000-b5156000 r-xs 00000000 08:02 3556204 /var/cache/fontconfig/da1bd5ca8443ffe22927a23ce431d198-x86.cache-2 +b5156000-b515e000 r-xs 00000000 08:02 3560169 /var/cache/fontconfig/e3de0de479f42330eadf588a55fb5bf4-x86.cache-2 +b515e000-b5166000 r-xs 00000000 08:02 2409868 /var/cache/fontconfig/0f34bcd4b6ee430af32735b75db7f02b-x86.cache-2 +b5166000-b5167000 r-xs 00000000 08:02 3560126 /var/cache/fontconfig/4794a0821666d79190d59a36cb4f44b5-x86.cache-2 +b5167000-b5189000 r-xs 00000000 08:02 1392718 /var/cache/fontconfig/365b55f210c0a22e9a19e35191240f32-x86.cache-2 +b5189000-b518b000 r-xs 00000000 08:02 3560017 /var/cache/fontconfig/2c5ba8142dffc8bf0377700342b8ca1a-x86.cache-2 +b518b000-b518e000 r-xs 00000000 08:02 3560022 /var/cache/fontconfig/de9486f0b47a4d768a594cb4198cb1c6-x86.cache-2 +b518e000-b5195000 r-xs 00000000 08:02 3556202 /var/cache/fontconfig/d52a8644073d54c13679302ca1180695-x86.cache-2 +b5195000-b519a000 r-xs 00000000 08:02 3558093 /var/cache/fontconfig/105b9c7e6f0a4f82d8c9b6e39c52c6f9-x86.cache-2 +b519a000-b519d000 r-xs 00000000 08:02 3560677 /var/cache/fontconfig/6386b86020ecc1ef9690bb720a13964f-x86.cache-2 +b519d000-b51a8000 r-xs 00000000 08:02 3556115 /var/cache/fontconfig/089dead882dea3570ffc31a9898cfb69-x86.cache-2 +b51a8000-b51b5000 r-xs 00000000 08:02 2409873 /var/cache/fontconfig/e13b20fdb08344e0e664864cc2ede53d-x86.cache-2 +b51b5000-b51bb000 r-xs 00091000 08:02 1065704 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/jsse.jar +b51bb000-b51be000 rwxp b51bb000 00:00 0 +b51be000-b520c000 rwxp b51be000 00:00 0 +b520c000-b520f000 ---p b520c000 00:00 0 +b520f000-b525d000 rwxp b520f000 00:00 0 +b525d000-b5264000 r-xp 00000000 08:02 1343649 /usr/lib/libXrender.so.1.3.0 +b5264000-b5265000 rwxp 00007000 08:02 1343649 /usr/lib/libXrender.so.1.3.0 +b5265000-b526d000 r-xp 00000000 08:02 1343710 /usr/lib/libXcursor.so.1.0.2 +b526d000-b526e000 rwxp 00007000 08:02 1343710 /usr/lib/libXcursor.so.1.0.2 +b526e000-b526f000 r--s 00002000 00:11 751021 /var/run/pcscd/pcscd.pub +b526f000-b5271000 r-xs 00017000 08:02 4065150 /home/clemens/workspace/mocca/BKUApplet/target/test-libs/iaik_jce_me4se-3.04.jar +b5271000-b5284000 r-xp 00000000 08:02 1085442 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/libnet.so +b5284000-b5285000 rwxp 00013000 08:02 1085442 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/libnet.so +b5285000-b5288000 ---p b5285000 00:00 0 +b5288000-b52d6000 rwxp b5288000 00:00 0 +b52d6000-b5354000 r-xp 00000000 08:02 1085586 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/libfontmanager.so +b5354000-b535e000 rwxp 0007e000 08:02 1085586 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/libfontmanager.so +b535e000-b5363000 rwxp b535e000 00:00 0 +b5363000-b536a000 r-xp 00000000 08:02 1343653 /usr/lib/libXi.so.6.0.0 +b536a000-b536b000 rwxp 00006000 08:02 1343653 /usr/lib/libXi.so.6.0.0 +b536b000-b5378000 r-xp 00000000 08:02 902010 /usr/lib/libXext.so.6.4.0 +b5378000-b5379000 rwxp 0000d000 08:02 902010 /usr/lib/libXext.so.6.4.0 +b5379000-b53ba000 r-xp 00000000 08:02 1085581 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/xawt/libmawt.so +b53ba000-b53bd000 rwxp 00040000 08:02 1085581 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/xawt/libmawt.so +b53bd000-b5438000 r-xp 00000000 08:02 1085578 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/libawt.so +b5438000-b543f000 rwxp 0007b000 08:02 1085578 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/libawt.so +b543f000-b5463000 rwxp b543f000 00:00 0 +b5463000-b54c2000 r-xs 00b89000 08:02 1085573 /usr/lib/jvm/java-6-sun-1.6.0.06/lib/tools.jar +b54c2000-b54f4000 rwxp b54c2000 00:00 0 +b54f4000-b567f000 r-xs 02df0000 08:02 1065570 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/rt.jar +b567f000-b5680000 ---p b567f000 00:00 0 +b5680000-b5800000 rwxp b5680000 00:00 0 +b5800000-b5801000 r--s 00001000 00:11 751021 /var/run/pcscd/pcscd.pub +b5801000-b5803000 r-xs 0000d000 08:02 4065123 /home/clemens/workspace/mocca/BKUApplet/target/test-libs/commons-logging-1.1.1.jar +b5803000-b5807000 r-xs 0002d000 08:02 4050367 /home/clemens/workspace/mocca/BKUApplet/target/BKUApplet-1.0-SNAPSHOT.jar +b5807000-b580b000 r-xp 00000000 08:02 1343688 /usr/lib/libXtst.so.6.1.0 +b580b000-b580c000 rwxp 00003000 08:02 1343688 /usr/lib/libXtst.so.6.1.0 +b580c000-b5810000 r-xp 00000000 08:02 905383 /usr/lib/libXfixes.so.3.1.0 +b5810000-b5811000 rwxp 00003000 08:02 905383 /usr/lib/libXfixes.so.3.1.0 +b5811000-b5815000 r-xs 00000000 08:02 3555788 /var/cache/fontconfig/4a195c91033ef4528a35b4a1ac51414e-x86.cache-2 +b5815000-b5823000 r-xs 00000000 08:02 3557818 /var/cache/fontconfig/865f88548240fee46819705c6468c165-x86.cache-2 +b5823000-b5826000 ---p b5823000 00:00 0 +b5826000-b5874000 rwxp b5826000 00:00 0 +b5874000-b5877000 ---p b5874000 00:00 0 +b5877000-b58f5000 rwxp b5877000 00:00 0 +b58f5000-b58f8000 ---p b58f5000 00:00 0 +b58f8000-b5946000 rwxp b58f8000 00:00 0 +b5946000-b594d000 r-xs 00000000 08:02 912666 /usr/lib/gconv/gconv-modules.cache +b594d000-b598c000 r-xp 00000000 08:02 2162962 /usr/lib/locale/de_AT.utf8/LC_CTYPE +b598c000-b598f000 ---p b598c000 00:00 0 +b598f000-b59dd000 rwxp b598f000 00:00 0 +b59dd000-b59e0000 ---p b59dd000 00:00 0 +b59e0000-b5a2e000 rwxp b59e0000 00:00 0 +b5a2e000-b5a2f000 ---p b5a2e000 00:00 0 +b5a2f000-b5abd000 rwxp b5a2f000 00:00 0 +b5abd000-b5ad7000 rwxp b5abd000 00:00 0 +b5ad7000-b5ada000 rwxp b5ad7000 00:00 0 +b5ada000-b5af5000 rwxp b5ada000 00:00 0 +b5af5000-b5af6000 rwxp b5af5000 00:00 0 +b5af6000-b5af7000 rwxp b5af6000 00:00 0 +b5af7000-b5afa000 rwxp b5af7000 00:00 0 +b5afa000-b5b15000 rwxp b5afa000 00:00 0 +b5b15000-b5b1b000 rwxp b5b15000 00:00 0 +b5b1b000-b5b35000 rwxp b5b1b000 00:00 0 +b5b35000-b5b46000 rwxp b5b35000 00:00 0 +b5b46000-b5bc0000 rwxp b5b46000 00:00 0 +b5bc0000-b5d10000 rwxp b5bc0000 00:00 0 +b5d10000-b7bc0000 rwxp b5d10000 00:00 0 +b7bc0000-b7bcf000 r-xp 00000000 08:02 1085437 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/libzip.so +b7bcf000-b7bd1000 rwxp 0000e000 08:02 1085437 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/libzip.so +b7bd1000-b7bf4000 r-xp 00000000 08:02 1085434 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/libjava.so +b7bf4000-b7bf6000 rwxp 00023000 08:02 1085434 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/libjava.so +b7bf6000-b7bff000 r-xp 00000000 08:02 2785878 /lib/tls/i686/cmov/libnss_files-2.7.so +b7bff000-b7c01000 rwxp 00008000 08:02 2785878 /lib/tls/i686/cmov/libnss_files-2.7.so +b7c01000-b7c09000 r-xp 00000000 08:02 2785986 /lib/tls/i686/cmov/libnss_nis-2.7.so +b7c09000-b7c0b000 rwxp 00007000 08:02 2785986 /lib/tls/i686/cmov/libnss_nis-2.7.so +b7c0b000-b7c1f000 r-xp 00000000 08:02 2785874 /lib/tls/i686/cmov/libnsl-2.7.so +b7c1f000-b7c21000 rwxp 00013000 08:02 2785874 /lib/tls/i686/cmov/libnsl-2.7.so +b7c21000-b7c23000 rwxp b7c21000 00:00 0 +b7c23000-b7c24000 r--s 00000000 00:11 751021 /var/run/pcscd/pcscd.pub +b7c24000-b7c25000 r-xs 00000000 08:02 3556750 /var/cache/fontconfig/4c599c202bc5c08e2d34565a40eac3b2-x86.cache-2 +b7c25000-b7c26000 r-xs 00000000 08:02 3556750 /var/cache/fontconfig/4c599c202bc5c08e2d34565a40eac3b2-x86.cache-2 +b7c26000-b7c31000 r-xp 00000000 08:02 1085433 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/libverify.so +b7c31000-b7c32000 rwxp 0000b000 08:02 1085433 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/libverify.so +b7c32000-b7c3a000 rwxs 00000000 08:02 1328188 /tmp/hsperfdata_clemens/32072 +b7c3a000-b7c41000 r-xp 00000000 08:02 2786023 /lib/tls/i686/cmov/librt-2.7.so +b7c41000-b7c43000 rwxp 00006000 08:02 2786023 /lib/tls/i686/cmov/librt-2.7.so +b7c43000-b7c46000 ---p b7c43000 00:00 0 +b7c46000-b7c94000 rwxp b7c46000 00:00 0 +b7c94000-b7cb7000 r-xp 00000000 08:02 2785871 /lib/tls/i686/cmov/libm-2.7.so +b7cb7000-b7cb9000 rwxp 00023000 08:02 2785871 /lib/tls/i686/cmov/libm-2.7.so +b7cb9000-b7cba000 rwxp b7cb9000 00:00 0 +b7cba000-b7cbe000 r-xp 00000000 08:02 905230 /usr/lib/libXdmcp.so.6.0.0 +b7cbe000-b7cbf000 rwxp 00003000 08:02 905230 /usr/lib/libXdmcp.so.6.0.0 +b7cbf000-b7cc1000 r-xp 00000000 08:02 901311 /usr/lib/libXau.so.6.0.0 +b7cc1000-b7cc2000 rwxp 00001000 08:02 901311 /usr/lib/libXau.so.6.0.0 +b7cc2000-b7cd9000 r-xp 00000000 08:02 901194 /usr/lib/libxcb.so.1.0.0 +b7cd9000-b7cda000 rwxp 00016000 08:02 901194 /usr/lib/libxcb.so.1.0.0 +b7cda000-b7cdb000 rwxp b7cda000 00:00 0 +b7cdb000-b7cdc000 r-xp 00000000 08:02 901196 /usr/lib/libxcb-xlib.so.0.0.0 +b7cdc000-b7cdd000 rwxp 00000000 08:02 901196 /usr/lib/libxcb-xlib.so.0.0.0 +b7cdd000-b7e26000 r-xp 00000000 08:02 2785863 /lib/tls/i686/cmov/libc-2.7.so +b7e26000-b7e27000 r-xp 00149000 08:02 2785863 /lib/tls/i686/cmov/libc-2.7.so +b7e27000-b7e29000 rwxp 0014a000 08:02 2785863 /lib/tls/i686/cmov/libc-2.7.so +b7e29000-b7e2c000 rwxp b7e29000 00:00 0 +b7e2c000-b7e2e000 r-xp 00000000 08:02 2785869 /lib/tls/i686/cmov/libdl-2.7.so +b7e2e000-b7e30000 rwxp 00001000 08:02 2785869 /lib/tls/i686/cmov/libdl-2.7.so +b7e30000-b7e37000 r-xp 00000000 08:02 1085436 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/jli/libjli.so +b7e37000-b7e39000 rwxp 00006000 08:02 1085436 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/jli/libjli.so +b7e39000-b7f1d000 r-xp 00000000 08:02 901308 /usr/lib/libX11.so.6.2.0 +b7f1d000-b7f20000 rwxp 000e4000 08:02 901308 /usr/lib/libX11.so.6.2.0 +b7f20000-b7f21000 rwxp b7f20000 00:00 0 +b7f21000-b7f35000 r-xp 00000000 08:02 2786020 /lib/tls/i686/cmov/libpthread-2.7.so +b7f35000-b7f37000 rwxp 00013000 08:02 2786020 /lib/tls/i686/cmov/libpthread-2.7.so +b7f37000-b7f3e000 rwxp b7f37000 00:00 0 +b7f3e000-b7f45000 r-xp 00000000 08:02 2785875 /lib/tls/i686/cmov/libnss_compat-2.7.so +b7f45000-b7f47000 rwxp 00006000 08:02 2785875 /lib/tls/i686/cmov/libnss_compat-2.7.so +b7f47000-b7f4d000 r-xp 00000000 08:02 1085422 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/native_threads/libhpi.so +b7f4d000-b7f4e000 rwxp 00006000 08:02 1085422 /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/native_threads/libhpi.so +b7f4e000-b7f4f000 rwxp b7f4e000 00:00 0 +b7f4f000-b7f50000 r-xp b7f4f000 00:00 0 +b7f50000-b7f52000 rwxp b7f50000 00:00 0 +b7f52000-b7f53000 r-xp b7f52000 00:00 0 [vdso] +b7f53000-b7f6d000 r-xp 00000000 08:02 2786582 /lib/ld-2.7.so +b7f6d000-b7f6f000 rwxp 00019000 08:02 2786582 /lib/ld-2.7.so +bfaac000-bfac1000 rwxp bffeb000 00:00 0 [stack] + +VM Arguments: +jvm_args: -Dapplication.home=/usr/lib/jvm/java-6-sun-1.6.0.06 +java_command: sun.applet.Main target/test-classes/appletTest.html +Launcher Type: SUN_STANDARD + +Environment Variables: +JAVA_HOME=/usr/lib/jvm/java-6-sun +PATH=/home/clemens/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games +LD_LIBRARY_PATH=/usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386/client:/usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/i386:/usr/lib/jvm/java-6-sun-1.6.0.06/jre/../lib/i386 +SHELL=/bin/bash +DISPLAY=:0 + +Signal Handlers: +SIGSEGV: [libjvm.so+0x3be710], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGBUS: [libjvm.so+0x3be710], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGFPE: [libjvm.so+0x30f810], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGPIPE: [libjvm.so+0x30f810], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGXFSZ: [libjvm.so+0x30f810], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGILL: [libjvm.so+0x30f810], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGUSR1: SIG_DFL, sa_mask[0]=0x00000000, sa_flags=0x00000000 +SIGUSR2: [libjvm.so+0x311850], sa_mask[0]=0x00000000, sa_flags=0x10000004 +SIGHUP: [libjvm.so+0x3115f0], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGINT: [libjvm.so+0x3115f0], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGTERM: [libjvm.so+0x3115f0], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 +SIGQUIT: [libjvm.so+0x3115f0], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004 + + +--------------- S Y S T E M --------------- + +OS:lenny/sid + +uname:Linux 2.6.24-19-generic #1 SMP Fri Jul 11 23:41:49 UTC 2008 i686 +libc:glibc 2.7 NPTL 2.7 +rlimit: STACK 8192k, CORE 0k, NPROC 16381, NOFILE 1024, AS infinity +load average:0.84 0.39 0.22 + +CPU:total 2 (1 cores per cpu, 2 threads per core) family 15 model 4 stepping 3, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ht + +Memory: 4k page, physical 2075432k(62584k free), swap 1542200k(1502244k free) + +vm_info: Java HotSpot(TM) Client VM (10.0-b22) for linux-x86 JRE (1.6.0_06-b02), built on Mar 25 2008 00:39:19 by "java_re" with gcc 3.2.1-7a (J2SE release) + +time: Thu Oct 9 12:01:31 2008 +elapsed time: 55 seconds + diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 34dd9bbd..6a781729 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -16,9 +16,12 @@ */ package at.gv.egiz.bku.online.applet; +import java.net.MalformedURLException; import java.util.Locale; import java.util.ResourceBundle; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.net.ssl.HttpsURLConnection; import javax.swing.JApplet; @@ -27,6 +30,7 @@ import org.apache.commons.logging.LogFactory; import at.gv.egiz.bku.gui.BKUGUIFacade; import at.gv.egiz.bku.gui.BKUGUIFactory; +import java.net.URL; /** * Note: all swing code is executed by the event dispatch thread (see @@ -40,6 +44,8 @@ public class BKUApplet extends JApplet { public final static String LOGO_URL_KEY = "LogoURL"; public final static String WSDL_URL = "WSDL_URL"; public final static String SESSION_ID = "SessionID"; + public static final String BACKGROUND_PARAM = "background"; + protected ResourceBundle resourceBundle; protected BKUWorker worker; protected Thread workerThread; @@ -58,8 +64,17 @@ public class BKUApplet extends JApplet { } else { resourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE); } + String backgroundString = getMyAppletParameter(BACKGROUND_PARAM); + URL background = null; + if (backgroundString != null) { + try { + background = new URL(backgroundString); + } catch (MalformedURLException ex) { + log.warn(ex.getMessage() + ", using default background"); + } + } BKUGUIFacade gui = BKUGUIFactory.createGUI(); - gui.init(getContentPane(), localeString); + gui.init(getContentPane(), localeString, background); worker = new BKUWorker(gui, this, resourceBundle); } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index 636a9fef..53ec1088 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -36,6 +36,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.net.URL; import java.text.MessageFormat; import java.util.List; import java.util.Locale; @@ -127,7 +128,7 @@ public class BKUGUI implements BKUGUIFacade { * @param localeString may be null */ @Override - public void init(final Container contentPane, String localeString) { + public void init(final Container contentPane, String localeString, final URL background) { if (localeString != null) { messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, new Locale(localeString)); @@ -149,7 +150,7 @@ public class BKUGUI implements BKUGUIFacade { log.debug("initializing gui"); // initIconPanel(); - initContentPanel(); + initContentPanel(background); GroupLayout layout = new GroupLayout(contentPane); contentPane.setLayout(layout); @@ -189,7 +190,7 @@ public class BKUGUI implements BKUGUIFacade { // .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); // } - protected void initContentPanel() { + protected void initContentPanel(URL background) { contentPanel = new JPanel(); 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 32eb4c3e..4925e7fa 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 @@ -20,6 +20,7 @@ import at.gv.egiz.stal.HashDataInput; import at.gv.egiz.smcc.PINSpec; import java.awt.Container; import java.awt.event.ActionListener; +import java.net.URL; import java.util.List; public interface BKUGUIFacade { @@ -32,7 +33,7 @@ public interface BKUGUIFacade { public static final String ERR_WRITE_HASHDATA = "error.write.hashdata"; public static final String ERR_INVALID_HASH = "error.invalid.hash"; - public void init(Container contentPane, String localeString); + public void init(Container contentPane, String localeString, URL background); public void showWelcomeDialog(); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ImagePanel.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ImagePanel.java new file mode 100644 index 00000000..e9c270ce --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ImagePanel.java @@ -0,0 +1,37 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package at.gv.egiz.bku.gui; + +import java.awt.Graphics; +import java.awt.Image; +import java.net.URL; +import javax.swing.ImageIcon; +import javax.swing.JPanel; + +/** + * + * @author clemens + */ +public class ImagePanel extends JPanel { + + protected Image backgroundImg; + + public ImagePanel(URL background) { + this(new ImageIcon(background).getImage()); + } + + public ImagePanel(Image img) { + this.backgroundImg = img; + this.setOpaque(false); + } + + @Override + public void paintComponent(Graphics g) { + super.paintComponent(g); + g.drawImage(backgroundImg, 0, this.getHeight() - backgroundImg.getHeight(null), null); + } + +} 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 b7d86d05..8e32d67e 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 @@ -36,6 +36,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.net.URL; import java.text.MessageFormat; import java.util.List; import java.util.Locale; @@ -53,6 +54,7 @@ import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.LayoutStyle; import javax.swing.SwingUtilities; +import javax.swing.border.TitledBorder; import javax.swing.table.TableColumn; import javax.swing.table.TableModel; import org.apache.commons.logging.Log; @@ -66,7 +68,7 @@ public class SimpleGUI implements BKUGUIFacade { private static final Log log = LogFactory.getLog(SimpleGUI.class); public static final String MESSAGES_BUNDLE = "at/gv/egiz/bku/gui/Messages"; - public static final String LOGO_RESOURCE = "/images/logo.png"; + public static final String DEFAULT_BACKGROUND = "/images/mocca_default.png"; //logo.png"; public static final String HASHDATA_FONT = "Monospaced"; public static final Color ERROR_COLOR = Color.RED; public static final Color HYPERLINK_COLOR = Color.BLUE; @@ -121,13 +123,13 @@ public class SimpleGUI implements BKUGUIFacade { protected int buttonSize; private static final int CHECKBOX_WIDTH = new JCheckBox().getPreferredSize().width; - + /** * @param contentPane * @param localeString may be null */ @Override - public void init(final Container contentPane, String localeString) { + public void init(final Container contentPane, String localeString, final URL background) { if (localeString != null) { messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, new Locale(localeString)); @@ -149,7 +151,7 @@ public class SimpleGUI implements BKUGUIFacade { log.debug("initializing gui"); // initIconPanel(); - initContentPanel(); + initContentPanel(background); GroupLayout layout = new GroupLayout(contentPane); contentPane.setLayout(layout); @@ -189,13 +191,20 @@ public class SimpleGUI implements BKUGUIFacade { // .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); // } - protected void initContentPanel() { + protected void initContentPanel(URL background) { - contentPanel = new JPanel(); + if (background == null) { + background = this.getClass().getResource(DEFAULT_BACKGROUND); + } + contentPanel = new ImagePanel(background); +// contentPanel.setBorder(new TitledBorder("content")); + // headerPanel = new JPanel(); mainPanel = new JPanel(); - buttonPanel = new JPanel(); + mainPanel.setOpaque(false); + buttonPanel = new JPanel(); // new ImagePanel(LOGO_RESOURCE); //new JPanel(); + buttonPanel.setOpaque(false); // headerPanel.setBorder(new TitledBorder("header")); // mainPanel.setBorder(new TitledBorder("main")); @@ -487,13 +496,14 @@ public class SimpleGUI implements BKUGUIFacade { // cancelButton.addActionListener(cancelListener); JButton okButton = new JButton(); + okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); okButton.setText(messages.getString(BUTTON_OK)); okButton.setEnabled(false); okButton.setActionCommand(okCommand); okButton.addActionListener(okListener); JLabel cardPinLabel = new JLabel(); - cardPinLabel.setFont(cardPinLabel.getFont().deriveFont(cardPinLabel.getFont().getStyle() | java.awt.Font.BOLD)); + cardPinLabel.setFont(cardPinLabel.getFont().deriveFont(cardPinLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); String pinLabel = messages.getString(LABEL_PIN); cardPinLabel.setText(MessageFormat.format(pinLabel, new Object[]{pinSpec.getLocalizedName()})); @@ -513,8 +523,8 @@ public class SimpleGUI implements BKUGUIFacade { }); JLabel infoLabel = new JLabel(); + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD, infoLabel.getFont().getSize()-2)); if (numRetries < 0) { - infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); String pinsizePattern = messages.getString(LABEL_PINSIZE); String pinSize = String.valueOf(pinSpec.getMinLength()); if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { @@ -658,13 +668,14 @@ public class SimpleGUI implements BKUGUIFacade { // cancelButton.addActionListener(cancelListener); JButton signButton = new JButton(); + signButton.setFont(signButton.getFont().deriveFont(signButton.getFont().getStyle() & ~java.awt.Font.BOLD)); signButton.setText(messages.getString(BUTTON_SIGN)); signButton.setEnabled(false); signButton.setActionCommand(signCommand); signButton.addActionListener(signListener); JLabel signPinLabel = new JLabel(); - signPinLabel.setFont(signPinLabel.getFont().deriveFont(signPinLabel.getFont().getStyle() | java.awt.Font.BOLD)); + signPinLabel.setFont(signPinLabel.getFont().deriveFont(signPinLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); String pinLabel = messages.getString(LABEL_PIN); signPinLabel.setText(MessageFormat.format(pinLabel, new Object[]{pinSpec.getLocalizedName()})); @@ -684,7 +695,7 @@ public class SimpleGUI implements BKUGUIFacade { //pinsize or error label JLabel infoLabel = new JLabel(); - infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD, infoLabel.getFont().getSize()-2)); if (numRetries < 0) { String pinsizePattern = messages.getString(LABEL_PINSIZE); String pinSize = String.valueOf(pinSpec.getMinLength()); @@ -721,7 +732,7 @@ public class SimpleGUI implements BKUGUIFacade { .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) // .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(infoLabel)); mainPanelLayout.setVerticalGroup( @@ -847,6 +858,7 @@ public class SimpleGUI implements BKUGUIFacade { .addComponent(errorMsgLabel)); JButton okButton = new JButton(); + okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); okButton.setText(messages.getString(BUTTON_OK)); okButton.setActionCommand(okCommand); okButton.addActionListener(okListener); @@ -1062,6 +1074,7 @@ public class SimpleGUI implements BKUGUIFacade { // mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(mainPanelLayout.createSequentialGroup().addComponent(refIdLabel).addGap(refIdLabel.getFont().getSize()).addComponent(hashDataScrollPane).addGap(refIdLabel.getFont().getSize()))); JButton backButton = new JButton(); + backButton.setFont(backButton.getFont().deriveFont(backButton.getFont().getStyle() & ~java.awt.Font.BOLD)); backButton.setText(messages.getString(BUTTON_BACK)); backButton.setActionCommand(cancelCommand); backButton.addActionListener(cancelListener); @@ -1215,6 +1228,7 @@ public class SimpleGUI implements BKUGUIFacade { JButton backButton = new JButton(); + backButton.setFont(backButton.getFont().deriveFont(backButton.getFont().getStyle() & ~java.awt.Font.BOLD)); backButton.setText(messages.getString(BUTTON_BACK)); backButton.setActionCommand(cancelCommand); backButton.addActionListener(cancelListener); 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 a2b5e0df..abed420f 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 @@ -34,7 +34,7 @@ message.hashdatalist={0} Signaturdatenobjekte: message.retries=Noch {0} Versuch(e) message.overwrite=M\u00F6chten Sie das existierende Dokument {0} \u00FCberschreiben? label.pin={0}: -label.pinsize=({0} stellig) +label.pinsize={0} stellig button.ok=OK button.cancel=Abbrechen button.back=Zur\u00FCck diff --git a/BKUCommonGUI/src/main/resources/images/mocca.png b/BKUCommonGUI/src/main/resources/images/mocca.png new file mode 100644 index 00000000..881a65c1 Binary files /dev/null and b/BKUCommonGUI/src/main/resources/images/mocca.png differ diff --git a/BKUCommonGUI/src/main/resources/images/mocca_default.png b/BKUCommonGUI/src/main/resources/images/mocca_default.png new file mode 100644 index 00000000..349d9ff0 Binary files /dev/null and b/BKUCommonGUI/src/main/resources/images/mocca_default.png differ diff --git a/BKUCommonGUI/src/main/resources/images/mocca_tiny.png b/BKUCommonGUI/src/main/resources/images/mocca_tiny.png new file mode 100644 index 00000000..1f125d9b Binary files /dev/null and b/BKUCommonGUI/src/main/resources/images/mocca_tiny.png differ diff --git a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java index 5f1bc8b2..308be642 100644 --- a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java +++ b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java @@ -40,7 +40,7 @@ public class BKUGUITest { BKUGUI gui = new BKUGUI(); Container contentPane = testFrame.getContentPane(); contentPane.setPreferredSize(new Dimension(380, 150)); - gui.init(contentPane, null); + gui.init(contentPane, null, null); BKUGUIWorker worker = new BKUGUIWorker(); worker.init(gui); testFrame.pack(); diff --git a/BKUOnline/src/main/webapp/META-INF/context.xml b/BKUOnline/src/main/webapp/META-INF/context.xml index 3568c9ec..cd11ce8e 100644 --- a/BKUOnline/src/main/webapp/META-INF/context.xml +++ b/BKUOnline/src/main/webapp/META-INF/context.xml @@ -16,3 +16,4 @@ limitations under the License. --> + diff --git a/BKUOnline/src/main/webapp/appletPage.jsp b/BKUOnline/src/main/webapp/appletPage.jsp index 59dc2ad5..11f46dca 100644 --- a/BKUOnline/src/main/webapp/appletPage.jsp +++ b/BKUOnline/src/main/webapp/appletPage.jsp @@ -42,7 +42,7 @@ height :<%= height %> }; var parameters = { - background : <%= backgroundImg %>, + background : '<%= backgroundImg %>', WSDL_URL :'../stal?wsdl', SessionID : '<%= session.getId() %>', redirectURL : '../bkuResult' diff --git a/BKUOnline/src/main/webapp/index.html b/BKUOnline/src/main/webapp/index.html index bf8b3ae0..8f1a338e 100644 --- a/BKUOnline/src/main/webapp/index.html +++ b/BKUOnline/src/main/webapp/index.html @@ -49,8 +49,6 @@

TestRequest

Security Layer Request -

FinanzOnline

-FinanzOnline Demo Integration

STAL Service

STAL Service Endpoint Information

-- cgit v1.2.3 From 8479ef50c84e8998f7909074df6a23c2ff0aa5b0 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 31 Oct 2008 12:33:18 +0000 Subject: Help Icon git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@132 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUApplet/nb-configuration.xml | 6 ++++++ .../applet/ExternalDisplaySignRequestHandler.java | 16 ++++++++++++++-- .../gv/egiz/bku/online/applet/ExternalHelpListener.java | 17 +++++++++++++++-- .../bku/online/applet/InternalSSLSocketFactory.java | 4 ---- .../bku/online/applet/WebServiceSignRequestHandler.java | 1 + .../src/main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 1 + .../src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java | 1 + .../java/at/gv/egiz/bku/gui/HashDataTableModel.java | 1 + .../main/java/at/gv/egiz/bku/gui/HelpMouseListener.java | 17 +++++++++++++++++ .../src/main/java/at/gv/egiz/bku/gui/ImagePanel.java | 16 ++++++++++++++-- .../src/main/java/at/gv/egiz/bku/gui/SimpleGUI.java | 5 +---- .../src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java | 2 +- .../java/at/gv/egiz/bku/local/stal/BKUGuiProxy.java | 4 ++-- .../java/at/gv/egiz/bku/local/stal/SMCCSTALFactory.java | 2 +- 14 files changed, 75 insertions(+), 18 deletions(-) create mode 100644 BKUApplet/nb-configuration.xml (limited to 'BKUCommonGUI/src/test/java') diff --git a/BKUApplet/nb-configuration.xml b/BKUApplet/nb-configuration.xml new file mode 100644 index 00000000..352a03be --- /dev/null +++ b/BKUApplet/nb-configuration.xml @@ -0,0 +1,6 @@ + + + + bka + + diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalDisplaySignRequestHandler.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalDisplaySignRequestHandler.java index 2ac1bc62..2c9fde71 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalDisplaySignRequestHandler.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalDisplaySignRequestHandler.java @@ -1,6 +1,18 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package at.gv.egiz.bku.online.applet; diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalHelpListener.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalHelpListener.java index 4d6d5851..f92a6963 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalHelpListener.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/ExternalHelpListener.java @@ -1,7 +1,20 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + package at.gv.egiz.bku.online.applet; import java.applet.AppletContext; diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java index fa3587e4..c3417d63 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/InternalSSLSocketFactory.java @@ -14,10 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ package at.gv.egiz.bku.online.applet; diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java index b417fd33..ddbe76bf 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/WebServiceSignRequestHandler.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package at.gv.egiz.bku.online.applet; import java.security.DigestException; 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 6c157e76..872f1874 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 @@ -14,6 +14,7 @@ * 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; diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java index 4a338f23..87676026 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package at.gv.egiz.bku.gui; public class BKUGUIFactory { 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 1a833f48..aea85523 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 @@ -14,6 +14,7 @@ * 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; diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpMouseListener.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpMouseListener.java index 6d814f01..531884d1 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpMouseListener.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HelpMouseListener.java @@ -1,3 +1,20 @@ +/* + * 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; diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ImagePanel.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ImagePanel.java index e9c270ce..1185cf53 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ImagePanel.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/ImagePanel.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.gui; 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 29913d2a..195db27a 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 @@ -14,10 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ + package at.gv.egiz.bku.gui; import at.gv.egiz.smcc.PINSpec; diff --git a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java index 308be642..c32a237a 100644 --- a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java +++ b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java @@ -40,7 +40,7 @@ public class BKUGUITest { BKUGUI gui = new BKUGUI(); Container contentPane = testFrame.getContentPane(); contentPane.setPreferredSize(new Dimension(380, 150)); - gui.init(contentPane, null, null); + gui.init(contentPane, null, null, null); BKUGUIWorker worker = new BKUGUIWorker(); worker.init(gui); testFrame.pack(); 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 d12be9ac..8a850549 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 @@ -37,8 +37,8 @@ public class BKUGuiProxy implements BKUGUIFacade { } @Override - public void init(Container contentPane, String localeString, URL bgImage) { - delegate.init(contentPane, localeString, bgImage); + public void init(Container contentPane, String localeString, URL bgImage, ActionListener helpListener) { + delegate.init(contentPane, localeString, bgImage, helpListener); } @Override 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 e1d434e3..df5c2b28 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 @@ -48,7 +48,7 @@ public class SMCCSTALFactory implements STALFactory { } dialog = new JDialog(); BKUGUIFacade gui = BKUGUIFactory.createGUI(BKUGUIFactory.ADVANCED_GUI); - gui.init(dialog.getContentPane(), locale.toString(), null); + gui.init(dialog.getContentPane(), locale.toString(), null, null); stal = new SMCCSTAL(new BKUGuiProxy(dialog, gui), dialog, resourceBundle); dialog.setPreferredSize(new Dimension(400, 200)); dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); -- 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/test/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 28e81afd92a6568ff78736b72c5257a86c0b9b91 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 18 Nov 2008 08:03:35 +0000 Subject: GUI refactoring 1 git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@177 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/online/applet/AppletBKUWorker.java | 13 +- .../bku/online/applet/AppletHashDataDisplay.java | 24 +- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 6 +- BKUApplet/src/test/resources/appletTest.html | 3 +- .../src/main/java/at/gv/egiz/bku/gui/BKUGUI.java | 6 +- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 6 +- .../java/at/gv/egiz/bku/gui/BKUGUIFactory.java | 25 +- .../at/gv/egiz/bku/gui/DefaultHelpListener.java | 37 +- .../java/at/gv/egiz/bku/gui/HashDataViewer.java | 6 - .../main/java/at/gv/egiz/bku/gui/HelpViewer.java | 2 +- .../main/java/at/gv/egiz/bku/gui/SimpleGUI.java | 1165 +++++++++++--------- .../at/gv/egiz/bku/gui/Messages.properties | 2 +- .../at/gv/egiz/bku/gui/Messages_en.properties | 2 +- .../test/java/at/gv/egiz/bku/gui/BKUGUITest.java | 5 +- .../test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java | 110 +- .../at/gv/egiz/bku/local/stal/BKUGuiProxy.java | 12 +- .../bku/local/stal/LocalSignRequestHandler.java | 2 +- .../at/gv/egiz/bku/local/stal/SMCCSTALFactory.java | 7 +- BKUOnline/src/main/webapp/HTTP-ohne.html | 2 +- .../gv/egiz/bku/smccstal/SignRequestHandler.java | 81 -- 20 files changed, 793 insertions(+), 723 deletions(-) (limited to 'BKUCommonGUI/src/test/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 f862360b..b2f9f89c 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java @@ -192,18 +192,19 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { private void registerSignRequestHandler() throws MalformedURLException { String hashDataDisplayStyle = params.getAppletParameter(BKUApplet.HASHDATA_DISPLAY); - if (BKUApplet.HASHDATA_DISPLAY_INTERNAL.equals(hashDataDisplayStyle)) { - log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); - AppletHashDataDisplay handler = new AppletHashDataDisplay(stalPort, sessionId, AppletHashDataDisplay.DISPLAY.applet); - addRequestHandler(SignRequest.class, handler); - } else if (BKUApplet.HASHDATA_DISPLAY_BROWSER.equals(hashDataDisplayStyle)) { +// if (BKUApplet.HASHDATA_DISPLAY_INTERNAL.equals(hashDataDisplayStyle)) { +// log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); +// AppletHashDataDisplay handler = new AppletHashDataDisplay(stalPort, sessionId, AppletHashDataDisplay.DISPLAY.applet); +// addRequestHandler(SignRequest.class, handler); +// } else + if (BKUApplet.HASHDATA_DISPLAY_BROWSER.equals(hashDataDisplayStyle)) { URL hashDataURL = params.getURLParameter(BKUApplet.HASHDATA_URL, sessionId); log.debug("register SignRequestHandler for HashDataURL " + hashDataURL); addRequestHandler(SignRequest.class, new BrowserHashDataDisplay(ctx, hashDataURL)); } else { //BKUApplet.HASHDATA_DISPLAY_FRAME log.debug("register SignRequestHandler for STAL port " + BKUApplet.WSDL_URL); - AppletHashDataDisplay handler = new AppletHashDataDisplay(stalPort, sessionId, AppletHashDataDisplay.DISPLAY.frame); + AppletHashDataDisplay handler = new AppletHashDataDisplay(stalPort, sessionId); addRequestHandler(SignRequest.class, handler); } } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java index 29a60f1d..ba502906 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java @@ -50,33 +50,32 @@ import java.security.NoSuchAlgorithmException; */ public class AppletHashDataDisplay extends SignRequestHandler { - public static enum DISPLAY { - applet, frame - } private static final Log log = LogFactory.getLog(AppletHashDataDisplay.class); protected STALPortType stalPort; protected String sessId; - protected DISPLAY display; - public AppletHashDataDisplay(STALPortType stalPort, String sessId, DISPLAY display) { + public AppletHashDataDisplay(STALPortType stalPort, String sessId) { if (stalPort == null || sessId == null) { throw new NullPointerException("STAL port must not be null"); } this.sessId = sessId; this.stalPort = stalPort; - this.display = display; } + /** + * TODO don't throw exceptions + * @param signedReferences + * @throws java.security.DigestException + * @throws java.lang.Exception + */ @Override public void displayHashDataInputs(List signedReferences) throws DigestException, Exception { List hdi = getHashDataInput(signedReferences); List verifiedHashDataInputs = verifyHashDataInput(signedReferences, hdi); - if (verifiedHashDataInputs.size() > 1) { - gui.showHashDataInputDialog(verifiedHashDataInputs, false, this, "ok"); - } else if (verifiedHashDataInputs.size() == 1) { - gui.showHashDataInputDialog(verifiedHashDataInputs, display==DISPLAY.frame, this, "ok"); + if (verifiedHashDataInputs.size() > 0) { + gui.showHashDataInputDialog(verifiedHashDataInputs, this, "ok"); } else { throw new Exception("No signature data (apart from any QualifyingProperties or a Manifest)"); } @@ -111,6 +110,11 @@ public class AppletHashDataDisplay extends SignRequestHandler { } } } + + if (request.getReference().size() < 1) { + log.error("No signature data (apart from any QualifyingProperties or a Manifest) for session " + sessId); + throw new Exception("No signature data (apart from any QualifyingProperties or a Manifest)"); + } if (log.isDebugEnabled()) { log.debug("WebService call GetHashDataInput for " + request.getReference().size() + " references in session " + sessId); diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 7963768e..5b45c8e1 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -53,7 +53,7 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { public static final String BACKGROUND_PARAM = "Background"; public static final String REDIRECT_URL = "RedirectURL"; public static final String REDIRECT_TARGET = "RedirectTarget"; - public static final String HASHDATA_DISPLAY_INTERNAL = "internal"; +// public static final String HASHDATA_DISPLAY_INTERNAL = "internal"; public static final String HASHDATA_DISPLAY_BROWSER = "browser"; public static final String HASHDATA_DISPLAY_FRAME = "frame"; @@ -106,8 +106,8 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { } log.debug("setting locale to " + getLocale()); - BKUGUIFacade gui = BKUGUIFactory.createGUI(guiStyle); - gui.init(getContentPane(), getLocale(), backgroundImgURL, helpListener); + BKUGUIFacade gui = BKUGUIFactory.createGUI(getContentPane(), getLocale(), guiStyle, backgroundImgURL, helpListener); +// gui.init(getContentPane(), getLocale(), BKUGUIFacade.Style.advanced, backgroundImgURL, helpListener); worker = new AppletBKUWorker(gui, getAppletContext(), this); } diff --git a/BKUApplet/src/test/resources/appletTest.html b/BKUApplet/src/test/resources/appletTest.html index eaf6376d..8204d0eb 100644 --- a/BKUApplet/src/test/resources/appletTest.html +++ b/BKUApplet/src/test/resources/appletTest.html @@ -21,7 +21,8 @@ archive="../BKUApplet-1.0-SNAPSHOT.jar, ../test-libs/commons-logging-1.1.1.jar , ../test-libs/iaik_jce_me4se-3.04.jar" width=300 height=200> - + + diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java index d661c71a..f68f2ece 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUI.java @@ -87,8 +87,8 @@ public class BKUGUI implements BKUGUIFacade { * @param contentPane * @param localeString may be null */ - @Override - public void init(final Container contentPane, Locale locale, final URL background, ActionListener helpListener) { +// @Override + public void init(final Container contentPane, Locale locale, Style guiStyle, final URL background, ActionListener helpListener) { if (locale != null) { messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, locale); @@ -814,7 +814,7 @@ public class BKUGUI implements BKUGUIFacade { } @Override - public void showHashDataInputDialog(final List signedReferences, boolean standalone, final ActionListener okListener, final String okCommand) { + public void showHashDataInputDialog(final List signedReferences, final ActionListener okListener, final String okCommand) { if (signedReferences == null) { showErrorDialog(messages.getString(ERR_NO_HASHDATA), new Object[] {"No SignedReferences provided"}, okListener, okCommand); 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 87982c79..2dbba730 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 @@ -91,7 +91,9 @@ public interface BKUGUIFacade { public static final String SAVE_HASHDATAINPUT_PREFIX = "save.hashdatainput.prefix"; public static final String ALT_HELP = "alt.help"; - public void init(Container contentPane, Locale locale, URL background, ActionListener helpListener); + public enum Style { simple, advanced }; + +// public void init(Container contentPane, Locale locale, Style guiStyle, URL background, ActionListener helpListener); /** * @@ -128,7 +130,7 @@ public interface BKUGUIFacade { * @param okListener * @param okCommand */ - public void showHashDataInputDialog(List signedReferences, boolean externalDisplay, ActionListener okListener, String okCommand); + public void showHashDataInputDialog(List signedReferences, ActionListener okListener, String okCommand); /** * TODO pull out from BKUGUIFacade. (or make this strictly an applet internal version) diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java index 87676026..f4981614 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java @@ -17,24 +17,29 @@ package at.gv.egiz.bku.gui; +import java.awt.Container; +import java.awt.event.ActionListener; +import java.net.URL; +import java.util.Locale; + public class BKUGUIFactory { public static final String SIMPLE_GUI = "simple"; public static final String ADVANCED_GUI = "advanced"; - private static BKUGUIFactory instance = new BKUGUIFactory(); +// private static BKUGUIFactory instance = new BKUGUIFactory(); - private BKUGUIFactory() { - } +// private BKUGUIFactory() { +// } +// +// protected BKUGUIFacade createNewGUI(Container contentPane, Locale locale, String style, URL background, ActionListener helpListener) { +// +// } - protected BKUGUIFacade createNewGUI(String style) { + public static BKUGUIFacade createGUI(Container contentPane, Locale locale, String style, URL background, ActionListener helpListener) { if (ADVANCED_GUI.equals(style)) { - return new BKUGUI(); + return new SimpleGUI(contentPane, locale, BKUGUIFacade.Style.advanced, background, helpListener); } - return new SimpleGUI(); - } - - public static BKUGUIFacade createGUI(String style) { - return instance.createNewGUI(style); + return new SimpleGUI(contentPane, locale, BKUGUIFacade.Style.simple, background, helpListener); } } 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 ba968a48..f03bf158 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 @@ -17,6 +17,7 @@ package at.gv.egiz.bku.gui; import java.applet.AppletContext; +import java.lang.reflect.InvocationTargetException; import java.net.URL; import java.util.Locale; import javax.swing.SwingUtilities; @@ -29,34 +30,56 @@ public class DefaultHelpListener extends AbstractHelpListener { protected AppletContext ctx; + /** + * + * @param ctx open external links via applet context + * @param helpURL + * @param locale + */ public DefaultHelpListener(AppletContext ctx, URL helpURL, Locale locale) { super(helpURL, locale); this.ctx = ctx; } + /** + * external links in help document are not opened + * @param helpURL + * @param locale + */ public DefaultHelpListener(URL helpURL, Locale locale) { super(helpURL, locale); this.ctx = null; } + /** + * blocks until help viewer returns (is closed) + * @param helpURL + * @param helpTopic + */ @Override - public void showDocument(final URL helpURL, final String helpTopic) throws Exception { - log.debug("schedule help dialog"); - - SwingUtilities.invokeLater(new Runnable() { + public void showDocument(final URL helpURL, final String helpTopic) { +// try { + log.debug("schedule help dialog"); + +// SwingUtilities.invokeAndWait(new Runnable() { + SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - + log.debug("show help dialog"); - + if (ctx == null) { HelpViewer.showHelpDialog(helpURL, helpTopic, messages); - } else { HelpViewer.showHelpDialog(ctx, helpURL, helpTopic, messages); } } }); +// } catch (InterruptedException ex) { +// log.error("Failed to display HelpViewer: " + ex.getMessage(), ex); +// } catch (InvocationTargetException ex) { +// log.error("Failed to display HelpViewer: " + ex.getMessage(), ex); +// } } } 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 index 31887bde..7b77faeb 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java @@ -16,7 +16,6 @@ */ package at.gv.egiz.bku.gui; -import at.gv.egiz.bku.gui.html.RestrictedHTMLEditorKit; import at.gv.egiz.stal.HashDataInput; import java.awt.Component; import java.awt.Container; @@ -49,11 +48,6 @@ import javax.swing.JScrollPane; import javax.swing.LayoutStyle; import javax.swing.text.Document; import javax.swing.text.EditorKit; -import javax.swing.text.Element; -import javax.swing.text.ViewFactory; -import javax.swing.text.html.HTML; -import javax.swing.text.html.HTMLEditorKit; -import javax.swing.text.html.ImageView; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; 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 173254e7..0fef3f75 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 @@ -105,7 +105,7 @@ public class HelpViewer extends JDialog JPanel helpPanel = createViewerPanel(viewerLabel, helpURL); JPanel buttonPanel = createButtonPanel(); - initContentPane(new Dimension(600, 400), helpPanel, buttonPanel); + initContentPane(new Dimension(600, 600), helpPanel, buttonPanel); pack(); if (frame != null) { setLocationRelativeTo(frame); 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 bb568b75..d4d6efef 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 @@ -32,6 +32,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; import java.net.URL; import java.text.MessageFormat; import java.util.List; @@ -40,7 +41,6 @@ import java.util.ResourceBundle; import javax.swing.GroupLayout; import javax.swing.ImageIcon; import javax.swing.JButton; -import javax.swing.JCheckBox; import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JOptionPane; @@ -51,7 +51,6 @@ import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.LayoutStyle; import javax.swing.SwingUtilities; -import javax.swing.table.TableColumn; import javax.swing.table.TableModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -69,38 +68,60 @@ public class SimpleGUI implements BKUGUIFacade { protected Container contentPane; protected ResourceBundle messages; /** left and right side main panels */ -// protected JPanel iconPanel; + protected JPanel iconPanel; protected JPanel contentPanel; /** right side content panels and layouts */ -// protected JPanel headerPanel; + protected JPanel headerPanel; protected JPanel mainPanel; protected JPanel buttonPanel; /** right side fixed labels */ -// protected JLabel titleLabel; + protected JLabel titleLabel; protected JLabel helpLabel; /** remember the pinfield to return to worker */ protected JPasswordField pinField; protected int buttonSize; -// private static final int CHECKBOX_WIDTH = new JCheckBox().getPreferredSize().width; + /** gui style config (default 'simple') */ + protected boolean renderHeaderPanel = false; + protected boolean renderIconPanel = false; + protected boolean renderCancelButton = false; /** + * set contentPane + * init message bundle + * configure the style + * register the help listener + * create GUI (on event-dispatching thread) + * * @param contentPane - * @param localeString may be null + * @param locale + * @param guiStyle + * @param background + * @param helpListener */ - @Override - public void init(final Container contentPane, Locale locale, final URL background, ActionListener helpListener) { + public SimpleGUI(Container contentPane, Locale locale, Style guiStyle, URL background, ActionListener helpListener) { + this.contentPane = contentPane; - if (locale != null) { - messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, locale); - } else { - messages = ResourceBundle.getBundle(MESSAGES_BUNDLE); - } + if (locale != null) { + messages = ResourceBundle.getBundle(MESSAGES_BUNDLE, locale); + } else { + messages = ResourceBundle.getBundle(MESSAGES_BUNDLE); + } + + if (guiStyle == Style.advanced) { + renderHeaderPanel = true; + renderIconPanel = false; + renderCancelButton = true; + } + + registerHelpListener(helpListener); + + createGUI(background); + } + + private void createGUI(final URL background) { - this.contentPane = contentPane; - registerHelpListener(helpListener); - try { log.debug("scheduling gui initialization"); @@ -112,21 +133,28 @@ public class SimpleGUI implements BKUGUIFacade { log.debug("initializing gui"); -// initIconPanel(); + if (renderIconPanel) { + initIconPanel(background); + initContentPanel(null); + } else { initContentPanel(background); - - GroupLayout layout = new GroupLayout(contentPane); - contentPane.setLayout(layout); + } + + GroupLayout layout = new GroupLayout(contentPane); + contentPane.setLayout(layout); + + if (renderIconPanel) { + layout.setHorizontalGroup(layout.createSequentialGroup() + .addComponent(iconPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); + layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(iconPanel, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); + } else { layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(contentPanel)); layout.setVerticalGroup(layout.createSequentialGroup().addComponent(contentPanel)); -// layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addGroup(layout.createSequentialGroup() -// .addComponent(iconPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) -// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) -// .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); -// layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addComponent(iconPanel, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) -// .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); + } } }); } catch (Exception ex) { @@ -134,119 +162,113 @@ public class SimpleGUI implements BKUGUIFacade { } } -// protected void initIconPanel() { -// iconPanel = new JPanel(); -// JLabel iconLabel = new JLabel(); -// iconLabel.setIcon(new ImageIcon(getClass().getResource(LOGO_RESOURCE))); // NOI18N -// -// GroupLayout iconPanelLayout = new GroupLayout(iconPanel); -// iconPanel.setLayout(iconPanelLayout); -// iconPanelLayout.setHorizontalGroup( -// iconPanelLayout.createSequentialGroup() -// .addContainerGap() -// .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, iconLabel.getPreferredSize().width, GroupLayout.PREFERRED_SIZE) -// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); -// iconPanelLayout.setVerticalGroup( -// iconPanelLayout.createSequentialGroup() -// .addContainerGap() -// .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, iconLabel.getPreferredSize().height, GroupLayout.PREFERRED_SIZE) -// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); //); -// } + protected void initIconPanel(URL background) { + if (background == null) { + background = getClass().getResource(DEFAULT_BACKGROUND); + } + if ("file".equals(background.getProtocol())) { + log.warn("file:// background images not permitted: " + background); + background = getClass().getResource(DEFAULT_BACKGROUND); + } + log.debug("loading icon panel background " + background); + + iconPanel = new JPanel(); + JLabel iconLabel = new JLabel(); + iconLabel.setIcon(new ImageIcon(background)); + + GroupLayout iconPanelLayout = new GroupLayout(iconPanel); + iconPanel.setLayout(iconPanelLayout); + iconPanelLayout.setHorizontalGroup( + iconPanelLayout.createSequentialGroup() + .addContainerGap() + .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)); + // no gap here (contentPanel has containerGap) + iconPanelLayout.setVerticalGroup( + iconPanelLayout.createSequentialGroup() + .addContainerGap() + .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); + } protected void initContentPanel(URL background) { if (background == null) { - background = this.getClass().getResource(DEFAULT_BACKGROUND); + background = getClass().getResource(DEFAULT_BACKGROUND); } if ("file".equals(background.getProtocol())) { - log.warn("local background image not allowed: " + background); - background = this.getClass().getResource(DEFAULT_BACKGROUND); + log.warn("file:// background images not permitted: " + background); + background = getClass().getResource(DEFAULT_BACKGROUND); } log.debug("loading background " + background); contentPanel = new ImagePanel(background); -// contentPanel.setBorder(new TitledBorder("content")); - -// headerPanel = new JPanel(); -// headerPanel.setOpaque(false); - mainPanel = new JPanel(); - mainPanel.setOpaque(false); - buttonPanel = new JPanel(); - buttonPanel.setOpaque(false); - -// headerPanel.setBorder(new TitledBorder("header")); -// mainPanel.setBorder(new TitledBorder("main")); -// buttonPanel.setBorder(new TitledBorder("button")); - -// titleLabel = new JLabel(); -// titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | -// java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); - - helpLabel = new JLabel(); - helpLabel.setIcon(new ImageIcon(getClass().getResource(HELP_IMG))); - helpLabel.getAccessibleContext().setAccessibleName(messages.getString(ALT_HELP)); - helpLabel.addMouseListener(helpListener); - helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - - JButton b = new JButton(); -// b.setText(messages.getString(BUTTON_CANCEL)); -// if (b.getPreferredSize().width > buttonSize) -// buttonSize = b.getPreferredSize().width; - b.setText(messages.getString(BUTTON_OK)); - if (b.getPreferredSize().width > buttonSize) - buttonSize = b.getPreferredSize().width; - b.setText(messages.getString(BUTTON_SIGN)); - if (b.getPreferredSize().width > buttonSize) - buttonSize = b.getPreferredSize().width; - b.setText(messages.getString(BUTTON_BACK)); - if (b.getPreferredSize().width > buttonSize) - buttonSize = b.getPreferredSize().width; -// b.setText(messages.getString(BUTTON_SAVE)); -// if (b.getPreferredSize().width > buttonSize) -// buttonSize = b.getPreferredSize().width; - -// if (cancelButton.getPreferredSize().width > buttonSize) -// buttonSize = cancelButton.getPreferredSize().width; -// if (signButton.getPreferredSize().width > buttonSize) -// buttonSize = signButton.getPreferredSize().width; -// if (backButton.getPreferredSize().width > buttonSize) -// buttonSize = backButton.getPreferredSize().width; -// if (saveButton.getPreferredSize().width > buttonSize) -// buttonSize = saveButton.getPreferredSize().width; + mainPanel = new JPanel(); + mainPanel.setOpaque(false); + buttonPanel = new JPanel(); + buttonPanel.setOpaque(false); + helpLabel = new JLabel(); + helpLabel.setIcon(new ImageIcon(getClass().getResource(HELP_IMG))); + helpLabel.getAccessibleContext().setAccessibleName(messages.getString(ALT_HELP)); + helpLabel.addMouseListener(helpListener); + helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + + buttonSize = initButtonSize(messages, renderCancelButton); -// GroupLayout headerPanelLayout = new GroupLayout(headerPanel); -// headerPanel.setLayout(headerPanelLayout); -// -// headerPanelLayout.setHorizontalGroup( -// headerPanelLayout.createSequentialGroup() -// .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); -// headerPanelLayout.setVerticalGroup( -// headerPanelLayout.createSequentialGroup() -// .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); - - - GroupLayout contentPanelLayout = new GroupLayout(contentPanel); - contentPanel.setLayout(contentPanelLayout); - - contentPanelLayout.setHorizontalGroup( - contentPanelLayout.createSequentialGroup() - .addContainerGap() - .addGroup( - contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) -// .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()); - contentPanelLayout.setVerticalGroup( - contentPanelLayout.createSequentialGroup() - .addContainerGap() -// .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) -// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) //, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addContainerGap()); + if (renderHeaderPanel) { + headerPanel = new JPanel(); + headerPanel.setOpaque(false); + + titleLabel = new JLabel(); + titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | + java.awt.Font.BOLD, titleLabel.getFont().getSize() + 2)); + + GroupLayout headerPanelLayout = new GroupLayout(headerPanel); + headerPanel.setLayout(headerPanelLayout); + + headerPanelLayout.setHorizontalGroup( + headerPanelLayout.createSequentialGroup() + .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel)); + headerPanelLayout.setVerticalGroup( + headerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(titleLabel, 0, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) + .addComponent(helpLabel)); + } + + GroupLayout contentPanelLayout = new GroupLayout(contentPanel); + contentPanel.setLayout(contentPanelLayout); + + GroupLayout.ParallelGroup horizontalContentInner = contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); + if (renderHeaderPanel) { + horizontalContentInner + .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE); + } + horizontalContentInner + .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE); + GroupLayout.SequentialGroup horizontalContentOuter = contentPanelLayout.createSequentialGroup(); + if (!renderIconPanel) { + horizontalContentOuter + .addContainerGap(); + } + horizontalContentOuter + .addGroup(horizontalContentInner) + .addContainerGap(); + contentPanelLayout.setHorizontalGroup(horizontalContentOuter); + + GroupLayout.SequentialGroup verticalContent = contentPanelLayout.createSequentialGroup(); + verticalContent.addContainerGap(); + if (renderHeaderPanel) { + verticalContent.addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED); + } + verticalContent.addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addContainerGap(); + contentPanelLayout.setVerticalGroup(verticalContent); } @Override @@ -269,26 +291,35 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// titleLabel.setText(messages.getString(TITLE_WELCOME)); - helpListener.setHelpTopic(HELP_WELCOME); JLabel welcomeMsgLabel = new JLabel(); welcomeMsgLabel.setFont(welcomeMsgLabel.getFont().deriveFont(welcomeMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - welcomeMsgLabel.setText(messages.getString(TITLE_WELCOME)); - + + if (renderHeaderPanel) { + titleLabel.setText(messages.getString(TITLE_WELCOME)); + welcomeMsgLabel.setText(messages.getString(MESSAGE_WAIT)); + } else { + welcomeMsgLabel.setText(messages.getString(TITLE_WELCOME)); + } + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(welcomeMsgLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(welcomeMsgLabel) - .addComponent(helpLabel)); + GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(welcomeMsgLabel); + GroupLayout.Group messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(welcomeMsgLabel); + if (!renderHeaderPanel) { + messageHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel); + messageVertical + .addComponent(helpLabel); + } + + mainPanelLayout.setHorizontalGroup(messageHorizontal); + mainPanelLayout.setVerticalGroup(messageVertical); contentPanel.validate(); @@ -311,8 +342,10 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// titleLabel.setText(messages.getString(TITLE_INSERTCARD)); - + if (renderHeaderPanel) { + titleLabel.setText(messages.getString(TITLE_INSERTCARD)); + } + helpListener.setHelpTopic(HELP_INSERTCARD); JLabel insertCardMsgLabel = new JLabel(); @@ -322,31 +355,39 @@ public class SimpleGUI implements BKUGUIFacade { GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(insertCardMsgLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(insertCardMsgLabel) - .addComponent(helpLabel)); + GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(insertCardMsgLabel); + GroupLayout.ParallelGroup messageVertical = mainPanelLayout.createParallelGroup() + .addComponent(insertCardMsgLabel); -// JButton cancelButton = new JButton(); -// cancelButton.setText(messages.getString(BUTTON_CANCEL)); -// cancelButton.addActionListener(cancelListener); -// cancelButton.setActionCommand(cancelCommand); -// -// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); -// buttonPanel.setLayout(buttonPanelLayout); -// -// buttonPanelLayout.setHorizontalGroup( -// buttonPanelLayout.createSequentialGroup() -// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) -// .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); -// buttonPanelLayout.setVerticalGroup( -// buttonPanelLayout.createSequentialGroup() -// .addComponent(cancelButton)); + if (!renderHeaderPanel) { + messageHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel); + messageVertical + .addComponent(helpLabel); + } + + mainPanelLayout.setHorizontalGroup(messageHorizontal); + mainPanelLayout.setVerticalGroup(messageVertical); + + if (renderCancelButton) { + JButton cancelButton = new JButton(); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.addActionListener(cancelListener); + cancelButton.setActionCommand(cancelCommand); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createSequentialGroup() + .addComponent(cancelButton)); + } contentPanel.validate(); } @@ -373,48 +414,89 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// titleLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); + JLabel insertCardMsgLabel = new JLabel(); + insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + + if (renderHeaderPanel) { + titleLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); + insertCardMsgLabel.setText(messages.getString(MESSAGE_INSERTCARD)); + } else { + insertCardMsgLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); + } helpListener.setHelpTopic(HELP_CARDNOTSUPPORTED); - JLabel insertCardMsgLabel = new JLabel(); - insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - insertCardMsgLabel.setText(messages.getString(TITLE_CARD_NOT_SUPPORTED)); + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(insertCardMsgLabel); + GroupLayout.Group messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(insertCardMsgLabel); + if (!renderHeaderPanel) { + messageHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel); + messageVertical + .addComponent(helpLabel); + } + + mainPanelLayout.setHorizontalGroup(messageHorizontal); + mainPanelLayout.setVerticalGroup(messageVertical); + + if (renderCancelButton) { + JButton cancelButton = new JButton(); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.addActionListener(cancelListener); + cancelButton.setActionCommand(cancelCommand); - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(insertCardMsgLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(insertCardMsgLabel) - .addComponent(helpLabel)); - -// JButton cancelButton = new JButton(); -// cancelButton.setText(messages.getString(BUTTON_CANCEL)); -// cancelButton.addActionListener(cancelListener); -// cancelButton.setActionCommand(cancelCommand); -// -// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); -// buttonPanel.setLayout(buttonPanelLayout); -// -// buttonPanelLayout.setHorizontalGroup( -// buttonPanelLayout.createSequentialGroup() -// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) -// .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); -// buttonPanelLayout.setVerticalGroup( -// buttonPanelLayout.createSequentialGroup() -// .addComponent(cancelButton)); - - contentPanel.validate(); + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createSequentialGroup() + .addComponent(cancelButton)); + } + + contentPanel.validate(); } }); } + private static int initButtonSize(ResourceBundle messages, boolean renderCancelButton) { + + int buttonSize = 0; + + JButton b = new JButton(); + b.setText(messages.getString(BUTTON_OK)); + if (b.getPreferredSize().width > buttonSize) { + buttonSize = b.getPreferredSize().width; + } + b.setText(messages.getString(BUTTON_SIGN)); + if (b.getPreferredSize().width > buttonSize) { + buttonSize = b.getPreferredSize().width; + } + b.setText(messages.getString(BUTTON_BACK)); + if (b.getPreferredSize().width > buttonSize) { + buttonSize = b.getPreferredSize().width; + } + b.setText(messages.getString(BUTTON_SAVE)); + if (b.getPreferredSize().width > buttonSize) { + buttonSize = b.getPreferredSize().width; + } + if (renderCancelButton) { + b.setText(messages.getString(BUTTON_CANCEL)); + if (b.getPreferredSize().width > buttonSize) { + buttonSize = b.getPreferredSize().width; + } + } + return buttonSize; + } + private void showCardPINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener okListener, final String okCommand, final ActionListener cancelListener, final String cancelCommand) { log.debug("scheduling card-pin dialog"); @@ -429,17 +511,14 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// if (numRetries < 0) { -// String cardpinTitle = messages.getString(TITLE_CARDPIN); -// titleLabel.setText(MessageFormat.format(cardpinTitle, new Object[]{pinSpec.getLocalizedName()})); -// } else { -// titleLabel.setText(messages.getString(TITLE_RETRY)); -// } - -// JButton cancelButton = new JButton(); -// cancelButton.setText(messages.getString(BUTTON_CANCEL)); -// cancelButton.setActionCommand(cancelCommand); -// cancelButton.addActionListener(cancelListener); + if (renderHeaderPanel) { + if (numRetries < 0) { + String cardpinTitle = messages.getString(TITLE_CARDPIN); + titleLabel.setText(MessageFormat.format(cardpinTitle, new Object[]{pinSpec.getLocalizedName()})); + } else { + titleLabel.setText(messages.getString(TITLE_RETRY)); + } + } JButton okButton = new JButton(); okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -492,55 +571,73 @@ public class SimpleGUI implements BKUGUIFacade { GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(infoLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addGroup(mainPanelLayout.createSequentialGroup() + GroupLayout.ParallelGroup mainHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); + GroupLayout.SequentialGroup pinHorizontal = mainPanelLayout.createSequentialGroup() .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) //)) - .addComponent(pinsizeLabel)))); - - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(infoLabel) - .addComponent(helpLabel)) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(cardPinLabel) - .addComponent(pinField)) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(pinsizeLabel)); + .addComponent(pinsizeLabel)); + + GroupLayout.SequentialGroup mainVertical = mainPanelLayout.createSequentialGroup(); + + if (!renderHeaderPanel) { + GroupLayout.SequentialGroup infoHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(infoLabel) //, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel); //, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + mainHorizontal + .addGroup(infoHorizontal) + .addGroup(pinHorizontal); + GroupLayout.ParallelGroup infoVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(infoLabel) + .addComponent(helpLabel); + mainVertical + .addGroup(infoVertical) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED); + } else { + mainHorizontal + .addGroup(pinHorizontal); + } + mainVertical + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(cardPinLabel) + .addComponent(pinField)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinsizeLabel); + + mainPanelLayout.setHorizontalGroup(mainHorizontal); + mainPanelLayout.setVerticalGroup(mainVertical); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createSequentialGroup() + GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup() .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createSequentialGroup() - .addComponent(okButton)); - -// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); -// buttonPanel.setLayout(buttonPanelLayout); -// -// buttonPanelLayout.setHorizontalGroup( -// buttonPanelLayout.createSequentialGroup() -// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) -// .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) -// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) -// .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); -// buttonPanelLayout.setVerticalGroup( -// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) -// .addComponent(okButton) -// .addComponent(cancelButton)); + .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); + GroupLayout.Group buttonVertical; + + if (renderCancelButton) { + JButton cancelButton = new JButton(); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.setActionCommand(cancelCommand); + cancelButton.addActionListener(cancelListener); + + buttonHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); + buttonVertical = buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(okButton) + .addComponent(cancelButton); + } else { + buttonVertical = buttonPanelLayout.createSequentialGroup() + .addComponent(okButton); + } + + buttonPanelLayout.setHorizontalGroup(buttonHorizontal); + buttonPanelLayout.setVerticalGroup(buttonVertical); pinField.requestFocusInWindow(); contentPanel.validate(); @@ -583,16 +680,13 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// if (numRetries < 0) { -// titleLabel.setText(messages.getString(TITLE_SIGN)); -// } else { -// titleLabel.setText(messages.getString(TITLE_RETRY)); -// } - -// JButton cancelButton = new JButton(); -// cancelButton.setText(messages.getString(BUTTON_CANCEL)); -// cancelButton.setActionCommand(cancelCommand); -// cancelButton.addActionListener(cancelListener); + if (renderHeaderPanel) { + if (numRetries < 0) { + titleLabel.setText(messages.getString(TITLE_SIGN)); + } else { + titleLabel.setText(messages.getString(TITLE_RETRY)); + } + } JButton signButton = new JButton(); signButton.setFont(signButton.getFont().deriveFont(signButton.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -653,13 +747,23 @@ public class SimpleGUI implements BKUGUIFacade { GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); + + GroupLayout.SequentialGroup infoHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(infoLabel); + GroupLayout.ParallelGroup infoVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(infoLabel); + + if (!renderHeaderPanel) { + infoHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel); //, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); + infoVertical + .addComponent(helpLabel); + } mainPanelLayout.setHorizontalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(infoLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addGroup(infoHorizontal) .addGroup(mainPanelLayout.createSequentialGroup() .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) @@ -669,9 +773,7 @@ public class SimpleGUI implements BKUGUIFacade { mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(infoLabel) - .addComponent(helpLabel)) + .addGroup(infoVertical) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(signPinLabel) @@ -682,27 +784,31 @@ public class SimpleGUI implements BKUGUIFacade { GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createSequentialGroup() + GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup() .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(signButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createSequentialGroup() - .addComponent(signButton)); - -// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); -// buttonPanel.setLayout(buttonPanelLayout); -// -// buttonPanelLayout.setHorizontalGroup( -// buttonPanelLayout.createSequentialGroup() -// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) -// .addComponent(signButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) -// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) -// .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); -// buttonPanelLayout.setVerticalGroup( -// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) -// .addComponent(signButton) -// .addComponent(cancelButton)); + .addComponent(signButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); + GroupLayout.Group buttonVertical; + + if (renderCancelButton) { + JButton cancelButton = new JButton(); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.setActionCommand(cancelCommand); + cancelButton.addActionListener(cancelListener); + + buttonHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); + + buttonVertical = buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(signButton) + .addComponent(cancelButton); + } else { + buttonVertical = buttonPanelLayout.createSequentialGroup() + .addComponent(signButton); + } + + buttonPanelLayout.setHorizontalGroup(buttonHorizontal); + buttonPanelLayout.setVerticalGroup(buttonVertical); pinField.requestFocusInWindow(); contentPanel.validate(); @@ -726,15 +832,12 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// titleLabel.setText(messages.getString(TITLE_ERROR)); + if (renderHeaderPanel) { + titleLabel.setText(messages.getString(TITLE_ERROR)); + } helpListener.setHelpTopic(errorMsgKey); - JLabel errorTitleLabel = new JLabel(); - errorTitleLabel.setFont(errorTitleLabel.getFont().deriveFont(errorTitleLabel.getFont().getStyle() | java.awt.Font.BOLD)); - errorTitleLabel.setText(messages.getString(TITLE_ERROR)); - errorTitleLabel.setForeground(ERROR_COLOR); - String errorMsgPattern = messages.getString(errorMsgKey); String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); @@ -745,19 +848,30 @@ public class SimpleGUI implements BKUGUIFacade { GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(errorTitleLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)) - .addComponent(errorMsgLabel)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(errorTitleLabel) - .addComponent(helpLabel)) - .addComponent(errorMsgLabel)); + GroupLayout.ParallelGroup mainHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); + GroupLayout.SequentialGroup mainVertical = mainPanelLayout.createSequentialGroup(); + + if (!renderHeaderPanel) { + JLabel errorTitleLabel = new JLabel(); + errorTitleLabel.setFont(errorTitleLabel.getFont().deriveFont(errorTitleLabel.getFont().getStyle() | java.awt.Font.BOLD)); + errorTitleLabel.setText(messages.getString(TITLE_ERROR)); + errorTitleLabel.setForeground(ERROR_COLOR); + + mainHorizontal + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(errorTitleLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel)); + mainVertical + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorTitleLabel) + .addComponent(helpLabel)); + } + + mainPanelLayout.setHorizontalGroup(mainHorizontal + .addComponent(errorMsgLabel)); + mainPanelLayout.setVerticalGroup(mainVertical + .addComponent(errorMsgLabel)); JButton okButton = new JButton(); okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -796,15 +910,12 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// titleLabel.setText(messages.getString(TITLE_ERROR)); + if (renderHeaderPanel) { + titleLabel.setText(messages.getString(TITLE_ERROR)); + } helpListener.setHelpTopic(errorMsgKey); - JLabel errorTitleLabel = new JLabel(); - errorTitleLabel.setFont(errorTitleLabel.getFont().deriveFont(errorTitleLabel.getFont().getStyle() | java.awt.Font.BOLD)); - errorTitleLabel.setText(messages.getString(TITLE_ERROR)); - errorTitleLabel.setForeground(ERROR_COLOR); - String errorMsgPattern = messages.getString(errorMsgKey); String errorMsg = MessageFormat.format(errorMsgPattern, errorMsgParams); @@ -815,20 +926,32 @@ public class SimpleGUI implements BKUGUIFacade { GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + + GroupLayout.ParallelGroup mainHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); + GroupLayout.SequentialGroup mainVertical = mainPanelLayout.createSequentialGroup(); + + if (!renderHeaderPanel) { + JLabel errorTitleLabel = new JLabel(); + errorTitleLabel.setFont(errorTitleLabel.getFont().deriveFont(errorTitleLabel.getFont().getStyle() | java.awt.Font.BOLD)); + errorTitleLabel.setText(messages.getString(TITLE_ERROR)); + errorTitleLabel.setForeground(ERROR_COLOR); + + mainHorizontal .addGroup(mainPanelLayout.createSequentialGroup() .addComponent(errorTitleLabel) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)) - .addComponent(errorMsgLabel)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() + .addComponent(helpLabel)); + mainVertical .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(errorTitleLabel) - .addComponent(helpLabel)) - .addComponent(errorMsgLabel)); + .addComponent(helpLabel)); + } + mainPanelLayout.setHorizontalGroup(mainHorizontal + .addComponent(errorMsgLabel)); + mainPanelLayout.setVerticalGroup(mainVertical + .addComponent(errorMsgLabel)); + contentPanel.validate(); } }); @@ -849,8 +972,10 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// titleLabel.setText(messages.getString(TITLE_WAIT)); - + if (renderHeaderPanel) { + titleLabel.setText(messages.getString(TITLE_WAIT)); + } + helpListener.setHelpTopic(HELP_WAIT); JLabel waitMsgLabel = new JLabel(); @@ -864,15 +989,20 @@ public class SimpleGUI implements BKUGUIFacade { GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createSequentialGroup() - .addComponent(waitMsgLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(waitMsgLabel) - .addComponent(helpLabel)); + GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(waitMsgLabel); + GroupLayout.ParallelGroup messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(waitMsgLabel); + + if (!renderHeaderPanel) { + messageHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel); + messageVertical + .addComponent(helpLabel); + } + mainPanelLayout.setHorizontalGroup(messageHorizontal); + mainPanelLayout.setVerticalGroup(messageVertical); contentPanel.validate(); } @@ -887,50 +1017,58 @@ public class SimpleGUI implements BKUGUIFacade { return null; } + /** + * TODO handle multiple references in HashDataViewer + * @param signedReferences + * @param okListener + * @param okCommand + */ @Override - public void showHashDataInputDialog(final List signedReferences, boolean standalone, final ActionListener okListener, final String okCommand) { + public void showHashDataInputDialog(final List signedReferences, final ActionListener okListener, final String okCommand) { if (signedReferences == null) { showErrorDialog(messages.getString(ERR_NO_HASHDATA), new Object[] {"No SignedReferences provided"}, okListener, okCommand); + return; } + ActionListener saveHashDataListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + showSaveHashDataInputDialog(signedReferences, okListener, okCommand); + } + }; + if (signedReferences.size() == 1) { - if (standalone) { - ActionListener saveHashDataListener = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - showSaveHashDataInputDialog(signedReferences, okListener, okCommand); - } - }; - showHashDataViewer(signedReferences, saveHashDataListener, "save"); +// if (standalone) { - } else { - if ("text/plain".equals(signedReferences.get(0).getMimeType())) { - - ActionListener saveHashDataListener = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - showSaveHashDataInputDialog(signedReferences, okListener, okCommand); - } - }; - - try { - String hashDataText = getText(signedReferences.get(0)); - showPlainTextHashDataInputDialog(hashDataText, saveHashDataListener, "save", okListener, okCommand); - } catch (IOException ex) { - showErrorDialog(messages.getString(ERR_NO_HASHDATA), new Object[] {ex.getMessage()}, okListener, okCommand); - } + showHashDataViewer(signedReferences, saveHashDataListener, "save"); - } else { - showSaveHashDataInputDialog(signedReferences, okListener, okCommand); - } - } +// } else { +// if ("text/plain".equals(signedReferences.get(0).getMimeType())) { +// +// ActionListener saveHashDataListener = new ActionListener() { +// +// @Override +// public void actionPerformed(ActionEvent e) { +// showSaveHashDataInputDialog(signedReferences, okListener, okCommand); +// } +// }; +// +// try { +// String hashDataText = getText(signedReferences.get(0)); +// showPlainTextHashDataInputDialog(hashDataText, saveHashDataListener, "save", okListener, okCommand); +// } catch (IOException ex) { +// showErrorDialog(messages.getString(ERR_NO_HASHDATA), new Object[] {ex.getMessage()}, okListener, okCommand); +// } +// +// } else { +// showSaveHashDataInputDialog(signedReferences, okListener, okCommand); +// } +// } } else { - SimpleHashDataTableModel tableModel = new SimpleHashDataTableModel(signedReferences); // final HashDataTableModel tableModel = new HashDataTableModel(signedReferences); // // ActionListener saveHashDataListener = new ActionListener() { @@ -940,128 +1078,112 @@ public class SimpleGUI implements BKUGUIFacade { // showSaveHashDataInputDialog(tableModel.getSelectedHashData(), okListener, okCommand); // } // }; - showMultipleHashDataInputDialog(tableModel, okListener, okCommand); + + SimpleHashDataTableModel tableModel = new SimpleHashDataTableModel(signedReferences); + showMultipleHashDataInputDialog(tableModel, okListener, okCommand, saveHashDataListener, "save"); } } /** - * TODO + * blocks until dialog returns (is closed) * @param hashDataText * @param saveListener * @param saveCommand */ private void showHashDataViewer(final List signedReferences, final ActionListener saveListener, final String saveCommand) { - log.debug("scheduling plaintext hashdatainput dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show plaintext hashdatainput dialog"); - - ActionListener l = helpListener.getActionListener(); - HashDataViewer.showHashDataInput(contentPane, signedReferences, messages, saveListener, saveCommand, l); - } - }); - } - - private void showPlainTextHashDataInputDialog(final String hashDataText, final ActionListener saveListener, final String saveCommand, final ActionListener cancelListener, final String cancelCommand) { - - log.debug("scheduling plaintext hashdatainput dialog"); - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show plaintext hashdatainput dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - -// titleLabel.setText(messages.getString(TITLE_HASHDATA)); - - helpListener.setHelpTopic(HELP_HASHDATA); - - JLabel refIdLabel = new JLabel(); - refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - refIdLabel.setText(messages.getString(MESSAGE_HASHDATA)); //MessageFormat.format(refIdLabelPattern, new Object[]{refId})); - - JTextArea hashDataTextArea = new JTextArea(hashDataText); - hashDataTextArea.setEditable(false); -// hashDataTextArea.setColumns(1); -// hashDataTextArea.setRows(1); - hashDataTextArea.setFont(new Font(HASHDATA_FONT, hashDataTextArea.getFont().getStyle(), hashDataTextArea.getFont().getSize())); -// hashDataScrollPane.setViewportView(hashDataTextArea); -// hashDataScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); //HORIZONTAL_SCROLLBAR_NEVER); - hashDataTextArea.setLineWrap(true); - hashDataTextArea.setWrapStyleWord(true); - - JScrollPane hashDataScrollPane = new JScrollPane(hashDataTextArea); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(refIdLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)) - .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); - - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(refIdLabel) - .addComponent(helpLabel)) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); - - JButton backButton = new JButton(); - backButton.setFont(backButton.getFont().deriveFont(backButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - backButton.setText(messages.getString(BUTTON_BACK)); - backButton.setActionCommand(cancelCommand); - backButton.addActionListener(cancelListener); + try { + log.debug("scheduling plaintext hashdatainput dialog"); -// JButton saveButton = new JButton(); -// saveButton.setText(messages.getString(BUTTON_SAVE)); -// saveButton.setActionCommand(saveCommand); -// saveButton.addActionListener(saveListener); + SwingUtilities.invokeAndWait(new Runnable() { - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); + @Override + public void run() { - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createSequentialGroup() - .addComponent(backButton)); + log.debug("show plaintext hashdatainput dialog"); + ActionListener l = helpListener.getActionListener(); + HashDataViewer.showHashDataInput(contentPane, signedReferences, messages, saveListener, saveCommand, l); + } + }); + + } catch (InterruptedException ex) { + log.error("Failed to display HashDataViewer: " + ex.getMessage()); + } catch (InvocationTargetException ex) { + log.error("Failed to display HashDataViewer: " + ex.getMessage()); + } + } + +// private void showPlainTextHashDataInputDialog(final String hashDataText, final ActionListener saveListener, final String saveCommand, final ActionListener cancelListener, final String cancelCommand) { +// +// log.debug("scheduling plaintext hashdatainput dialog"); +// +// SwingUtilities.invokeLater(new Runnable() { +// +// @Override +// public void run() { +// +// log.debug("show plaintext hashdatainput dialog"); +// +// mainPanel.removeAll(); +// buttonPanel.removeAll(); +// +// helpListener.setHelpTopic(HELP_HASHDATA); +// +// JLabel refIdLabel = new JLabel(); +// refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); +// refIdLabel.setText(messages.getString(MESSAGE_HASHDATA)); //MessageFormat.format(refIdLabelPattern, new Object[]{refId})); +// +// JTextArea hashDataTextArea = new JTextArea(hashDataText); +// hashDataTextArea.setEditable(false); +// hashDataTextArea.setFont(new Font(HASHDATA_FONT, hashDataTextArea.getFont().getStyle(), hashDataTextArea.getFont().getSize())); +// hashDataTextArea.setLineWrap(true); +// hashDataTextArea.setWrapStyleWord(true); +// +// JScrollPane hashDataScrollPane = new JScrollPane(hashDataTextArea); +// +// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); +// mainPanel.setLayout(mainPanelLayout); +// +// mainPanelLayout.setHorizontalGroup( +// mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addGroup(mainPanelLayout.createSequentialGroup() +// .addComponent(refIdLabel) +// .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) +// .addComponent(helpLabel)) +// .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); +// +// mainPanelLayout.setVerticalGroup( +// mainPanelLayout.createSequentialGroup() +// .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addComponent(refIdLabel) +// .addComponent(helpLabel)) +// .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) +// .addComponent(hashDataScrollPane, 0, 0, Short.MAX_VALUE)); +// +// JButton backButton = new JButton(); +// backButton.setFont(backButton.getFont().deriveFont(backButton.getFont().getStyle() & ~java.awt.Font.BOLD)); +// backButton.setText(messages.getString(BUTTON_BACK)); +// backButton.setActionCommand(cancelCommand); +// backButton.addActionListener(cancelListener); +// // 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(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); // buttonPanelLayout.setVerticalGroup( -// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) -// .addComponent(saveButton) -// .addComponent(backButton)); - - contentPanel.validate(); - } - }); - } +// buttonPanelLayout.createSequentialGroup() +// .addComponent(backButton)); +// +// contentPanel.validate(); +// } +// }); +// } - 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"); @@ -1075,8 +1197,10 @@ public class SimpleGUI implements BKUGUIFacade { mainPanel.removeAll(); buttonPanel.removeAll(); -// titleLabel.setText(messages.getString(TITLE_HASHDATA)); - + if (renderHeaderPanel) { + titleLabel.setText(messages.getString(TITLE_HASHDATA)); + } + helpListener.setHelpTopic(HELP_HASHDATALIST); JLabel refIdLabel = new JLabel(); @@ -1124,36 +1248,31 @@ public class SimpleGUI implements BKUGUIFacade { backButton.setActionCommand(cancelCommand); backButton.addActionListener(cancelListener); -// JButton saveButton = new JButton(); -// saveButton.setText(messages.getString(BUTTON_SAVE)); -// saveButton.setActionCommand(saveCommand); -// saveButton.addActionListener(saveListener); - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createSequentialGroup() + GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup() .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createSequentialGroup() - .addComponent(backButton)); - - -// 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(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); -// buttonPanelLayout.setVerticalGroup( -// buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) -// .addComponent(saveButton) -// .addComponent(backButton)); + .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); + GroupLayout.ParallelGroup buttonVertical = buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(backButton); + + if (renderCancelButton) { + //render save button + JButton saveButton = new JButton(); + saveButton.setText(messages.getString(BUTTON_SAVE)); + saveButton.setActionCommand(saveCommand); + saveButton.addActionListener(saveListener); + + buttonHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); + buttonVertical + .addComponent(saveButton); + } + + buttonPanelLayout.setHorizontalGroup(buttonHorizontal); + buttonPanelLayout.setVerticalGroup(buttonVertical); contentPanel.validate(); } @@ -1243,36 +1362,36 @@ public class SimpleGUI implements BKUGUIFacade { }); } - private static String getText(HashDataInput hdi) throws IOException { - ByteArrayOutputStream baos = null; - try { - InputStream hashDataIS = hdi.getHashDataInput(); - if (hashDataIS == null) { - log.error("No HashDataInput stream for reference " + hdi.getReferenceId()); - return null; - } else { - baos = new ByteArrayOutputStream(hashDataIS.available()); - int c; - while ((c = hashDataIS.read()) != -1) { - baos.write(c); - } - String encoding = hdi.getEncoding(); - if (encoding == null) { - //default for URL-encoded - encoding = "UTF-8"; - } - return baos.toString(encoding); - } - } catch (IOException ex) { - log.error("Failed to read HashDataInput for reference " + hdi.getReferenceId() + ": " + ex.getMessage()); - throw ex; - } finally { - try { - baos.close(); - } catch (IOException ex) { - } - } - } +// private static String getText(HashDataInput hdi) throws IOException { +// ByteArrayOutputStream baos = null; +// try { +// InputStream hashDataIS = hdi.getHashDataInput(); +// if (hashDataIS == null) { +// log.error("No HashDataInput stream for reference " + hdi.getReferenceId()); +// return null; +// } else { +// baos = new ByteArrayOutputStream(hashDataIS.available()); +// int c; +// while ((c = hashDataIS.read()) != -1) { +// baos.write(c); +// } +// String encoding = hdi.getEncoding(); +// if (encoding == null) { +// //default for URL-encoded +// encoding = "UTF-8"; +// } +// return baos.toString(encoding); +// } +// } catch (IOException ex) { +// log.error("Failed to read HashDataInput for reference " + hdi.getReferenceId() + ": " + ex.getMessage()); +// throw ex; +// } finally { +// try { +// baos.close(); +// } catch (IOException ex) { +// } +// } +// } private void registerHelpListener(ActionListener helpListener) { if (helpListener != null) { 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 5f62c05a..b5a74ac1 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 @@ -14,7 +14,7 @@ # limitations under the License. title.welcome=Willkommen -title.insertcard=Bitte B\u00FCrgerkarte in den Kartenleser stecken +title.insertcard=Keine B\u00FCrgerkarte gefunden title.cardnotsupported=Die Karte wird nicht unterst\u00FCtzt title.cardpin={0} eingeben title.sign=Signatur erstellen 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 d963fd5f..94464982 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=Please insert your citizen-card into the reader +title.insertcard=No citizen-card found title.cardnotsupported=This card is not supported title.cardpin=Enter {0} title.sign=Create signature diff --git a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java index c32a237a..b57e1923 100644 --- a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java +++ b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java @@ -32,15 +32,16 @@ import org.junit.Test; * * @author clemens */ +@Ignore public class BKUGUITest { - @Ignore + @Test public void testBKUGUI() { JFrame testFrame = new JFrame("BKUGUITest"); BKUGUI gui = new BKUGUI(); Container contentPane = testFrame.getContentPane(); contentPane.setPreferredSize(new Dimension(380, 150)); - gui.init(contentPane, null, null, null); + gui.init(contentPane, null, BKUGUIFacade.Style.advanced, null, null); BKUGUIWorker worker = new BKUGUIWorker(); worker.init(gui); testFrame.pack(); 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 af1368e5..e4936067 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 @@ -43,7 +43,7 @@ public class BKUGUIWorker implements Runnable { @Override public void run() { - try { +// try { final PINSpec signPinSpec = new PINSpec(6, 10, "[0-9]", "Signatur-PIN"); @@ -176,7 +176,7 @@ public class BKUGUIWorker implements Runnable { // signedRefs.add(signedRef4); // signedRefs.add(signedRef4); // signedRefs = Collections.singletonList(signedRef1); - gui.showHashDataInputDialog(signedRefs, true, returnListener, "return"); + gui.showHashDataInputDialog(signedRefs, returnListener, "return"); } }; @@ -184,64 +184,64 @@ public class BKUGUIWorker implements Runnable { gui.showWelcomeDialog(); - Thread.sleep(2000); - - gui.showWaitDialog(null); - - Thread.sleep(1000); - - gui.showWaitDialog("test"); - - Thread.sleep(1000); - - - gui.showInsertCardDialog(cancelListener, "cancel"); - - Thread.sleep(2000); - - gui.showCardNotSupportedDialog(cancelListener, "cancel"); - - Thread.sleep(2000); - - PINSpec cardPinSpec = new PINSpec(4, 4, "[0-9]", "Karten-PIN"); - - gui.showCardPINDialog(cardPinSpec, okListener, "ok", cancelListener, "cancel"); - - Thread.sleep(2000); - - gui.showSignaturePINDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); - - Thread.sleep(4000); - - gui.showSignaturePINRetryDialog(signPinSpec, 2, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); - - Thread.sleep(2000); - - gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, new Object[] {"Testfehler"}, null, null); - - Thread.sleep(2000); - - gui.showErrorDialog("error.test", new Object[] {"Testfehler", "noch ein TestFehler"}); - - Thread.sleep(2000); - - gui.showErrorDialog("error.no.hashdata", null); - - Thread.sleep(2000); - - gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, new Object[] {"Testfehler"}); - - Thread.sleep(2000); - - gui.showErrorDialog("error.unknown", null); +// Thread.sleep(2000); +// +// gui.showWaitDialog(null); +// +// Thread.sleep(1000); +// +// gui.showWaitDialog("test"); +// +// Thread.sleep(1000); +// +// +// gui.showInsertCardDialog(cancelListener, "cancel"); +// +// Thread.sleep(2000); +// +// gui.showCardNotSupportedDialog(cancelListener, "cancel"); +// +// Thread.sleep(2000); +// +// PINSpec cardPinSpec = new PINSpec(4, 4, "[0-9]", "Karten-PIN"); +// +// gui.showCardPINDialog(cardPinSpec, okListener, "ok", cancelListener, "cancel"); +// +// Thread.sleep(2000); +// +// gui.showSignaturePINDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); +// +// Thread.sleep(4000); +// +// gui.showSignaturePINRetryDialog(signPinSpec, 2, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); +// +// Thread.sleep(2000); +// +// gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, new Object[] {"Testfehler"}, null, null); +// +// Thread.sleep(2000); +// +// gui.showErrorDialog("error.test", new Object[] {"Testfehler", "noch ein TestFehler"}); +// +// Thread.sleep(2000); +// +// gui.showErrorDialog("error.no.hashdata", null); +// +// Thread.sleep(2000); +// +// gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, new Object[] {"Testfehler"}); +// +// Thread.sleep(2000); +// +// gui.showErrorDialog("error.unknown", null); // gui.showTextPlainHashDataInput("hallo,\n welt!", "12345", null, "cancel", null, "save"); // gui.showTextPlainHashDataInput("hallo,\n welt!", "12345", null, "cancel", null, "save"); // Thread.sleep(2000); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } +// } catch (InterruptedException ex) { +// ex.printStackTrace(); +// } } } 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 fb8f2432..eaa4d6ad 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 @@ -37,10 +37,10 @@ public class BKUGuiProxy implements BKUGUIFacade { return delegate.getPin(); } - @Override - public void init(Container contentPane, Locale locale, URL bgImage, ActionListener helpListener) { - delegate.init(contentPane, locale, bgImage, helpListener); - } +// @Override +// public void init(Container contentPane, Locale locale, URL bgImage, ActionListener helpListener) { +// delegate.init(contentPane, locale, bgImage, helpListener); +// } @Override public Locale getLocale() { @@ -126,11 +126,9 @@ public class BKUGuiProxy implements BKUGUIFacade { @Override public void showHashDataInputDialog(List signedReferences, - boolean externalDisplay, ActionListener okListener, String okCommand) { showDialog(); - delegate.showHashDataInputDialog(signedReferences, externalDisplay, okListener, - okCommand); + delegate.showHashDataInputDialog(signedReferences, okListener, okCommand); } } diff --git a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSignRequestHandler.java b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSignRequestHandler.java index 19e6a657..bfce0f0d 100644 --- a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSignRequestHandler.java +++ b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSignRequestHandler.java @@ -109,7 +109,7 @@ public class LocalSignRequestHandler extends SignRequestHandler { log.error("dsig:SignedInfo does not contain a data reference"); throw new Exception("dsig:SignedInfo does not contain a data reference"); } - gui.showHashDataInputDialog(selectedHashDataInputs, false, this, "ok"); + gui.showHashDataInputDialog(selectedHashDataInputs, this, "ok"); } private ByteArrayHashDataInput getByteArrayHashDataInput(HashDataInput hashDataInput) throws IOException { 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 cad8cfb6..7012fec0 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 @@ -48,7 +48,6 @@ public class SMCCSTALFactory implements STALFactory { if (locale != null) { dialog.setLocale(locale); } - BKUGUIFacade gui = BKUGUIFactory.createGUI(BKUGUIFactory.ADVANCED_GUI); DefaultHelpListener helpListener = null; try { if (helpURL != null) { @@ -60,7 +59,11 @@ public class SMCCSTALFactory implements STALFactory { } catch (MalformedURLException ex) { log.error("failed to configure help listener: " + ex.getMessage(), ex); } - gui.init(dialog.getContentPane(), dialog.getLocale(), null, helpListener); + BKUGUIFacade gui = BKUGUIFactory.createGUI(dialog.getContentPane(), + dialog.getLocale(), + BKUGUIFactory.ADVANCED_GUI, + null, + helpListener); stal = new SMCCSTAL(new BKUGuiProxy(dialog, gui), dialog); dialog.setPreferredSize(new Dimension(400, 200)); dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); diff --git a/BKUOnline/src/main/webapp/HTTP-ohne.html b/BKUOnline/src/main/webapp/HTTP-ohne.html index 112a1d92..607fa5d4 100644 --- a/BKUOnline/src/main/webapp/HTTP-ohne.html +++ b/BKUOnline/src/main/webapp/HTTP-ohne.html @@ -101,7 +101,7 @@ legend { Frame Browser - Applet +

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 9d23315c..38247174 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 @@ -38,6 +38,8 @@ import java.util.Collections; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.swing.CellRendererPane; import javax.swing.GroupLayout; import javax.swing.ImageIcon; @@ -50,8 +52,12 @@ import javax.swing.JPasswordField; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.LayoutStyle; +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; @@ -1013,80 +1019,75 @@ public class BKUGUIImpl implements BKUGUIFacade { } if (signedReferences.size() == 1) { - ActionListener saveHashDataListener = new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - HashDataInput hdi = signedReferences.get(0); - showSaveHashDataInputDialog(Collections.singletonList(hdi), okListener, okCommand); - } - }; - showHashDataViewer(signedReferences.get(0), saveHashDataListener, "save"); + try { + log.debug("scheduling hashdata viewer"); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + ActionListener saveHashDataListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + HashDataInput hdi = signedReferences.get(0); + showSaveHashDataInputDialog(Collections.singletonList(hdi), okListener, okCommand); + } + }; + showHashDataViewer(signedReferences.get(0), saveHashDataListener, "save"); + } + }); + + } catch (InterruptedException ex) { + log.error("Failed to display HashDataViewer: " + ex.getMessage()); + } catch (InvocationTargetException ex) { + log.error("Failed to display HashDataViewer: " + ex.getMessage()); + } } else { - HashDataTableModel tableModel = new HashDataTableModel(signedReferences); - showSignedReferencesListDialog(tableModel, okListener, okCommand); + showSignedReferencesListDialog(signedReferences, okListener, okCommand); } } /** * Opens HashDataViewer on mouse clicked event */ - public class HashDataMouseListener extends MouseAdapter { - - private HashDataInput hashData; - - public void setHashData(HashDataInput hashData) { - this.hashData = hashData; - } - - @Override - public void mouseClicked(MouseEvent e) { - ActionListener saveListener = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - showSaveHashDataInputDialog(Collections.singletonList(hashData), null, null); - } - }; - showHashDataViewer(hashData, saveListener, "save"); - super.mouseClicked(e); - } - - - - } +// public class HashDataMouseListener extends MouseAdapter { +// +// private HashDataInput hashData; +// +// public void setHashData(HashDataInput hashData) { +// this.hashData = hashData; +// } +// +// @Override +// public void mouseClicked(MouseEvent e) { +// ActionListener saveListener = new ActionListener() { +// +// @Override +// public void actionPerformed(ActionEvent e) { +// showSaveHashDataInputDialog(Collections.singletonList(hashData), null, null); +// } +// }; +// showHashDataViewer(hashData, saveListener, "save"); +// super.mouseClicked(e); +// } +// } /** - * blocks until dialog returns (is closed) + * has to be called from event dispatcher thread * @param hashDataText * @param saveListener * @param saveCommand */ private void showHashDataViewer(final HashDataInput hashDataInput, final ActionListener saveListener, final String saveCommand) { - try { - log.debug("scheduling plaintext hashdatainput dialog"); - - // avoid double-clicks on hashdata link - SwingUtilities.invokeAndWait(new Runnable() { - - @Override - public void run() { - - log.debug("show plaintext hashdatainput dialog"); + log.debug("show hashdata viewer"); - ActionListener l = helpListener.getActionListener(); - HashDataViewer.showHashDataInput(contentPane, hashDataInput, messages, saveListener, saveCommand, l); - } - }); - - } catch (InterruptedException ex) { - log.error("Failed to display HashDataViewer: " + ex.getMessage()); - } catch (InvocationTargetException ex) { - log.error("Failed to display HashDataViewer: " + ex.getMessage()); - } + ActionListener l = helpListener.getActionListener(); + HashDataViewer.showHashDataInput(contentPane, hashDataInput, messages, saveListener, saveCommand, l); } - private void showSignedReferencesListDialog(final HashDataTableModel signedReferences, final ActionListener backListener, final String backCommand) { + private void showSignedReferencesListDialog(final List signedReferences, final ActionListener backListener, final String backCommand) { log.debug("scheduling signed references list dialog"); @@ -1109,21 +1110,40 @@ public class BKUGUIImpl implements BKUGUIFacade { JLabel refIdLabel = new JLabel(); refIdLabel.setFont(refIdLabel.getFont().deriveFont(refIdLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); String refIdLabelPattern = messages.getString(MESSAGE_HASHDATALIST); - refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[]{signedReferences.getRowCount()})); + refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[]{signedReferences.size()})); - JTable hashDataTable = new JTable(signedReferences); - hashDataTable.setDefaultRenderer(HashDataInput.class, signedReferences.getRenderer()); - + HashDataTableModel tableModel = new HashDataTableModel(signedReferences); + JTable hashDataTable = new JTable(tableModel); +// hashDataTable.setDefaultRenderer(HashDataInput.class, signedReferences.getRenderer()); hashDataTable.setTableHeader(null); - // hashDataTable.setShowVerticalLines(false); - hashDataTable.setRowSelectionAllowed(true); -// TableColumn selectCol = hashDataTable.getColumnModel().getColumn(1); -// selectCol.setMinWidth(CHECKBOX_WIDTH); -// selectCol.setMaxWidth(CHECKBOX_WIDTH); + + hashDataTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + hashDataTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + @Override + public void valueChanged(final ListSelectionEvent e) { + //invoke later to allow thread to paint selection background + SwingUtilities.invokeLater(new Runnable() { -// hashDataTable.setPreferredScrollableViewportSize(mainPanel.getPreferredSize()); + @Override + public void run() { + ListSelectionModel lsm = (ListSelectionModel) e.getSource(); + int selectionIdx = lsm.getMinSelectionIndex(); + if (selectionIdx >= 0) { + final HashDataInput selection = signedReferences.get(selectionIdx); + showHashDataViewer(selection, new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + showSaveHashDataInputDialog(Collections.singletonList(selection), null, null); + } + }, "save"); + } + } + }); + } + }); + JScrollPane hashDataScrollPane = new JScrollPane(hashDataTable); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); @@ -1174,6 +1194,12 @@ public class BKUGUIImpl implements BKUGUIFacade { }); } + /** + * + * @param signedRefs + * @param okListener may be null + * @param okCommand + */ private void showSaveHashDataInputDialog(final List signedRefs, final ActionListener okListener, final String okCommand) { log.debug("scheduling save hashdatainput dialog"); 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 a6709860..9a43e99d 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 @@ -17,21 +17,8 @@ package at.gv.egiz.bku.gui; import at.gv.egiz.stal.HashDataInput; -import java.awt.Color; -import java.awt.Component; -import java.awt.Cursor; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; import java.util.List; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JTable; import javax.swing.table.DefaultTableModel; -import javax.swing.table.TableCellRenderer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -43,17 +30,15 @@ class HashDataTableModel extends DefaultTableModel { protected static final Log log = LogFactory.getLog(HashDataTableModel.class); - protected Class[] types = new Class[]{HashDataInput.class}; + protected Class[] types = new Class[]{ String.class, String.class }; protected List hashDataInputs; - private HashDataLinkRenderer renderer; public HashDataTableModel(List hashDataInputs) { - super(0, 1); + super(0, 2); this.hashDataInputs = hashDataInputs; for (HashDataInput hdi : hashDataInputs) { - addRow(new Object[]{hdi}); + addRow(new Object[]{hdi.getReferenceId(), hdi.getMimeType()}); } - this.renderer = new HashDataLinkRenderer(); } @Override @@ -66,46 +51,45 @@ class HashDataTableModel extends DefaultTableModel { return false; } - - - public HashDataLinkRenderer getRenderer() { - return renderer; - } +// public HashDataInput getValue(int rowIndex) { +// return hashDataInputs.get(rowIndex); +// } +// - public class HashDataLinkRenderer extends JLabel - implements TableCellRenderer { -// extends DefaultTableCellRenderer { - -// protected ActionListener saveHashDataListener; +// public class HashDataLinkRenderer extends JLabel +// implements TableCellRenderer { +//// extends DefaultTableCellRenderer { +// +//// protected ActionListener saveHashDataListener; +//// +//// public HashDataLinkRenderer(ActionListener saveHashDataListener) { +//// this.saveHashDataListener = saveHashDataListener; +//// } +// +// @Override +// public Component getTableCellRendererComponent(JTable table, +// Object value, +// boolean isSelected, +// boolean hasFocus, +// final int row, +// int column) { +// final HashDataInput hdi = (HashDataInput) value; +// log.debug("render hashdatainput " + hdi.getReferenceId() + " - (" + row + "," + column + ") " + isSelected + hasFocus); +// setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); +// setFont(getFont().deriveFont(getFont().getStyle() & ~java.awt.Font.BOLD)); +// setText(hdi.getReferenceId() + " (" + hdi.getMimeType() + ")"); +// addMouseListener(new MouseAdapter() { +// +// @Override +// public void mouseClicked(MouseEvent e) { +// log.debug("received mouseclick on " + hdi.getReferenceId()); +//// saveHashDataListener.actionPerformed(); +// JOptionPane.showInputDialog(hashDataInputs.get(row).getReferenceId()); +// } +// +// }); // -// public HashDataLinkRenderer(ActionListener saveHashDataListener) { -// this.saveHashDataListener = saveHashDataListener; +// return this; // } - - @Override - public Component getTableCellRendererComponent(JTable table, - Object value, - boolean isSelected, - boolean hasFocus, - final int row, - int column) { - final HashDataInput hdi = (HashDataInput) value; - log.debug("render hashdatainput " + hdi.getReferenceId() + " - (" + row + "," + column + ") " + isSelected + hasFocus); - setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - setFont(getFont().deriveFont(getFont().getStyle() & ~java.awt.Font.BOLD)); - setText(hdi.getReferenceId() + " (" + hdi.getMimeType() + ")"); - addMouseListener(new MouseAdapter() { - - @Override - public void mouseClicked(MouseEvent e) { - log.debug("received mouseclick on " + hdi.getReferenceId()); -// saveHashDataListener.actionPerformed(); - JOptionPane.showInputDialog(hashDataInputs.get(row).getReferenceId()); - } - - }); - - return this; - } - } +// } } \ 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 index db66bd52..263c3c04 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java @@ -16,6 +16,7 @@ */ package at.gv.egiz.bku.gui; +import at.gv.egiz.bku.gui.html.RestrictedHTMLEditorKit; import at.gv.egiz.stal.HashDataInput; import java.awt.Component; import java.awt.Container; @@ -45,6 +46,7 @@ import javax.swing.JScrollPane; import javax.swing.LayoutStyle; import javax.swing.text.Document; import javax.swing.text.EditorKit; +import javax.swing.text.StyledEditorKit; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -182,9 +184,11 @@ public class HashDataViewer extends JDialog JEditorPane viewer = new JEditorPane(); if ("text/plain".equals(mimeType)) { + //line wrapping, etc. + viewer.setEditorKit(new StyledEditorKit()); viewer.setFont(new Font(PLAINTEXT_FONT, viewer.getFont().getStyle(), viewer.getFont().getSize())); // } else if ("text/html".equals(mimeType)) { -// viewer.setEditorKitForContentType("text/html", new RestrictedHTMLEditorKit()); +// viewer.setEditorKit(new RestrictedHTMLEditorKit()); } viewer.setEditable(false); viewer.setContentType(mimeType); 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 82b42d0f..fec097f5 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 @@ -81,7 +81,7 @@ public class BKUGUIWorker implements Runnable { }; HashDataInput signedRef1 = new ByteArrayHashDataInput( "Ich bin ein einfacher Text mit Umlauten: öäüßéç@€\n123\n456\n\tHello, world!\n\nlkjsd\nnksdjf".getBytes(), - "ref-id-000000001", + "ref-id-0000000000000000000000001", "text/plain", "UTF-8"); 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 26905f50..d041a8cb 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 @@ -48,7 +48,6 @@ import at.gv.egiz.stal.SignResponse; import at.gv.egiz.stal.signedinfo.ObjectFactory; import at.gv.egiz.stal.signedinfo.SignedInfoType; import at.gv.egiz.stal.util.JCEAlgorithmNames; -import java.awt.event.ActionListener; import java.security.DigestException; import java.util.List; @@ -128,9 +127,6 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen return true; } -// @Override -// public String providePIN(PINSpec spec, int retries) { - class STALPinProvider implements PINProvider { protected SignedInfoType signedInfo; @@ -178,7 +174,7 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen } else if (actionCommand.equals("sign")) { retryCounter++; return new String(gui.getPin()); - } else if (actionCommand.equals("ok")) { + } else if (actionCommand.equals("hashDataDone")) { showSignaturePINDialog(spec, retries); } else if (actionCommand.equals("error")) { return null; -- cgit v1.2.3 From b93f035e2c9df0ad430300c4f755b775a4aa1ed3 Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 24 Nov 2008 13:37:11 +0000 Subject: xhtml warning git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@192 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 3 +- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 15 +++-- .../java/at/gv/egiz/bku/gui/HashDataViewer.java | 72 +++++++++++----------- .../at/gv/egiz/bku/gui/Messages.properties | 3 +- .../at/gv/egiz/bku/gui/Messages_en.properties | 3 +- .../test/java/at/gv/egiz/bku/gui/BKUGUITest.java | 6 +- .../test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java | 5 +- 7 files changed, 59 insertions(+), 48 deletions(-) (limited to 'BKUCommonGUI/src/test/java') 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 7d912f11..d3cb76f2 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 @@ -62,11 +62,12 @@ public interface BKUGUIFacade { 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_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 WARNING_XHTML = "warning.xhtml"; public static final String LABEL_PIN = "label.pin"; public static final String LABEL_PINSIZE = "label.pinsize"; public static final String HELP_WELCOME = "help.welcome"; 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 a190b9c0..c786a291 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 @@ -208,13 +208,16 @@ public class BKUGUIImpl implements BKUGUIFacade { if (background == null) { background = getClass().getResource(DEFAULT_BACKGROUND); } - if ("file".equals(background.getProtocol())) { - log.warn("file:// background images not permitted: " + background); - background = getClass().getResource(DEFAULT_BACKGROUND); + if (background == null) { + contentPanel = new JPanel(); + } else { + if ("file".equals(background.getProtocol())) { + log.warn("file:// background images not permitted: " + background); + background = getClass().getResource(DEFAULT_BACKGROUND); + } + log.debug("loading background " + background); + contentPanel = new ImagePanel(background); } - log.debug("loading background " + background); - contentPanel = new ImagePanel(background); - mainPanel = new JPanel(); mainPanel.setOpaque(false); buttonPanel = new JPanel(); 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 index 777e8960..6c097b2a 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java @@ -125,9 +125,7 @@ public class HashDataViewer extends JDialog InputStreamReader isr = new InputStreamReader(hashDataInput.getHashDataInput(), cs); Reader content = new BufferedReader(isr); - JPanel hashDataPanel = createViewerPanel( - messages.getString(BKUGUIFacade.MESSAGE_HASHDATA), - content, + JPanel hashDataPanel = createViewerPanel(content, hashDataInput.getMimeType(), helpListener); JPanel buttonPanel = createButtonPanel(saveListener, saveCommand); @@ -169,29 +167,28 @@ public class HashDataViewer extends JDialog * @param helpListener may be null * @return */ - private JPanel createViewerPanel(String viewerLabelText, - Reader content, + private JPanel createViewerPanel(Reader content, String mimeType, final ActionListener helpListener) { - log.debug("viewer dialog: " + mimeType); if (mimeType == null) { mimeType = "text/plain"; - } else if ("application/xhtml+xml".equals(mimeType)) { - mimeType = "text/html"; } + log.debug("viewer dialog: " + mimeType); JEditorPane viewer = new JEditorPane(); + viewer.setEditable(false); + viewer.setContentType(mimeType); if ("text/plain".equals(mimeType)) { viewer.setEditorKit(new StyledEditorKit()); viewer.setFont(new Font(PLAINTEXT_FONT, viewer.getFont().getStyle(), viewer.getFont().getSize())); // } else if ("text/html".equals(mimeType)) { // viewer.setEditorKit(new RestrictedHTMLEditorKit()); + } else if ("application/xhtml+xml".equals(mimeType)) { + viewer.setContentType("text/html"); } - viewer.setEditable(false); - viewer.setContentType(mimeType); - + EditorKit editorKit = viewer.getEditorKit(); Document document = editorKit.createDefaultDocument(); // document.putProperty("IgnoreCharsetDirective", new Boolean(true)); @@ -210,15 +207,23 @@ public class HashDataViewer 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); - JPanel viewerPanel = new JPanel(); GroupLayout viewerPanelLayout = new GroupLayout(viewerPanel); viewerPanel.setLayout(viewerPanelLayout); + GroupLayout.SequentialGroup infoHorizontal = viewerPanelLayout.createSequentialGroup(); + GroupLayout.ParallelGroup infoVertical = viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); + + if ("application/xhtml+xml".equals(mimeType)) { + JLabel viewerLabel = new JLabel(); + viewerLabel.setText(messages.getString(BKUGUIFacade.WARNING_XHTML)); + viewerLabel.setFont(viewerLabel.getFont().deriveFont(viewerLabel.getFont().getStyle() | java.awt.Font.BOLD)); + viewerLabel.setLabelFor(viewer); + + infoHorizontal.addComponent(viewerLabel); + infoVertical.addComponent(viewerLabel); + } + if (helpListener != null) { JLabel helpLabel = new JLabel(); helpLabel.setIcon(new ImageIcon(getClass().getResource(BKUGUIFacade.HELP_IMG))); @@ -232,27 +237,24 @@ public class HashDataViewer extends JDialog } }); 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)); + infoHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel); + infoVertical + .addComponent(helpLabel); } + + viewerPanelLayout.setHorizontalGroup( + viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(infoHorizontal) + .addComponent(scrollPane)); + viewerPanelLayout.setVerticalGroup( + viewerPanelLayout.createSequentialGroup() + .addGroup(infoVertical) + .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 88119fe2..a7363421 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 @@ -32,13 +32,14 @@ message.wait=Bitte warten... message.insertcard=Bitte die B\u00FCrgerkarte in den Kartenleser stecken message.enterpin={0} eingeben message.hashdatalink=Signaturdaten anzeigen -message.hashdata=Hinweis: Dies ist eine Voransicht des zu signierenden Inhalts. F\u00FCr eine standardkonforme Darstellung siehe Hilfe (i). +#message.hashdata=Hinweis: Dies ist eine Voransicht des zu signierenden Inhalts. F\u00FCr eine standardkonforme Darstellung siehe Hilfe (i). #message.hashdata=Dies ist eine Voransicht des zu signierenden Inhaltes. F\u00FCr Details siehe Hilfe (i). #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} +warning.xhtml=Hinweis: Dies ist eine Voransicht des zu signierenden Inhalts. F\u00FCr eine standardkonforme Darstellung siehe Hilfe (i). label.pin={0}: label.pinsize=({0} stellig) button.ok=OK 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 63c8bf77..7aae8eae 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 @@ -32,11 +32,12 @@ message.wait=Please wait... message.insertcard=Please insert your citizencard 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. +#message.hashdata=Remark: This is a preview of the data to-be signed. For standards compliant display see help. message.hashdatalist={0} signature data objects: message.retries={0} tries left message.overwrite=Overwrite {0}? message.help=Help topic {0} +warning.xhtml=Remark: This is a preview of the data to-be signed. For standards compliant display see help. label.pin={0}: label.pinsize=({0} digits) button.ok=OK diff --git a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java index 0d2712dd..bc4bdb97 100644 --- a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java +++ b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java @@ -32,15 +32,15 @@ import org.junit.Test; * * @author clemens */ -//@Ignore +@Ignore public class BKUGUITest { @Test public void testBKUGUI() { JFrame testFrame = new JFrame("BKUGUITest"); Container contentPane = testFrame.getContentPane(); - contentPane.setPreferredSize(new Dimension(380, 150)); - BKUGUIFacade gui = BKUGUIFactory.createGUI(contentPane, null, BKUGUIFacade.Style.advanced, null, null); + contentPane.setPreferredSize(new Dimension(190, 130)); + BKUGUIFacade gui = BKUGUIFactory.createGUI(contentPane, null, BKUGUIFacade.Style.simple, null, null); BKUGUIWorker worker = new BKUGUIWorker(); worker.init(gui); testFrame.pack(); 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 fec097f5..4d97f9fb 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 @@ -147,10 +147,13 @@ public class BKUGUIWorker implements Runnable { // // Thread.sleep(2000); // - gui.showSignaturePINDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); +// gui.showSignaturePINDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); // // Thread.sleep(4000); // + + gui.showErrorDialog(BKUGUIFacade.ERR_NO_PCSC, null, null, null); + // gui.showSignaturePINRetryDialog(signPinSpec, 2, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); // // Thread.sleep(2000); -- cgit v1.2.3 From 9ef5d25ffec1c26ccf76ad46131e33a861335da1 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 23 Jan 2009 13:45:39 +0000 Subject: tiny applet git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@286 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 5 +- BKUApplet/src/test/resources/appletTest.html | 12 +- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 4 +- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 140 ++++++++++++++++----- .../at/gv/egiz/bku/gui/HashDataTableModel.java | 21 +++- .../java/at/gv/egiz/bku/gui/HyperlinkRenderer.java | 14 ++- .../at/gv/egiz/bku/gui/Messages.properties | 4 +- .../at/gv/egiz/bku/gui/Messages_en.properties | 5 +- .../test/java/at/gv/egiz/bku/gui/BKUGUITest.java | 4 +- .../test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java | 6 +- 10 files changed, 158 insertions(+), 57 deletions(-) (limited to 'BKUCommonGUI/src/test/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 41dae3ba..5e60ed3e 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -91,8 +91,11 @@ public class BKUApplet extends JApplet implements AppletParameterProvider { log.debug("setting locale to " + getLocale()); BKUGUIFacade.Style guiStyle; - if ("advanced".equals(getAppletParameter(GUI_STYLE))) { + String guiStyleParam = getAppletParameter(GUI_STYLE); + if ("advanced".equals(guiStyleParam)) { guiStyle = BKUGUIFacade.Style.advanced; + } else if ("tiny".equals(guiStyleParam)) { + guiStyle = BKUGUIFacade.Style.tiny; } else { guiStyle = BKUGUIFacade.Style.simple; } diff --git a/BKUApplet/src/test/resources/appletTest.html b/BKUApplet/src/test/resources/appletTest.html index 2bf9ba0c..c8bd99d3 100644 --- a/BKUApplet/src/test/resources/appletTest.html +++ b/BKUApplet/src/test/resources/appletTest.html @@ -19,15 +19,13 @@
- - + width=152 height=145> + + - - + + - - 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 5ee0058f..51906616 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 @@ -63,9 +63,11 @@ public interface BKUGUIFacade { 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_HASHDATALINK_TINY = "message.hashdatalink.tiny"; // 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_LAST_RETRY = "message.retries.last"; public static final String MESSAGE_OVERWRITE = "message.overwrite"; public static final String MESSAGE_HELP = "message.help"; public static final String WARNING_XHTML = "warning.xhtml"; @@ -90,7 +92,7 @@ public interface BKUGUIFacade { public static final String SAVE_HASHDATAINPUT_PREFIX = "save.hashdatainput.prefix"; public static final String ALT_HELP = "alt.help"; - public enum Style { simple, advanced }; + public enum Style { tiny, simple, advanced }; // public void init(Container contentPane, Locale locale, Style guiStyle, URL background, ActionListener helpListener); 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 d61c9a03..1e63c8d7 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 @@ -53,6 +53,7 @@ import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JScrollPane; import javax.swing.JTable; +import javax.swing.JTextField; import javax.swing.LayoutStyle; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; @@ -69,6 +70,10 @@ public class BKUGUIImpl implements BKUGUIFacade { private static final Log log = LogFactory.getLog(BKUGUIImpl.class); + protected enum PinLabelPosition { + LEFT, ABOVE + } + protected HelpMouseListener helpListener; protected Container contentPane; @@ -92,6 +97,9 @@ public class BKUGUIImpl implements BKUGUIFacade { protected boolean renderHeaderPanel = false; protected boolean renderIconPanel = false; protected boolean renderCancelButton = false; + protected boolean shortText = false; + protected PinLabelPosition pinLabelPos = PinLabelPosition.LEFT; + protected boolean renderRefId = false; /** * set contentPane @@ -125,6 +133,10 @@ public class BKUGUIImpl implements BKUGUIFacade { renderHeaderPanel = true; renderIconPanel = false; renderCancelButton = true; + renderRefId = true; + } else if (guiStyle == Style.tiny) { + shortText = true; + pinLabelPos = PinLabelPosition.ABOVE; } registerHelpListener(helpListener); @@ -537,11 +549,21 @@ public class BKUGUIImpl implements BKUGUIFacade { if (numRetries < 0) { infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); String infoPattern = messages.getString(MESSAGE_ENTERPIN); - infoLabel.setText(MessageFormat.format(infoPattern, new Object[] {pinSpec.getLocalizedName()})); + if (shortText) { + infoLabel.setText(MessageFormat.format(infoPattern, new Object[] {"PIN"})); + } else { + infoLabel.setText(MessageFormat.format(infoPattern, new Object[] {pinSpec.getLocalizedName()})); + } helpListener.setHelpTopic(HELP_CARDPIN); } else { + String retryPattern; + if (numRetries < 2) { + retryPattern = messages.getString(MESSAGE_LAST_RETRY); + } else { + retryPattern = messages.getString(MESSAGE_RETRIES); + } infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); - infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); + infoLabel.setText(MessageFormat.format(retryPattern, new Object[]{String.valueOf(numRetries)})); infoLabel.setForeground(ERROR_COLOR); helpListener.setHelpTopic(HELP_RETRY); } @@ -570,27 +592,47 @@ public class BKUGUIImpl implements BKUGUIFacade { infoVertical .addComponent(helpLabel); } - - mainPanelLayout.setHorizontalGroup( - mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(infoHorizontal) + + GroupLayout.Group pinHorizontal; + GroupLayout.Group pinVertical; + + if (pinLabelPos == PinLabelPosition.ABOVE) { + pinHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) //)) - .addComponent(pinsizeLabel)))); - mainPanelLayout.setVerticalGroup( - mainPanelLayout.createSequentialGroup() - .addGroup(infoVertical) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(pinsizeLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)); + pinVertical = mainPanelLayout.createSequentialGroup() + .addComponent(cardPinLabel) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(cardPinLabel) - .addComponent(pinField)) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); + } else { + pinHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(cardPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(pinsizeLabel)); - - + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(pinsizeLabel)); + pinVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(cardPinLabel) + .addComponent(pinField); + } + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(infoHorizontal) + .addGroup(pinHorizontal)); + + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() + .addGroup(infoVertical) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(pinVertical) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinsizeLabel)); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); @@ -707,7 +749,11 @@ public class BKUGUIImpl implements BKUGUIFacade { JLabel infoLabel = new JLabel(); if (numRetries < 0) { infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - infoLabel.setText(messages.getString(MESSAGE_HASHDATALINK)); + if (shortText) { + infoLabel.setText(messages.getString(MESSAGE_HASHDATALINK_TINY)); + } else { + infoLabel.setText(messages.getString(MESSAGE_HASHDATALINK)); + } infoLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); infoLabel.setForeground(HYPERLINK_COLOR); infoLabel.addMouseListener(new MouseAdapter() { @@ -720,8 +766,14 @@ public class BKUGUIImpl implements BKUGUIFacade { }); helpListener.setHelpTopic(HELP_SIGNPIN); } else { + String retryPattern; + if (numRetries < 2) { + retryPattern = messages.getString(MESSAGE_LAST_RETRY); + } else { + retryPattern = messages.getString(MESSAGE_RETRIES); + } + infoLabel.setText(MessageFormat.format(retryPattern, new Object[]{String.valueOf(numRetries)})); infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); - infoLabel.setText(MessageFormat.format(messages.getString(MESSAGE_RETRIES), new Object[]{String.valueOf(numRetries)})); infoLabel.setForeground(ERROR_COLOR); helpListener.setHelpTopic(HELP_RETRY); } @@ -737,28 +789,48 @@ public class BKUGUIImpl implements BKUGUIFacade { if (!renderHeaderPanel) { infoHorizontal .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel); //, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); + .addComponent(helpLabel); infoVertical .addComponent(helpLabel); } + GroupLayout.Group pinHorizontal; + GroupLayout.Group pinVertical; + + if (pinLabelPos == PinLabelPosition.ABOVE) { + pinHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(mainPanelLayout.createSequentialGroup() + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(pinsizeLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)); + + pinVertical = mainPanelLayout.createSequentialGroup() + .addComponent(signPinLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); + } else { + pinHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(pinsizeLabel)); + pinVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(signPinLabel) + .addComponent(pinField); + } + mainPanelLayout.setHorizontalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(infoHorizontal) - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(pinsizeLabel)))); + .addGroup(pinHorizontal)); mainPanelLayout.setVerticalGroup( mainPanelLayout.createSequentialGroup() .addGroup(infoVertical) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(signPinLabel) - .addComponent(pinField)) + .addGroup(pinVertical) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(pinsizeLabel)); @@ -1084,9 +1156,9 @@ public class BKUGUIImpl implements BKUGUIFacade { String refIdLabelPattern = messages.getString(MESSAGE_HASHDATALIST); refIdLabel.setText(MessageFormat.format(refIdLabelPattern, new Object[]{signedReferences.size()})); - HashDataTableModel tableModel = new HashDataTableModel(signedReferences); + HashDataTableModel tableModel = new HashDataTableModel(signedReferences, renderRefId); final JTable hashDataTable = new JTable(tableModel); - hashDataTable.setDefaultRenderer(HashDataInput.class, new HyperlinkRenderer()); + hashDataTable.setDefaultRenderer(HashDataInput.class, new HyperlinkRenderer(renderRefId)); hashDataTable.setTableHeader(null); // not possible to add mouse listener to TableCellRenderer 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 b0f51a78..70842102 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 @@ -31,14 +31,23 @@ class HashDataTableModel extends DefaultTableModel { protected static final Log log = LogFactory.getLog(HashDataTableModel.class); /** HashDataInput in first column, register hyperlinkrenderer only here */ - protected Class[] types = new Class[]{ HashDataInput.class, String.class }; + protected Class[] types; protected List hashDataInputs; - - public HashDataTableModel(List hashDataInputs) { - super(0, 2); + + public HashDataTableModel(List hashDataInputs, boolean twoColLayout) { + super(0, (twoColLayout) ? 2 : 1); this.hashDataInputs = hashDataInputs; - for (HashDataInput hdi : hashDataInputs) { - addRow(new Object[]{ hdi, hdi.getMimeType()}); + + if (twoColLayout) { + types = new Class[] { HashDataInput.class, String.class }; + for (HashDataInput hdi : hashDataInputs) { + addRow(new Object[] { hdi, hdi.getMimeType() }); + } + } else { + types = new Class[] { HashDataInput.class }; + for (HashDataInput hdi : hashDataInputs) { + addRow(new Object[] { hdi }); + } } } 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 index f983706e..16024fcc 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperlinkRenderer.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HyperlinkRenderer.java @@ -26,13 +26,25 @@ import javax.swing.table.DefaultTableCellRenderer; */ public class HyperlinkRenderer extends DefaultTableCellRenderer { + protected boolean renderReferenceId; + + public HyperlinkRenderer(boolean renderReferenceId) { + this.renderReferenceId = renderReferenceId; + } + /** * cannot change mouse cursor here, do in jTable * @param value */ @Override protected void setValue(Object value) { - super.setText("" + ((HashDataInput) value).getReferenceId() + ""); + String hrefText; + if (renderReferenceId) { + hrefText = ((HashDataInput) value).getReferenceId(); + } else { + hrefText = ((HashDataInput) value).getMimeType(); + } + super.setText("" + hrefText + ""); setForeground(BKUGUIFacade.HYPERLINK_COLOR); } } 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 d2b47a9d..4562fda5 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 @@ -32,11 +32,13 @@ message.wait=Bitte warten... message.insertcard=Bitte die B\u00FCrgerkarte in den Kartenleser stecken message.enterpin={0} eingeben message.hashdatalink=Signaturdaten anzeigen +message.hashdatalink.tiny=Signaturdaten #message.hashdata=Hinweis: Dies ist eine Voransicht des zu signierenden Inhalts. F\u00FCr eine standardkonforme Darstellung siehe Hilfe (i). #message.hashdata=Dies ist eine Voransicht des zu signierenden Inhaltes. F\u00FCr Details siehe Hilfe (i). #verwenden sie bitte die von ihrem System zur Verf\u00FCgung gestellte {0} Anwendung. message.hashdatalist={0} Signaturdaten: -message.retries=Noch {0} Versuch(e) +message.retries.last=Letzter Versuch! +message.retries=Noch {0} Versuche message.overwrite=M\u00F6chten Sie das existierende Dokument {0} \u00FCberschreiben? message.help=Hilfe zu {0} warning.xhtml=Hinweis: Dies ist eine Voransicht des zu signierenden Inhalts. F\u00FCr eine standardkonforme Darstellung siehe Hilfe (i). 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 524a2a98..0faa3dba 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 @@ -32,8 +32,10 @@ message.wait=Please wait... message.insertcard=Please insert your citizen card into the reader message.enterpin=Enter {0} message.hashdatalink=Display signature data +message.hashdatalink.tiny=signature data #message.hashdata=Remark: This is a preview of the data to-be signed. For standards compliant display see help. message.hashdatalist={0} signature data objects: +message.retries.last=Last try! message.retries={0} tries left message.overwrite=Overwrite {0}? message.help=Help topic {0} @@ -60,7 +62,8 @@ error.no.hashdata=No signature data available: {0} error.display.hashdata=Could not display signature data: {0} error.write.hashdata=Could not save signature data: {0} error.invalid.hash=Invalid signature data: {0} -error.ws.unreachable=Web-service unreachable: {0} +error.ws.unreachable=Server unreachable +#error.ws.unreachable=Web-service unreachable: {0} error.pcsc=No PC/SC interface for smartcard access provided error.cardterminal=Could not find smartcard reader error.unknown=An error occured: {0} diff --git a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java index bc4bdb97..d413f812 100644 --- a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java +++ b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java @@ -39,8 +39,8 @@ public class BKUGUITest { public void testBKUGUI() { JFrame testFrame = new JFrame("BKUGUITest"); Container contentPane = testFrame.getContentPane(); - contentPane.setPreferredSize(new Dimension(190, 130)); - BKUGUIFacade gui = BKUGUIFactory.createGUI(contentPane, null, BKUGUIFacade.Style.simple, null, null); + contentPane.setPreferredSize(new Dimension(170, 150)); + BKUGUIFacade gui = BKUGUIFactory.createGUI(contentPane, null, BKUGUIFacade.Style.tiny, null, null); BKUGUIWorker worker = new BKUGUIWorker(); worker.init(gui); testFrame.pack(); 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 4d97f9fb..73aaab46 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 @@ -142,17 +142,17 @@ public class BKUGUIWorker implements Runnable { // Thread.sleep(2000); // // PINSpec cardPinSpec = new PINSpec(4, 4, "[0-9]", "Karten-PIN"); -// +// // gui.showCardPINDialog(cardPinSpec, okListener, "ok", cancelListener, "cancel"); // // Thread.sleep(2000); // -// gui.showSignaturePINDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); + gui.showSignaturePINDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); // // Thread.sleep(4000); // - gui.showErrorDialog(BKUGUIFacade.ERR_NO_PCSC, null, null, null); +// gui.showErrorDialog(BKUGUIFacade.ERR_NO_PCSC, null, null, null); // gui.showSignaturePINRetryDialog(signPinSpec, 2, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); // -- cgit v1.2.3 From ff9a71fe2a2beb94ad7aa52ba2c77a24dd39509e Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 11 Feb 2009 20:04:58 +0000 Subject: removed BKUGUIFactory git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@297 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 1 + .../java/at/gv/egiz/bku/gui/BKUGUIFactory.java | 34 ---------------------- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 4 +-- .../at/gv/egiz/bku/gui/Messages.properties | 3 +- .../at/gv/egiz/bku/gui/Messages_en.properties | 3 +- .../test/java/at/gv/egiz/bku/gui/BKUGUITest.java | 2 +- 6 files changed, 7 insertions(+), 40 deletions(-) delete mode 100644 BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java (limited to 'BKUCommonGUI/src/test/java') 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 51906616..6fd29ba9 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 @@ -25,6 +25,7 @@ import java.util.Locale; public interface BKUGUIFacade { + public static final String ERR_UNKNOWN_WITH_PARAM = "error.unknown.param"; 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"; diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java deleted file mode 100644 index 998aaa86..00000000 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUGUIFactory.java +++ /dev/null @@ -1,34 +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 java.awt.Container; -import java.awt.event.ActionListener; -import java.net.URL; -import java.util.Locale; - -public class BKUGUIFactory { - - public static BKUGUIFacade createGUI(Container contentPane, - Locale locale, - BKUGUIFacade.Style style, - URL background, - ActionListener helpListener) { - return new BKUGUIImpl(contentPane, locale, style, background, helpListener); - } -} 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 1e63c8d7..f564c07a 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 @@ -19,14 +19,12 @@ package at.gv.egiz.bku.gui; import at.gv.egiz.smcc.PINSpec; import at.gv.egiz.stal.HashDataInput; -import at.gv.egiz.stal.impl.ByteArrayHashDataInput; import java.awt.Container; import java.awt.Cursor; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; import java.awt.event.MouseMotionAdapter; import java.io.BufferedOutputStream; import java.io.File; @@ -68,7 +66,7 @@ import org.apache.commons.logging.LogFactory; */ public class BKUGUIImpl implements BKUGUIFacade { - private static final Log log = LogFactory.getLog(BKUGUIImpl.class); + protected static final Log log = LogFactory.getLog(BKUGUIImpl.class); protected enum PinLabelPosition { LEFT, ABOVE 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 4562fda5..8436a730 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 @@ -68,7 +68,8 @@ error.ws.unreachable=Der Server ist nicht erreichbar #error.ws.unreachable=Das Web-Service ist nicht erreichbar: {0} error.pcsc=Es konnte keine PC/SC Schnittstelle gefunden werden error.cardterminal=Es konnte kein Smartcard-Leser gefunden werden -error.unknown=Leider trat ein Fehler auf: {0} +error.unknown.param=Ein Fehler trat auf: {0} +error.unknown=Ein Fehler trat auf error.test=Fehler1 {0} - Fehler2 {1} error.card.locked=B\u00FCrgerkarte ist gesperrt error.card.notactivated=B\u00FCrgerkartenfunktion ist nicht aktiviert 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 0faa3dba..4fbccd5b 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 @@ -66,7 +66,8 @@ error.ws.unreachable=Server unreachable #error.ws.unreachable=Web-service unreachable: {0} error.pcsc=No PC/SC interface for smartcard access provided error.cardterminal=Could not find smartcard reader -error.unknown=An error occured: {0} +error.unknown.param=An error occured: {0} +error.unknown=An error occured error.test=Error1 {0} - Error2 {1} error.card.locked=Citizen card is locked error.card.notactivated=Citizen card not activated diff --git a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java index d413f812..c8cff617 100644 --- a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java +++ b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java @@ -40,7 +40,7 @@ public class BKUGUITest { JFrame testFrame = new JFrame("BKUGUITest"); Container contentPane = testFrame.getContentPane(); contentPane.setPreferredSize(new Dimension(170, 150)); - BKUGUIFacade gui = BKUGUIFactory.createGUI(contentPane, null, BKUGUIFacade.Style.tiny, null, null); + BKUGUIFacade gui = new BKUGUIImpl(contentPane, null, BKUGUIFacade.Style.tiny, null, null); BKUGUIWorker worker = new BKUGUIWorker(); worker.init(gui); testFrame.pack(); -- cgit v1.2.3 From 6576428966f1e3d688269a407b072fb01f9f7647 Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 26 Feb 2009 19:39:00 +0000 Subject: 1.1 candidate (activation) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@309 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/online/applet/AppletBKUWorker.java | 9 +- .../java/at/gv/egiz/bku/gui/PINManagementGUI.java | 519 ++++- .../at/gv/egiz/bku/gui/PINManagementGUIFacade.java | 47 +- .../java/at/gv/egiz/bku/gui/PINSpecRenderer.java | 39 + .../java/at/gv/egiz/bku/gui/PINStatusProvider.java | 32 - .../java/at/gv/egiz/bku/gui/PINStatusRenderer.java | 63 + .../at/gv/egiz/bku/gui/PINStatusTableModel.java | 60 + .../bku/online/applet/PINManagementApplet.java | 3 +- .../bku/online/applet/PINManagementBKUWorker.java | 82 +- .../smccstal/ext/PINManagementRequestHandler.java | 331 ++++ .../bku/smccstal/ext/PINMgmtRequestHandler.java | 93 - .../gv/egiz/bku/gui/ActivationMessages.properties | 28 +- .../egiz/bku/gui/ActivationMessages_en.properties | 30 +- .../test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java | 4 +- BKUAppletExt/src/test/resources/appletTest.html | 2 +- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 8 +- .../main/java/at/gv/egiz/bku/gui/PinDocument.java | 28 +- .../at/gv/egiz/bku/gui/Messages.properties | 4 +- .../test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java | 2 +- .../at/gv/egiz/stal/ext/ActivatePINRequest.java | 28 - .../java/at/gv/egiz/stal/ext/ChangePINRequest.java | 28 - .../at/gv/egiz/stal/ext/PINManagementRequest.java | 31 + .../at/gv/egiz/stal/ext/PINManagementResponse.java | 28 + .../at/gv/egiz/stal/ext/UnblockPINRequest.java | 28 - .../egiz/bku/slcommands/impl/xsect/DataObject.java | 2078 ++++++++++---------- .../egiz/bku/slcommands/impl/xsect/Signature.java | 5 +- .../bku/slcommands/impl/xsect/SignatureTest.java | 1505 +++++++------- .../egiz/bku/slcommands/impl/TransformsInfo_2.xml | 397 ++++ smcc/src/main/java/at/gv/egiz/smcc/ACOSCard.java | 25 +- .../at/gv/egiz/smcc/AbstractSignatureCard.java | 10 + smcc/src/main/java/at/gv/egiz/smcc/PINSpec.java | 30 +- .../src/main/java/at/gv/egiz/smcc/STARCOSCard.java | 25 +- smcc/src/main/java/at/gv/egiz/smcc/SWCard.java | 14 +- .../main/java/at/gv/egiz/smcc/SignatureCard.java | 5 +- .../at/gv/egiz/bku/smccstal/AbstractBKUWorker.java | 3 + .../java/at/gv/egiz/smcc/AbstractSMCCSTALTest.java | 9 +- .../java/at/gv/egiz/marshal/NamespacePrefix.java | 34 + .../gv/egiz/marshal/NamespacePrefixMapperImpl.java | 16 +- .../at/gv/egiz/slbinding/RedirectEventFilter.java | 389 ++-- .../gv/egiz/slbinding/impl/TransformsInfoType.java | 1 + .../at/gv/egiz/slbinding/impl/XMLContentType.java | 2 +- .../org/w3/_2000/_09/xmldsig_/ObjectFactory.java | 1 + .../org/w3/_2000/_09/xmldsig_/TransformsType.java | 2 +- .../java/at/gv/egiz/slbinding/RedirectTest.java | 29 +- .../CreateXMLSignatureRequest02.xml_redirect.txt | 5 +- 45 files changed, 3813 insertions(+), 2299 deletions(-) create mode 100644 BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINSpecRenderer.java delete mode 100644 BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINStatusProvider.java create mode 100644 BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINStatusRenderer.java create mode 100644 BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINStatusTableModel.java create mode 100644 BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PINManagementRequestHandler.java delete mode 100644 BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PINMgmtRequestHandler.java delete mode 100644 STALExt/src/main/java/at/gv/egiz/stal/ext/ActivatePINRequest.java delete mode 100644 STALExt/src/main/java/at/gv/egiz/stal/ext/ChangePINRequest.java create mode 100644 STALExt/src/main/java/at/gv/egiz/stal/ext/PINManagementRequest.java create mode 100644 STALExt/src/main/java/at/gv/egiz/stal/ext/PINManagementResponse.java delete mode 100644 STALExt/src/main/java/at/gv/egiz/stal/ext/UnblockPINRequest.java create mode 100644 bkucommon/src/test/resources/at/gv/egiz/bku/slcommands/impl/TransformsInfo_2.xml create mode 100644 utils/src/main/java/at/gv/egiz/marshal/NamespacePrefix.java (limited to 'BKUCommonGUI/src/test/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 5a57ef18..8c1bd2bd 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java @@ -195,11 +195,16 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { } } + /** + * + * @param err_code + * @param ex if not null, the message will be appended as parameter to the error message + */ protected void showErrorDialog(String err_code, Exception ex) { actionCommandList.clear(); actionCommandList.add("ok"); - gui.showErrorDialog(err_code, - new Object[]{ex.getMessage()}, this, "ok"); + Object[] params = (ex != null) ? new Object[] { ex.getMessage() } : null; + gui.showErrorDialog(err_code, params, this, "ok"); try { waitForAction(); } catch (InterruptedException e) { diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUI.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUI.java index 8acf051e..8eef8aea 100644 --- a/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUI.java +++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUI.java @@ -17,15 +17,28 @@ package at.gv.egiz.bku.gui; +import at.gv.egiz.smcc.PINSpec; import java.awt.Container; +import java.awt.Cursor; +import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionAdapter; import java.net.URL; +import java.text.MessageFormat; import java.util.Locale; +import java.util.Map; import javax.swing.GroupLayout; import javax.swing.JButton; import javax.swing.JLabel; +import javax.swing.JPasswordField; +import javax.swing.JScrollPane; +import javax.swing.JTable; import javax.swing.LayoutStyle; +import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; /** * TODO pull out ResourceBundle to common superclass for activationGUI and pinMgmtGUI @@ -33,9 +46,10 @@ import javax.swing.SwingUtilities; */ public class PINManagementGUI extends ActivationGUI implements PINManagementGUIFacade { - public static final String BUTTON_ACTIVATE = "button.activate"; - public static final String BUTTON_UNBLOCK = "button.unblock"; - public static final String BUTTON_CHANGE = "button.change"; + /** remember the pinfield to return to worker */ + protected JPasswordField oldPinField; + /** remember the pinSpec to return to worker */ + protected PINSpec pinSpec; public PINManagementGUI(Container contentPane, Locale locale, @@ -46,12 +60,31 @@ public class PINManagementGUI extends ActivationGUI implements PINManagementGUIF } @Override - public void showPINManagementDialog(final PINStatusProvider pinStatusProvider, - final ActionListener activateListener, final String activateCmd, - final ActionListener changeListener, final String changeCmd, - final ActionListener unblockListener, final String unblockCmd, - final ActionListener cancelListener, final String cancelCmd) { -// try { + public char[] getOldPin() { + if (oldPinField != null) { + char[] pin = oldPinField.getPassword(); + oldPinField = null; + return pin; + } + return null; + } + + @Override + public PINSpec getSelectedPIN() { + return pinSpec; + } + + @Override + public void showPINManagementDialog(final Map pins, + final ActionListener activateListener, + final String activateCmd, + final String changeCmd, + final String unblockCmd, + final ActionListener cancelListener, + final String cancelCmd) { + + log.debug("scheduling PIN managment dialog"); + SwingUtilities.invokeLater(new Runnable() { @Override @@ -68,13 +101,76 @@ public class PINManagementGUI extends ActivationGUI implements PINManagementGUIF if (renderHeaderPanel) { titleLabel.setText(cardmgmtMessages.getString(TITLE_PINMGMT)); - mgmtLabel.setText(cardmgmtMessages.getString(MESSAGE_PINMGMT)); + String infoPattern = cardmgmtMessages.getString(MESSAGE_PINMGMT); + mgmtLabel.setText(MessageFormat.format(infoPattern, pins.size())); } else { mgmtLabel.setText(cardmgmtMessages.getString(TITLE_PINMGMT)); } + final PINStatusTableModel tableModel = new PINStatusTableModel(pins); + final JTable pinStatusTable = new JTable(tableModel); + pinStatusTable.setDefaultRenderer(PINSpec.class, new PINSpecRenderer()); + pinStatusTable.setDefaultRenderer(STATUS.class, new PINStatusRenderer(cardmgmtMessages)); + pinStatusTable.setTableHeader(null); - + pinStatusTable.addMouseMotionListener(new MouseMotionAdapter() { + + @Override + public void mouseMoved(MouseEvent e) { + if (pinStatusTable.columnAtPoint(e.getPoint()) == 0) { + pinStatusTable.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + } else { + pinStatusTable.setCursor(Cursor.getDefaultCursor()); + } + } + }); + + final JButton activateButton = new JButton(); + activateButton.setFont(activateButton.getFont().deriveFont(activateButton.getFont().getStyle() & ~java.awt.Font.BOLD)); + activateButton.addActionListener(activateListener); + + pinStatusTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + pinStatusTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + + @Override + public void valueChanged(final ListSelectionEvent e) { + //invoke later to allow thread to paint selection background + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + ListSelectionModel lsm = (ListSelectionModel) e.getSource(); + int selectionIdx = lsm.getMinSelectionIndex(); + if (selectionIdx >= 0) { + pinSpec = (PINSpec) tableModel.getValueAt(selectionIdx, 0); + STATUS status = (STATUS) tableModel.getValueAt(selectionIdx, 1); + + if (status == STATUS.NOT_ACTIV) { + activateButton.setText(cardmgmtMessages.getString(BUTTON_ACTIVATE)); + activateButton.setEnabled(true); + activateButton.setActionCommand(activateCmd); + } else if (status == STATUS.BLOCKED) { + activateButton.setText(cardmgmtMessages.getString(BUTTON_UNBLOCK)); + activateButton.setEnabled(true); + activateButton.setActionCommand(unblockCmd); + } else if (status == STATUS.ACTIV) { + activateButton.setText(cardmgmtMessages.getString(BUTTON_CHANGE)); + activateButton.setEnabled(true); + activateButton.setActionCommand(changeCmd); + } else { + activateButton.setText(cardmgmtMessages.getString(BUTTON_ACTIVATE)); + activateButton.setEnabled(false); + } + } + } + }); + } + }); + + //select first entry + pinStatusTable.getSelectionModel().setSelectionInterval(0, 0); + + JScrollPane pinStatusScrollPane = new JScrollPane(pinStatusTable); GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); @@ -91,30 +187,16 @@ public class PINManagementGUI extends ActivationGUI implements PINManagementGUIF .addComponent(helpLabel); } - mainPanelLayout.setHorizontalGroup(messageHorizontal); - mainPanelLayout.setVerticalGroup(messageVertical); + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(messageHorizontal) + .addComponent(pinStatusScrollPane, 0, 0, Short.MAX_VALUE)); - - JButton activateButton = new JButton(); - activateButton.setFont(activateButton.getFont().deriveFont(activateButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - activateButton.setText(cardmgmtMessages.getString(BUTTON_ACTIVATE)); - activateButton.setEnabled(true);//false); - activateButton.setActionCommand(activateCmd); - activateButton.addActionListener(activateListener); - - JButton changeButton = new JButton(); - changeButton.setFont(activateButton.getFont().deriveFont(activateButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - changeButton.setText(cardmgmtMessages.getString(BUTTON_CHANGE)); - changeButton.setEnabled(false); - changeButton.setActionCommand(changeCmd); - changeButton.addActionListener(changeListener); - - JButton unblockButton = new JButton(); - unblockButton.setFont(activateButton.getFont().deriveFont(activateButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - unblockButton.setText(cardmgmtMessages.getString(BUTTON_UNBLOCK)); - unblockButton.setEnabled(false); - unblockButton.setActionCommand(unblockCmd); - unblockButton.addActionListener(unblockListener); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() + .addGroup(messageVertical) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinStatusScrollPane, 0, 0, pinStatusTable.getPreferredSize().height+3)); JButton cancelButton = new JButton(); cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -129,30 +211,377 @@ public class PINManagementGUI extends ActivationGUI implements PINManagementGUIF .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(activateButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(changeButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(unblockButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); GroupLayout.Group buttonVertical = buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(activateButton) - .addComponent(changeButton) - .addComponent(unblockButton) .addComponent(cancelButton); buttonPanelLayout.setHorizontalGroup(buttonHorizontal); buttonPanelLayout.setVerticalGroup(buttonVertical); contentPanel.validate(); - } }); + } + + @Override + public void showActivatePINDialog(final PINSpec pin, + final ActionListener okListener, final String okCommand, + final ActionListener cancelListener, final String cancelCommand) { + log.debug("scheduling activate pin dialog"); + showPINDialog(false, pin, okListener, okCommand, cancelListener, cancelCommand); + } + + + private void showPINDialog(final boolean changePin, final PINSpec pinSpec, + final ActionListener okListener, final String okCommand, + final ActionListener cancelListener, final String cancelCommand) { + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + String HELP_TOPIC, TITLE, MESSAGE_MGMT; + if (changePin) { + log.debug("show change pin dialog"); + HELP_TOPIC = HELP_PINMGMT; + TITLE = TITLE_CHANGE_PIN; + MESSAGE_MGMT = MESSAGE_CHANGE_PIN; + } else { + log.debug("show activate pin dialog"); + HELP_TOPIC = HELP_PINMGMT; + TITLE = TITLE_ACTIVATE_PIN; + MESSAGE_MGMT = MESSAGE_ACTIVATE_PIN; + oldPinField = null; + } + + mainPanel.removeAll(); + buttonPanel.removeAll(); + + helpListener.setHelpTopic(HELP_TOPIC); + + JLabel mgmtLabel = new JLabel(); + mgmtLabel.setFont(mgmtLabel.getFont().deriveFont(mgmtLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + + if (renderHeaderPanel) { + titleLabel.setText(cardmgmtMessages.getString(TITLE)); + String mgmtPattern = cardmgmtMessages.getString(MESSAGE_MGMT); + if (shortText) { + mgmtLabel.setText(MessageFormat.format(mgmtPattern, "PIN")); + } else { + mgmtLabel.setText(MessageFormat.format(mgmtPattern, pinSpec.getLocalizedName())); + } + } else { + mgmtLabel.setText(cardmgmtMessages.getString(TITLE)); + } + + JButton okButton = new JButton(); + okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); + okButton.setText(messages.getString(BUTTON_OK)); + okButton.setEnabled(false); + okButton.setActionCommand(okCommand); + okButton.addActionListener(okListener); + + JLabel pinLabel = new JLabel(); + pinLabel.setFont(pinLabel.getFont().deriveFont(pinLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + String pinLabelPattern = (changePin) ? cardmgmtMessages.getString(LABEL_NEW_PIN) : messages.getString(LABEL_PIN); + pinLabel.setText(MessageFormat.format(pinLabelPattern, new Object[]{pinSpec.getLocalizedName()})); + + final JPasswordField repeatPinField = new JPasswordField(); + pinField = new JPasswordField(); + pinField.setText(""); + pinField.setDocument(new PINDocument(pinSpec, null)); + pinField.setActionCommand(okCommand); + pinField.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + if (pinField.getPassword().length >= pinSpec.getMinLength()) { + repeatPinField.requestFocusInWindow(); + } + } + }); + JLabel repeatPinLabel = new JLabel(); + repeatPinLabel.setFont(pinLabel.getFont()); + String repeatPinLabelPattern = cardmgmtMessages.getString(LABEL_REPEAT_PIN); + repeatPinLabel.setText(MessageFormat.format(repeatPinLabelPattern, new Object[]{pinSpec.getLocalizedName()})); + + repeatPinField.setText(""); + repeatPinField.setDocument(new PINDocument(pinSpec, okButton, pinField.getDocument())); + repeatPinField.setActionCommand(okCommand); + repeatPinField.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + if (pinField.getPassword().length >= pinSpec.getMinLength()) { + okListener.actionPerformed(e); + } + } + }); + + JLabel oldPinLabel = null; + if (changePin) { + oldPinLabel = new JLabel(); + oldPinLabel.setFont(oldPinLabel.getFont().deriveFont(oldPinLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + String oldPinLabelPattern = cardmgmtMessages.getString(LABEL_OLD_PIN); + oldPinLabel.setText(MessageFormat.format(oldPinLabelPattern, new Object[]{pinSpec.getLocalizedName()})); + + oldPinField = new JPasswordField(); + oldPinField.setText(""); + oldPinField.setDocument(new PINDocument(pinSpec, null)); + oldPinField.setActionCommand(okCommand); + oldPinField.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + if (oldPinField.getPassword().length >= pinSpec.getMinLength()) { + pinField.requestFocusInWindow(); + } + } + }); + } + + JLabel pinsizeLabel = new JLabel(); + pinsizeLabel.setFont(pinsizeLabel.getFont().deriveFont(pinsizeLabel.getFont().getStyle() & ~java.awt.Font.BOLD, pinsizeLabel.getFont().getSize()-2)); + String pinsizePattern = messages.getString(LABEL_PINSIZE); + String pinSize = String.valueOf(pinSpec.getMinLength()); + if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { + pinSize += "-" + pinSpec.getMaxLength(); + } + pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + GroupLayout.SequentialGroup infoHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(mgmtLabel); + GroupLayout.ParallelGroup infoVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(mgmtLabel); + + if (!renderHeaderPanel) { + infoHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel); + infoVertical + .addComponent(helpLabel); + } -// } catch (Exception ex) { -// log.error(ex.getMessage(), ex); -// showErrorDialog(ERR_UNKNOWN_WITH_PARAM, new Object[] {ex.getMessage()}); -// } + GroupLayout.ParallelGroup pinHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); + GroupLayout.SequentialGroup pinVertical = mainPanelLayout.createSequentialGroup(); + + if (pinLabelPos == PinLabelPosition.ABOVE) { + if (changePin) { + pinHorizontal + .addComponent(oldPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(oldPinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE); + pinVertical + .addComponent(oldPinLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(oldPinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED); + } + pinHorizontal + .addComponent(pinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(repeatPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(repeatPinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(mainPanelLayout.createSequentialGroup() + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(pinsizeLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)); + pinVertical + .addComponent(pinLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(repeatPinLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(repeatPinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinsizeLabel); + } else { + if (changePin) { + pinHorizontal + .addGroup(mainPanelLayout.createSequentialGroup() + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(oldPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(pinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(repeatPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(oldPinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(repeatPinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); + + pinVertical + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(oldPinLabel) + .addComponent(oldPinField)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED); + } else { + pinHorizontal + .addGroup(mainPanelLayout.createSequentialGroup() + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(pinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addComponent(repeatPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(repeatPinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); + + } + pinHorizontal + .addGroup(mainPanelLayout.createSequentialGroup() + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(pinsizeLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)); + pinVertical + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(pinLabel) + .addComponent(pinField)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(repeatPinLabel) + .addComponent(repeatPinField)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinsizeLabel); + } + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(infoHorizontal) + .addGroup(pinHorizontal)); + + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() + .addGroup(infoVertical) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addGroup(pinVertical)); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); + GroupLayout.Group buttonVertical; + + JButton cancelButton = new JButton(); + cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); + cancelButton.setText(messages.getString(BUTTON_CANCEL)); + cancelButton.setActionCommand(cancelCommand); + cancelButton.addActionListener(cancelListener); + + buttonHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); + buttonVertical = buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(okButton) + .addComponent(cancelButton); + + buttonPanelLayout.setHorizontalGroup(buttonHorizontal); + buttonPanelLayout.setVerticalGroup(buttonVertical); + + if (oldPinField != null) { + oldPinField.requestFocusInWindow(); + } else { + pinField.requestFocusInWindow(); + } + contentPanel.validate(); + + } + }); + } + + @Override + public void showChangePINDialog(final PINSpec pin, + final ActionListener okListener, final String okCommand, + final ActionListener cancelListener, final String cancelCommand) { + + log.debug("scheduling change pin dialog"); + showPINDialog(true, pin, okListener, okCommand, cancelListener, cancelCommand); + } + + @Override + public void showUnblockPINDialog(final PINSpec pin, + final ActionListener okListener, final String okCommand, + final ActionListener cancelListener, final String cancelCommand) { + + log.debug("scheduling unblock PIN dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show unblock PIN dialog"); + + log.error("unblock pin not supported"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); + + if (renderHeaderPanel) { + titleLabel.setText(messages.getString(TITLE_ERROR)); + } + + helpListener.setHelpTopic(HELP_PINMGMT); + + String errorMsgPattern = cardmgmtMessages.getString(ERR_UNBLOCK); + String errorMsg = MessageFormat.format(errorMsgPattern, pin.getLocalizedName()); + + JLabel errorMsgLabel = new JLabel(); + errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + errorMsgLabel.setText(errorMsg); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + GroupLayout.ParallelGroup mainHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); + GroupLayout.SequentialGroup mainVertical = mainPanelLayout.createSequentialGroup(); + + if (!renderHeaderPanel) { + JLabel errorTitleLabel = new JLabel(); + errorTitleLabel.setFont(errorTitleLabel.getFont().deriveFont(errorTitleLabel.getFont().getStyle() | java.awt.Font.BOLD)); + errorTitleLabel.setText(messages.getString(TITLE_ERROR)); + errorTitleLabel.setForeground(ERROR_COLOR); + + mainHorizontal + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(errorTitleLabel) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel)); + mainVertical + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(errorTitleLabel) + .addComponent(helpLabel)); + } + + mainPanelLayout.setHorizontalGroup(mainHorizontal + .addComponent(errorMsgLabel)); + mainPanelLayout.setVerticalGroup(mainVertical + .addComponent(errorMsgLabel)); + + JButton okButton = new JButton(); + okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); + okButton.setText(messages.getString(BUTTON_OK)); + okButton.setActionCommand(cancelCommand); + okButton.addActionListener(cancelListener); + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + buttonPanelLayout.setHorizontalGroup( + buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); + buttonPanelLayout.setVerticalGroup( + buttonPanelLayout.createSequentialGroup() + .addComponent(okButton)); + + contentPanel.validate(); + } + }); } diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUIFacade.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUIFacade.java index 3d653fab..2a8f28d2 100644 --- a/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUIFacade.java +++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUIFacade.java @@ -17,7 +17,9 @@ package at.gv.egiz.bku.gui; +import at.gv.egiz.smcc.PINSpec; import java.awt.event.ActionListener; +import java.util.Map; /** * @@ -27,8 +29,49 @@ public interface PINManagementGUIFacade extends BKUGUIFacade { public static final String HELP_PINMGMT = "help.pin.mgmt"; public static final String TITLE_PINMGMT = "title.pin.mgmt"; + public static final String TITLE_ACTIVATE_PIN = "title.activate.pin"; + public static final String TITLE_CHANGE_PIN = "title.change.pin"; + public static final String TITLE_UNBLOCK_PIN = "title.unblock.pin"; public static final String MESSAGE_PINMGMT = "message.pin.mgmt"; - - public void showPINManagementDialog(PINStatusProvider pinStatusProvider, ActionListener activateListener, String activateCmd, ActionListener changeListener, String changeCmd, ActionListener unblockListener, String unblockCmd, ActionListener cancelListener, String cancelCmd); + public static final String MESSAGE_ACTIVATE_PIN = "message.activate.pin"; + public static final String MESSAGE_CHANGE_PIN = "message.change.pin"; + public static final String MESSAGE_UNBLOCK_PIN = "message.unblock.pin"; + public static final String LABEL_OLD_PIN = "label.old.pin"; + public static final String LABEL_NEW_PIN = "label.new.pin"; + public static final String LABEL_REPEAT_PIN = "label.repeat.pin"; + public static final String ERR_ACTIVATE = "err.activate"; + public static final String ERR_CHANGE = "err.change"; + public static final String ERR_UNBLOCK = "err.unblock"; + + public static final String BUTTON_ACTIVATE = "button.activate"; + public static final String BUTTON_UNBLOCK = "button.unblock"; + public static final String BUTTON_CHANGE = "button.change"; + + public static final String STATUS_ACTIVE = "status.active"; + public static final String STATUS_BLOCKED = "status.blocked"; + public static final String STATUS_NOT_ACTIVE = "status.not.active"; + public static final String STATUS_UNKNOWN = "status.unknown"; + + public enum STATUS { ACTIV, NOT_ACTIV, BLOCKED, UNKNOWN }; + + public void showPINManagementDialog(Map pins, + ActionListener activateListener, String activateCmd, String changeCmd, String unblockCmd, + ActionListener cancelListener, String cancelCmd); + + public void showActivatePINDialog(PINSpec pin, + ActionListener okListener, String okCmd, + ActionListener cancelListener, String cancelCmd); + + public void showChangePINDialog(PINSpec pin, + ActionListener okListener, String okCmd, + ActionListener cancelListener, String cancelCmd); + + public void showUnblockPINDialog(PINSpec pin, + ActionListener okListener, String okCmd, + ActionListener cancelListener, String cancelCmd); + + public char[] getOldPin(); + + public PINSpec getSelectedPIN(); } diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINSpecRenderer.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINSpecRenderer.java new file mode 100644 index 00000000..e3d73e1f --- /dev/null +++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINSpecRenderer.java @@ -0,0 +1,39 @@ +/* + * 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.smcc.PINSpec; +import javax.swing.table.DefaultTableCellRenderer; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author Clemens Orthacker + */ +public class PINSpecRenderer extends DefaultTableCellRenderer { + + private static final Log log = LogFactory.getLog(PINSpecRenderer.class); + + @Override + protected void setValue(Object value) { + PINSpec pinSpec = (PINSpec) value; + super.setText(pinSpec.getLocalizedName()); + } + +} diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINStatusProvider.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINStatusProvider.java deleted file mode 100644 index 73fa0920..00000000 --- a/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINStatusProvider.java +++ /dev/null @@ -1,32 +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.smcc.SignatureCardException; - -/** - * - * @author Clemens Orthacker - */ -public interface PINStatusProvider { - - public enum STATUS { ACTIV, NOT_ACTIV, BLOCKED }; - - public STATUS getPINStatus(int pin) throws SignatureCardException; - -} diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINStatusRenderer.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINStatusRenderer.java new file mode 100644 index 00000000..2f8852ff --- /dev/null +++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINStatusRenderer.java @@ -0,0 +1,63 @@ +/* + * 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.bku.gui.PINManagementGUIFacade.STATUS; +import java.awt.Color; +import java.awt.Font; +import java.util.ResourceBundle; +import javax.swing.table.DefaultTableCellRenderer; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author Clemens Orthacker + */ +public class PINStatusRenderer extends DefaultTableCellRenderer { + + private static final Log log = LogFactory.getLog(PINStatusRenderer.class); + + public static final Color RED = new Color(0.9f, 0.0f, 0.0f); + public static final Color GREEN = new Color(0.0f, 0.8f, 0.0f); + protected ResourceBundle messages; + + public PINStatusRenderer(ResourceBundle messages) { + this.messages = messages; + } + + @Override + protected void setValue(Object value) { + STATUS pinStatus = (STATUS) value; + super.setFont(super.getFont().deriveFont(super.getFont().getStyle() | Font.BOLD)); + + if (pinStatus == STATUS.NOT_ACTIV) { + super.setForeground(RED); + super.setText("" + messages.getString(PINManagementGUIFacade.STATUS_NOT_ACTIVE) + ""); + } else if (pinStatus == STATUS.ACTIV) { + super.setForeground(GREEN); + super.setText("" + messages.getString(PINManagementGUIFacade.STATUS_ACTIVE) + ""); + } else if (pinStatus == STATUS.BLOCKED) { + super.setForeground(RED); + super.setText("" + messages.getString(PINManagementGUIFacade.STATUS_BLOCKED) + ""); + } else { + super.setForeground(Color.BLACK); + super.setText("" + messages.getString(PINManagementGUIFacade.STATUS_UNKNOWN) + ""); + } + } +} diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINStatusTableModel.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINStatusTableModel.java new file mode 100644 index 00000000..feaa5072 --- /dev/null +++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINStatusTableModel.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.bku.gui.PINManagementGUIFacade.STATUS; +import at.gv.egiz.smcc.PINSpec; +import java.util.Map; +import javax.swing.table.DefaultTableModel; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author Clemens Orthacker + */ +public class PINStatusTableModel extends DefaultTableModel { + + protected static final Log log = LogFactory.getLog(PINStatusTableModel.class); + protected Class[] types; + + public PINStatusTableModel(Map pinStatuses) { + super(0, 2); + if (pinStatuses == null) { + throw new RuntimeException("pinStatuses must not be null"); + } + log.trace(pinStatuses.size() + " PINs"); + types = new Class[] { PINSpec.class, STATUS.class }; + for (PINSpec pinSpec : pinStatuses.keySet()) { + addRow(new Object[] { pinSpec, pinStatuses.get(pinSpec) }); + } +// PINSpec activePIN = new PINSpec(0, 1, null, "active-PIN", (byte) 0x01); +// PINSpec blockedPIN = new PINSpec(0, 1, null, "blocked-PIN", (byte) 0x01); +// addRow(new Object[] { activePIN, PINStatusProvider.STATUS.ACTIV }); +// addRow(new Object[] { blockedPIN, PINStatusProvider.STATUS.BLOCKED }); + } + + @Override + public Class getColumnClass(int columnIndex) { + return types[columnIndex]; + } + + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + return false; + } +} diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/PINManagementApplet.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/PINManagementApplet.java index 72d06618..d948ac03 100644 --- a/BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/PINManagementApplet.java +++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/PINManagementApplet.java @@ -19,6 +19,7 @@ package at.gv.egiz.bku.online.applet; import at.gv.egiz.bku.gui.AbstractHelpListener; import at.gv.egiz.bku.gui.BKUGUIFacade; import at.gv.egiz.bku.gui.PINManagementGUI; +import at.gv.egiz.bku.gui.PINManagementGUIFacade; import java.awt.Container; import java.net.URL; import java.util.Locale; @@ -45,6 +46,6 @@ public class PINManagementApplet extends BKUApplet { @Override protected AppletBKUWorker createBKUWorker(BKUApplet applet, BKUGUIFacade gui) { - return new PINManagementBKUWorker(applet, gui); + return new PINManagementBKUWorker(applet, (PINManagementGUIFacade) gui); } } diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/PINManagementBKUWorker.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/PINManagementBKUWorker.java index e65d98ca..ffd83e42 100644 --- a/BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/PINManagementBKUWorker.java +++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/PINManagementBKUWorker.java @@ -18,35 +18,28 @@ package at.gv.egiz.bku.online.applet; import at.gv.egiz.bku.gui.BKUGUIFacade; import at.gv.egiz.bku.gui.PINManagementGUIFacade; -import at.gv.egiz.bku.smccstal.ext.PINMgmtRequestHandler; +import at.gv.egiz.bku.smccstal.ext.PINManagementRequestHandler; +import at.gv.egiz.stal.ErrorResponse; import at.gv.egiz.stal.STALResponse; -import at.gv.egiz.stal.ext.ActivatePINRequest; -import at.gv.egiz.stal.ext.ChangePINRequest; -import at.gv.egiz.stal.ext.UnblockPINRequest; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.Collection; +import at.gv.egiz.stal.ext.PINManagementRequest; +import at.gv.egiz.stal.ext.PINManagementResponse; import java.util.Collections; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; /** - * + * This BKU Worker does not connect to STAL webservice + * (no Internet connection permitted while activating PINs). + * * @author Clemens Orthacker */ public class PINManagementBKUWorker extends AppletBKUWorker { - protected PINMgmtRequestHandler handler = new PINMgmtRequestHandler(); - protected PINManagementActionListener listener = new PINManagementActionListener(); - - public PINManagementBKUWorker(BKUApplet applet, BKUGUIFacade gui) { + public PINManagementBKUWorker(BKUApplet applet, PINManagementGUIFacade gui) { super(applet, gui); handlerMap.clear(); -// PINMgmtRequestHandler handler = new PINMgmtRequestHandler(); -// addRequestHandler(ActivatePINRequest.class, handler); -// addRequestHandler(ChangePINRequest.class, handler); -// addRequestHandler(UnblockPINRequest.class, handler); + addRequestHandler(PINManagementRequest.class, new PINManagementRequestHandler()); } @Override @@ -54,22 +47,24 @@ public class PINManagementBKUWorker extends AppletBKUWorker { gui.showWelcomeDialog(); try { - - if (waitForCard()) { - gui.showErrorDialog("no card, canceled PIN mgmt dialog", null); + List responses = handleRequest(Collections.singletonList(new PINManagementRequest())); + + if (responses.size() == 1) { + STALResponse response = responses.get(0); + if (response instanceof PINManagementResponse) { + log.debug("PIN management dialog finished"); + } else if (response instanceof ErrorResponse) { + showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, null); + } else { + throw new RuntimeException("Invalid STAL response: " + response.getClass().getName()); + } + } else { + throw new RuntimeException("invalid number of STAL responses: " + responses.size()); } - actionCommandList.clear(); - actionCommandList.add("cancel"); - - ((PINManagementGUIFacade) gui).showPINManagementDialog(handler, - listener, "activate", - listener, "change", - listener, "unblock", - this, "cancel"); - - waitForAction(); - + } catch (RuntimeException ex) { + log.error("unexpected error: " + ex.getMessage(), ex); + showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, null); } catch (Exception ex) { log.error(ex.getMessage(), ex); showErrorDialog(BKUGUIFacade.ERR_UNKNOWN_WITH_PARAM, ex); @@ -82,31 +77,4 @@ public class PINManagementBKUWorker extends AppletBKUWorker { applet.sendRedirect(sessionId); } - protected class PINManagementActionListener implements ActionListener { - - @Override - public void actionPerformed(ActionEvent e) { - try { - String cmd = e.getActionCommand(); - if ("activate".equals(cmd)) { - //create STAL request, call handle(req) - ActivatePINRequest stalReq = new ActivatePINRequest(); - STALResponse stalResp = handler.handleRequest(stalReq); - gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN_WITH_PARAM, new Object[]{"debug"}, this, "back"); - } else if ("change".equals(cmd)) { - } else if ("unblock".equals(cmd)) { - } else if ("back".equals(cmd)) { - - ((PINManagementGUIFacade) gui).showPINManagementDialog(handler, - this, "activate", - this, "change", - this, "unblock", - PINManagementBKUWorker.this, "cancel"); - - } - } catch (InterruptedException ex) { - log.fatal(ex); - } - } } -} diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PINManagementRequestHandler.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PINManagementRequestHandler.java new file mode 100644 index 00000000..fcef3191 --- /dev/null +++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PINManagementRequestHandler.java @@ -0,0 +1,331 @@ +/* + * 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.ext; + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.bku.gui.PINManagementGUIFacade; +import at.gv.egiz.bku.gui.PINManagementGUIFacade.STATUS; +import at.gv.egiz.bku.smccstal.AbstractRequestHandler; +import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.smcc.SignatureCardException; +import at.gv.egiz.smcc.util.SMCCHelper; +import at.gv.egiz.stal.ErrorResponse; +import at.gv.egiz.stal.STALRequest; +import at.gv.egiz.stal.STALResponse; +import at.gv.egiz.stal.ext.PINManagementRequest; +import at.gv.egiz.stal.ext.PINManagementResponse; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.smartcardio.Card; +import javax.smartcardio.CardChannel; +import javax.smartcardio.CardException; +import javax.smartcardio.CommandAPDU; +import javax.smartcardio.ResponseAPDU; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author Clemens Orthacker + */ +public class PINManagementRequestHandler extends AbstractRequestHandler { + + public static final String ERR_NOPIN_SELECTED = "err.no.pin.selected"; + protected static final Log log = LogFactory.getLog(PINManagementRequestHandler.class); + +// protected ResourceBundle messages; + +// public PINManagementRequestHandler(ResourceBundle messages) { +// this.messages = messages; +// } + @Override + public STALResponse handleRequest(STALRequest request) throws InterruptedException { + if (request instanceof PINManagementRequest) { + + PINManagementGUIFacade gui = (PINManagementGUIFacade) this.gui; + + showPINManagementDialog(gui); + + while (true) { + + waitForAction(); + + if ("cancel".equals(actionCommand)) { + return new PINManagementResponse(); + } else if ("back".equals(actionCommand)) { + showPINManagementDialog(gui); + } else { + PINSpec selectedPIN = gui.getSelectedPIN(); + + if (selectedPIN == null) { + throw new RuntimeException("no PIN selected for activation/change"); + } + + if ("activate_enterpin".equals(actionCommand)) { + gui.showActivatePINDialog(selectedPIN, this, "activate", this, "back"); + } else if ("change_enterpin".equals(actionCommand)) { + gui.showChangePINDialog(selectedPIN, this, "change", this, "back"); + } else if ("unblock_enterpuk".equals(actionCommand)) { + gui.showUnblockPINDialog(selectedPIN, this, "unblock", this, "back"); + } else if ("activate".equals(actionCommand)) { + try { + byte[] pin = encodePIN(gui.getPin()); + activatePIN(selectedPIN.getKID(), selectedPIN.getContextAID(), pin); + showPINManagementDialog(gui); + } catch (SignatureCardException ex) { + log.error("failed to activate " + selectedPIN.getLocalizedName() + ": " + ex.getMessage()); + gui.showErrorDialog(PINManagementGUIFacade.ERR_ACTIVATE, + new Object[] {selectedPIN.getLocalizedName()}, + this, "cancel"); + } + } else if ("change".equals(actionCommand)) { + try { + byte[] oldPin = encodePIN(gui.getOldPin()); //new byte[]{(byte) 0x25, (byte) 0x40, (byte) 0x01}; + byte[] pin = encodePIN(gui.getPin()); //new byte[]{(byte) 0x25, (byte) 0x40}; + changePIN(selectedPIN.getKID(), selectedPIN.getContextAID(), oldPin, pin); + showPINManagementDialog(gui); + } catch (SignatureCardException ex) { + log.error("failed to change " + selectedPIN.getLocalizedName() + ": " + ex.getMessage()); + gui.showErrorDialog(PINManagementGUIFacade.ERR_CHANGE, + new Object[] {selectedPIN.getLocalizedName()}, + this, "cancel"); + } + } else if ("unblock".equals(actionCommand)) { + log.error("unblock PIN not implemented"); + gui.showErrorDialog(PINManagementGUIFacade.ERR_UNBLOCK, null, this, "cancel"); + } else { + throw new RuntimeException("unsupported action " + actionCommand); + } + } + } + } else { + log.error("Got unexpected STAL request: " + request); + return new ErrorResponse(1000); + } + } + + @Override + public boolean requireCard() { + return true; + } + + /** + * pin.length < 4bit + * @param kid + * @param contextAID + * @param pin + * @throws at.gv.egiz.smcc.SignatureCardException + */ + private void activatePIN(byte kid, byte[] contextAID, byte[] pin) throws SignatureCardException { + try { + Card icc = card.getCard(); + icc.beginExclusive(); + CardChannel channel = icc.getBasicChannel(); + + if (contextAID != null) { + CommandAPDU selectAPDU = new CommandAPDU(0x00, 0xa4, 0x04, 0x0c, contextAID); + ResponseAPDU responseAPDU = channel.transmit(selectAPDU); + if (responseAPDU.getSW() != 0x9000) { + String msg = "Failed to activate PIN " + SMCCHelper.toString(new byte[]{kid}) + + ": Failed to select AID " + SMCCHelper.toString(contextAID) + + ": " + SMCCHelper.toString(responseAPDU.getBytes()); + log.error(msg); + throw new SignatureCardException(msg); + } + } + + if (pin.length > 7) { + log.error("Invalid PIN"); + throw new SignatureCardException("Invalid PIN"); + } + byte length = (byte) (0x20 | pin.length * 2); + + byte[] apdu = new byte[]{ + (byte) 0x00, (byte) 0x24, (byte) 0x01, kid, (byte) 0x08, + (byte) length, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF}; + for (int i = 0; i < pin.length; i++) { + apdu[i + 6] = pin[i]; + } + + CommandAPDU verifyAPDU = new CommandAPDU(apdu); + ResponseAPDU responseAPDU = channel.transmit(verifyAPDU); + + if (responseAPDU.getSW() != 0x9000) { + String msg = "Failed to activate PIN " + SMCCHelper.toString(new byte[]{kid}) + ": " + SMCCHelper.toString(responseAPDU.getBytes()); + log.error(msg); + throw new SignatureCardException(msg); + } + + + icc.endExclusive(); + + + } catch (CardException ex) { + log.error("Failed to get PIN status: " + ex.getMessage()); + throw new SignatureCardException("Failed to get PIN status", ex); + } + } + + private void changePIN(byte kid, byte[] contextAID, byte[] oldPIN, byte[] newPIN) throws SignatureCardException { + try { + Card icc = card.getCard(); + icc.beginExclusive(); + CardChannel channel = icc.getBasicChannel(); + + if (contextAID != null) { + CommandAPDU selectAPDU = new CommandAPDU(0x00, 0xa4, 0x04, 0x0c, contextAID); + ResponseAPDU responseAPDU = channel.transmit(selectAPDU); + if (responseAPDU.getSW() != 0x9000) { + String msg = "Failed to change PIN " + SMCCHelper.toString(new byte[]{kid}) + + ": Failed to select AID " + SMCCHelper.toString(contextAID) + + ": " + SMCCHelper.toString(responseAPDU.getBytes()); + log.error(msg); + throw new SignatureCardException(msg); + } + } + + if (oldPIN.length > 7 || newPIN.length > 7) { + log.error("Invalid PIN"); + throw new SignatureCardException("Invalid PIN"); + } + byte oldLength = (byte) (0x20 | oldPIN.length * 2); + byte newLength = (byte) (0x20 | newPIN.length * 2); + + byte[] apdu = new byte[]{ + (byte) 0x00, (byte) 0x24, (byte) 0x00, kid, (byte) 0x10, + oldLength, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, + newLength, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF}; + for (int i = 0; i < oldPIN.length; i++) { + apdu[i + 6] = oldPIN[i]; + } + for (int i = 0; i < newPIN.length; i++) { + apdu[i + 14] = newPIN[i]; + } + + CommandAPDU verifyAPDU = new CommandAPDU(apdu); + ResponseAPDU responseAPDU = channel.transmit(verifyAPDU); + + if (responseAPDU.getSW() != 0x9000) { + String msg = "Failed to change PIN " + SMCCHelper.toString(new byte[]{kid}) + ": " + SMCCHelper.toString(responseAPDU.getBytes()); + log.error(msg); + throw new SignatureCardException(msg); + } + + + icc.endExclusive(); + + + } catch (CardException ex) { + log.error("Failed to get PIN status: " + ex.getMessage()); + throw new SignatureCardException("Failed to get PIN status", ex); + } + } + + public Map getPINStatuses() throws SignatureCardException { + try { + Card icc = card.getCard(); + icc.beginExclusive(); + CardChannel channel = icc.getBasicChannel(); + + HashMap pinStatuses = new HashMap(); + List pins = card.getPINSpecs(); + + //select DF_SichereSignatur 00 A4 04 0C 08 D0 40 00 00 17 00 12 01 +// CommandAPDU selectAPDU = new CommandAPDU(new byte[]{(byte) 0x00, (byte) 0xa4, (byte) 0x04, (byte) 0x0c, (byte) 0x08, +// (byte) 0xd0, (byte) 0x40, (byte) 0x00, (byte) 0x00, (byte) 0x17, (byte) 0x00, (byte) 0x12, (byte) 0x01}); +// ResponseAPDU rAPDU = channel.transmit(selectAPDU); +// log.debug("SELECT FILE DF_SichereSignatur: " + SMCCHelper.toString(rAPDU.getBytes())); + + //select DF_SIG DF 70 +// CommandAPDU selectAPDU = new CommandAPDU(new byte[]{(byte) 0x00, (byte) 0xa4, (byte) 0x00, (byte) 0x0c, (byte) 0x02, +// (byte) 0xdf, (byte) 0x70 }); +// ResponseAPDU rAPDU = channel.transmit(selectAPDU); +// log.debug("SELECT FILE DF_SIG: " + SMCCHelper.toString(rAPDU.getBytes())); + + //select DF_DEC DF 71 +// CommandAPDU selectAPDU = new CommandAPDU(new byte[]{(byte) 0x00, (byte) 0xa4, (byte) 0x04, (byte) 0x0c, (byte) 0x08, +// (byte) 0xd0, (byte) 0x40, (byte) 0x00, (byte) 0x00, (byte) 0x17, (byte) 0x00, (byte) 0x12, (byte) 0x01}); +// ResponseAPDU rAPDU = channel.transmit(selectAPDU); +// log.debug("SELECT FILE DF_SichereSignatur: " + SMCCHelper.toString(rAPDU.getBytes())); + + for (PINSpec pinSpec : pins) { + byte kid = pinSpec.getKID(); + byte[] contextAID = pinSpec.getContextAID(); + + if (contextAID != null) { + CommandAPDU selectAPDU = new CommandAPDU(0x00, 0xa4, 0x04, 0x0c, contextAID); + ResponseAPDU responseAPDU = channel.transmit(selectAPDU); + if (responseAPDU.getSW() != 0x9000) { + String msg = "Failed to activate PIN " + SMCCHelper.toString(new byte[]{kid}) + + ": Failed to select AID " + SMCCHelper.toString(contextAID) + + ": " + SMCCHelper.toString(responseAPDU.getBytes()); + log.error(msg); + throw new SignatureCardException(msg); + } + } + + CommandAPDU verifyAPDU = new CommandAPDU(new byte[]{(byte) 0x00, (byte) 0x20, (byte) 00, kid}); + ResponseAPDU responseAPDU = channel.transmit(verifyAPDU); + + STATUS status = STATUS.UNKNOWN; + if (responseAPDU.getSW() == 0x6984) { + status = STATUS.NOT_ACTIV; + } else if (responseAPDU.getSW() == 0x63c0) { + status = STATUS.BLOCKED; + } else if (responseAPDU.getSW1() == 0x63) { + status = STATUS.ACTIV; + } + if (log.isDebugEnabled()) { + log.debug("PIN " + pinSpec.getLocalizedName() + " status: " + SMCCHelper.toString(responseAPDU.getBytes())); + } + + pinStatuses.put(pinSpec, status); + } + icc.endExclusive(); + + return pinStatuses; + + } catch (CardException ex) { + log.error("Failed to get PIN status: " + ex.getMessage()); + throw new SignatureCardException("Failed to get PIN status", ex); + } + } + + private byte[] encodePIN(char[] pinChars) { + int length = (int) Math.ceil(pinChars.length/2); + byte[] pin = new byte[length]; + for (int i = 0; i < length; i++) { + pin[i] = (byte) (16*Character.digit(pinChars[i*2], 16) + Character.digit(pinChars[i*2+1], 16)); + } + log.trace("***** " + SMCCHelper.toString(pin) + " ******"); + return pin; + } + + private void showPINManagementDialog(PINManagementGUIFacade gui) { + try { + Map pins = getPINStatuses(); + gui.showPINManagementDialog(pins, + this, "activate_enterpin", "change_enterpin", "unblock_enterpuk", + this, "cancel"); + } catch (SignatureCardException ex) { + gui.showErrorDialog(BKUGUIFacade.ERR_UNKNOWN_WITH_PARAM, + new Object[]{"FAILED TO GET PIN STATUSES: " + ex.getMessage()}, + this, "cancel"); + } + } +} diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PINMgmtRequestHandler.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PINMgmtRequestHandler.java deleted file mode 100644 index b2d34ff2..00000000 --- a/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PINMgmtRequestHandler.java +++ /dev/null @@ -1,93 +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.smccstal.ext; - -import at.gv.egiz.bku.gui.PINStatusProvider; -import at.gv.egiz.bku.smccstal.AbstractRequestHandler; -import at.gv.egiz.smcc.SignatureCardException; -import at.gv.egiz.stal.ErrorResponse; -import at.gv.egiz.stal.STALRequest; -import at.gv.egiz.stal.STALResponse; -import at.gv.egiz.stal.ext.ActivatePINRequest; -import at.gv.egiz.stal.ext.ChangePINRequest; -import at.gv.egiz.stal.ext.UnblockPINRequest; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.smartcardio.Card; -import javax.smartcardio.CardChannel; -import javax.smartcardio.CardException; -import javax.smartcardio.CommandAPDU; -import javax.smartcardio.ResponseAPDU; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * - * @author Clemens Orthacker - */ -public class PINMgmtRequestHandler extends AbstractRequestHandler implements PINStatusProvider { - - protected static final Log log = LogFactory.getLog(PINMgmtRequestHandler.class); - - @Override - public STALResponse handleRequest(STALRequest request) throws InterruptedException { - if (request instanceof ActivatePINRequest) { - log.error("not implemented yet"); - return new ErrorResponse(1000); - - } else if (request instanceof ChangePINRequest) { - log.error("not implemented yet"); - return new ErrorResponse(1000); - - } else if (request instanceof UnblockPINRequest) { - log.error("not implemented yet"); - return new ErrorResponse(1000); - - } else { - log.error("Got unexpected STAL request: " + request); - return new ErrorResponse(1000); - } - } - - @Override - public boolean requireCard() { - return true; - } - - @Override - public STATUS getPINStatus(int pin) throws SignatureCardException { - try { - Card icc = card.getCard(); - icc.beginExclusive(); - CardChannel channel = icc.getBasicChannel(); - CommandAPDU verifyAPDU = new CommandAPDU(new byte[] {(byte) 0x00} ); - ResponseAPDU responseAPDU = channel.transmit(verifyAPDU); - byte sw1 = (byte) responseAPDU.getSW1(); - byte[] sw = new byte[] { - (byte) (0xFF & responseAPDU.getSW1()), - (byte) (0xFF & responseAPDU.getSW2()) }; - - icc.endExclusive(); - return STATUS.ACTIV; - } catch (CardException ex) { - log.error("Failed to get PIN status: " + ex.getMessage()); - throw new SignatureCardException("Failed to get PIN status", ex); - } - } - -} diff --git a/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages.properties b/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages.properties index 469af15f..e51044af 100644 --- a/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages.properties +++ b/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages.properties @@ -15,10 +15,34 @@ title.activation=Aktivierung title.pin.mgmt=PIN Verwaltung -message.pin.mgmt=under construction +title.activate.pin=PIN Aktivieren +title.change.pin=PIN \u00C4ndern +title.unblock.pin=PIN Entsperren + +message.pin.mgmt=Die Karte verf\u00FCgt \u00FCber {0} PINs +message.activate.pin={0} eingeben und best\u00E4tigen +message.change.pin={0} eingeben und best\u00E4tigen +message.unblock.pin=PUK zu {0} eingeben + label.activation=e-card Aktivierungsprozess label.activation.step=Schritt {0} label.activation.idle=Warte auf Server... +label.old.pin=Alte {0}: +label.new.pin=Neue {0}: +label.repeat.pin=Best\u00E4tigung: + button.activate=Aktivieren button.change=\u00C4ndern -button.unblock=Entsperren \ No newline at end of file +button.unblock=Entsperren + +help.activation=help.activation +help.pin.mgmt=help.pin.mgmt + +err.activate=Beim Aktivieren der {0} trat ein Fehler auf. +err.change=Beim \u00C4ndern der {0} trat ein Fehler auf. +err.unblock=Das Entsperren der {0} wird nicht unterst\u00FCtzt. + +status.not.active=NICHT AKTIV +status.active=AKTIV +status.blocked=GESPERRT +status.unknown=UNBEKANNT diff --git a/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages_en.properties b/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages_en.properties index 16ac7d0b..1cf4a102 100644 --- a/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages_en.properties +++ b/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages_en.properties @@ -13,12 +13,36 @@ # See the License for the specific language governing permissions and # limitations under the License. -title.activation=Aktivation +title.activation=Activation title.pin.mgmt=PIN Management -message.pin.mgmt=under construction +title.activate.pin=Activate PIN +title.change.pin=Change PIN +title.unblock.pin=Unblock PIN + +message.pin.mgmt=The smartcard has {0} PINs +message.activate.pin=Enter and confirm {0} +message.change.pin=Enter and confirm {0} +message.unblock.pin=Enter PUK for {0} + label.activation=e-card activation process label.activation.step=Step {0} label.activation.idle=Wait for server... +label.old.pin=Old {0}: +label.new.pin=New {0}: +label.repeat.pin=Confirmation: + button.activate=Activate button.change=Change -button.unblock=Unblock \ No newline at end of file +button.unblock=Unblock + +help.activation=help.activation +help.pin.mgmt=help.pin.mgmt + +err.activate=An error occured during activation of {0}. +err.change=An error occured during changing of {0}. +err.unblock=Unblocking of {0} is not supported. + +status.not.active=Not active +status.active=Active +status.blocked=Blocked +status.unknown=Unknown diff --git a/BKUAppletExt/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java b/BKUAppletExt/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java index 669a63fc..ef8c87e4 100644 --- a/BKUAppletExt/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java +++ b/BKUAppletExt/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java @@ -25,8 +25,6 @@ import at.gv.egiz.stal.HashDataInput; import at.gv.egiz.stal.impl.ByteArrayHashDataInput; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.io.ByteArrayInputStream; -import java.io.InputStream; import java.util.ArrayList; import java.util.List; @@ -46,7 +44,7 @@ public class BKUGUIWorker implements Runnable { public void run() { try { - final PINSpec signPinSpec = new PINSpec(6, 10, "[0-9]", "Signatur-PIN"); + final PINSpec signPinSpec = new PINSpec(6, 10, "[0-9]", "Signatur-PIN", (byte)0x00, null); final ActionListener cancelListener = new ActionListener() { diff --git a/BKUAppletExt/src/test/resources/appletTest.html b/BKUAppletExt/src/test/resources/appletTest.html index 9add4309..813ee1f0 100644 --- a/BKUAppletExt/src/test/resources/appletTest.html +++ b/BKUAppletExt/src/test/resources/appletTest.html @@ -19,7 +19,7 @@
+ width=270 height=180> 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 f564c07a..1d5a2cf4 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 @@ -38,9 +38,6 @@ import java.util.Collections; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.CellRendererPane; import javax.swing.GroupLayout; import javax.swing.ImageIcon; import javax.swing.JButton; @@ -51,7 +48,6 @@ import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JScrollPane; import javax.swing.JTable; -import javax.swing.JTextField; import javax.swing.LayoutStyle; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; @@ -1064,7 +1060,9 @@ public class BKUGUIImpl implements BKUGUIFacade { @Override public char[] getPin() { if (pinField != null) { - return pinField.getPassword(); + char[] pin = pinField.getPassword(); + pinField = null; + return pin; } return null; } diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java index 2054ae86..87b636f0 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java @@ -22,6 +22,7 @@ import java.util.regex.Pattern; import javax.swing.JButton; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; +import javax.swing.text.Document; import javax.swing.text.PlainDocument; /** @@ -30,9 +31,10 @@ import javax.swing.text.PlainDocument; */ class PINDocument extends PlainDocument { - private PINSpec pinSpec; - private Pattern pinPattern; - private JButton enterButton; + protected PINSpec pinSpec; + protected Pattern pinPattern; + protected JButton enterButton; + protected Document compareTo; public PINDocument(PINSpec pinSpec, JButton enterButton) { this.pinSpec = pinSpec; @@ -44,6 +46,11 @@ class PINDocument extends PlainDocument { this.enterButton = enterButton; } + public PINDocument(PINSpec pinSpec, JButton enterButton, Document compareTo) { + this(pinSpec, enterButton); + this.compareTo = compareTo; + } + @Override public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { if (pinSpec.getMaxLength() < 0 || pinSpec.getMaxLength() >= (getLength() + str.length())) { @@ -58,12 +65,23 @@ class PINDocument extends PlainDocument { super.insertString(offs, str, a); } } - enterButton.setEnabled(getLength() >= pinSpec.getMinLength()); + if (enterButton != null) { + enterButton.setEnabled(getLength() >= pinSpec.getMinLength() && compare()); + } } @Override public void remove(int offs, int len) throws BadLocationException { super.remove(offs, len); - enterButton.setEnabled(getLength() >= pinSpec.getMinLength()); + if (enterButton != null) { + enterButton.setEnabled(getLength() >= pinSpec.getMinLength() && compare()); + } + } + + private boolean compare() throws BadLocationException { + if (compareTo == null) { + return true; + } + return compareTo.getText(0, compareTo.getLength()).equals(getText(0, getLength())); } } \ No newline at end of file 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 8436a730..1e0bc9f5 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 @@ -20,7 +20,7 @@ title.cardnotsupported=Die Karte wird nicht unterst\u00FCtzt title.cardpin=Karte wird gelesen title.sign=Signatur erstellen title.error=Fehler -title.retry=Falscher PIN +title.retry=Falsche PIN title.wait=Bitte warten title.hashdata=Signaturdaten windowtitle.save=Signaturdaten speichern @@ -84,7 +84,7 @@ 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.retry=Falsche 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/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java index 73aaab46..08ecaa7f 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 @@ -46,7 +46,7 @@ public class BKUGUIWorker implements Runnable { public void run() { // try { - final PINSpec signPinSpec = new PINSpec(6, 10, "[0-9]", "Signatur-PIN"); + final PINSpec signPinSpec = new PINSpec(6, 10, "[0-9]", "Signatur-PIN", (byte) 0x81, null); final ActionListener cancelListener = new ActionListener() { diff --git a/STALExt/src/main/java/at/gv/egiz/stal/ext/ActivatePINRequest.java b/STALExt/src/main/java/at/gv/egiz/stal/ext/ActivatePINRequest.java deleted file mode 100644 index f2039388..00000000 --- a/STALExt/src/main/java/at/gv/egiz/stal/ext/ActivatePINRequest.java +++ /dev/null @@ -1,28 +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.stal.ext; - -import at.gv.egiz.stal.STALRequest; - -/** - * - * @author Clemens Orthacker - */ -public class ActivatePINRequest extends STALRequest { - -} diff --git a/STALExt/src/main/java/at/gv/egiz/stal/ext/ChangePINRequest.java b/STALExt/src/main/java/at/gv/egiz/stal/ext/ChangePINRequest.java deleted file mode 100644 index ea508146..00000000 --- a/STALExt/src/main/java/at/gv/egiz/stal/ext/ChangePINRequest.java +++ /dev/null @@ -1,28 +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.stal.ext; - -import at.gv.egiz.stal.STALRequest; - -/** - * - * @author Clemens Orthacker - */ -public class ChangePINRequest extends STALRequest { - -} diff --git a/STALExt/src/main/java/at/gv/egiz/stal/ext/PINManagementRequest.java b/STALExt/src/main/java/at/gv/egiz/stal/ext/PINManagementRequest.java new file mode 100644 index 00000000..87c53e24 --- /dev/null +++ b/STALExt/src/main/java/at/gv/egiz/stal/ext/PINManagementRequest.java @@ -0,0 +1,31 @@ +/* + * 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.stal.ext; + +import at.gv.egiz.stal.STALRequest; + +/** + * Dummy STAL request to trigger PIN Management. (no proper STAL requests + * for PIN activation, unblocking) + * + * + * @author Clemens Orthacker + */ +public class PINManagementRequest extends STALRequest { + +} diff --git a/STALExt/src/main/java/at/gv/egiz/stal/ext/PINManagementResponse.java b/STALExt/src/main/java/at/gv/egiz/stal/ext/PINManagementResponse.java new file mode 100644 index 00000000..b8b90604 --- /dev/null +++ b/STALExt/src/main/java/at/gv/egiz/stal/ext/PINManagementResponse.java @@ -0,0 +1,28 @@ +/* + * 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.stal.ext; + +import at.gv.egiz.stal.STALResponse; + +/** + * + * @author Clemens Orthacker + */ +public class PINManagementResponse extends STALResponse { + +} diff --git a/STALExt/src/main/java/at/gv/egiz/stal/ext/UnblockPINRequest.java b/STALExt/src/main/java/at/gv/egiz/stal/ext/UnblockPINRequest.java deleted file mode 100644 index 543de31c..00000000 --- a/STALExt/src/main/java/at/gv/egiz/stal/ext/UnblockPINRequest.java +++ /dev/null @@ -1,28 +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.stal.ext; - -import at.gv.egiz.stal.STALRequest; - -/** - * - * @author Clemens Orthacker - */ -public class UnblockPINRequest extends STALRequest { - -} diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/DataObject.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/DataObject.java index ae4918ce..b64306aa 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/DataObject.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/DataObject.java @@ -14,98 +14,105 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package at.gv.egiz.bku.slcommands.impl.xsect; - -import iaik.xml.crypto.dom.DOMCryptoContext; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.SequenceInputStream; -import java.io.StringWriter; -import java.io.UnsupportedEncodingException; -import java.net.URISyntaxException; -import java.nio.charset.Charset; -import java.security.InvalidAlgorithmParameterException; -import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; +package at.gv.egiz.bku.slcommands.impl.xsect; + +import iaik.xml.crypto.dom.DOMCryptoContext; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.SequenceInputStream; +import java.io.StringWriter; +import java.io.UnsupportedEncodingException; +import java.net.URISyntaxException; +import java.nio.charset.Charset; +import java.security.InvalidAlgorithmParameterException; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.xml.crypto.MarshalException; -import javax.xml.crypto.dom.DOMStructure; -import javax.xml.crypto.dsig.CanonicalizationMethod; -import javax.xml.crypto.dsig.DigestMethod; -import javax.xml.crypto.dsig.Reference; -import javax.xml.crypto.dsig.Transform; -import javax.xml.crypto.dsig.XMLObject; -import javax.xml.crypto.dsig.spec.TransformParameterSpec; -import javax.xml.crypto.dsig.spec.XPathFilter2ParameterSpec; -import javax.xml.crypto.dsig.spec.XPathType; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.w3c.dom.DOMConfiguration; -import org.w3c.dom.DOMException; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentFragment; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.Text; -import org.w3c.dom.bootstrap.DOMImplementationRegistry; -import org.w3c.dom.ls.DOMImplementationLS; -import org.w3c.dom.ls.LSException; -import org.w3c.dom.ls.LSInput; -import org.w3c.dom.ls.LSOutput; -import org.w3c.dom.ls.LSParser; -import org.w3c.dom.ls.LSSerializer; - -import at.buergerkarte.namespaces.securitylayer._1.Base64XMLLocRefOptRefContentType; -import at.buergerkarte.namespaces.securitylayer._1.DataObjectInfoType; -import at.buergerkarte.namespaces.securitylayer._1.MetaInfoType; -import at.buergerkarte.namespaces.securitylayer._1.TransformsInfoType; -import at.gv.egiz.bku.binding.HttpUtil; -import at.gv.egiz.bku.slexceptions.SLCommandException; -import at.gv.egiz.bku.slexceptions.SLRequestException; -import at.gv.egiz.bku.slexceptions.SLRuntimeException; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.crypto.MarshalException; +import javax.xml.crypto.dom.DOMStructure; +import javax.xml.crypto.dsig.CanonicalizationMethod; +import javax.xml.crypto.dsig.DigestMethod; +import javax.xml.crypto.dsig.Reference; +import javax.xml.crypto.dsig.Transform; +import javax.xml.crypto.dsig.XMLObject; +import javax.xml.crypto.dsig.spec.TransformParameterSpec; +import javax.xml.crypto.dsig.spec.XPathFilter2ParameterSpec; +import javax.xml.crypto.dsig.spec.XPathType; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.w3._2000._09.xmldsig_.TransformType; +import org.w3._2000._09.xmldsig_.TransformsType; +import org.w3c.dom.DOMConfiguration; +import org.w3c.dom.DOMException; +import org.w3c.dom.Document; +import org.w3c.dom.DocumentFragment; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.Text; +import org.w3c.dom.bootstrap.DOMImplementationRegistry; +import org.w3c.dom.ls.DOMImplementationLS; +import org.w3c.dom.ls.LSException; +import org.w3c.dom.ls.LSInput; +import org.w3c.dom.ls.LSOutput; +import org.w3c.dom.ls.LSParser; +import org.w3c.dom.ls.LSSerializer; + +import at.buergerkarte.namespaces.securitylayer._1.Base64XMLLocRefOptRefContentType; +import at.buergerkarte.namespaces.securitylayer._1.DataObjectInfoType; +import at.buergerkarte.namespaces.securitylayer._1.MetaInfoType; +import at.buergerkarte.namespaces.securitylayer._1.TransformsInfoType; +import at.gv.egiz.bku.binding.HttpUtil; +import at.gv.egiz.bku.slexceptions.SLCommandException; +import at.gv.egiz.bku.slexceptions.SLRequestException; +import at.gv.egiz.bku.slexceptions.SLRuntimeException; import at.gv.egiz.bku.slexceptions.SLViewerException; -import at.gv.egiz.bku.utils.urldereferencer.StreamData; -import at.gv.egiz.bku.utils.urldereferencer.URLDereferencer; +import at.gv.egiz.bku.utils.urldereferencer.StreamData; +import at.gv.egiz.bku.utils.urldereferencer.URLDereferencer; import at.gv.egiz.bku.viewer.ValidationException; import at.gv.egiz.bku.viewer.Validator; import at.gv.egiz.bku.viewer.ValidatorFactory; -import at.gv.egiz.dom.DOMUtils; -import at.gv.egiz.slbinding.impl.XMLContentType; - -/** - * This class represents a DataObject of an XML-Signature - * created by the security layer command CreateXMLSignature. - * - * @author mcentner - */ -public class DataObject { - - /** - * Logging facility. - */ - private static Log log = LogFactory.getLog(DataObject.class); - - /** - * DOM Implementation. - */ - private static final String DOM_LS_3_0 = "LS 3.0"; - - /** - * The array of the default preferred MIME type order. - */ - private static final String[] DEFAULT_PREFFERED_MIME_TYPES = - new String[] { +import at.gv.egiz.dom.DOMUtils; +import at.gv.egiz.marshal.NamespacePrefix; +import at.gv.egiz.marshal.NamespacePrefixMapperImpl; +import at.gv.egiz.slbinding.impl.XMLContentType; +import javax.xml.namespace.NamespaceContext; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +/** + * This class represents a DataObject of an XML-Signature + * created by the security layer command CreateXMLSignature. + * + * @author mcentner + */ +public class DataObject { + + /** + * Logging facility. + */ + private static Log log = LogFactory.getLog(DataObject.class); + + /** + * DOM Implementation. + */ + private static final String DOM_LS_3_0 = "LS 3.0"; + + /** + * The array of the default preferred MIME type order. + */ + private static final String[] DEFAULT_PREFFERED_MIME_TYPES = + new String[] { "text/plain", - "application/xhtml+xml" + "application/xhtml+xml" }; /** @@ -149,87 +156,87 @@ public class DataObject { validMimeTypes = mediaTypes; } - /** - * The DOM implementation used. - */ - private DOMImplementationLS domImplLS; - - /** - * The signature context. - */ - private SignatureContext ctx; - - /** - * The Reference for this DataObject. - */ - private XSECTReference reference; - - /** - * The XMLObject for this DataObject. - */ - private XMLObject xmlObject; - - /** - * The MIME-Type of the digest input. - */ - private String mimeType; - - /** - * An optional description of the digest input. - */ - private String description; - - /** - * Creates a new instance. - * - * @param document the document of the target signature - */ - public DataObject(SignatureContext signatureContext) { - this.ctx = signatureContext; - - DOMImplementationRegistry registry; - try { - registry = DOMImplementationRegistry.newInstance(); - } catch (Exception e) { - log.error("Failed to get DOMImplementationRegistry.", e); - throw new SLRuntimeException("Failed to get DOMImplementationRegistry."); - } - - domImplLS = (DOMImplementationLS) registry.getDOMImplementation(DOM_LS_3_0); - if (domImplLS == null) { - log.error("Failed to get DOMImplementation " + DOM_LS_3_0); - throw new SLRuntimeException("Failed to get DOMImplementation " + DOM_LS_3_0); - } - - } - - /** - * @return the reference - */ - public Reference getReference() { - return reference; - } - - /** - * @return the xmlObject - */ - public XMLObject getXmlObject() { - return xmlObject; - } - - /** - * @return the mimeType - */ - public String getMimeType() { - return mimeType; - } - - /** - * @return the description - */ - public String getDescription() { - return description; - } + /** + * The DOM implementation used. + */ + private DOMImplementationLS domImplLS; + + /** + * The signature context. + */ + private SignatureContext ctx; + + /** + * The Reference for this DataObject. + */ + private XSECTReference reference; + + /** + * The XMLObject for this DataObject. + */ + private XMLObject xmlObject; + + /** + * The MIME-Type of the digest input. + */ + private String mimeType; + + /** + * An optional description of the digest input. + */ + private String description; + + /** + * Creates a new instance. + * + * @param document the document of the target signature + */ + public DataObject(SignatureContext signatureContext) { + this.ctx = signatureContext; + + DOMImplementationRegistry registry; + try { + registry = DOMImplementationRegistry.newInstance(); + } catch (Exception e) { + log.error("Failed to get DOMImplementationRegistry.", e); + throw new SLRuntimeException("Failed to get DOMImplementationRegistry."); + } + + domImplLS = (DOMImplementationLS) registry.getDOMImplementation(DOM_LS_3_0); + if (domImplLS == null) { + log.error("Failed to get DOMImplementation " + DOM_LS_3_0); + throw new SLRuntimeException("Failed to get DOMImplementation " + DOM_LS_3_0); + } + + } + + /** + * @return the reference + */ + public Reference getReference() { + return reference; + } + + /** + * @return the xmlObject + */ + public XMLObject getXmlObject() { + return xmlObject; + } + + /** + * @return the mimeType + */ + public String getMimeType() { + return mimeType; + } + + /** + * @return the description + */ + public String getDescription() { + return description; + } public void validateHashDataInput() throws SLViewerException { @@ -293,823 +300,920 @@ public class DataObject { } } - - /** - * Configures this DataObject with the information provided within the given - * sl:DataObjectInfo. - * - * @param dataObjectInfo - * the sl:DataObjectInfo - * - * @throws SLCommandException - * if configuring this DataObject with the information provided in - * the sl:DataObjectInfo fails. - * @throws SLRequestException - * if the information provided in the sl:DataObjectInfo - * does not conform to the security layer specification. - * @throws NullPointerException - * if dataObjectInfo is null - */ - public void setDataObjectInfo(DataObjectInfoType dataObjectInfo) throws SLCommandException, SLRequestException { - - Base64XMLLocRefOptRefContentType dataObject = dataObjectInfo.getDataObject(); - String structure = dataObjectInfo.getStructure(); - - // select and unmarshal an appropriate transformation path if provided - // and set the final data meta information - XSECTTransforms transforms = createTransformsAndSetFinalDataMetaInfo(dataObjectInfo.getTransformsInfo()); - - if ("enveloping".equals(structure)) { - - // configure this DataObject as an enveloped DataObject - setEnvelopedDataObject(dataObject, transforms); - - } else if ("detached".equals(structure)) { - - // configure this DataObject as an detached DataObject - setDetachedDataObject(dataObject, transforms); - - } - // other values are not allowed by the schema and are therefore ignored - - } - - /** - * Configures this DataObject as an enveloped DataObject with the information - * provided within the given sl:DataObject. - * - * @param dataObject - * the sl:DataObject - * @param transforms - * an optional Transforms element (may be - * null) - * - * @throws SLCommandException - * if configuring this DataObject with the information provided in - * the sl:DataObject fails. - * @throws SLRequestException - * if the information provided in the sl:DataObject - * does not conform to the security layer specification. - * @throws NullPointerException - * if dataObject is null - */ - private void setEnvelopedDataObject( - Base64XMLLocRefOptRefContentType dataObject, XSECTTransforms transforms) - throws SLCommandException, SLRequestException { - - String reference = dataObject.getReference(); - if (reference == null) { - // - // case A - // - // The Reference attribute is not used; the content of sl:DataObject represents the data object. - // If the data object is XML-coded (the sl:XMLContent element is used in sl:DataObject), then it - // must be incorporated in the signature structure as parsed XML. - // - - if (dataObject.getBase64Content() != null) { - - log.debug("Adding DataObject (Base64Content) without a reference URI."); - - // create XMLObject - XMLObject xmlObject = createXMLObject(new ByteArrayInputStream(dataObject.getBase64Content())); - - setXMLObjectAndReferenceBase64(xmlObject, transforms); - - } else if (dataObject.getXMLContent() != null) { - - log.debug("Adding DataObject (XMLContent) without a reference URI."); - - // create XMLObject - DocumentFragment content = parseDataObject((XMLContentType) dataObject.getXMLContent()); - XMLObject xmlObject = createXMLObject(content); - - setXMLObjectAndReferenceXML(xmlObject, transforms); - - } else if (dataObject.getLocRefContent() != null) { - - log.debug("Adding DataObject (LocRefContent) without a reference URI."); - - setEnvelopedDataObject(dataObject.getLocRefContent(), transforms); - - } else { - - // not allowed - log.info("XML structure of the command request contains an " + - "invalid combination of optional elements or attributes. " + - "DataObject of structure='enveloped' without a reference must contain content."); - throw new SLRequestException(3003); - - } - - } else { - - if (dataObject.getBase64Content() == null && - dataObject.getXMLContent() == null && - dataObject.getLocRefContent() == null) { - - // - // case B - // - // The Reference attribute contains a URI that must be resolved by the - // Citizen Card Environment to obtain the data object. - // The content of sl:DataObject remains empty - // - - log.debug("Adding DataObject from reference URI '" + reference + "'."); - - setEnvelopedDataObject(reference, transforms); - - } else { - - // not allowed - log.info("XML structure of the command request contains an " + - "invalid combination of optional elements or attributes. " + - "DataObject of structure='enveloped' with reference must not contain content."); - throw new SLRequestException(3003); - - } - - - } - - } - - /** - * Configures this DataObject as an enveloped DataObject with the content to - * be dereferenced from the given reference. - * - * @param reference - * the reference URI - * @param transforms - * an optional Transforms element (may be - * null) - * - * @throws SLCommandException - * if dereferencing the given reference fails, or if - * configuring this DataObject with the data dereferenced from the - * given reference fails. - * @throws NullPointerException - * if reference is null - */ - private void setEnvelopedDataObject(String reference, XSECTTransforms transforms) throws SLCommandException { - - if (reference == null) { - throw new NullPointerException("Argument 'reference' must not be null."); - } - - // dereference URL - URLDereferencer dereferencer = URLDereferencer.getInstance(); - - StreamData streamData; - try { - streamData = dereferencer.dereference(reference, ctx.getDereferencerContext()); - } catch (IOException e) { - log.info("Failed to dereference XMLObject from '" + reference + "'.", e); - throw new SLCommandException(4110); - } - - Node childNode; - - String contentType = streamData.getContentType(); - if (contentType.startsWith("text/xml")) { - - // If content type is text/xml parse content. - String charset = HttpUtil.getCharset(contentType, true); - - Document doc = parseDataObject(streamData.getStream(), charset); - - childNode = doc.getDocumentElement(); - - if (childNode == null) { - log.info("Failed to parse XMLObject from '" + reference + "'."); - throw new SLCommandException(4111); - } - - XMLObject xmlObject = createXMLObject(childNode); - - setXMLObjectAndReferenceXML(xmlObject, transforms); - - } else { - - // Include content Base64 encoded. - XMLObject xmlObject = createXMLObject(streamData.getStream()); - - setXMLObjectAndReferenceBase64(xmlObject, transforms); - - } - - } - - /** - * Configures this DataObject as an detached DataObject with the information - * provided in the given sl:DataObject and optionally - * transforms. - * - * @param dataObject - * the sl:DataObject - * @param transforms - * an optional Transforms object, may be null - * - * @throws SLCommandException - * if configuring this DataObject with the information provided in - * the sl:DataObject fails. - * @throws SLRequestException - * if the information provided in the sl:DataObject - * does not conform to the security layer specification. - * @throws NullPointerException - * if dataObject is null - */ - private void setDetachedDataObject( - Base64XMLLocRefOptRefContentType dataObject, XSECTTransforms transforms) - throws SLCommandException, SLRequestException { - - String referenceURI = dataObject.getReference(); - - if (referenceURI == null) { - - // not allowed - log.info("XML structure of the command request contains an " + - "invalid combination of optional elements or attributes. " + - "DataObject of structure='detached' must contain a reference."); - throw new SLRequestException(3003); - - } else { - - DigestMethod dm; - try { - dm = ctx.getAlgorithmMethodFactory().createDigestMethod(ctx); - } catch (NoSuchAlgorithmException e) { - log.error("Failed to get DigestMethod.", e); - throw new SLCommandException(4006); - } catch (InvalidAlgorithmParameterException e) { - log.error("Failed to get DigestMethod.", e); - throw new SLCommandException(4006); - } - - String idValue = ctx.getIdValueFactory().createIdValue("Reference"); - - reference = new XSECTReference(referenceURI, dm, transforms, null, idValue); - - // case D: - // - // The Reference attribute contains a URI that is used by the Citizen Card - // Environment to code the reference to the data object as part of the XML - // signature (attribute URI in the dsig:Reference) element. The content of - // sl:DataObject represents the data object. - - if (dataObject.getLocRefContent() != null) { - String locRef = dataObject.getLocRefContent(); - try { - this.reference.setDereferencer(new LocRefDereferencer(ctx.getDereferencerContext(), locRef)); - } catch (URISyntaxException e) { - log.info("Invalid URI '" + locRef + "' in DataObject.", e); - throw new SLCommandException(4003); - } catch (IllegalArgumentException e) { - log.info("LocRef URI of '" + locRef + "' not supported in DataObject. ", e); - throw new SLCommandException(4003); - } - } else if (dataObject.getBase64Content() != null) { - byte[] base64Content = dataObject.getBase64Content(); - this.reference.setDereferencer(new ByteArrayDereferencer(base64Content)); - } else if (dataObject.getXMLContent() != null) { - XMLContentType xmlContent = (XMLContentType) dataObject.getXMLContent(); - byte[] bytes = xmlContent.getRedirectedStream().toByteArray(); - this.reference.setDereferencer(new ByteArrayDereferencer(bytes)); - } else { - - // case C: - // - // The Reference attribute contains a URI that must be resolved by the - // Citizen Card Environment to obtain the data object. The Reference - // attribute contains a URI that is used by the Citizen Card Environment - // to code the reference to the data object as part of the XML signature - // (attribute URI in the dsig:Reference) element. The content of - // sl:DataObject remains empty. - - } - - } - } - - /** - * Returns the preferred sl:TransformInfo from the given list of - * transformInfos, or null if none of the given - * transformInfos is preferred over the others. - * - * @param transformsInfos - * a list of sl:TransformInfos - * - * @return the selected sl:TransformInfo or null, if - * none is preferred over the others - */ - private TransformsInfoType selectPreferredTransformsInfo(List transformsInfos) { - - Map mimeTypes = new HashMap(); - - StringBuilder debugString = null; - if (log.isDebugEnabled()) { - debugString = new StringBuilder(); - debugString.append("Got " + transformsInfos.size() + " TransformsInfo(s):"); - } - - for (TransformsInfoType transformsInfoType : transformsInfos) { - MetaInfoType finalDataMetaInfo = transformsInfoType.getFinalDataMetaInfo(); - String mimeType = finalDataMetaInfo.getMimeType(); - String description = finalDataMetaInfo.getDescription(); - mimeTypes.put(mimeType, transformsInfoType); - if (debugString != null) { - debugString.append("\n FinalDataMetaInfo: MIME-Type="); - debugString.append(mimeType); - if (description != null) { - debugString.append(" "); - debugString.append(description); - } - } - } - - if (debugString != null) { - log.debug(debugString); - } - - // look for preferred transform - for (String mimeType : DEFAULT_PREFFERED_MIME_TYPES) { - if (mimeTypes.containsKey(mimeType)) { - return mimeTypes.get(mimeType); - } - } - - // no preferred transform - return null; - - } - - /** - * Create an instance of ds:Transforms from the given - * sl:TransformsInfo. - * - * @param transformsInfo - * the sl:TransformsInfo - * - * @return a corresponding unmarshalled ds:Transforms, or - * null if the given sl:TransformsInfo does - * not contain a dsig:Transforms element - * - * @throws SLRequestException - * if the ds:Transforms in the given - * transformsInfo are not valid or cannot be parsed. - * - * @throws MarshalException - * if the ds:Transforms in the given - * transformsInfo cannot be unmarshalled. - */ - private XSECTTransforms createTransforms(TransformsInfoType transformsInfo) throws SLRequestException, MarshalException { - - ByteArrayOutputStream redirectedStream = ((at.gv.egiz.slbinding.impl.TransformsInfoType) transformsInfo).getRedirectedStream(); - byte[] transformBytes = (redirectedStream != null) ? redirectedStream.toByteArray() : null; - - if (transformBytes != null && transformBytes.length > 0) { - - // debug - if (log.isTraceEnabled()) { - StringBuilder sb = new StringBuilder(); - sb.append("Trying to parse transforms:\n"); - sb.append(new String(transformBytes, Charset.forName("UTF-8"))); - log.trace(sb); - } - - DOMImplementationLS domImplLS = DOMUtils.getDOMImplementationLS(); - LSInput input = domImplLS.createLSInput(); - input.setByteStream(new ByteArrayInputStream(transformBytes)); - - LSParser parser = domImplLS.createLSParser( - DOMImplementationLS.MODE_SYNCHRONOUS, null); - DOMConfiguration domConfig = parser.getDomConfig(); - SimpleDOMErrorHandler errorHandler = new SimpleDOMErrorHandler(); - domConfig.setParameter("error-handler", errorHandler); - domConfig.setParameter("validate", Boolean.FALSE); - - Document document; - try { - document = parser.parse(input); - } catch (DOMException e) { - log.info("Failed to parse dsig:Transforms.", e); - throw new SLRequestException(3002); - } catch (LSException e) { - log.info("Failed to parse dsig:Transforms.", e); - throw new SLRequestException(3002); - } - - // adopt ds:Transforms - Element documentElement = document.getDocumentElement(); - Node adoptedTransforms = ctx.getDocument().adoptNode(documentElement); - - DOMCryptoContext context = new DOMCryptoContext(); - - // unmarshall ds:Transforms - return new XSECTTransforms(context, adoptedTransforms); - - } else { - return null; - } - - } - - /** - * Sets the mimeType and the description value - * for this DataObject. - * - * @param metaInfoType the sl:FinalMetaDataInfo - * - * @throws NullPointerException if metaInfoType is null - */ - private void setFinalDataMetaInfo(MetaInfoType metaInfoType) { - - this.mimeType = metaInfoType.getMimeType(); - this.description = metaInfoType.getDescription(); - - } - - /** - * Selects an appropriate transformation path (if present) from the given list - * of sl:TransformInfos, sets the corresponding final data meta info and - * returns the corresponding unmarshalled ds:Transforms. - * - * @param transformsInfos the sl:TransformInfos - * - * @return the unmarshalled ds:Transforms, or null if - * no transformation path has been selected. - * - * @throws SLRequestException if the given list ds:TransformsInfo contains - * an invalid ds:Transforms element, or no suitable transformation path - * can be found. - */ - private XSECTTransforms createTransformsAndSetFinalDataMetaInfo( - List transformsInfos) throws SLRequestException { - - TransformsInfoType preferredTransformsInfo = selectPreferredTransformsInfo(transformsInfos); - // try preferred transform - if (preferredTransformsInfo != null) { - - try { - XSECTTransforms transforms = createTransforms(preferredTransformsInfo); - setFinalDataMetaInfo(preferredTransformsInfo.getFinalDataMetaInfo()); - return transforms; - } catch (MarshalException e) { - - String mimeType = preferredTransformsInfo.getFinalDataMetaInfo().getMimeType(); - log.info("Failed to unmarshal preferred transformation path (MIME-Type=" - + mimeType + ").", e); - - } - - } - - // look for another suitable transformation path - for (TransformsInfoType transformsInfoType : transformsInfos) { - - try { - XSECTTransforms transforms = createTransforms(transformsInfoType); - setFinalDataMetaInfo(transformsInfoType.getFinalDataMetaInfo()); - return transforms; - } catch (MarshalException e) { - - String mimeType = transformsInfoType.getFinalDataMetaInfo().getMimeType(); - log.info("Failed to unmarshal transformation path (MIME-Type=" - + mimeType + ").", e); - } - - } - - // no suitable transformation path found - throw new SLRequestException(3003); - - } - - /** - * Create an XMLObject with the Base64 encoding of the given - * content. - * - * @param content - * the to-be Base64 encoded content - * @return an XMLObject with the Base64 encoded content - */ - private XMLObject createXMLObject(InputStream content) { - - Text textNode; - try { - textNode = at.gv.egiz.dom.DOMUtils.createBase64Text(content, ctx.getDocument()); - } catch (IOException e) { - log.error(e); - throw new SLRuntimeException(e); - } - - DOMStructure structure = new DOMStructure(textNode); - - String idValue = ctx.getIdValueFactory().createIdValue("Object"); - - return ctx.getSignatureFactory().newXMLObject(Collections.singletonList(structure), idValue, null, null); - - } - - /** - * Create an XMLObject with the given content node. - * - * @param content the content node - * - * @return an XMLObject with the given content - */ - private XMLObject createXMLObject(Node content) { - - String idValue = ctx.getIdValueFactory().createIdValue("Object"); - - List structures = Collections.singletonList(new DOMStructure(content)); - - return ctx.getSignatureFactory().newXMLObject(structures, idValue, null, null); - - } - - /** - * Sets the given xmlObject and creates and sets a corresponding - * Reference. - *

- * A transform to Base64-decode the xmlObject's content is inserted at the top - * of to the optional transforms if given, or to a newly created - * Transforms element if transforms is - * null. - * - * @param xmlObject - * the XMLObject - * @param transforms - * an optional Transforms element (may be - * null) - * - * @throws SLCommandException - * if creating the Reference fails - * @throws NullPointerException - * if xmlObject is null - */ - private void setXMLObjectAndReferenceBase64(XMLObject xmlObject, XSECTTransforms transforms) throws SLCommandException { - - // create reference URI - // - // NOTE: the ds:Object can be referenced directly, as the Base64 transform - // operates on the text() of the input nodelist. - // - String referenceURI = "#" + xmlObject.getId(); - - // create Base64 Transform - Transform transform; - try { - transform = ctx.getSignatureFactory().newTransform(Transform.BASE64, (TransformParameterSpec) null); - } catch (NoSuchAlgorithmException e) { - // algorithm must be present - throw new SLRuntimeException(e); - } catch (InvalidAlgorithmParameterException e) { - // algorithm does not take parameters - throw new SLRuntimeException(e); - } - - if (transforms == null) { - transforms = new XSECTTransforms(Collections.singletonList(transform)); - } else { - transforms.insertTransform(transform); - } - - DigestMethod dm; - try { - dm = ctx.getAlgorithmMethodFactory().createDigestMethod(ctx); - } catch (NoSuchAlgorithmException e) { - log.error("Failed to get DigestMethod.", e); - throw new SLCommandException(4006); - } catch (InvalidAlgorithmParameterException e) { - log.error("Failed to get DigestMethod.", e); - throw new SLCommandException(4006); - } - String id = ctx.getIdValueFactory().createIdValue("Reference"); - - this.xmlObject = xmlObject; - this.reference = new XSECTReference(referenceURI, dm, transforms, null, id); - - } - - /** - * Sets the given xmlObject and creates and sets a corresponding - * Reference. - *

- * A transform to select the xmlObject's content is inserted at the top of to - * the optional transforms if given, or to a newly created - * Transforms element if transforms is - * null. - *

- * - * @param xmlObject - * the XMLObject - * @param transforms - * an optional Transforms element (may be - * null) - * - * @throws SLCommandException - * if creating the Reference fails - * @throws NullPointerException - * if xmlObject is null - */ - private void setXMLObjectAndReferenceXML(XMLObject xmlObject, XSECTTransforms transforms) throws SLCommandException { - - // create reference URI - String referenceURI = "#" + xmlObject.getId(); - - // create Transform to select ds:Object's children - Transform xpathTransform; - Transform c14nTransform; - try { - - XPathType xpath = new XPathType("id(\"" + xmlObject.getId() + "\")/node()", XPathType.Filter.INTERSECT); - List xpaths = Collections.singletonList(xpath); - XPathFilter2ParameterSpec params = new XPathFilter2ParameterSpec(xpaths); - - xpathTransform = ctx.getSignatureFactory().newTransform(Transform.XPATH2, params); - - // add exclusive canonicalization to avoid signing the namespace context of the ds:Object - c14nTransform = ctx.getSignatureFactory().newTransform(CanonicalizationMethod.EXCLUSIVE, (TransformParameterSpec) null); - - } catch (NoSuchAlgorithmException e) { - // algorithm must be present - throw new SLRuntimeException(e); - } catch (InvalidAlgorithmParameterException e) { - // params must be appropriate - throw new SLRuntimeException(e); - } - - if (transforms == null) { - List newTransfroms = new ArrayList(); - newTransfroms.add(xpathTransform); - newTransfroms.add(c14nTransform); - transforms = new XSECTTransforms(newTransfroms); - } else { - transforms.insertTransform(xpathTransform); - } - - DigestMethod dm; - try { - dm = ctx.getAlgorithmMethodFactory().createDigestMethod(ctx); - } catch (NoSuchAlgorithmException e) { - log.error("Failed to get DigestMethod.", e); - throw new SLCommandException(4006); - } catch (InvalidAlgorithmParameterException e) { - log.error("Failed to get DigestMethod.", e); - throw new SLCommandException(4006); - } - String id = ctx.getIdValueFactory().createIdValue("Reference"); - - this.xmlObject = xmlObject; - this.reference = new XSECTReference(referenceURI, dm, transforms, null, id); - - } - - /** - * Parses the given xmlContent and returns a corresponding - * document fragment. - * - *

- * The to-be parsed content is surrounded by ... elements to - * allow for mixed (e.g. Text and Element) content in XMLContent. - *

- * - * @param xmlContent - * the XMLContent to-be parsed - * - * @return a document fragment containing the parsed nodes - * - * @throws SLCommandException - * if parsing the given xmlContent fails - * - * @throws NullPointerException - * if xmlContent is null - */ - private DocumentFragment parseDataObject(XMLContentType xmlContent) throws SLCommandException { - - ByteArrayOutputStream redirectedStream = xmlContent.getRedirectedStream(); - - // Note: We can assume a fixed character encoding of UTF-8 for the - // content of the redirect stream as the content has already been parsed - // and serialized again to the redirect stream. - - List inputStreams = new ArrayList(); - try { - // dummy start element - inputStreams.add(new ByteArrayInputStream("".getBytes("UTF-8"))); - - // content - inputStreams.add(new ByteArrayInputStream(redirectedStream.toByteArray())); - - // dummy end element - inputStreams.add(new ByteArrayInputStream("".getBytes("UTF-8"))); - } catch (UnsupportedEncodingException e) { - throw new SLRuntimeException(e); - } - - SequenceInputStream inputStream = new SequenceInputStream(Collections.enumeration(inputStreams)); - - // parse DataObject - Document doc = parseDataObject(inputStream, "UTF-8"); - - Element documentElement = doc.getDocumentElement(); - - if (documentElement == null || - !"dummy".equals(documentElement.getLocalName())) { - log.info("Failed to parse DataObject XMLContent."); - throw new SLCommandException(4111); - } - - DocumentFragment fragment = doc.createDocumentFragment(); - while (documentElement.getFirstChild() != null) { - fragment.appendChild(documentElement.getFirstChild()); - } - - // log parsed document - if (log.isTraceEnabled()) { - - StringWriter writer = new StringWriter(); - - writer.write("DataObject:\n"); - - LSOutput output = domImplLS.createLSOutput(); - output.setCharacterStream(writer); - output.setEncoding("UTF-8"); - LSSerializer serializer = domImplLS.createLSSerializer(); - serializer.getDomConfig().setParameter("xml-declaration", Boolean.FALSE); - serializer.write(fragment, output); - - log.trace(writer.toString()); - } - - return fragment; - - } - - /** - * Parses the given inputStream using the given - * encoding and returns the parsed document. - * - * @param inputStream - * the to-be parsed input - * - * @param encoding - * the encoding to be used for parsing the given - * inputStream - * - * @return the parsed document - * - * @throws SLCommandException - * if parsing the inputStream fails. - * - * @throws NullPointerException - * if inputStram is null - */ - private Document parseDataObject(InputStream inputStream, String encoding) throws SLCommandException { - - LSInput input = domImplLS.createLSInput(); - input.setByteStream(inputStream); - - if (encoding != null) { - input.setEncoding(encoding); - } - - LSParser parser = domImplLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null); - DOMConfiguration domConfig = parser.getDomConfig(); - SimpleDOMErrorHandler errorHandler = new SimpleDOMErrorHandler(); - domConfig.setParameter("error-handler", errorHandler); - domConfig.setParameter("validate", Boolean.FALSE); - - Document doc; - try { - doc = parser.parse(input); - } catch (DOMException e) { - log.info("Existing XML document cannot be parsed.", e); - throw new SLCommandException(4111); - } catch (LSException e) { - log.info("Existing XML document cannot be parsed. ", e); - throw new SLCommandException(4111); - } - - if (errorHandler.hasErrors()) { - // log errors - if (log.isInfoEnabled()) { - List errorMessages = errorHandler.getErrorMessages(); - StringBuffer sb = new StringBuffer(); - for (String errorMessage : errorMessages) { - sb.append(" "); - sb.append(errorMessage); - } - log.info("Existing XML document cannot be parsed. " + sb.toString()); - } - throw new SLCommandException(4111); - } - - return doc; - - } - - -} + + /** + * Configures this DataObject with the information provided within the given + * sl:DataObjectInfo. + * + * @param dataObjectInfo + * the sl:DataObjectInfo + * + * @throws SLCommandException + * if configuring this DataObject with the information provided in + * the sl:DataObjectInfo fails. + * @throws SLRequestException + * if the information provided in the sl:DataObjectInfo + * does not conform to the security layer specification. + * @throws NullPointerException + * if dataObjectInfo is null + */ + public void setDataObjectInfo(DataObjectInfoType dataObjectInfo) throws SLCommandException, SLRequestException { + + Base64XMLLocRefOptRefContentType dataObject = dataObjectInfo.getDataObject(); + String structure = dataObjectInfo.getStructure(); + + // select and unmarshal an appropriate transformation path if provided + // and set the final data meta information + XSECTTransforms transforms = createTransformsAndSetFinalDataMetaInfo(dataObjectInfo.getTransformsInfo()); + + if ("enveloping".equals(structure)) { + + // configure this DataObject as an enveloped DataObject + setEnvelopedDataObject(dataObject, transforms); + + } else if ("detached".equals(structure)) { + + // configure this DataObject as an detached DataObject + setDetachedDataObject(dataObject, transforms); + + } + // other values are not allowed by the schema and are therefore ignored + + } + + private byte[] getTransformsBytes(at.gv.egiz.slbinding.impl.TransformsInfoType ti) { + return ti.getRedirectedStream().toByteArray(); +// byte[] transformsBytes = ti.getRedirectedStream().toByteArray(); +// +// if (transformsBytes == null || transformsBytes.length == 0) { +// return null; +// } +// +// String dsigPrefix = ti.getNamespaceContext().getNamespaceURI("http://www.w3.org/2000/09/xmldsig#"); +// byte[] pre, post; +// if (dsigPrefix == null) { +// log.trace("XMLDSig not declared in outside dsig:Transforms"); +// pre = "".getBytes(); +// post = "".getBytes(); +// } else { +// log.trace("XMLDSig bound to prefix " + dsigPrefix); +// pre = ("").getBytes(); +// post = "".getBytes(); +// } +// +// byte[] workaround = new byte[pre.length + transformsBytes.length + post.length]; +// System.arraycopy(pre, 0, workaround, 0, pre.length); +// System.arraycopy(transformsBytes, 0, workaround, pre.length, transformsBytes.length); +// System.arraycopy(post, 0, workaround, pre.length + transformsBytes.length, post.length); +// return workaround; + } + + /** + * Configures this DataObject as an enveloped DataObject with the information + * provided within the given sl:DataObject. + * + * @param dataObject + * the sl:DataObject + * @param transforms + * an optional Transforms element (may be + * null) + * + * @throws SLCommandException + * if configuring this DataObject with the information provided in + * the sl:DataObject fails. + * @throws SLRequestException + * if the information provided in the sl:DataObject + * does not conform to the security layer specification. + * @throws NullPointerException + * if dataObject is null + */ + private void setEnvelopedDataObject( + Base64XMLLocRefOptRefContentType dataObject, XSECTTransforms transforms) + throws SLCommandException, SLRequestException { + + String reference = dataObject.getReference(); + if (reference == null) { + // + // case A + // + // The Reference attribute is not used; the content of sl:DataObject represents the data object. + // If the data object is XML-coded (the sl:XMLContent element is used in sl:DataObject), then it + // must be incorporated in the signature structure as parsed XML. + // + + if (dataObject.getBase64Content() != null) { + + log.debug("Adding DataObject (Base64Content) without a reference URI."); + + // create XMLObject + XMLObject xmlObject = createXMLObject(new ByteArrayInputStream(dataObject.getBase64Content())); + + setXMLObjectAndReferenceBase64(xmlObject, transforms); + + } else if (dataObject.getXMLContent() != null) { + + log.debug("Adding DataObject (XMLContent) without a reference URI."); + + // create XMLObject + DocumentFragment content = parseDataObject((XMLContentType) dataObject.getXMLContent()); + XMLObject xmlObject = createXMLObject(content); + + setXMLObjectAndReferenceXML(xmlObject, transforms); + + } else if (dataObject.getLocRefContent() != null) { + + log.debug("Adding DataObject (LocRefContent) without a reference URI."); + + setEnvelopedDataObject(dataObject.getLocRefContent(), transforms); + + } else { + + // not allowed + log.info("XML structure of the command request contains an " + + "invalid combination of optional elements or attributes. " + + "DataObject of structure='enveloped' without a reference must contain content."); + throw new SLRequestException(3003); + + } + + } else { + + if (dataObject.getBase64Content() == null && + dataObject.getXMLContent() == null && + dataObject.getLocRefContent() == null) { + + // + // case B + // + // The Reference attribute contains a URI that must be resolved by the + // Citizen Card Environment to obtain the data object. + // The content of sl:DataObject remains empty + // + + log.debug("Adding DataObject from reference URI '" + reference + "'."); + + setEnvelopedDataObject(reference, transforms); + + } else { + + // not allowed + log.info("XML structure of the command request contains an " + + "invalid combination of optional elements or attributes. " + + "DataObject of structure='enveloped' with reference must not contain content."); + throw new SLRequestException(3003); + + } + + + } + + } + + /** + * Configures this DataObject as an enveloped DataObject with the content to + * be dereferenced from the given reference. + * + * @param reference + * the reference URI + * @param transforms + * an optional Transforms element (may be + * null) + * + * @throws SLCommandException + * if dereferencing the given reference fails, or if + * configuring this DataObject with the data dereferenced from the + * given reference fails. + * @throws NullPointerException + * if reference is null + */ + private void setEnvelopedDataObject(String reference, XSECTTransforms transforms) throws SLCommandException { + + if (reference == null) { + throw new NullPointerException("Argument 'reference' must not be null."); + } + + // dereference URL + URLDereferencer dereferencer = URLDereferencer.getInstance(); + + StreamData streamData; + try { + streamData = dereferencer.dereference(reference, ctx.getDereferencerContext()); + } catch (IOException e) { + log.info("Failed to dereference XMLObject from '" + reference + "'.", e); + throw new SLCommandException(4110); + } + + Node childNode; + + String contentType = streamData.getContentType(); + if (contentType.startsWith("text/xml")) { + + // If content type is text/xml parse content. + String charset = HttpUtil.getCharset(contentType, true); + + Document doc = parseDataObject(streamData.getStream(), charset); + + childNode = doc.getDocumentElement(); + + if (childNode == null) { + log.info("Failed to parse XMLObject from '" + reference + "'."); + throw new SLCommandException(4111); + } + + XMLObject xmlObject = createXMLObject(childNode); + + setXMLObjectAndReferenceXML(xmlObject, transforms); + + } else { + + // Include content Base64 encoded. + XMLObject xmlObject = createXMLObject(streamData.getStream()); + + setXMLObjectAndReferenceBase64(xmlObject, transforms); + + } + + } + + /** + * Configures this DataObject as an detached DataObject with the information + * provided in the given sl:DataObject and optionally + * transforms. + * + * @param dataObject + * the sl:DataObject + * @param transforms + * an optional Transforms object, may be null + * + * @throws SLCommandException + * if configuring this DataObject with the information provided in + * the sl:DataObject fails. + * @throws SLRequestException + * if the information provided in the sl:DataObject + * does not conform to the security layer specification. + * @throws NullPointerException + * if dataObject is null + */ + private void setDetachedDataObject( + Base64XMLLocRefOptRefContentType dataObject, XSECTTransforms transforms) + throws SLCommandException, SLRequestException { + + String referenceURI = dataObject.getReference(); + + if (referenceURI == null) { + + // not allowed + log.info("XML structure of the command request contains an " + + "invalid combination of optional elements or attributes. " + + "DataObject of structure='detached' must contain a reference."); + throw new SLRequestException(3003); + + } else { + + DigestMethod dm; + try { + dm = ctx.getAlgorithmMethodFactory().createDigestMethod(ctx); + } catch (NoSuchAlgorithmException e) { + log.error("Failed to get DigestMethod.", e); + throw new SLCommandException(4006); + } catch (InvalidAlgorithmParameterException e) { + log.error("Failed to get DigestMethod.", e); + throw new SLCommandException(4006); + } + + String idValue = ctx.getIdValueFactory().createIdValue("Reference"); + + reference = new XSECTReference(referenceURI, dm, transforms, null, idValue); + + // case D: + // + // The Reference attribute contains a URI that is used by the Citizen Card + // Environment to code the reference to the data object as part of the XML + // signature (attribute URI in the dsig:Reference) element. The content of + // sl:DataObject represents the data object. + + if (dataObject.getLocRefContent() != null) { + String locRef = dataObject.getLocRefContent(); + try { + this.reference.setDereferencer(new LocRefDereferencer(ctx.getDereferencerContext(), locRef)); + } catch (URISyntaxException e) { + log.info("Invalid URI '" + locRef + "' in DataObject.", e); + throw new SLCommandException(4003); + } catch (IllegalArgumentException e) { + log.info("LocRef URI of '" + locRef + "' not supported in DataObject. ", e); + throw new SLCommandException(4003); + } + } else if (dataObject.getBase64Content() != null) { + byte[] base64Content = dataObject.getBase64Content(); + this.reference.setDereferencer(new ByteArrayDereferencer(base64Content)); + } else if (dataObject.getXMLContent() != null) { + XMLContentType xmlContent = (XMLContentType) dataObject.getXMLContent(); + byte[] bytes = xmlContent.getRedirectedStream().toByteArray(); + this.reference.setDereferencer(new ByteArrayDereferencer(bytes)); + } else { + + // case C: + // + // The Reference attribute contains a URI that must be resolved by the + // Citizen Card Environment to obtain the data object. The Reference + // attribute contains a URI that is used by the Citizen Card Environment + // to code the reference to the data object as part of the XML signature + // (attribute URI in the dsig:Reference) element. The content of + // sl:DataObject remains empty. + + } + + } + } + + /** + * Returns the preferred sl:TransformInfo from the given list of + * transformInfos, or null if none of the given + * transformInfos is preferred over the others. + * + * @param transformsInfos + * a list of sl:TransformInfos + * + * @return the selected sl:TransformInfo or null, if + * none is preferred over the others + */ + private TransformsInfoType selectPreferredTransformsInfo(List transformsInfos) { + + Map mimeTypes = new HashMap(); + + StringBuilder debugString = null; + if (log.isDebugEnabled()) { + debugString = new StringBuilder(); + debugString.append("Got " + transformsInfos.size() + " TransformsInfo(s):"); + } + + for (TransformsInfoType transformsInfoType : transformsInfos) { + MetaInfoType finalDataMetaInfo = transformsInfoType.getFinalDataMetaInfo(); + String mimeType = finalDataMetaInfo.getMimeType(); + String description = finalDataMetaInfo.getDescription(); + mimeTypes.put(mimeType, transformsInfoType); + if (debugString != null) { + debugString.append("\n FinalDataMetaInfo: MIME-Type="); + debugString.append(mimeType); + if (description != null) { + debugString.append(" "); + debugString.append(description); + } + } + } + + if (debugString != null) { + log.debug(debugString); + } + + // look for preferred transform + for (String mimeType : DEFAULT_PREFFERED_MIME_TYPES) { + if (mimeTypes.containsKey(mimeType)) { + return mimeTypes.get(mimeType); + } + } + + // no preferred transform + return null; + + } + + /** + * Create an instance of ds:Transforms from the given + * sl:TransformsInfo. + * + * @param transformsInfo + * the sl:TransformsInfo + * + * @return a corresponding unmarshalled ds:Transforms, or + * null if the given sl:TransformsInfo does + * not contain a dsig:Transforms element + * + * @throws SLRequestException + * if the ds:Transforms in the given + * transformsInfo are not valid or cannot be parsed. + * + * @throws MarshalException + * if the ds:Transforms in the given + * transformsInfo cannot be unmarshalled. + */ + private XSECTTransforms createTransforms(TransformsInfoType transformsInfo) throws SLRequestException, MarshalException { + + byte[] transforms = getTransformsBytes((at.gv.egiz.slbinding.impl.TransformsInfoType) transformsInfo); + + if (transforms != null && transforms.length > 0) { + // debug + if (log.isTraceEnabled()) { + StringBuilder sb = new StringBuilder(); + sb.append("Trying to parse transforms:\n"); + sb.append(new String(transforms, Charset.forName("UTF-8"))); + log.trace(sb); + } + + DOMImplementationLS domImplLS = DOMUtils.getDOMImplementationLS(); + LSInput input = domImplLS.createLSInput(); + input.setByteStream(new ByteArrayInputStream(transforms)); + + LSParser parser = domImplLS.createLSParser( + DOMImplementationLS.MODE_SYNCHRONOUS, null); + DOMConfiguration domConfig = parser.getDomConfig(); + SimpleDOMErrorHandler errorHandler = new SimpleDOMErrorHandler(); + domConfig.setParameter("error-handler", errorHandler); + domConfig.setParameter("validate", Boolean.FALSE); + + Document document; + try { + document = parser.parse(input); + } catch (DOMException e) { + log.info("Failed to parse dsig:Transforms.", e); + throw new SLRequestException(3002); + } catch (LSException e) { + log.info("Failed to parse dsig:Transforms.", e); + throw new SLRequestException(3002); + } + + // adopt ds:Transforms + Element transformsElt = document.getDocumentElement(); + Node adoptedTransforms = ctx.getDocument().adoptNode(transformsElt); + + DOMCryptoContext context = new DOMCryptoContext(); + + // unmarshall ds:Transforms + return new XSECTTransforms(context, adoptedTransforms); + + } else { + return null; + } + + +// TransformsType transformsType = transformsInfo.getTransforms(); +// if (transformsType == null) { +// return null; +// } +// List transformList = transformsType.getTransform(); +// +// DOMImplementationLS domImplLS = DOMUtils.getDOMImplementationLS(); +//// Document transformsDoc = ((DOMImplementation) domImplLS).createDocument("http://www.w3.org/2000/09/xmldsig#", "Transforms", null); +//// Element transforms = transformsDoc.getDocumentElement(); +// Document transformsDoc = DOMUtils.createDocument(); +// Element transforms = transformsDoc.createElementNS( +// "http://www.w3.org/2000/09/xmldsig#", +// Signature.XMLDSIG_PREFIX + ":Transforms"); +// transformsDoc.appendChild(transforms); +// +// for (TransformType transformType : transformList) { +// log.trace("found " + transformType.getClass().getName()); +// Element transform = transformsDoc.createElementNS( +// "http://www.w3.org/2000/09/xmldsig#", +// Signature.XMLDSIG_PREFIX + ":Transform"); +// String algorithm = transformType.getAlgorithm(); +// if (algorithm != null) { +// log.trace("found algorithm " + algorithm); +// transform.setAttribute("Algorithm", algorithm); +// } +// +// at.gv.egiz.slbinding.impl.TransformType t = (at.gv.egiz.slbinding.impl.TransformType) transformType; +// byte[] redirectedBytes = t.getRedirectedStream().toByteArray(); +// if (redirectedBytes != null && redirectedBytes.length > 0) { +// if (log.isTraceEnabled()) { +// StringBuilder sb = new StringBuilder(); +// sb.append("Trying to parse dsig:Transform:\n"); +// sb.append(new String(redirectedBytes, Charset.forName("UTF-8"))); +// log.trace(sb); +// } +// LSInput input = domImplLS.createLSInput(); +// input.setByteStream(new ByteArrayInputStream(redirectedBytes)); +// +// LSParser parser = domImplLS.createLSParser( +// DOMImplementationLS.MODE_SYNCHRONOUS, null); +// DOMConfiguration domConfig = parser.getDomConfig(); +// SimpleDOMErrorHandler errorHandler = new SimpleDOMErrorHandler(); +// domConfig.setParameter("error-handler", errorHandler); +// domConfig.setParameter("validate", Boolean.FALSE); +// +// try { +// Document redirectedDoc = parser.parse(input); +// Node redirected = transformsDoc.adoptNode(redirectedDoc.getDocumentElement()); +// transform.appendChild(redirected); +// +// //not supported by Xerces2.9.1 +//// Node redirected = parser.parseWithContext(input, transform, LSParser.ACTION_APPEND_AS_CHILDREN); +// +// } catch (DOMException e) { +// log.info("Failed to parse dsig:Transform.", e); +// throw new SLRequestException(3002); +// } catch (LSException e) { +// log.info("Failed to parse dsig:Transform.", e); +// throw new SLRequestException(3002); +// } +// } +// transforms.appendChild(transform); +// } +// +// //adopt ds:Transforms +// Node adoptedTransforms = ctx.getDocument().adoptNode(transforms); +// DOMCryptoContext context = new DOMCryptoContext(); +// +// // unmarshall ds:Transforms +// return new XSECTTransforms(context, adoptedTransforms); + + } + + /** + * Sets the mimeType and the description value + * for this DataObject. + * + * @param metaInfoType the sl:FinalMetaDataInfo + * + * @throws NullPointerException if metaInfoType is null + */ + private void setFinalDataMetaInfo(MetaInfoType metaInfoType) { + + this.mimeType = metaInfoType.getMimeType(); + this.description = metaInfoType.getDescription(); + + } + + /** + * Selects an appropriate transformation path (if present) from the given list + * of sl:TransformInfos, sets the corresponding final data meta info and + * returns the corresponding unmarshalled ds:Transforms. + * + * @param transformsInfos the sl:TransformInfos + * + * @return the unmarshalled ds:Transforms, or null if + * no transformation path has been selected. + * + * @throws SLRequestException if the given list ds:TransformsInfo contains + * an invalid ds:Transforms element, or no suitable transformation path + * can be found. + */ + private XSECTTransforms createTransformsAndSetFinalDataMetaInfo( + List transformsInfos) throws SLRequestException { + + TransformsInfoType preferredTransformsInfo = selectPreferredTransformsInfo(transformsInfos); + // try preferred transform + if (preferredTransformsInfo != null) { + + try { + XSECTTransforms transforms = createTransforms(preferredTransformsInfo); + setFinalDataMetaInfo(preferredTransformsInfo.getFinalDataMetaInfo()); + return transforms; + } catch (MarshalException e) { + + String mimeType = preferredTransformsInfo.getFinalDataMetaInfo().getMimeType(); + log.info("Failed to unmarshal preferred transformation path (MIME-Type=" + + mimeType + ").", e); + + } + + } + + // look for another suitable transformation path + for (TransformsInfoType transformsInfoType : transformsInfos) { + + try { + XSECTTransforms transforms = createTransforms(transformsInfoType); + setFinalDataMetaInfo(transformsInfoType.getFinalDataMetaInfo()); + return transforms; + } catch (MarshalException e) { + + String mimeType = transformsInfoType.getFinalDataMetaInfo().getMimeType(); + log.info("Failed to unmarshal transformation path (MIME-Type=" + + mimeType + ").", e); + } + + } + + // no suitable transformation path found + throw new SLRequestException(3003); + + } + + /** + * Create an XMLObject with the Base64 encoding of the given + * content. + * + * @param content + * the to-be Base64 encoded content + * @return an XMLObject with the Base64 encoded content + */ + private XMLObject createXMLObject(InputStream content) { + + Text textNode; + try { + textNode = at.gv.egiz.dom.DOMUtils.createBase64Text(content, ctx.getDocument()); + } catch (IOException e) { + log.error(e); + throw new SLRuntimeException(e); + } + + DOMStructure structure = new DOMStructure(textNode); + + String idValue = ctx.getIdValueFactory().createIdValue("Object"); + + return ctx.getSignatureFactory().newXMLObject(Collections.singletonList(structure), idValue, null, null); + + } + + /** + * Create an XMLObject with the given content node. + * + * @param content the content node + * + * @return an XMLObject with the given content + */ + private XMLObject createXMLObject(Node content) { + + String idValue = ctx.getIdValueFactory().createIdValue("Object"); + + List structures = Collections.singletonList(new DOMStructure(content)); + + return ctx.getSignatureFactory().newXMLObject(structures, idValue, null, null); + + } + + /** + * Sets the given xmlObject and creates and sets a corresponding + * Reference. + *

+ * A transform to Base64-decode the xmlObject's content is inserted at the top + * of to the optional transforms if given, or to a newly created + * Transforms element if transforms is + * null. + * + * @param xmlObject + * the XMLObject + * @param transforms + * an optional Transforms element (may be + * null) + * + * @throws SLCommandException + * if creating the Reference fails + * @throws NullPointerException + * if xmlObject is null + */ + private void setXMLObjectAndReferenceBase64(XMLObject xmlObject, XSECTTransforms transforms) throws SLCommandException { + + // create reference URI + // + // NOTE: the ds:Object can be referenced directly, as the Base64 transform + // operates on the text() of the input nodelist. + // + String referenceURI = "#" + xmlObject.getId(); + + // create Base64 Transform + Transform transform; + try { + transform = ctx.getSignatureFactory().newTransform(Transform.BASE64, (TransformParameterSpec) null); + } catch (NoSuchAlgorithmException e) { + // algorithm must be present + throw new SLRuntimeException(e); + } catch (InvalidAlgorithmParameterException e) { + // algorithm does not take parameters + throw new SLRuntimeException(e); + } + + if (transforms == null) { + transforms = new XSECTTransforms(Collections.singletonList(transform)); + } else { + transforms.insertTransform(transform); + } + + DigestMethod dm; + try { + dm = ctx.getAlgorithmMethodFactory().createDigestMethod(ctx); + } catch (NoSuchAlgorithmException e) { + log.error("Failed to get DigestMethod.", e); + throw new SLCommandException(4006); + } catch (InvalidAlgorithmParameterException e) { + log.error("Failed to get DigestMethod.", e); + throw new SLCommandException(4006); + } + String id = ctx.getIdValueFactory().createIdValue("Reference"); + + this.xmlObject = xmlObject; + this.reference = new XSECTReference(referenceURI, dm, transforms, null, id); + + } + + /** + * Sets the given xmlObject and creates and sets a corresponding + * Reference. + *

+ * A transform to select the xmlObject's content is inserted at the top of to + * the optional transforms if given, or to a newly created + * Transforms element if transforms is + * null. + *

+ * + * @param xmlObject + * the XMLObject + * @param transforms + * an optional Transforms element (may be + * null) + * + * @throws SLCommandException + * if creating the Reference fails + * @throws NullPointerException + * if xmlObject is null + */ + private void setXMLObjectAndReferenceXML(XMLObject xmlObject, XSECTTransforms transforms) throws SLCommandException { + + // create reference URI + String referenceURI = "#" + xmlObject.getId(); + + // create Transform to select ds:Object's children + Transform xpathTransform; + Transform c14nTransform; + try { + + XPathType xpath = new XPathType("id(\"" + xmlObject.getId() + "\")/node()", XPathType.Filter.INTERSECT); + List xpaths = Collections.singletonList(xpath); + XPathFilter2ParameterSpec params = new XPathFilter2ParameterSpec(xpaths); + + xpathTransform = ctx.getSignatureFactory().newTransform(Transform.XPATH2, params); + + // add exclusive canonicalization to avoid signing the namespace context of the ds:Object + c14nTransform = ctx.getSignatureFactory().newTransform(CanonicalizationMethod.EXCLUSIVE, (TransformParameterSpec) null); + + } catch (NoSuchAlgorithmException e) { + // algorithm must be present + throw new SLRuntimeException(e); + } catch (InvalidAlgorithmParameterException e) { + // params must be appropriate + throw new SLRuntimeException(e); + } + + if (transforms == null) { + List newTransfroms = new ArrayList(); + newTransfroms.add(xpathTransform); + newTransfroms.add(c14nTransform); + transforms = new XSECTTransforms(newTransfroms); + } else { + transforms.insertTransform(xpathTransform); + } + + DigestMethod dm; + try { + dm = ctx.getAlgorithmMethodFactory().createDigestMethod(ctx); + } catch (NoSuchAlgorithmException e) { + log.error("Failed to get DigestMethod.", e); + throw new SLCommandException(4006); + } catch (InvalidAlgorithmParameterException e) { + log.error("Failed to get DigestMethod.", e); + throw new SLCommandException(4006); + } + String id = ctx.getIdValueFactory().createIdValue("Reference"); + + this.xmlObject = xmlObject; + this.reference = new XSECTReference(referenceURI, dm, transforms, null, id); + + } + + /** + * Parses the given xmlContent and returns a corresponding + * document fragment. + * + *

+ * The to-be parsed content is surrounded by ... elements to + * allow for mixed (e.g. Text and Element) content in XMLContent. + *

+ * + * @param xmlContent + * the XMLContent to-be parsed + * + * @return a document fragment containing the parsed nodes + * + * @throws SLCommandException + * if parsing the given xmlContent fails + * + * @throws NullPointerException + * if xmlContent is null + */ + private DocumentFragment parseDataObject(XMLContentType xmlContent) throws SLCommandException { + + ByteArrayOutputStream redirectedStream = xmlContent.getRedirectedStream(); + + // Note: We can assume a fixed character encoding of UTF-8 for the + // content of the redirect stream as the content has already been parsed + // and serialized again to the redirect stream. + + List inputStreams = new ArrayList(); + try { + // dummy start element + inputStreams.add(new ByteArrayInputStream("".getBytes("UTF-8"))); + + // content + inputStreams.add(new ByteArrayInputStream(redirectedStream.toByteArray())); + + // dummy end element + inputStreams.add(new ByteArrayInputStream("".getBytes("UTF-8"))); + } catch (UnsupportedEncodingException e) { + throw new SLRuntimeException(e); + } + + SequenceInputStream inputStream = new SequenceInputStream(Collections.enumeration(inputStreams)); + + // parse DataObject + Document doc = parseDataObject(inputStream, "UTF-8"); + + Element documentElement = doc.getDocumentElement(); + + if (documentElement == null || + !"dummy".equals(documentElement.getLocalName())) { + log.info("Failed to parse DataObject XMLContent."); + throw new SLCommandException(4111); + } + + DocumentFragment fragment = doc.createDocumentFragment(); + while (documentElement.getFirstChild() != null) { + fragment.appendChild(documentElement.getFirstChild()); + } + + // log parsed document + if (log.isTraceEnabled()) { + + StringWriter writer = new StringWriter(); + + writer.write("DataObject:\n"); + + LSOutput output = domImplLS.createLSOutput(); + output.setCharacterStream(writer); + output.setEncoding("UTF-8"); + LSSerializer serializer = domImplLS.createLSSerializer(); + serializer.getDomConfig().setParameter("xml-declaration", Boolean.FALSE); + serializer.write(fragment, output); + + log.trace(writer.toString()); + } + + return fragment; + + } + + /** + * Parses the given inputStream using the given + * encoding and returns the parsed document. + * + * @param inputStream + * the to-be parsed input + * + * @param encoding + * the encoding to be used for parsing the given + * inputStream + * + * @return the parsed document + * + * @throws SLCommandException + * if parsing the inputStream fails. + * + * @throws NullPointerException + * if inputStram is null + */ + private Document parseDataObject(InputStream inputStream, String encoding) throws SLCommandException { + + LSInput input = domImplLS.createLSInput(); + input.setByteStream(inputStream); + + if (encoding != null) { + input.setEncoding(encoding); + } + + LSParser parser = domImplLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null); + DOMConfiguration domConfig = parser.getDomConfig(); + SimpleDOMErrorHandler errorHandler = new SimpleDOMErrorHandler(); + domConfig.setParameter("error-handler", errorHandler); + domConfig.setParameter("validate", Boolean.FALSE); + + Document doc; + try { + doc = parser.parse(input); + } catch (DOMException e) { + log.info("Existing XML document cannot be parsed.", e); + throw new SLCommandException(4111); + } catch (LSException e) { + log.info("Existing XML document cannot be parsed. ", e); + throw new SLCommandException(4111); + } + + if (errorHandler.hasErrors()) { + // log errors + if (log.isInfoEnabled()) { + List errorMessages = errorHandler.getErrorMessages(); + StringBuffer sb = new StringBuffer(); + for (String errorMessage : errorMessages) { + sb.append(" "); + sb.append(errorMessage); + } + log.info("Existing XML document cannot be parsed. " + sb.toString()); + } + throw new SLCommandException(4111); + } + + return doc; + + } + + +} diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/Signature.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/Signature.java index 8baa0137..9182e824 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/Signature.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/Signature.java @@ -87,6 +87,8 @@ import at.gv.egiz.bku.utils.urldereferencer.StreamData; import at.gv.egiz.bku.utils.urldereferencer.URLDereferencer; import at.gv.egiz.bku.utils.urldereferencer.URLDereferencerContext; import at.gv.egiz.dom.DOMUtils; +import at.gv.egiz.marshal.NamespacePrefix; +import at.gv.egiz.marshal.NamespacePrefixMapperImpl; import at.gv.egiz.slbinding.impl.XMLContentType; import at.gv.egiz.stal.STAL; import at.gv.egiz.xades.QualifyingPropertiesException; @@ -99,6 +101,7 @@ import at.gv.egiz.xades.QualifyingPropertiesFactory; * @author mcentner */ public class Signature { + public static final String XMLDSIG_PREFIX = "dsig"; /** * Logging facility. @@ -407,7 +410,7 @@ public class Signature { signContext.setProperty("javax.xml.crypto.dsig.cacheReference", Boolean.TRUE); - signContext.putNamespacePrefix(XMLSignature.XMLNS, "dsig"); + signContext.putNamespacePrefix(XMLSignature.XMLNS,XMLDSIG_PREFIX); signContext.setURIDereferencer(new URIDereferncerAdapter(ctx.getDereferencerContext())); diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/xsect/SignatureTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/xsect/SignatureTest.java index 78172dcb..7ce7b42d 100644 --- a/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/xsect/SignatureTest.java +++ b/bkucommon/src/test/java/at/gv/egiz/bku/slcommands/impl/xsect/SignatureTest.java @@ -14,185 +14,186 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package at.gv.egiz.bku.slcommands.impl.xsect; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import iaik.xml.crypto.XSecProvider; - -import java.io.IOException; -import java.io.InputStream; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.PrivateKey; -import java.security.UnrecoverableKeyException; -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; -import java.util.List; - +package at.gv.egiz.bku.slcommands.impl.xsect; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import iaik.xml.crypto.XSecProvider; + +import java.io.IOException; +import java.io.InputStream; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.util.List; + import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLSocketFactory; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBElement; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; -import javax.xml.crypto.MarshalException; -import javax.xml.crypto.dsig.CanonicalizationMethod; -import javax.xml.crypto.dsig.DigestMethod; -import javax.xml.crypto.dsig.Reference; -import javax.xml.crypto.dsig.SignatureMethod; -import javax.xml.crypto.dsig.Transform; -import javax.xml.crypto.dsig.XMLObject; -import javax.xml.crypto.dsig.XMLSignatureException; -import javax.xml.crypto.dsig.XMLSignatureFactory; -import javax.xml.crypto.dsig.dom.DOMSignContext; -import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec; -import javax.xml.crypto.dsig.spec.DigestMethodParameterSpec; -import javax.xml.crypto.dsig.spec.SignatureMethodParameterSpec; -import javax.xml.stream.XMLEventReader; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamException; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.ls.DOMImplementationLS; -import org.w3c.dom.ls.LSOutput; -import org.w3c.dom.ls.LSSerializer; - -import at.buergerkarte.namespaces.securitylayer._1.CreateXMLSignatureRequestType; -import at.buergerkarte.namespaces.securitylayer._1.DataObjectInfoType; -import at.buergerkarte.namespaces.securitylayer._1.ObjectFactory; -import at.buergerkarte.namespaces.securitylayer._1.SignatureInfoCreationType; -import at.gv.egiz.bku.slexceptions.SLCommandException; -import at.gv.egiz.bku.slexceptions.SLRequestException; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import javax.xml.crypto.MarshalException; +import javax.xml.crypto.dsig.CanonicalizationMethod; +import javax.xml.crypto.dsig.DigestMethod; +import javax.xml.crypto.dsig.Reference; +import javax.xml.crypto.dsig.SignatureMethod; +import javax.xml.crypto.dsig.Transform; +import javax.xml.crypto.dsig.XMLObject; +import javax.xml.crypto.dsig.XMLSignatureException; +import javax.xml.crypto.dsig.XMLSignatureFactory; +import javax.xml.crypto.dsig.dom.DOMSignContext; +import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec; +import javax.xml.crypto.dsig.spec.DigestMethodParameterSpec; +import javax.xml.crypto.dsig.spec.SignatureMethodParameterSpec; +import javax.xml.stream.XMLEventReader; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.ls.DOMImplementationLS; +import org.w3c.dom.ls.LSOutput; +import org.w3c.dom.ls.LSSerializer; + +import at.buergerkarte.namespaces.securitylayer._1.CreateXMLSignatureRequestType; +import at.buergerkarte.namespaces.securitylayer._1.DataObjectInfoType; +import at.buergerkarte.namespaces.securitylayer._1.ObjectFactory; +import at.buergerkarte.namespaces.securitylayer._1.SignatureInfoCreationType; +import at.gv.egiz.bku.slexceptions.SLCommandException; +import at.gv.egiz.bku.slexceptions.SLRequestException; import at.gv.egiz.bku.slexceptions.SLViewerException; -import at.gv.egiz.bku.utils.urldereferencer.StreamData; -import at.gv.egiz.bku.utils.urldereferencer.URLDereferencer; -import at.gv.egiz.bku.utils.urldereferencer.URLDereferencerContext; -import at.gv.egiz.bku.utils.urldereferencer.URLProtocolHandler; -import at.gv.egiz.dom.DOMUtils; -import at.gv.egiz.slbinding.RedirectEventFilter; -import at.gv.egiz.slbinding.RedirectUnmarshallerListener; - -public class SignatureTest { - - private class AlgorithmMethodFactoryImpl implements AlgorithmMethodFactory { - - @Override - public CanonicalizationMethod createCanonicalizationMethod( - SignatureContext signatureContext) { - - XMLSignatureFactory signatureFactory = signatureContext.getSignatureFactory(); - - try { - return signatureFactory.newCanonicalizationMethod(CanonicalizationMethod.EXCLUSIVE, (C14NMethodParameterSpec) null); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - @Override - public DigestMethod createDigestMethod(SignatureContext signatureContext) { - - XMLSignatureFactory signatureFactory = signatureContext.getSignatureFactory(); - - try { - return signatureFactory.newDigestMethod(DigestMethod.SHA1, (DigestMethodParameterSpec) null); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - @Override - public SignatureMethod createSignatureMethod( - SignatureContext signatureContext) { - - XMLSignatureFactory signatureFactory = signatureContext.getSignatureFactory(); - - try { - return signatureFactory.newSignatureMethod(SignatureMethod.RSA_SHA1, (SignatureMethodParameterSpec) null); - } catch (Exception e) { - throw new RuntimeException(e); - } - - } - - } - - private static final String RESOURCE_PREFIX = "at/gv/egiz/bku/slcommands/impl/"; - - private static Unmarshaller unmarshaller; - - private static PrivateKey privateKey; - - private static X509Certificate certificate; - - @BeforeClass - public static void setUpClass() throws JAXBException, NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException, UnrecoverableKeyException { - - XSecProvider.addAsProvider(true); - - String packageName = ObjectFactory.class.getPackage().getName(); - packageName += ":" - + org.w3._2000._09.xmldsig_.ObjectFactory.class.getPackage().getName(); - JAXBContext jaxbContext = JAXBContext.newInstance(packageName); - - unmarshaller = jaxbContext.createUnmarshaller(); - - initURLDereferencer(); - - ClassLoader classLoader = SignatureTest.class.getClassLoader(); - InputStream certStream = classLoader.getResourceAsStream(RESOURCE_PREFIX + "Cert.p12"); - assertNotNull("Certificate not found.", certStream); - - char[] passwd = "1622".toCharArray(); - - KeyStore keystore = KeyStore.getInstance("PKCS12"); - keystore.load(certStream, passwd); - String firstAlias = keystore.aliases().nextElement(); - certificate = (X509Certificate) keystore.getCertificate(firstAlias); - privateKey = (PrivateKey) keystore.getKey(firstAlias, passwd); - - } - - private static void initURLDereferencer() { - - URLDereferencer.getInstance().registerHandler("testlocal", new URLProtocolHandler() { - - @Override - public StreamData dereference(String url, URLDereferencerContext context) - throws IOException { - - ClassLoader classLoader = SignatureTest.class.getClassLoader(); - - String filename = url.split(":", 2)[1]; - - InputStream stream = classLoader.getResourceAsStream(RESOURCE_PREFIX + filename); - - if (stream == null) { - - throw new IOException("Failed to resolve resource '" + url + "'."); - - } else { - - String contentType; - if (filename.endsWith(".xml")) { - contentType = "text/xml"; - } else if (filename.endsWith(".txt")) { - contentType = "text/plain"; - } else { - contentType = ""; - } - - return new StreamData(url, contentType, stream); - - } - +import at.gv.egiz.bku.utils.urldereferencer.StreamData; +import at.gv.egiz.bku.utils.urldereferencer.URLDereferencer; +import at.gv.egiz.bku.utils.urldereferencer.URLDereferencerContext; +import at.gv.egiz.bku.utils.urldereferencer.URLProtocolHandler; +import at.gv.egiz.dom.DOMUtils; +import at.gv.egiz.slbinding.RedirectEventFilter; +import at.gv.egiz.slbinding.RedirectUnmarshallerListener; +import org.junit.Ignore; + +public class SignatureTest { + + private class AlgorithmMethodFactoryImpl implements AlgorithmMethodFactory { + + @Override + public CanonicalizationMethod createCanonicalizationMethod( + SignatureContext signatureContext) { + + XMLSignatureFactory signatureFactory = signatureContext.getSignatureFactory(); + + try { + return signatureFactory.newCanonicalizationMethod(CanonicalizationMethod.EXCLUSIVE, (C14NMethodParameterSpec) null); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public DigestMethod createDigestMethod(SignatureContext signatureContext) { + + XMLSignatureFactory signatureFactory = signatureContext.getSignatureFactory(); + + try { + return signatureFactory.newDigestMethod(DigestMethod.SHA1, (DigestMethodParameterSpec) null); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public SignatureMethod createSignatureMethod( + SignatureContext signatureContext) { + + XMLSignatureFactory signatureFactory = signatureContext.getSignatureFactory(); + + try { + return signatureFactory.newSignatureMethod(SignatureMethod.RSA_SHA1, (SignatureMethodParameterSpec) null); + } catch (Exception e) { + throw new RuntimeException(e); + } + + } + + } + + private static final String RESOURCE_PREFIX = "at/gv/egiz/bku/slcommands/impl/"; + + private static Unmarshaller unmarshaller; + + private static PrivateKey privateKey; + + private static X509Certificate certificate; + + @BeforeClass + public static void setUpClass() throws JAXBException, NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException, UnrecoverableKeyException { + + XSecProvider.addAsProvider(true); + + String packageName = ObjectFactory.class.getPackage().getName(); + packageName += ":" + + org.w3._2000._09.xmldsig_.ObjectFactory.class.getPackage().getName(); + JAXBContext jaxbContext = JAXBContext.newInstance(packageName); + + unmarshaller = jaxbContext.createUnmarshaller(); + + initURLDereferencer(); + + ClassLoader classLoader = SignatureTest.class.getClassLoader(); + InputStream certStream = classLoader.getResourceAsStream(RESOURCE_PREFIX + "Cert.p12"); + assertNotNull("Certificate not found.", certStream); + + char[] passwd = "1622".toCharArray(); + + KeyStore keystore = KeyStore.getInstance("PKCS12"); + keystore.load(certStream, passwd); + String firstAlias = keystore.aliases().nextElement(); + certificate = (X509Certificate) keystore.getCertificate(firstAlias); + privateKey = (PrivateKey) keystore.getKey(firstAlias, passwd); + + } + + private static void initURLDereferencer() { + + URLDereferencer.getInstance().registerHandler("testlocal", new URLProtocolHandler() { + + @Override + public StreamData dereference(String url, URLDereferencerContext context) + throws IOException { + + ClassLoader classLoader = SignatureTest.class.getClassLoader(); + + String filename = url.split(":", 2)[1]; + + InputStream stream = classLoader.getResourceAsStream(RESOURCE_PREFIX + filename); + + if (stream == null) { + + throw new IOException("Failed to resolve resource '" + url + "'."); + + } else { + + String contentType; + if (filename.endsWith(".xml")) { + contentType = "text/xml"; + } else if (filename.endsWith(".txt")) { + contentType = "text/plain"; + } else { + contentType = ""; + } + + return new StreamData(url, contentType, stream); + + } + } @Override @@ -205,558 +206,600 @@ public class SignatureTest { public void setSSLSocketFactory(SSLSocketFactory socketFactory) { // TODO Auto-generated method stub - } - - }); - - } - - private Object unmarshal(String file) throws XMLStreamException, JAXBException { - - ClassLoader classLoader = SignatureTest.class.getClassLoader(); - InputStream resourceStream = classLoader.getResourceAsStream(RESOURCE_PREFIX + file); - assertNotNull(resourceStream); - - XMLInputFactory inputFactory = XMLInputFactory.newInstance(); - XMLEventReader eventReader = inputFactory.createXMLEventReader(resourceStream); - RedirectEventFilter redirectEventFilter = new RedirectEventFilter(); - XMLEventReader filteredReader = inputFactory.createFilteredReader(eventReader, redirectEventFilter); - - unmarshaller.setListener(new RedirectUnmarshallerListener(redirectEventFilter)); - - return unmarshaller.unmarshal(filteredReader); - - } - - // - // - // SignatureInfo - // - // - - @SuppressWarnings("unchecked") - private SignatureInfoCreationType unmarshalSignatureInfo(String file) throws JAXBException, XMLStreamException { - - Object object = unmarshal(file); - - Object requestType = ((JAXBElement) object).getValue(); - - assertTrue(requestType instanceof CreateXMLSignatureRequestType); - - SignatureInfoCreationType signatureInfo = ((CreateXMLSignatureRequestType) requestType).getSignatureInfo(); - - assertNotNull(signatureInfo); - - return signatureInfo; - - } - - @Test - public void testSetSignatureInfo_Base64_1() throws JAXBException, SLCommandException, XMLStreamException { - - SignatureInfoCreationType signatureInfo = unmarshalSignatureInfo("SignatureInfo_Base64_1.xml"); - - Signature signature = new Signature(null, new IdValueFactoryImpl(), null); - - signature.setSignatureInfo(signatureInfo); - - Node parent = signature.getParent(); - Node nextSibling = signature.getNextSibling(); - - assertNotNull(parent); - assertTrue("urn:document".equals(parent.getNamespaceURI())); - assertTrue("XMLDocument".equals(parent.getLocalName())); - - assertNotNull(nextSibling); - assertTrue("urn:document".equals(nextSibling.getNamespaceURI())); - assertTrue("Paragraph".equals(nextSibling.getLocalName())); - - } - - @Test - public void testSetSignature_Base64_2() throws JAXBException, SLCommandException, XMLStreamException { - - SignatureInfoCreationType signatureInfo = unmarshalSignatureInfo("SignatureInfo_Base64_2.xml"); - - Signature signature = new Signature(null, new IdValueFactoryImpl(), null); - - signature.setSignatureInfo(signatureInfo); - - Node parent = signature.getParent(); - Node nextSibling = signature.getNextSibling(); - - assertNotNull(parent); - assertTrue("XMLDocument".equals(parent.getLocalName())); - - assertNotNull(nextSibling); - assertTrue("Paragraph".equals(nextSibling.getLocalName())); - - } - - @Test - public void testSetSignature_Base64_3() throws JAXBException, SLCommandException, XMLStreamException { - - SignatureInfoCreationType signatureInfo = unmarshalSignatureInfo("SignatureInfo_Base64_3.xml"); - - Signature signature = new Signature(null, new IdValueFactoryImpl(), null); - - signature.setSignatureInfo(signatureInfo); - - Node parent = signature.getParent(); - Node nextSibling = signature.getNextSibling(); - - assertNotNull(parent); - assertTrue("XMLDocument".equals(parent.getLocalName())); - - assertNotNull(nextSibling); - assertTrue("Paragraph".equals(nextSibling.getLocalName())); - - } - - @Test - public void testSetSignatureInfo_XMLContent_1() throws JAXBException, SLCommandException, XMLStreamException { - - SignatureInfoCreationType signatureInfo = unmarshalSignatureInfo("SignatureInfo_XMLContent_1.xml"); - - Signature signature = new Signature(null, new IdValueFactoryImpl(), null); - - signature.setSignatureInfo(signatureInfo); - - Node parent = signature.getParent(); - Node nextSibling = signature.getNextSibling(); - - assertNotNull(parent); - assertTrue("urn:document".equals(parent.getNamespaceURI())); - assertTrue("Whole".equals(parent.getLocalName())); - - assertNull(nextSibling); - - } - - @Test - public void testSetSignature_Reference_1() throws JAXBException, SLCommandException, XMLStreamException { - - SignatureInfoCreationType signatureInfo = unmarshalSignatureInfo("SignatureInfo_Reference_1.xml"); - - Signature signature = new Signature(null, new IdValueFactoryImpl(), null); - - signature.setSignatureInfo(signatureInfo); - - Node parent = signature.getParent(); - Node nextSibling = signature.getNextSibling(); - - assertNotNull(parent); - assertTrue("urn:document".equals(parent.getNamespaceURI())); - assertTrue("Paragraph".equals(parent.getLocalName())); - - assertNull(nextSibling); - - } - - // - // - // DataObject - // - // - - @SuppressWarnings("unchecked") - private List unmarshalDataObjectInfo(String file) throws JAXBException, XMLStreamException { - - Object object = unmarshal(file); - - Object requestType = ((JAXBElement) object).getValue(); - - assertTrue(requestType instanceof CreateXMLSignatureRequestType); - - List dataObjectInfos = ((CreateXMLSignatureRequestType) requestType).getDataObjectInfo(); - - assertNotNull(dataObjectInfos); - - return dataObjectInfos; - - } - - private void signAndMarshalSignature(Signature signature) throws MarshalException, XMLSignatureException, SLCommandException, SLViewerException { - - Node parent = signature.getParent(); - Node nextSibling = signature.getNextSibling(); - - DOMSignContext signContext = (nextSibling == null) - ? new DOMSignContext(privateKey, parent) - : new DOMSignContext(privateKey, parent, nextSibling); - - signature.sign(signContext); - - Document document = signature.getDocument(); - - DOMImplementationLS domImplLS = DOMUtils.getDOMImplementationLS(); - LSOutput output = domImplLS.createLSOutput(); - output.setByteStream(System.out); - - LSSerializer serializer = domImplLS.createLSSerializer(); -// serializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); - serializer.getDomConfig().setParameter("namespaces", Boolean.FALSE); - serializer.write(document, output); - - } - - @SuppressWarnings("unchecked") - @Test - public void testDataObject_Base64Content_1() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException, SLViewerException { - - List dataObjectInfos = unmarshalDataObjectInfo("DataObjectInfo_Base64Content_1.xml"); - - Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl()); - - for (DataObjectInfoType dataObjectInfo : dataObjectInfos) { - signature.addDataObject(dataObjectInfo); - } - - signature.setSignerCeritifcate(certificate); - - signature.buildXMLSignature(); - - signAndMarshalSignature(signature); - - List references = signature.getReferences(); - assertTrue(references.size() == 2); - - Reference reference = references.get(0); - assertNotNull(reference.getId()); - - List transforms = reference.getTransforms(); - assertTrue(transforms.size() == 1); - - Transform transform = transforms.get(0); - assertTrue(Transform.BASE64.equals(transform.getAlgorithm())); - - List objects = signature.getXMLObjects(); - assertNotNull(objects); - assertTrue("Size " + objects.size() + " but should be 2.", objects.size() == 2); - - XMLObject object = objects.get(0); - - assertTrue(("#" + object.getId()).equals(reference.getURI())); - - } - - @SuppressWarnings("unchecked") - @Test - public void testDataObject_XMLContent_1() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException, SLViewerException { - - List dataObjectInfos = unmarshalDataObjectInfo("DataObjectInfo_XMLContent_1.xml"); - - Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl()); - - for (DataObjectInfoType dataObjectInfo : dataObjectInfos) { - signature.addDataObject(dataObjectInfo); - } - - signature.setSignerCeritifcate(certificate); - - signature.buildXMLSignature(); - - signAndMarshalSignature(signature); - - List references = signature.getReferences(); - assertTrue(references.size() == 2); - - Reference reference = references.get(0); - assertNotNull(reference.getId()); - - List transforms = reference.getTransforms(); - assertTrue(transforms.size() == 2); - - Transform transform = transforms.get(0); - assertTrue(Transform.XPATH2.equals(transform.getAlgorithm())); - - List objects = signature.getXMLObjects(); - assertNotNull(objects); - assertTrue("Size " + objects.size() + " but should be 2.", objects.size() == 2); - - XMLObject object = objects.get(0); - - assertTrue(("#" + object.getId()).equals(reference.getURI())); - - } - - @SuppressWarnings("unchecked") - @Test - public void testDataObject_XMLContent_2() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException, SLViewerException { - - List dataObjectInfos = unmarshalDataObjectInfo("DataObjectInfo_XMLContent_2.xml"); - - Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl()); - - for (DataObjectInfoType dataObjectInfo : dataObjectInfos) { - signature.addDataObject(dataObjectInfo); - } - - signature.setSignerCeritifcate(certificate); - - signature.buildXMLSignature(); - - signAndMarshalSignature(signature); - - List references = signature.getReferences(); - assertTrue(references.size() == 2); - - Reference reference = references.get(0); - assertNotNull(reference.getId()); - - List transforms = reference.getTransforms(); - assertTrue(transforms.size() == 2); - - Transform transform = transforms.get(0); - assertTrue(Transform.XPATH2.equals(transform.getAlgorithm())); - - List objects = signature.getXMLObjects(); - assertNotNull(objects); - assertTrue("Size " + objects.size() + " but should be 2.", objects.size() == 2); - - XMLObject object = objects.get(0); - - assertTrue(("#" + object.getId()).equals(reference.getURI())); - - } - - - @SuppressWarnings("unchecked") - @Test - public void testDataObject_LocRefContent_1() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException, SLViewerException { - - List dataObjectInfos = unmarshalDataObjectInfo("DataObjectInfo_LocRefContent_1.xml"); - - Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl()); - - for (DataObjectInfoType dataObjectInfo : dataObjectInfos) { - signature.addDataObject(dataObjectInfo); - } - - signature.buildXMLSignature(); - - signAndMarshalSignature(signature); - - List references = signature.getReferences(); - assertTrue(references.size() == 2); - - Reference reference = references.get(0); - assertNotNull(reference.getId()); - - List transforms = reference.getTransforms(); - assertTrue(transforms.size() == 2); - - Transform transform = transforms.get(0); - assertTrue(Transform.XPATH2.equals(transform.getAlgorithm())); - - List objects = signature.getXMLObjects(); - assertNotNull(objects); - assertTrue("Size " + objects.size() + " but should be 2.", objects.size() == 2); - - XMLObject object = objects.get(0); - - assertTrue(("#" + object.getId()).equals(reference.getURI())); - - } - - @SuppressWarnings("unchecked") - @Test - public void testDataObject_LocRefContent_2() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException, SLViewerException { - - List dataObjectInfos = unmarshalDataObjectInfo("DataObjectInfo_LocRefContent_2.xml"); - - Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl()); - - for (DataObjectInfoType dataObjectInfo : dataObjectInfos) { - signature.addDataObject(dataObjectInfo); - } - - signature.buildXMLSignature(); - - signAndMarshalSignature(signature); - - List references = signature.getReferences(); - assertTrue(references.size() == 2); - - Reference reference = references.get(0); - assertNotNull(reference.getId()); - - List transforms = reference.getTransforms(); - assertTrue(transforms.size() == 1); - - Transform transform = transforms.get(0); - assertTrue(Transform.BASE64.equals(transform.getAlgorithm())); - - List objects = signature.getXMLObjects(); - assertNotNull(objects); - assertTrue("Size " + objects.size() + " but should be 2.", objects.size() == 2); - - XMLObject object = objects.get(0); - - assertTrue(("#" + object.getId()).equals(reference.getURI())); - - } - - @SuppressWarnings("unchecked") - @Test - public void testDataObject_Reference_1() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException, SLViewerException { - - List dataObjectInfos = unmarshalDataObjectInfo("DataObjectInfo_Reference_1.xml"); - - Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl()); - - for (DataObjectInfoType dataObjectInfo : dataObjectInfos) { - signature.addDataObject(dataObjectInfo); - } - - signature.buildXMLSignature(); - - signAndMarshalSignature(signature); - - List references = signature.getReferences(); - assertTrue(references.size() == 2); - - Reference reference = references.get(0); - assertNotNull(reference.getId()); - - List transforms = reference.getTransforms(); - assertTrue(transforms.size() == 1); - - Transform transform = transforms.get(0); - assertTrue(Transform.BASE64.equals(transform.getAlgorithm())); - - List objects = signature.getXMLObjects(); - assertNotNull(objects); - assertTrue("Size " + objects.size() + " but should be 2.", objects.size() == 2); - - XMLObject object = objects.get(0); - - assertTrue(("#" + object.getId()).equals(reference.getURI())); - - } - - @SuppressWarnings("unchecked") - @Test - public void testDataObject_Detached_1() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException, SLViewerException { - - List dataObjectInfos = unmarshalDataObjectInfo("DataObjectInfo_Detached_1.xml"); - - Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl()); - - for (DataObjectInfoType dataObjectInfo : dataObjectInfos) { - signature.addDataObject(dataObjectInfo); - } - - signature.buildXMLSignature(); - - signAndMarshalSignature(signature); - - List references = signature.getReferences(); - assertTrue(references.size() == 2); - - Reference reference = references.get(0); - assertNotNull(reference.getId()); - - List transforms = reference.getTransforms(); - assertTrue(transforms.size() == 0); - - List objects = signature.getXMLObjects(); - assertNotNull(objects); - assertTrue(objects.size() == 1); - - } - - @SuppressWarnings("unchecked") - @Test - public void testDataObject_Detached_Base64Content() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException, SLViewerException { - - List dataObjectInfos = unmarshalDataObjectInfo("DataObjectInfo_Detached_Base64Content.xml"); - - Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl()); - - for (DataObjectInfoType dataObjectInfo : dataObjectInfos) { - signature.addDataObject(dataObjectInfo); - } - - signature.buildXMLSignature(); - - signAndMarshalSignature(signature); - - List references = signature.getReferences(); - assertTrue(references.size() == 2); - - Reference reference = references.get(0); - assertNotNull(reference.getId()); - - List transforms = reference.getTransforms(); - assertTrue(transforms.size() == 0); - - List objects = signature.getXMLObjects(); - assertNotNull(objects); - assertTrue(objects.size() == 1); - - } - - // - // - // TransformsInfo - // - // - - @SuppressWarnings("unchecked") - private CreateXMLSignatureRequestType unmarshalCreateXMLSignatureRequest(String file) throws JAXBException, XMLStreamException { - - Object object = unmarshal(file); - - Object requestType = ((JAXBElement) object).getValue(); - - assertTrue(requestType instanceof CreateXMLSignatureRequestType); - - return (CreateXMLSignatureRequestType) requestType; - - } - - - @SuppressWarnings("unchecked") - @Test - public void testTransformsInfo_1() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException, SLViewerException { - - CreateXMLSignatureRequestType requestType = unmarshalCreateXMLSignatureRequest("TransformsInfo_1.xml"); - - Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl()); - - - signature.setSignatureInfo(requestType.getSignatureInfo()); - - List dataObjectInfos = requestType.getDataObjectInfo(); - - for (DataObjectInfoType dataObjectInfo : dataObjectInfos) { - signature.addDataObject(dataObjectInfo); - } - - signature.setSignerCeritifcate(certificate); - - signature.buildXMLSignature(); - - signAndMarshalSignature(signature); - - List references = signature.getReferences(); - assertTrue(references.size() == 2); - - Reference reference = references.get(0); - assertNotNull(reference.getId()); - - List transforms = reference.getTransforms(); - assertTrue("Size " + transforms.size() + "", transforms.size() == 3); - - Transform transform = transforms.get(0); - assertTrue(Transform.ENVELOPED.equals(transform.getAlgorithm())); - - List objects = signature.getXMLObjects(); - assertNotNull(objects); - assertTrue("Size " + objects.size() + " but should be 1.", objects.size() == 1); - - } - - -} + } + + }); + + } + + private Object unmarshal(String file) throws XMLStreamException, JAXBException { + + ClassLoader classLoader = SignatureTest.class.getClassLoader(); + InputStream resourceStream = classLoader.getResourceAsStream(RESOURCE_PREFIX + file); + assertNotNull(resourceStream); + + XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + XMLEventReader eventReader = inputFactory.createXMLEventReader(resourceStream); + RedirectEventFilter redirectEventFilter = new RedirectEventFilter(); + XMLEventReader filteredReader = inputFactory.createFilteredReader(eventReader, redirectEventFilter); + + unmarshaller.setListener(new RedirectUnmarshallerListener(redirectEventFilter)); + + return unmarshaller.unmarshal(filteredReader); + + } + + // + // + // SignatureInfo + // + // + + @SuppressWarnings("unchecked") + private SignatureInfoCreationType unmarshalSignatureInfo(String file) throws JAXBException, XMLStreamException { + + Object object = unmarshal(file); + + Object requestType = ((JAXBElement) object).getValue(); + + assertTrue(requestType instanceof CreateXMLSignatureRequestType); + + SignatureInfoCreationType signatureInfo = ((CreateXMLSignatureRequestType) requestType).getSignatureInfo(); + + assertNotNull(signatureInfo); + + return signatureInfo; + + } + + @Test + public void testSetSignatureInfo_Base64_1() throws JAXBException, SLCommandException, XMLStreamException { + + SignatureInfoCreationType signatureInfo = unmarshalSignatureInfo("SignatureInfo_Base64_1.xml"); + + Signature signature = new Signature(null, new IdValueFactoryImpl(), null); + + signature.setSignatureInfo(signatureInfo); + + Node parent = signature.getParent(); + Node nextSibling = signature.getNextSibling(); + + assertNotNull(parent); + assertTrue("urn:document".equals(parent.getNamespaceURI())); + assertTrue("XMLDocument".equals(parent.getLocalName())); + + assertNotNull(nextSibling); + assertTrue("urn:document".equals(nextSibling.getNamespaceURI())); + assertTrue("Paragraph".equals(nextSibling.getLocalName())); + + } + + @Test + public void testSetSignature_Base64_2() throws JAXBException, SLCommandException, XMLStreamException { + + SignatureInfoCreationType signatureInfo = unmarshalSignatureInfo("SignatureInfo_Base64_2.xml"); + + Signature signature = new Signature(null, new IdValueFactoryImpl(), null); + + signature.setSignatureInfo(signatureInfo); + + Node parent = signature.getParent(); + Node nextSibling = signature.getNextSibling(); + + assertNotNull(parent); + assertTrue("XMLDocument".equals(parent.getLocalName())); + + assertNotNull(nextSibling); + assertTrue("Paragraph".equals(nextSibling.getLocalName())); + + } + + @Test + public void testSetSignature_Base64_3() throws JAXBException, SLCommandException, XMLStreamException { + + SignatureInfoCreationType signatureInfo = unmarshalSignatureInfo("SignatureInfo_Base64_3.xml"); + + Signature signature = new Signature(null, new IdValueFactoryImpl(), null); + + signature.setSignatureInfo(signatureInfo); + + Node parent = signature.getParent(); + Node nextSibling = signature.getNextSibling(); + + assertNotNull(parent); + assertTrue("XMLDocument".equals(parent.getLocalName())); + + assertNotNull(nextSibling); + assertTrue("Paragraph".equals(nextSibling.getLocalName())); + + } + + @Test + public void testSetSignatureInfo_XMLContent_1() throws JAXBException, SLCommandException, XMLStreamException { + + SignatureInfoCreationType signatureInfo = unmarshalSignatureInfo("SignatureInfo_XMLContent_1.xml"); + + Signature signature = new Signature(null, new IdValueFactoryImpl(), null); + + signature.setSignatureInfo(signatureInfo); + + Node parent = signature.getParent(); + Node nextSibling = signature.getNextSibling(); + + assertNotNull(parent); + assertTrue("urn:document".equals(parent.getNamespaceURI())); + assertTrue("Whole".equals(parent.getLocalName())); + + assertNull(nextSibling); + + } + + @Test + public void testSetSignature_Reference_1() throws JAXBException, SLCommandException, XMLStreamException { + + SignatureInfoCreationType signatureInfo = unmarshalSignatureInfo("SignatureInfo_Reference_1.xml"); + + Signature signature = new Signature(null, new IdValueFactoryImpl(), null); + + signature.setSignatureInfo(signatureInfo); + + Node parent = signature.getParent(); + Node nextSibling = signature.getNextSibling(); + + assertNotNull(parent); + assertTrue("urn:document".equals(parent.getNamespaceURI())); + assertTrue("Paragraph".equals(parent.getLocalName())); + + assertNull(nextSibling); + + } + + // + // + // DataObject + // + // + + @SuppressWarnings("unchecked") + private List unmarshalDataObjectInfo(String file) throws JAXBException, XMLStreamException { + + Object object = unmarshal(file); + + Object requestType = ((JAXBElement) object).getValue(); + + assertTrue(requestType instanceof CreateXMLSignatureRequestType); + + List dataObjectInfos = ((CreateXMLSignatureRequestType) requestType).getDataObjectInfo(); + + assertNotNull(dataObjectInfos); + + return dataObjectInfos; + + } + + private void signAndMarshalSignature(Signature signature) throws MarshalException, XMLSignatureException, SLCommandException, SLViewerException { + + Node parent = signature.getParent(); + Node nextSibling = signature.getNextSibling(); + + DOMSignContext signContext = (nextSibling == null) + ? new DOMSignContext(privateKey, parent) + : new DOMSignContext(privateKey, parent, nextSibling); + + signature.sign(signContext); + + Document document = signature.getDocument(); + + DOMImplementationLS domImplLS = DOMUtils.getDOMImplementationLS(); + LSOutput output = domImplLS.createLSOutput(); + output.setByteStream(System.out); + + LSSerializer serializer = domImplLS.createLSSerializer(); +// serializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); + serializer.getDomConfig().setParameter("namespaces", Boolean.FALSE); + serializer.write(document, output); + + } + + @SuppressWarnings("unchecked") + @Test + public void testDataObject_Base64Content_1() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException, SLViewerException { + + List dataObjectInfos = unmarshalDataObjectInfo("DataObjectInfo_Base64Content_1.xml"); + + Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl()); + + for (DataObjectInfoType dataObjectInfo : dataObjectInfos) { + signature.addDataObject(dataObjectInfo); + } + + signature.setSignerCeritifcate(certificate); + + signature.buildXMLSignature(); + + signAndMarshalSignature(signature); + + List references = signature.getReferences(); + assertTrue(references.size() == 2); + + Reference reference = references.get(0); + assertNotNull(reference.getId()); + + List transforms = reference.getTransforms(); + assertTrue(transforms.size() == 1); + + Transform transform = transforms.get(0); + assertTrue(Transform.BASE64.equals(transform.getAlgorithm())); + + List objects = signature.getXMLObjects(); + assertNotNull(objects); + assertTrue("Size " + objects.size() + " but should be 2.", objects.size() == 2); + + XMLObject object = objects.get(0); + + assertTrue(("#" + object.getId()).equals(reference.getURI())); + + } + + @SuppressWarnings("unchecked") + @Test + public void testDataObject_XMLContent_1() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException, SLViewerException { + + List dataObjectInfos = unmarshalDataObjectInfo("DataObjectInfo_XMLContent_1.xml"); + + Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl()); + + for (DataObjectInfoType dataObjectInfo : dataObjectInfos) { + signature.addDataObject(dataObjectInfo); + } + + signature.setSignerCeritifcate(certificate); + + signature.buildXMLSignature(); + + signAndMarshalSignature(signature); + + List references = signature.getReferences(); + assertTrue(references.size() == 2); + + Reference reference = references.get(0); + assertNotNull(reference.getId()); + + List transforms = reference.getTransforms(); + assertTrue(transforms.size() == 2); + + Transform transform = transforms.get(0); + assertTrue(Transform.XPATH2.equals(transform.getAlgorithm())); + + List objects = signature.getXMLObjects(); + assertNotNull(objects); + assertTrue("Size " + objects.size() + " but should be 2.", objects.size() == 2); + + XMLObject object = objects.get(0); + + assertTrue(("#" + object.getId()).equals(reference.getURI())); + + } + + @SuppressWarnings("unchecked") + @Test + public void testDataObject_XMLContent_2() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException, SLViewerException { + + List dataObjectInfos = unmarshalDataObjectInfo("DataObjectInfo_XMLContent_2.xml"); + + Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl()); + + for (DataObjectInfoType dataObjectInfo : dataObjectInfos) { + signature.addDataObject(dataObjectInfo); + } + + signature.setSignerCeritifcate(certificate); + + signature.buildXMLSignature(); + + signAndMarshalSignature(signature); + + List references = signature.getReferences(); + assertTrue(references.size() == 2); + + Reference reference = references.get(0); + assertNotNull(reference.getId()); + + List transforms = reference.getTransforms(); + assertTrue(transforms.size() == 2); + + Transform transform = transforms.get(0); + assertTrue(Transform.XPATH2.equals(transform.getAlgorithm())); + + List objects = signature.getXMLObjects(); + assertNotNull(objects); + assertTrue("Size " + objects.size() + " but should be 2.", objects.size() == 2); + + XMLObject object = objects.get(0); + + assertTrue(("#" + object.getId()).equals(reference.getURI())); + + } + + + @SuppressWarnings("unchecked") + @Test + public void testDataObject_LocRefContent_1() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException, SLViewerException { + + List dataObjectInfos = unmarshalDataObjectInfo("DataObjectInfo_LocRefContent_1.xml"); + + Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl()); + + for (DataObjectInfoType dataObjectInfo : dataObjectInfos) { + signature.addDataObject(dataObjectInfo); + } + + signature.buildXMLSignature(); + + signAndMarshalSignature(signature); + + List references = signature.getReferences(); + assertTrue(references.size() == 2); + + Reference reference = references.get(0); + assertNotNull(reference.getId()); + + List transforms = reference.getTransforms(); + assertTrue(transforms.size() == 2); + + Transform transform = transforms.get(0); + assertTrue(Transform.XPATH2.equals(transform.getAlgorithm())); + + List objects = signature.getXMLObjects(); + assertNotNull(objects); + assertTrue("Size " + objects.size() + " but should be 2.", objects.size() == 2); + + XMLObject object = objects.get(0); + + assertTrue(("#" + object.getId()).equals(reference.getURI())); + + } + + @SuppressWarnings("unchecked") + @Test + public void testDataObject_LocRefContent_2() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException, SLViewerException { + + List dataObjectInfos = unmarshalDataObjectInfo("DataObjectInfo_LocRefContent_2.xml"); + + Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl()); + + for (DataObjectInfoType dataObjectInfo : dataObjectInfos) { + signature.addDataObject(dataObjectInfo); + } + + signature.buildXMLSignature(); + + signAndMarshalSignature(signature); + + List references = signature.getReferences(); + assertTrue(references.size() == 2); + + Reference reference = references.get(0); + assertNotNull(reference.getId()); + + List transforms = reference.getTransforms(); + assertTrue(transforms.size() == 1); + + Transform transform = transforms.get(0); + assertTrue(Transform.BASE64.equals(transform.getAlgorithm())); + + List objects = signature.getXMLObjects(); + assertNotNull(objects); + assertTrue("Size " + objects.size() + " but should be 2.", objects.size() == 2); + + XMLObject object = objects.get(0); + + assertTrue(("#" + object.getId()).equals(reference.getURI())); + + } + + @SuppressWarnings("unchecked") + @Test + public void testDataObject_Reference_1() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException, SLViewerException { + + List dataObjectInfos = unmarshalDataObjectInfo("DataObjectInfo_Reference_1.xml"); + + Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl()); + + for (DataObjectInfoType dataObjectInfo : dataObjectInfos) { + signature.addDataObject(dataObjectInfo); + } + + signature.buildXMLSignature(); + + signAndMarshalSignature(signature); + + List references = signature.getReferences(); + assertTrue(references.size() == 2); + + Reference reference = references.get(0); + assertNotNull(reference.getId()); + + List transforms = reference.getTransforms(); + assertTrue(transforms.size() == 1); + + Transform transform = transforms.get(0); + assertTrue(Transform.BASE64.equals(transform.getAlgorithm())); + + List objects = signature.getXMLObjects(); + assertNotNull(objects); + assertTrue("Size " + objects.size() + " but should be 2.", objects.size() == 2); + + XMLObject object = objects.get(0); + + assertTrue(("#" + object.getId()).equals(reference.getURI())); + + } + + @SuppressWarnings("unchecked") + @Test + public void testDataObject_Detached_1() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException, SLViewerException { + + List dataObjectInfos = unmarshalDataObjectInfo("DataObjectInfo_Detached_1.xml"); + + Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl()); + + for (DataObjectInfoType dataObjectInfo : dataObjectInfos) { + signature.addDataObject(dataObjectInfo); + } + + signature.buildXMLSignature(); + + signAndMarshalSignature(signature); + + List references = signature.getReferences(); + assertTrue(references.size() == 2); + + Reference reference = references.get(0); + assertNotNull(reference.getId()); + + List transforms = reference.getTransforms(); + assertTrue(transforms.size() == 0); + + List objects = signature.getXMLObjects(); + assertNotNull(objects); + assertTrue(objects.size() == 1); + + } + + @SuppressWarnings("unchecked") + @Test + public void testDataObject_Detached_Base64Content() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException, SLViewerException { + + List dataObjectInfos = unmarshalDataObjectInfo("DataObjectInfo_Detached_Base64Content.xml"); + + Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl()); + + for (DataObjectInfoType dataObjectInfo : dataObjectInfos) { + signature.addDataObject(dataObjectInfo); + } + + signature.buildXMLSignature(); + + signAndMarshalSignature(signature); + + List references = signature.getReferences(); + assertTrue(references.size() == 2); + + Reference reference = references.get(0); + assertNotNull(reference.getId()); + + List transforms = reference.getTransforms(); + assertTrue(transforms.size() == 0); + + List objects = signature.getXMLObjects(); + assertNotNull(objects); + assertTrue(objects.size() == 1); + + } + + // + // + // TransformsInfo + // + // + + @SuppressWarnings("unchecked") + private CreateXMLSignatureRequestType unmarshalCreateXMLSignatureRequest(String file) throws JAXBException, XMLStreamException { + + Object object = unmarshal(file); + + Object requestType = ((JAXBElement) object).getValue(); + + assertTrue(requestType instanceof CreateXMLSignatureRequestType); + + return (CreateXMLSignatureRequestType) requestType; + + } + + + @SuppressWarnings("unchecked") + @Test + public void testTransformsInfo_1() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException, SLViewerException { + + CreateXMLSignatureRequestType requestType = unmarshalCreateXMLSignatureRequest("TransformsInfo_1.xml"); + + Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl()); + + + signature.setSignatureInfo(requestType.getSignatureInfo()); + + List dataObjectInfos = requestType.getDataObjectInfo(); + + for (DataObjectInfoType dataObjectInfo : dataObjectInfos) { + signature.addDataObject(dataObjectInfo); + } + + signature.setSignerCeritifcate(certificate); + + signature.buildXMLSignature(); + + signAndMarshalSignature(signature); + + List references = signature.getReferences(); + assertTrue(references.size() == 2); + + Reference reference = references.get(0); + assertNotNull(reference.getId()); + + List transforms = reference.getTransforms(); + assertTrue("Size " + transforms.size() + "", transforms.size() == 3); + + Transform transform = transforms.get(0); + assertTrue(Transform.ENVELOPED.equals(transform.getAlgorithm())); + + List objects = signature.getXMLObjects(); + assertNotNull(objects); + assertTrue("Size " + objects.size() + " but should be 1.", objects.size() == 1); + + } + + @SuppressWarnings("unchecked") + @Test + @Ignore + public void testTransformsInfo_2() throws JAXBException, SLCommandException, XMLStreamException, SLRequestException, MarshalException, XMLSignatureException, SLViewerException { + + CreateXMLSignatureRequestType requestType = unmarshalCreateXMLSignatureRequest("TransformsInfo_2.xml"); + + Signature signature = new Signature(null, new IdValueFactoryImpl(), new AlgorithmMethodFactoryImpl()); + + + signature.setSignatureInfo(requestType.getSignatureInfo()); + + List dataObjectInfos = requestType.getDataObjectInfo(); + + for (DataObjectInfoType dataObjectInfo : dataObjectInfos) { + signature.addDataObject(dataObjectInfo); + } + + signature.setSignerCeritifcate(certificate); + + signature.buildXMLSignature(); + + signAndMarshalSignature(signature); + + List references = signature.getReferences(); + assertTrue(references.size() == 2); + + Reference reference = references.get(0); + assertNotNull(reference.getId()); + + List transforms = reference.getTransforms(); + assertTrue("Size " + transforms.size() + "", transforms.size() == 2); + + Transform transform = transforms.get(0); + assertTrue(Transform.XSLT.equals(transform.getAlgorithm())); + + List objects = signature.getXMLObjects(); + assertNotNull(objects); + assertTrue("Size " + objects.size() + " but should be 1.", objects.size() == 1); + + } + + +} diff --git a/bkucommon/src/test/resources/at/gv/egiz/bku/slcommands/impl/TransformsInfo_2.xml b/bkucommon/src/test/resources/at/gv/egiz/bku/slcommands/impl/TransformsInfo_2.xml new file mode 100644 index 00000000..f43dc61a --- /dev/null +++ b/bkucommon/src/test/resources/at/gv/egiz/bku/slcommands/impl/TransformsInfo_2.xml @@ -0,0 +1,397 @@ + + + SecureSignatureKeypair + + + + + + + + + + + Signatur der Anmeldedaten + + + +

Signatur der Anmeldedaten

+

+

Mit meiner elektronischen Signatur beantrage ich, + + , geboren am . . , in der Rolle als (OID***= ), den Zugang zur gesicherten Anwendung.

+

+

Datum und Uhrzeit: . . , : + : +

+ +

HPI(**):

+
+ +

wbPK(*):

+
+ +
+

Ich bin weiters ermächtigt als von + , geboren am . . + + , + , in deren Auftrag zu handeln. +

wbPK(*) des Vollmachtgebers:

+
+

+

+ + + +

+


+ + +

+


+
+ +

+


+
+ + +
(*) wbPK: Das wirtschaftsbereichsspezifische + Personenkennzeichen wird aus den jeweiligen + Stammzahlen des Bürgers und des Wirtschaftsunternehmens + berechnet und ermöglicht eine eindeutige Zuordnung des + Bürgers zum Wirtschaftsunternehmen.
+
+ +
(**) HPI: Der eHealth Professional + Identifier wird aus den jeweiligen Stammzahlen + der Gesundheitsdiensteanbieterinnen / + Gesundheitsdiensteanbieter berechnet und ermöglicht eine + eindeutige Zuordnung der Gesundheitsdiensteanbieterin / + des Gesundheitsdiensteanbieters im + Gesundheitsbereich.
+
+ +
(***) OID: Object Identifier sind + standardisierte Objekt-Bezeichner und beschreiben + eindeutig die Rollen des GDA-Token Inhabers.
+
+ + +
+
+
+ +
+ + application/xhtml+xml + +
+ + + + + + + + + + Signatur der Anmeldedaten + + +

Signatur der Anmeldedaten

+

+

Mit meiner elektronischen Signatur beantrage ich, + + , geboren am . . , in der Rolle als (OID***= ), den Zugang zur gesicherten Anwendung.

+

+

Datum und Uhrzeit: . . , : + : +

+ +

HPI(**):

+
+ +

wbPK(*):

+
+ +
+

Ich bin weiters ermächtigt als von + , geboren am . . + + , + , in deren Auftrag zu handeln. +

wbPK(*) des Vollmachtgebers:

+
+

+

+ + + +

+


+ + +

+


+
+ +

+


+
+ + +
(*) wbPK: Das wirtschaftsbereichsspezifische + Personenkennzeichen wird aus den jeweiligen + Stammzahlen des Bürgers und des Wirtschaftsunternehmens + berechnet und ermöglicht eine eindeutige Zuordnung des + Bürgers zum Wirtschaftsunternehmen.
+
+ +
(**) HPI: Der eHealth Professional Identifier + wird aus den jeweiligen Stammzahlen der + Gesundheitsdiensteanbieterinnen / + Gesundheitsdiensteanbieter berechnet und ermöglicht eine + eindeutige Zuordnung der Gesundheitsdiensteanbieterin / + des Gesundheitsdiensteanbieters im + Gesundheitsbereich.
+
+ +
(***) OID: Object Identifier sind standardisierte + Objekt-Bezeichner und beschreiben eindeutig die Rollen + des GDA-Token Inhabers.
+
+ + +
+
+
+ +
+ + text/html + +
+ + + + + + + + Mit meiner elektronischen Signatur beantrage ich, + + , geboren am + + . + + . + + , + + in der Rolle als + + (OID***= + ) + , + + den Zugang zur gesicherten Anwendung. + Datum und Uhrzeit: + + . + + . + + , + + : + + : + + + + HPI(**): + + + + + wbPK(*): + + + + + Ich bin weiters ermächtigt als + + von + + + , geboren am + + . + + . + + + + , + + + , in deren Auftrag zu handeln. + + + wbPK(*) des Vollmachtgebers: + + + + + + (*) wbPK: Das wirtschaftsbereichsspezifische Personenkennzeichen wird aus den jeweiligen Stammzahlen des Bürgers und des Wirtschaftsunternehmens berechnet und ermöglicht eine eindeutige Zuordnung des Bürgers zum Wirtschaftsunternehmen. + + + (**) HPI: Der eHealth Professional Identifier wird aus den jeweiligen Stammzahlen der Gesundheitsdiensteanbieterinnen / Gesundheitsdiensteanbieter berechnet und ermöglicht eine eindeutige Zuordnung der Gesundheitsdiensteanbieterin / des Gesundheitsdiensteanbieters im Gesundheitsbereich. + + + (***) OID: Object Identifier sind standardisierte Objekt-Bezeichner und beschreiben eindeutig die Rollen des GDA-Token Inhabers. + + + + + + + not(text()) + + + + text/plain + + +
+ + + + + + + https://demo.egiz.gv.at/exchange-moa-id-auth/ + + + + + LTpz8VYzns2jrx0J8Gm/R/nAhxA= + urn:publicid:gv.at:wbpk+FN+TODO + + + + + https://apps.egiz.gv.at/urlaubsschein-frontend/moaid-login + + + 1971-11-10 + + + + + + /saml:Assertion + +
diff --git a/smcc/src/main/java/at/gv/egiz/smcc/ACOSCard.java b/smcc/src/main/java/at/gv/egiz/smcc/ACOSCard.java index 13c57686..86223854 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/ACOSCard.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/ACOSCard.java @@ -30,8 +30,6 @@ package at.gv.egiz.smcc; import java.nio.charset.Charset; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.smartcardio.CardChannel; import javax.smartcardio.CardException; import javax.smartcardio.CommandAPDU; @@ -41,7 +39,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class ACOSCard extends AbstractSignatureCard implements SignatureCard { - + private static Log log = LogFactory.getLog(ACOSCard.class); public static final byte[] AID_DEC = new byte[] { (byte) 0xA0, (byte) 0x00, @@ -100,8 +98,15 @@ public class ACOSCard extends AbstractSignatureCard implements SignatureCard { (byte) 0x01 // RSA // TODO: Not verified yet }; + private static final int PINSPEC_INF = 0; + private static final int PINSPEC_DEC = 1; + private static final int PINSPEC_SIG = 2; + public ACOSCard() { super("at/gv/egiz/smcc/ACOSCard"); + pinSpecs.add(PINSPEC_INF, new PINSpec(4, 4, "[0-9]", getResourceBundle().getString("inf.pin.name"), KID_PIN_INF, null)); + pinSpecs.add(PINSPEC_DEC, new PINSpec(4, 4, "[0-9]", getResourceBundle().getString("dec.pin.name"), KID_PIN_DEC, null)); + pinSpecs.add(PINSPEC_SIG, new PINSpec(6, 10, "[0-9]", getResourceBundle().getString("sig.pin.name"), KID_PIN_SIG, null)); } /* (non-Javadoc) @@ -165,7 +170,8 @@ public class ACOSCard extends AbstractSignatureCard implements SignatureCard { try { if ("IdentityLink".equals(infobox)) { - PINSpec spec = new PINSpec(4, 4, "[0-9]", getResourceBundle().getString("inf.pin.name")); + PINSpec spec = pinSpecs.get(PINSPEC_INF); + //new PINSpec(4, 4, "[0-9]", getResourceBundle().getString("inf.pin.name")); int retries = -1; String pin = null; @@ -219,7 +225,8 @@ public class ACOSCard extends AbstractSignatureCard implements SignatureCard { if (KeyboxName.SECURE_SIGNATURE_KEYPAIR.equals(keyboxName)) { - PINSpec spec = new PINSpec(6, 10, "[0-9]", getResourceBundle().getString("sig.pin.name")); + PINSpec spec = pinSpecs.get(PINSPEC_SIG); + //new PINSpec(6, 10, "[0-9]", getResourceBundle().getString("sig.pin.name")); int retries = -1; String pin = null; @@ -260,7 +267,8 @@ public class ACOSCard extends AbstractSignatureCard implements SignatureCard { } else if (KeyboxName.CERITIFIED_KEYPAIR.equals(keyboxName)) { - PINSpec spec = new PINSpec(4, 4, "[0-9]", getResourceBundle().getString("dec.pin.name")); + PINSpec spec = pinSpecs.get(PINSPEC_DEC); + //new PINSpec(4, 4, "[0-9]", getResourceBundle().getString("dec.pin.name")); int retries = -1; String pin = null; @@ -321,11 +329,6 @@ public class ACOSCard extends AbstractSignatureCard implements SignatureCard { 0x00, fid, 256)); } - @Override - public byte[] getKIDs() { - return new byte[] { KID_PIN_DEC, KID_PIN_INF, KID_PIN_SIG }; - } - @Override public int verifyPIN(String pin, byte kid) throws LockedException, NotActivatedException, SignatureCardException { diff --git a/smcc/src/main/java/at/gv/egiz/smcc/AbstractSignatureCard.java b/smcc/src/main/java/at/gv/egiz/smcc/AbstractSignatureCard.java index 67f090a5..cb068725 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/AbstractSignatureCard.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/AbstractSignatureCard.java @@ -31,7 +31,11 @@ package at.gv.egiz.smcc; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.ResourceBundle; import javax.smartcardio.ATR; @@ -49,6 +53,8 @@ public abstract class AbstractSignatureCard implements SignatureCard { private static Log log = LogFactory.getLog(AbstractSignatureCard.class); + protected List pinSpecs = new ArrayList(); + private ResourceBundle i18n; private String resourceBundleName; @@ -433,4 +439,8 @@ public abstract class AbstractSignatureCard implements SignatureCard { } } + @Override + public List getPINSpecs() { + return pinSpecs; + } } diff --git a/smcc/src/main/java/at/gv/egiz/smcc/PINSpec.java b/smcc/src/main/java/at/gv/egiz/smcc/PINSpec.java index 0852d664..d180ddf0 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/PINSpec.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/PINSpec.java @@ -35,23 +35,40 @@ public class PINSpec { String name_; + byte kid_; + + byte[] context_aid_; + + /** + * + * @param minLenght + * @param maxLength + * @param rexepPattern + * @param resourceBundle + * @param name + * @param kid the keyId for this pin + */ public PINSpec(int minLenght, int maxLength, String rexepPattern, - ResourceBundle resourceBundle, String name) { + ResourceBundle resourceBundle, String name, byte kid, byte[] contextAID) { minLength_ = minLenght; maxLength_ = maxLength; rexepPattern_ = rexepPattern; resourceBundle_ = resourceBundle; name_ = name; + kid_ = kid; + context_aid_ = contextAID; } public PINSpec(int minLenght, int maxLength, String rexepPattern, - String name) { + String name, byte kid, byte[] contextAID) { minLength_ = minLenght; maxLength_ = maxLength; rexepPattern_ = rexepPattern; name_ = name; + kid_ = kid; + context_aid_ = contextAID; } @@ -75,7 +92,14 @@ public class PINSpec { public String getRexepPattern() { return rexepPattern_; } - + + public byte getKID() { + return kid_; + } + + public byte[] getContextAID() { + return context_aid_; + } } diff --git a/smcc/src/main/java/at/gv/egiz/smcc/STARCOSCard.java b/smcc/src/main/java/at/gv/egiz/smcc/STARCOSCard.java index e80c6683..ae43629e 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/STARCOSCard.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/STARCOSCard.java @@ -29,10 +29,8 @@ package at.gv.egiz.smcc; import java.math.BigInteger; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; import javax.smartcardio.CardChannel; import javax.smartcardio.CardException; import javax.smartcardio.CommandAPDU; @@ -42,7 +40,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class STARCOSCard extends AbstractSignatureCard implements SignatureCard { - + /** * Logging facility. */ @@ -155,12 +153,17 @@ public class STARCOSCard extends AbstractSignatureCard implements SignatureCard }; public static final byte KID_PIN_CARD = (byte) 0x01; - + + private static final int PINSPEC_CARD = 0; + private static final int PINSPEC_SS = 1; + /** * Creates an new instance. */ public STARCOSCard() { super("at/gv/egiz/smcc/STARCOSCard"); + pinSpecs.add(PINSPEC_CARD, new PINSpec(4, 4, "[0-9]", getResourceBundle().getString("card.pin.name"), KID_PIN_CARD, null)); + pinSpecs.add(PINSPEC_SS, new PINSpec(6, 10, "[0-9]", getResourceBundle().getString("sig.pin.name"), KID_PIN_SS, AID_DF_SS)); } @Override @@ -210,7 +213,8 @@ public class STARCOSCard extends AbstractSignatureCard implements SignatureCard try { if ("IdentityLink".equals(infobox)) { - PINSpec spec = new PINSpec(4, 4, "[0-9]", getResourceBundle().getString("card.pin.name")); + PINSpec spec = pinSpecs.get(PINSPEC_CARD); + //new PINSpec(4, 4, "[0-9]", getResourceBundle().getString("card.pin.name")); int retries = -1; String pin = null; @@ -302,7 +306,8 @@ public class STARCOSCard extends AbstractSignatureCard implements SignatureCard if (KeyboxName.SECURE_SIGNATURE_KEYPAIR.equals(keyboxName)) { - PINSpec spec = new PINSpec(6, 10, "[0-9]", getResourceBundle().getString("sig.pin.name")); + PINSpec spec = pinSpecs.get(PINSPEC_SS); + //new PINSpec(6, 10, "[0-9]", getResourceBundle().getString("sig.pin.name")); int retries = -1; String pin = null; @@ -334,7 +339,8 @@ public class STARCOSCard extends AbstractSignatureCard implements SignatureCard } else if (KeyboxName.CERITIFIED_KEYPAIR.equals(keyboxName)) { - PINSpec spec = new PINSpec(4, 4, "[0-9]", getResourceBundle().getString("card.pin.name")); + PINSpec spec = pinSpecs.get(PINSPEC_CARD); + //new PINSpec(4, 4, "[0-9]", getResourceBundle().getString("card.pin.name")); int retries = -1; String pin = null; @@ -455,11 +461,6 @@ public class STARCOSCard extends AbstractSignatureCard implements SignatureCard } } - @Override - public byte[] getKIDs() { - return new byte[] { KID_PIN_CARD, KID_PIN_SS }; - } - /** * VERIFY PIN *

diff --git a/smcc/src/main/java/at/gv/egiz/smcc/SWCard.java b/smcc/src/main/java/at/gv/egiz/smcc/SWCard.java index bad7ccf6..8dc4ac2a 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/SWCard.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/SWCard.java @@ -36,9 +36,13 @@ import java.security.cert.Certificate; import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; +import java.util.ArrayList; import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; import java.util.Locale; +import java.util.Map; import javax.smartcardio.Card; import javax.smartcardio.CardTerminal; @@ -311,7 +315,7 @@ public class SWCard implements SignatureCard { if (password == null) { - PINSpec pinSpec = new PINSpec(0, -1, ".", "KeyStore-Password"); + PINSpec pinSpec = new PINSpec(0, -1, ".", "KeyStore-Password", (byte) 0x01, null); password = provider.providePIN(pinSpec, -1); @@ -390,13 +394,13 @@ public class SWCard implements SignatureCard { } @Override - public byte[] getKIDs() { - return null; + public int verifyPIN(String pin, byte kid) throws LockedException, NotActivatedException, SignatureCardException { + return -1; } @Override - public int verifyPIN(String pin, byte kid) throws LockedException, NotActivatedException, SignatureCardException { - return -1; + public List getPINSpecs() { + return new ArrayList(); } } diff --git a/smcc/src/main/java/at/gv/egiz/smcc/SignatureCard.java b/smcc/src/main/java/at/gv/egiz/smcc/SignatureCard.java index 1ec35b78..1e5e09c8 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/SignatureCard.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/SignatureCard.java @@ -31,6 +31,7 @@ package at.gv.egiz.smcc; import java.util.List; import java.util.Locale; +import java.util.Map; import javax.smartcardio.Card; import javax.smartcardio.CardTerminal; @@ -118,10 +119,10 @@ public interface SignatureCard { PINProvider provider) throws SignatureCardException, InterruptedException; /** - * get the KIDs for the availabel PINs + * Get the KIDs for all available PINs and the corresponding PINSpecs * @return array of KIDs */ - public byte[] getKIDs(); + public List getPINSpecs(); /** * diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java index e10ba8f9..b6c5a8ca 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java @@ -102,6 +102,9 @@ public abstract class AbstractBKUWorker extends AbstractSMCCSTAL implements Acti @Override protected boolean waitForCard() { + if (signatureCard != null) { + return false; + } SMCCHelper smccHelper = new SMCCHelper(); actionCommandList.clear(); actionCommandList.add("cancel"); diff --git a/smccSTAL/src/test/java/at/gv/egiz/smcc/AbstractSMCCSTALTest.java b/smccSTAL/src/test/java/at/gv/egiz/smcc/AbstractSMCCSTALTest.java index a5f8a771..a5d6df23 100644 --- a/smccSTAL/src/test/java/at/gv/egiz/smcc/AbstractSMCCSTALTest.java +++ b/smccSTAL/src/test/java/at/gv/egiz/smcc/AbstractSMCCSTALTest.java @@ -86,15 +86,16 @@ public class AbstractSMCCSTALTest extends AbstractSMCCSTAL implements } - @Override - public byte[] getKIDs() { - return null; - } @Override public int verifyPIN(String pin, byte kid) throws LockedException, NotActivatedException, SignatureCardException { return 0; } + + @Override + public List getPINSpecs() { + return new ArrayList(); + } }; return false; diff --git a/utils/src/main/java/at/gv/egiz/marshal/NamespacePrefix.java b/utils/src/main/java/at/gv/egiz/marshal/NamespacePrefix.java new file mode 100644 index 00000000..c03f17cd --- /dev/null +++ b/utils/src/main/java/at/gv/egiz/marshal/NamespacePrefix.java @@ -0,0 +1,34 @@ +/* + * 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.marshal; + +/** + * + * @author Clemens Orthacker + */ +public interface NamespacePrefix { + String CARDCHANNEL_PREFIX = "cc"; + String ECDSA_PREFIX = "ecdsa"; + String PERSONDATA_PREFIX = "pr"; + String SAML10_PREFIX = "saml"; + String SL_PREFIX = "sl"; + String XADES_PREFIX = "xades"; + String XMLDSIG_PREFIX = "xmldsig"; + String XSI_PREFIX = "xsi"; + +} diff --git a/utils/src/main/java/at/gv/egiz/marshal/NamespacePrefixMapperImpl.java b/utils/src/main/java/at/gv/egiz/marshal/NamespacePrefixMapperImpl.java index a08c1188..519f6b1f 100644 --- a/utils/src/main/java/at/gv/egiz/marshal/NamespacePrefixMapperImpl.java +++ b/utils/src/main/java/at/gv/egiz/marshal/NamespacePrefixMapperImpl.java @@ -36,35 +36,35 @@ public class NamespacePrefixMapperImpl extends NamespacePrefixMapper { log.trace("prefix for namespace " + namespaceUri + " requested"); } if ("http://www.w3.org/2001/XMLSchema-instance".equals(namespaceUri)) { - return "xsi"; + return NamespacePrefix.XSI_PREFIX; } if ("http://www.w3.org/2000/09/xmldsig#".equals(namespaceUri)) { - return "dsig"; + return NamespacePrefix.XMLDSIG_PREFIX; } if ("http://www.buergerkarte.at/namespaces/securitylayer/1.2#".equals(namespaceUri)) { - return "sl"; + return NamespacePrefix.SL_PREFIX; } if ("http://www.buergerkarte.at/cardchannel".equals(namespaceUri)) { - return "cc"; + return NamespacePrefix.CARDCHANNEL_PREFIX; } if ("http://www.w3.org/2001/04/xmldsig-more#".equals(namespaceUri)) { - return "ecdsa"; + return NamespacePrefix.ECDSA_PREFIX; } if ("http://reference.e-government.gv.at/namespace/persondata/20020228#".equals(namespaceUri)) { - return "pr"; + return NamespacePrefix.PERSONDATA_PREFIX; } if ("urn:oasis:names:tc:SAML:1.0:assertion".equals(namespaceUri)) { - return "saml"; + return NamespacePrefix.SAML10_PREFIX; } if ("http://uri.etsi.org/01903/v1.1.1#".equals(namespaceUri)) { - return "xades"; + return NamespacePrefix.XADES_PREFIX; } return suggestion; diff --git a/utils/src/main/java/at/gv/egiz/slbinding/RedirectEventFilter.java b/utils/src/main/java/at/gv/egiz/slbinding/RedirectEventFilter.java index d2a7fb30..14c5ba48 100644 --- a/utils/src/main/java/at/gv/egiz/slbinding/RedirectEventFilter.java +++ b/utils/src/main/java/at/gv/egiz/slbinding/RedirectEventFilter.java @@ -1,19 +1,19 @@ /* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /* * To change this template, choose Tools | Templates * and open the template in the editor. @@ -33,79 +33,84 @@ import javax.xml.stream.events.XMLEvent; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +/* + * TODO: don't set redirect stream from caller (caller does not know whether redirection will be triggered) + * rather create on trigger and pass to caller + */ public class RedirectEventFilter implements EventFilter { - public static final String DEFAULT_ENCODING = "UTF-8"; - private static Log log = LogFactory.getLog(RedirectEventFilter.class); - protected XMLEventWriter redirectWriter = null; - protected Set redirectTriggers = null; - private int depth = -1; - protected NamespaceContext currentNamespaceContext = null; + public static final String DEFAULT_ENCODING = "UTF-8"; + private static Log log = LogFactory.getLog(RedirectEventFilter.class); + protected XMLEventWriter redirectWriter = null; + protected Set redirectTriggers = null; + private int depth = -1; + protected NamespaceContext currentNamespaceContext = null; - /** - * Event redirection is disabled, set a redirect stream to enable. - */ - public RedirectEventFilter() { - redirectWriter = null; - // redirectTriggers = null; - } + /** + * Event redirection is disabled, set a redirect stream to enable. + */ + public RedirectEventFilter() { + redirectWriter = null; + // redirectTriggers = null; + } - /** - * - * @param redirectStream - * if null, no events are redirected - * @param redirectTriggers - * if null, all events are redirected - */ - public RedirectEventFilter(OutputStream redirectStream, String encoding) - throws XMLStreamException { // , List redirectTriggers - if (redirectStream != null) { - XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); - if (encoding == null) { - encoding = DEFAULT_ENCODING; - } - this.redirectWriter = outputFactory.createXMLEventWriter(redirectStream, + /** + * + * @param redirectStream + * if null, no events are redirected + * @param redirectTriggers + * if null, all events are redirected + */ + public RedirectEventFilter(OutputStream redirectStream, String encoding) + throws XMLStreamException { // , List redirectTriggers + if (redirectStream != null) { + XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); + if (encoding == null) { + encoding = DEFAULT_ENCODING; + } + this.redirectWriter = outputFactory.createXMLEventWriter(redirectStream, encoding); - } - // this.redirectTriggers = redirectTriggers; } + // this.redirectTriggers = redirectTriggers; + } - /** - * All startElement events occuring in the redirectTriggers list will trigger - * redirection of the entire (sub-)fragment. - * - * @param event - * @return false if an event is redirected - */ - @Override - public boolean accept(XMLEvent event) { - int eventType = event.getEventType(); + /** + * All startElement events occuring in the redirectTriggers list will trigger + * redirection of the entire (sub-)fragment. + * + * @param event + * @return false if an event is redirected + */ + @Override + public boolean accept(XMLEvent event) { + int eventType = event.getEventType(); - if (eventType == XMLStreamConstants.START_ELEMENT) { - currentNamespaceContext = event.asStartElement().getNamespaceContext(); - } - if (redirectWriter == null) { - return true; - } - if (eventType == XMLStreamConstants.START_ELEMENT) { - if (depth >= 0 || triggersRedirect(event.asStartElement().getName())) { - depth++; - } - } else if (eventType == XMLStreamConstants.END_ELEMENT) { - if (depth >= 0 && --depth < 0) { - // redirect the end element of the trigger, - // but do not redirect the end element of the calling type - if (redirectTriggers != null) { - redirectEvent(event); - return false; - } - } - } - if (depth >= 0) { //|| (depth == 0 && redirectTriggers == null)) { - redirectEvent(event); - return false; + if (eventType == XMLStreamConstants.START_ELEMENT) { + //hopefully, this is a copy + currentNamespaceContext = event.asStartElement().getNamespaceContext(); + } + if (redirectWriter == null) { + return true; + } + if (eventType == XMLStreamConstants.START_ELEMENT) { + if (depth >= 0 || triggersRedirect(event.asStartElement().getName())) { + depth++; + } + } else if (eventType == XMLStreamConstants.END_ELEMENT) { + if (depth >= 0 && --depth < 0) { + // redirect the end element of the trigger, + // but do not redirect the end element of the calling type + if (redirectTriggers != null) { + redirectEvent(event); + return false; } - return true; // depth < 0; + } + } + if (depth >= 0) { //|| (depth == 0 && redirectTriggers == null)) { + redirectEvent(event); + return false; + } + return true; // depth < 0; // switch (event.getEventType()) { // case XMLStreamConstants.START_ELEMENT: @@ -132,128 +137,130 @@ public class RedirectEventFilter implements EventFilter { // return false; // } // return true; // depth < 0; - } + } - /** - * @param startElt - * @return true if the set of triggers contains startElement - * (or no triggers are registered, i.e. everything is redirected) - */ - private boolean triggersRedirect(QName startElement) { - if (redirectTriggers != null) { - return redirectTriggers.contains(startElement); - } - return true; + /** + * @param startElt + * @return true if the set of triggers contains startElement + * (or no triggers are registered, i.e. everything is redirected) + */ + private boolean triggersRedirect(QName startElement) { + if (redirectTriggers != null) { + return redirectTriggers.contains(startElement); } + return true; + } - private void redirectEvent(XMLEvent event) { - try { - if (log.isTraceEnabled()) { - log.trace("redirecting StAX event " + event); - } - redirectWriter.add(event); - } catch (XMLStreamException ex) { - ex.printStackTrace(); - } + private void redirectEvent(XMLEvent event) { + try { + if (log.isTraceEnabled()) { + log.trace("redirecting StAX event " + event); + } + redirectWriter.add(event); + } catch (XMLStreamException ex) { + ex.printStackTrace(); } + } - /** - * Enable/disable redirection of all events from now on. - * The redirected events will be UTF-8 encoded and written to the stream. - * - * @param redirectstream - * if null, redirection is disabled - */ - public void setRedirectStream(OutputStream redirectStream) throws XMLStreamException { - setRedirectStream(redirectStream, DEFAULT_ENCODING, null); - } + /** + * Enable/disable redirection of all events from now on. + * The redirected events will be UTF-8 encoded and written to the stream. + * + * @param redirectstream + * if null, redirection is disabled + */ + public void setRedirectStream(OutputStream redirectStream) throws XMLStreamException { + setRedirectStream(redirectStream, DEFAULT_ENCODING, null); + } - /** - * Enable/disable redirection of all events from now on. - * - * @param redirectStream if null, redirection is disabled - * @param encoding The encoding for the redirect stream - * @throws javax.xml.stream.XMLStreamException - */ - public void setRedirectStream(OutputStream redirectStream, String encoding) throws XMLStreamException { - setRedirectStream(redirectStream, encoding, null); - } + /** + * Enable/disable redirection of all events from now on. + * + * @param redirectStream if null, redirection is disabled + * @param encoding The encoding for the redirect stream + * @throws javax.xml.stream.XMLStreamException + */ + public void setRedirectStream(OutputStream redirectStream, String encoding) throws XMLStreamException { + setRedirectStream(redirectStream, encoding, null); + } - /** - * Enable/disable redirection of all (child) elements contained in redirect triggers. - * The redirected events will be UTF-8 encoded and written to the stream. - * - * @param redirectstream - * if null, redirection is disabled - * @param redirectTriggers elements that trigger the redirection - */ - public void setRedirectStream(OutputStream redirectStream, Set redirectTriggers) throws XMLStreamException { - setRedirectStream(redirectStream, DEFAULT_ENCODING, redirectTriggers); - } + /** + * Enable/disable redirection of all (child) elements contained in redirect triggers. + * The redirected events will be UTF-8 encoded and written to the stream. + * + * @param redirectstream + * if null, redirection is disabled + * @param redirectTriggers elements that trigger the redirection + */ + public void setRedirectStream(OutputStream redirectStream, Set redirectTriggers) throws XMLStreamException { + setRedirectStream(redirectStream, DEFAULT_ENCODING, redirectTriggers); + } - /** - * Enable/disable redirection of all (child) elements contained in redirect triggers. - * - * @param redirectstream - * if null, redirection is disabled - * @param encoding The encoding for the redirect stream - * @param redirectTriggers elements that trigger the redirection - */ - public void setRedirectStream(OutputStream redirectStream, String encoding, Set redirectTriggers) throws XMLStreamException { - if (redirectStream != null) { - XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); - if (encoding == null) { - encoding = DEFAULT_ENCODING; - } - redirectWriter = outputFactory.createXMLEventWriter(redirectStream, + /** + * Enable/disable redirection of all (child) elements contained in redirect triggers. + * + * TODO: don't set redirect stream from caller (caller does not know whether redirection will be triggered) + * rather create on trigger and pass to caller + * @param redirectstream + * if null, redirection is disabled + * @param encoding The encoding for the redirect stream + * @param redirectTriggers elements that trigger the redirection + */ + public void setRedirectStream(OutputStream redirectStream, String encoding, Set redirectTriggers) throws XMLStreamException { + if (redirectStream != null) { + XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); + if (encoding == null) { + encoding = DEFAULT_ENCODING; + } + redirectWriter = outputFactory.createXMLEventWriter(redirectStream, encoding); - if (redirectTriggers == null) { - // start redirecting - depth = 0; - } - this.redirectTriggers = redirectTriggers; - } else { - redirectWriter = null; - this.redirectTriggers = null; - } + if (redirectTriggers == null) { + // start redirecting + depth = 0; + } + this.redirectTriggers = redirectTriggers; + } else { + redirectWriter = null; + this.redirectTriggers = null; } + } - /** - * Enable/disable redirection of fragments (defined by elements in - * redirectTriggers) - * - * @param redirectStream - * if null, redirection is disabled - * @param redirectTriggers - * All startElement events occuring in this list will trigger - * redirection of the entire fragment. If null, all events are - * redirected - */ - // public void setRedirectStream(OutputStream redirectStream, List - // redirectTriggers) throws XMLStreamException { - // if (redirectStream != null) { - // XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); - // redirectWriter = outputFactory.createXMLEventWriter(redirectStream); - // } else { - // redirectWriter = null; - // } - // this.redirectTriggers = (redirectStream == null) ? null : redirectTriggers; - // } - /** - * flushes the internal EventWriter - * - * @throws javax.xml.stream.XMLStreamException - */ - public void flushRedirectStream() throws XMLStreamException { - redirectWriter.flush(); - } + /** + * Enable/disable redirection of fragments (defined by elements in + * redirectTriggers) + * + * @param redirectStream + * if null, redirection is disabled + * @param redirectTriggers + * All startElement events occuring in this list will trigger + * redirection of the entire fragment. If null, all events are + * redirected + */ + // public void setRedirectStream(OutputStream redirectStream, List + // redirectTriggers) throws XMLStreamException { + // if (redirectStream != null) { + // XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); + // redirectWriter = outputFactory.createXMLEventWriter(redirectStream); + // } else { + // redirectWriter = null; + // } + // this.redirectTriggers = (redirectStream == null) ? null : redirectTriggers; + // } + /** + * flushes the internal EventWriter + * + * @throws javax.xml.stream.XMLStreamException + */ + public void flushRedirectStream() throws XMLStreamException { + redirectWriter.flush(); + } - /** - * the namespaceContext of the last startelement event read - * - * @return - */ - public NamespaceContext getCurrentNamespaceContext() { - return currentNamespaceContext; - } + /** + * the namespaceContext of the last startelement event read + * + * @return + */ + public NamespaceContext getCurrentNamespaceContext() { + return currentNamespaceContext; + } } diff --git a/utils/src/main/java/at/gv/egiz/slbinding/impl/TransformsInfoType.java b/utils/src/main/java/at/gv/egiz/slbinding/impl/TransformsInfoType.java index b4e988f0..1180e9fa 100644 --- a/utils/src/main/java/at/gv/egiz/slbinding/impl/TransformsInfoType.java +++ b/utils/src/main/java/at/gv/egiz/slbinding/impl/TransformsInfoType.java @@ -25,6 +25,7 @@ import java.io.ByteArrayOutputStream; import java.util.HashSet; import java.util.Set; import javax.xml.bind.annotation.XmlTransient; +import javax.xml.namespace.NamespaceContext; import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamException; import org.apache.commons.logging.Log; diff --git a/utils/src/main/java/at/gv/egiz/slbinding/impl/XMLContentType.java b/utils/src/main/java/at/gv/egiz/slbinding/impl/XMLContentType.java index c32542aa..eb147f88 100644 --- a/utils/src/main/java/at/gv/egiz/slbinding/impl/XMLContentType.java +++ b/utils/src/main/java/at/gv/egiz/slbinding/impl/XMLContentType.java @@ -35,7 +35,7 @@ import org.apache.commons.logging.LogFactory; public class XMLContentType extends at.buergerkarte.namespaces.securitylayer._1.XMLContentType implements RedirectCallback { @XmlTransient - private static Log log = LogFactory.getLog(TransformsInfoType.class); + private static Log log = LogFactory.getLog(XMLContentType.class); @XmlTransient protected ByteArrayOutputStream redirectOS = null; diff --git a/utils/src/main/java/org/w3/_2000/_09/xmldsig_/ObjectFactory.java b/utils/src/main/java/org/w3/_2000/_09/xmldsig_/ObjectFactory.java index 4ab376f1..fae77451 100644 --- a/utils/src/main/java/org/w3/_2000/_09/xmldsig_/ObjectFactory.java +++ b/utils/src/main/java/org/w3/_2000/_09/xmldsig_/ObjectFactory.java @@ -167,6 +167,7 @@ public class ObjectFactory { * */ public TransformType createTransformType() { +// return new at.gv.egiz.slbinding.impl.TransformType(); return new TransformType(); } diff --git a/utils/src/main/java/org/w3/_2000/_09/xmldsig_/TransformsType.java b/utils/src/main/java/org/w3/_2000/_09/xmldsig_/TransformsType.java index 584baf80..c7044c4c 100644 --- a/utils/src/main/java/org/w3/_2000/_09/xmldsig_/TransformsType.java +++ b/utils/src/main/java/org/w3/_2000/_09/xmldsig_/TransformsType.java @@ -57,7 +57,7 @@ import javax.xml.bind.annotation.XmlType; }) public class TransformsType { - @XmlElement(name = "Transform", required = true) + @XmlElement(name = "Transform", required = true) //, type=at.gv.egiz.slbinding.impl.TransformType.class) protected List transform; /** diff --git a/utils/src/test/java/at/gv/egiz/slbinding/RedirectTest.java b/utils/src/test/java/at/gv/egiz/slbinding/RedirectTest.java index 99d353ac..7c8c206a 100644 --- a/utils/src/test/java/at/gv/egiz/slbinding/RedirectTest.java +++ b/utils/src/test/java/at/gv/egiz/slbinding/RedirectTest.java @@ -52,6 +52,8 @@ import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLInputFactory; import static org.junit.Assert.*; +import org.w3._2000._09.xmldsig_.TransformType; +import org.w3._2000._09.xmldsig_.TransformsType; /** * @@ -131,11 +133,34 @@ public class RedirectTest { Iterator tiIt = transformsInfos.iterator(); while (tiIt.hasNext()) { at.gv.egiz.slbinding.impl.TransformsInfoType ti = (at.gv.egiz.slbinding.impl.TransformsInfoType) tiIt.next(); +// TransformsInfoType ti = tiIt.next(); assertNotNull(ti); - System.out.println("found at.gv.egiz.slbinding.impl.TransformsInfoType TransformsInfo"); + System.out.println("found sl:TransformsInfo: " + ti.getClass().getName()); //at.gv.egiz.slbinding.impl.TransformsInfoType TransformsInfo"); +// TransformsType ts = ti.getTransforms(); +// assertNotNull(ts); +// System.out.println("found dsig:Transforms " + ts.getClass().getName()); //org.w3._2000._09.xmldsig_.TransformsType dsig:Transforms"); +// List tL = ts.getTransform(); +// assertNotNull(tL); +// System.out.println("found " + tL.size() + " org.w3._2000._09.xmldsig_.TransformType dsig:Transform"); +// for (TransformType t : tL) { +// if (t instanceof at.gv.egiz.slbinding.impl.TransformType) { +// System.out.println("found at.gv.egiz.slbinding.impl.TransformType"); +// byte[] redirectedBytes = ((at.gv.egiz.slbinding.impl.TransformType) t).getRedirectedStream().toByteArray(); +// if (redirectedBytes != null && redirectedBytes.length > 0) { +// System.out.println("reading redirected stream..."); +// os.write("--- redirected Transform ---".getBytes()); +// os.write(redirectedBytes); +// os.write("\n".getBytes()); +// } else { +// System.out.println("no redirected stream"); +// } +// } +// } + ByteArrayOutputStream dsigTransforms = ti.getRedirectedStream(); + os.write("--- redirected TransformsInfo content ---".getBytes()); os.write(dsigTransforms.toByteArray()); - os.write("\n".getBytes()); + os.write("\n---".getBytes()); MetaInfoType mi = ti.getFinalDataMetaInfo(); assertNotNull(mi); diff --git a/utils/src/test/requests/CreateXMLSignatureRequest02.xml_redirect.txt b/utils/src/test/requests/CreateXMLSignatureRequest02.xml_redirect.txt index 31be50b7..fc0e4f14 100644 --- a/utils/src/test/requests/CreateXMLSignatureRequest02.xml_redirect.txt +++ b/utils/src/test/requests/CreateXMLSignatureRequest02.xml_redirect.txt @@ -1,4 +1,4 @@ - +--- redirected TransformsInfo content --- @@ -82,7 +82,7 @@ - +------ redirected TransformsInfo content --- @@ -162,3 +162,4 @@ +--- \ No newline at end of file -- cgit v1.2.3 From 28e772965f4fb313aeb5018e6104943a1177bc06 Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 10 Mar 2009 11:10:55 +0000 Subject: pinfield and pinsize label aligned trailing git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@317 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'BKUCommonGUI/src/test/java') 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 08ecaa7f..ef64ac59 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 @@ -21,6 +21,7 @@ package at.gv.egiz.bku.gui; import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.smcc.STARCOSCard; import at.gv.egiz.stal.HashDataInput; import at.gv.egiz.stal.impl.ByteArrayHashDataInput; import java.awt.event.ActionEvent; @@ -46,7 +47,8 @@ public class BKUGUIWorker implements Runnable { public void run() { // try { - final PINSpec signPinSpec = new PINSpec(6, 10, "[0-9]", "Signatur-PIN", (byte) 0x81, null); + final PINSpec signPinSpec = new PINSpec(6, 10, "[0-9]", "Test-PIN", (byte) 0x81, null); + final PINSpec cardPinSpec = new PINSpec(4, 4, "[0-9]", "Test-PIN", (byte) 0x01, null); final ActionListener cancelListener = new ActionListener() { -- cgit v1.2.3 From 2a1df5e58e44f8d77f34eb80df74e8c0d27caceb Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 18 Mar 2009 22:27:28 +0000 Subject: 1.1-rc5 (pinProviderFactories, gui refactoring, signatureCard, secureViewer) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@322 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/online/applet/AppletBKUWorker.java | 5 +- .../bku/online/applet/AppletHashDataDisplay.java | 217 -------- .../egiz/bku/online/applet/AppletSecureViewer.java | 221 ++++++++ .../java/at/gv/egiz/bku/gui/PINManagementGUI.java | 365 +++++++------- .../at/gv/egiz/bku/gui/PINManagementGUIFacade.java | 46 +- .../bku/online/applet/PINManagementBKUWorker.java | 10 +- .../smccstal/ext/ManagementPINProviderFactory.java | 53 ++ .../smccstal/ext/PINManagementRequestHandler.java | 319 ++++++------ .../bku/smccstal/ext/PinpadPINProviderFactory.java | 126 +++++ .../smccstal/ext/SoftwarePINProviderFactory.java | 148 ++++++ .../gv/egiz/bku/gui/ActivationMessages.properties | 17 +- .../egiz/bku/gui/ActivationMessages_en.properties | 15 +- .../test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java | 4 +- .../gv/egiz/bku/smccstal/ext/FileSystemTest.java | 435 ---------------- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 66 ++- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 560 +++++++++++---------- .../main/java/at/gv/egiz/bku/gui/PinDocument.java | 30 +- .../at/gv/egiz/bku/gui/Messages.properties | 28 +- .../at/gv/egiz/bku/gui/Messages_en.properties | 28 +- .../test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java | 6 +- .../at/gv/egiz/bku/local/stal/BKUGuiProxy.java | 106 ++-- .../bku/local/stal/LocalSignRequestHandler.java | 4 +- .../java/at/gv/egiz/bku/local/app/Container.java | 5 - .../main/webapp/helpfiles/de/cardnotsupported.html | 47 ++ .../main/webapp/helpfiles/de/cardnotsupported.png | Bin 0 -> 2120 bytes .../webapp/helpfiles/de/help.cardnotsupported.html | 47 -- .../webapp/helpfiles/de/help.cardnotsupported.png | Bin 2120 -> 0 bytes .../main/webapp/helpfiles/de/help.insertcard.html | 42 -- .../main/webapp/helpfiles/de/help.insertcard.png | Bin 2270 -> 0 bytes .../src/main/webapp/helpfiles/de/help.wait.html | 39 -- .../src/main/webapp/helpfiles/de/help.wait.png | Bin 1542 -> 0 bytes .../src/main/webapp/helpfiles/de/help.welcome.html | 40 -- .../src/main/webapp/helpfiles/de/help.welcome.png | Bin 1537 -> 0 bytes .../src/main/webapp/helpfiles/de/insertcard.html | 42 ++ .../src/main/webapp/helpfiles/de/insertcard.png | Bin 0 -> 2270 bytes BKUOnline/src/main/webapp/helpfiles/de/wait.html | 39 ++ BKUOnline/src/main/webapp/helpfiles/de/wait.png | Bin 0 -> 1542 bytes .../src/main/webapp/helpfiles/de/welcome.html | 40 ++ BKUOnline/src/main/webapp/helpfiles/de/welcome.png | Bin 0 -> 1537 bytes smcc/src/main/java/at/gv/egiz/smcc/ACOS04Card.java | 30 ++ smcc/src/main/java/at/gv/egiz/smcc/ACOSCard.java | 410 ++++++++++----- .../at/gv/egiz/smcc/AbstractSignatureCard.java | 352 +++++++++++-- .../java/at/gv/egiz/smcc/ChangePINProvider.java | 39 ++ .../src/main/java/at/gv/egiz/smcc/PINProvider.java | 26 +- .../src/main/java/at/gv/egiz/smcc/STARCOSCard.java | 479 +++++++++++------- smcc/src/main/java/at/gv/egiz/smcc/SWCard.java | 36 +- .../main/java/at/gv/egiz/smcc/SignatureCard.java | 42 +- .../java/at/gv/egiz/smcc/SignatureCardFactory.java | 2 +- .../java/at/gv/egiz/smcc/TimeoutException.java | 39 ++ smcc/src/test/resources/log4j.properties | 2 +- .../at/gv/egiz/bku/smccstal/AbstractBKUWorker.java | 8 +- .../gv/egiz/bku/smccstal/AbstractPINProvider.java | 67 +++ .../at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java | 6 + .../bku/smccstal/InfoBoxReadRequestHandler.java | 40 +- .../gv/egiz/bku/smccstal/PINProviderFactory.java | 47 ++ .../bku/smccstal/PinpadPINProviderFactory.java | 155 ++++++ .../java/at/gv/egiz/bku/smccstal/SecureViewer.java | 44 ++ .../gv/egiz/bku/smccstal/SignRequestHandler.java | 149 +++--- .../bku/smccstal/SoftwarePINProviderFactory.java | 140 ++++++ .../java/at/gv/egiz/smcc/AbstractSMCCSTALTest.java | 16 +- 60 files changed, 3278 insertions(+), 2001 deletions(-) delete mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java create mode 100644 BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java create mode 100644 BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/ManagementPINProviderFactory.java create mode 100644 BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PinpadPINProviderFactory.java create mode 100644 BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/SoftwarePINProviderFactory.java delete mode 100644 BKUAppletExt/src/test/java/at/gv/egiz/bku/smccstal/ext/FileSystemTest.java create mode 100644 BKUOnline/src/main/webapp/helpfiles/de/cardnotsupported.html create mode 100644 BKUOnline/src/main/webapp/helpfiles/de/cardnotsupported.png delete mode 100644 BKUOnline/src/main/webapp/helpfiles/de/help.cardnotsupported.html delete mode 100644 BKUOnline/src/main/webapp/helpfiles/de/help.cardnotsupported.png delete mode 100644 BKUOnline/src/main/webapp/helpfiles/de/help.insertcard.html delete mode 100644 BKUOnline/src/main/webapp/helpfiles/de/help.insertcard.png delete mode 100644 BKUOnline/src/main/webapp/helpfiles/de/help.wait.html delete mode 100644 BKUOnline/src/main/webapp/helpfiles/de/help.wait.png delete mode 100644 BKUOnline/src/main/webapp/helpfiles/de/help.welcome.html delete mode 100644 BKUOnline/src/main/webapp/helpfiles/de/help.welcome.png create mode 100644 BKUOnline/src/main/webapp/helpfiles/de/insertcard.html create mode 100644 BKUOnline/src/main/webapp/helpfiles/de/insertcard.png create mode 100644 BKUOnline/src/main/webapp/helpfiles/de/wait.html create mode 100644 BKUOnline/src/main/webapp/helpfiles/de/wait.png create mode 100644 BKUOnline/src/main/webapp/helpfiles/de/welcome.html create mode 100644 BKUOnline/src/main/webapp/helpfiles/de/welcome.png create mode 100644 smcc/src/main/java/at/gv/egiz/smcc/ACOS04Card.java create mode 100644 smcc/src/main/java/at/gv/egiz/smcc/ChangePINProvider.java create mode 100644 smcc/src/main/java/at/gv/egiz/smcc/TimeoutException.java create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractPINProvider.java create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PinpadPINProviderFactory.java create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SecureViewer.java create mode 100644 smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SoftwarePINProviderFactory.java (limited to 'BKUCommonGUI/src/test/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 eb6cf30b..9b9735f6 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java @@ -60,14 +60,15 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { @Override public void run() { - gui.showWelcomeDialog(); + gui.showMessageDialog(BKUGUIFacade.TITLE_WELCOME, + BKUGUIFacade.MESSAGE_WELCOME); try { STALPortType stalPort = applet.getSTALPort(); STALTranslator stalTranslator = applet.getSTALTranslator(); addRequestHandler(SignRequest.class, - new AppletHashDataDisplay(stalPort, sessionId)); + new AppletSecureViewer(stalPort, sessionId)); GetNextRequestResponseType nextRequestResp = stalPort.connect(sessionId); diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java deleted file mode 100644 index 2ed9aa5b..00000000 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletHashDataDisplay.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright 2008 Federal Chancellery Austria and - * Graz University of Technology - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package at.gv.egiz.bku.online.applet; - -import java.security.DigestException; -import java.security.MessageDigest; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import at.gv.egiz.bku.smccstal.SignRequestHandler; -import at.gv.egiz.stal.HashDataInput; -import at.gv.egiz.stal.impl.ByteArrayHashDataInput; -import at.gv.egiz.stal.service.GetHashDataInputFault; -import at.gv.egiz.stal.service.STALPortType; -import at.gv.egiz.stal.service.types.GetHashDataInputResponseType; -import at.gv.egiz.stal.service.types.GetHashDataInputType; -import at.gv.egiz.stal.signedinfo.ReferenceType; -import java.security.NoSuchAlgorithmException; - -/** - * A SignRequesthandler that obtains hashdata inputs from a STAL webservice and - * displays these either within the applet or in a separate frame. - * The internal viewer displays plaintext data only, other mimetypes can be saved to disk. - * The standalone (frame) viewer displays all mimetypes. - * - * (This class depends on STALService and therefore is not part of BKUCommonGUI.) - * - * @author Clemens Orthacker - */ -public class AppletHashDataDisplay extends SignRequestHandler { - - private static final Log log = LogFactory.getLog(AppletHashDataDisplay.class); - protected STALPortType stalPort; - protected String sessId; - - public AppletHashDataDisplay(STALPortType stalPort, String sessId) { - if (stalPort == null || sessId == null) { - throw new NullPointerException("STAL port must not be null"); - } - this.sessId = sessId; - this.stalPort = stalPort; - } - - /** - * TODO don't throw exceptions - * @param signedReferences - * @throws java.security.DigestException - * @throws java.lang.Exception - */ - @Override - public void displayHashDataInputs(List signedReferences) throws DigestException, Exception { - - List hdi = getHashDataInput(signedReferences); - List verifiedHashDataInputs = verifyHashDataInput(signedReferences, hdi); - - if (verifiedHashDataInputs.size() > 0) { - gui.showHashDataInputDialog(verifiedHashDataInputs, this, "hashDataDone"); - } else { - throw new Exception("No signature data (apart from any QualifyingProperties or a Manifest)"); - } - } - - /** - * Get all hashdata inputs that contain an ID attribute but no Type attribute. - * @param signedReferences - * @return - * @throws at.gv.egiz.stal.service.GetHashDataInputFault - */ - private List getHashDataInput(List signedReferences) throws GetHashDataInputFault, Exception { - GetHashDataInputType request = new GetHashDataInputType(); - request.setSessionId(sessId); - -// HashMap idSignedRefMap = new HashMap(); - for (ReferenceType signedRef : signedReferences) { - //don't get Manifest, QualifyingProperties, ... - if (signedRef.getType() == null) { - String signedRefId = signedRef.getId(); - if (signedRefId != null) { - if (log.isTraceEnabled()) { - log.trace("requesting hashdata input for reference " + signedRefId); - } -// idSignedRefMap.put(signedRefId, signedRef); - GetHashDataInputType.Reference ref = new GetHashDataInputType.Reference(); - ref.setID(signedRefId); - request.getReference().add(ref); - - } else { - throw new Exception("Cannot resolve signature data for dsig:Reference without Id attribute"); - } - } - } - - if (request.getReference().size() < 1) { - log.error("No signature data (apart from any QualifyingProperties or a Manifest) for session " + sessId); - throw new Exception("No signature data (apart from any QualifyingProperties or a Manifest)"); - } - - if (log.isDebugEnabled()) { - log.debug("WebService call GetHashDataInput for " + request.getReference().size() + " references in session " + sessId); - } - GetHashDataInputResponseType response = stalPort.getHashDataInput(request); - return response.getReference(); - } - - /** - * Verifies all signed references and returns STAL HashDataInputs - * @param signedReferences - * @param hashDataInputs - * @return - * @throws java.security.DigestException - * @throws java.security.NoSuchAlgorithmException - * @throws Exception if no hashdata input is provided for a signed reference - */ - private List verifyHashDataInput(List signedReferences, List hashDataInputs) throws DigestException, NoSuchAlgorithmException, Exception { - - ArrayList verifiedHashDataInputs = new ArrayList(); - - for (ReferenceType signedRef : signedReferences) { - if (signedRef.getType() == null) { - log.info("Verifying digest for signed reference " + signedRef.getId()); - - String signedRefId = signedRef.getId(); - byte[] signedDigest = signedRef.getDigestValue(); - String signedDigestAlg = null; - if (signedRef.getDigestMethod() != null) { - signedDigestAlg = signedRef.getDigestMethod().getAlgorithm(); - } else { - throw new NoSuchAlgorithmException("Failed to verify digest value for reference " + signedRefId + ": no digest algorithm"); - } - - // usually, there is just one item here - GetHashDataInputResponseType.Reference hashDataInput = null; - for (GetHashDataInputResponseType.Reference hdi : hashDataInputs) { - if (signedRefId.equals(hdi.getID())) { - hashDataInput = hdi; - break; - } - } - if (hashDataInput == null) { - throw new Exception("No hashdata input for reference " + signedRefId + " returned by service"); - } - - byte[] hdi = hashDataInput.getValue(); - String mimeType = hashDataInput.getMimeType(); - String encoding = hashDataInput.getEncoding(); - - if (hdi == null) { - throw new Exception("No hashdata input for reference " + signedRefId + " provided by service"); - } - if (log.isDebugEnabled()) { - log.debug("Got HashDataInput " + signedRefId + " (" + mimeType + ";" + encoding + ")"); - } - - byte[] hashDataInputDigest = digest(hdi, signedDigestAlg); - - if (log.isDebugEnabled()) { - log.debug("Comparing digest values... "); - } -// log.warn("***************** DISABLED HASHDATA VERIFICATION"); - if (!Arrays.equals(hashDataInputDigest, signedDigest)) { - log.error("Bad digest value for reference " + signedRefId); - throw new DigestException("Bad digest value for reference " + signedRefId); - } - - verifiedHashDataInputs.add(new ByteArrayHashDataInput(hdi, signedRefId, mimeType, encoding)); - } - } - - return verifiedHashDataInputs; - } - - //TODO - private byte[] digest(byte[] hashDataInput, String mdAlg) throws NoSuchAlgorithmException { - if ("http://www.w3.org/2000/09/xmldsig#sha1".equals(mdAlg)) { - mdAlg = "SHA-1"; - } else if ("http://www.w3.org/2001/04/xmlenc#sha256".equals(mdAlg)) { - mdAlg = "SHA-256"; - } else if ("http://www.w3.org/2001/04/xmlenc#sha224".equals(mdAlg)) { - mdAlg = "SHA-224"; - } else if ("http://www.w3.org/2001/04/xmldsig-more#sha224".equals(mdAlg)) { - mdAlg = "SHA-224"; - } else if ("http://www.w3.org/2001/04/xmldsig-more#sha384".equals(mdAlg)) { - mdAlg = "SHA-384"; - } else if ("http://www.w3.org/2001/04/xmlenc#sha512".equals(mdAlg)) { - mdAlg = "SHA-512"; - } else if ("http://www.w3.org/2001/04/xmldsig-more#md2".equals(mdAlg)) { - mdAlg = "MD2"; - } else if ("http://www.w3.org/2001/04/xmldsig-more#md5".equals(mdAlg)) { - mdAlg = "MD5"; - } else if ("http://www.w3.org/2001/04/xmlenc#ripemd160".equals(mdAlg)) { - mdAlg = "RipeMD-160"; - } else { - throw new NoSuchAlgorithmException("Failed to verify digest value: unsupported digest algorithm " + mdAlg); - } - - MessageDigest md = MessageDigest.getInstance(mdAlg); - return md.digest(hashDataInput); - } -} diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java new file mode 100644 index 00000000..e2551e2d --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java @@ -0,0 +1,221 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package at.gv.egiz.bku.online.applet; + +import at.gv.egiz.bku.smccstal.SecureViewer; +import java.security.DigestException; +import java.security.MessageDigest; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.gv.egiz.bku.smccstal.SignRequestHandler; +import at.gv.egiz.stal.HashDataInput; +import at.gv.egiz.stal.impl.ByteArrayHashDataInput; +import at.gv.egiz.stal.service.GetHashDataInputFault; +import at.gv.egiz.stal.service.STALPortType; +import at.gv.egiz.stal.service.types.GetHashDataInputResponseType; +import at.gv.egiz.stal.service.types.GetHashDataInputType; +import at.gv.egiz.stal.signedinfo.ReferenceType; +import java.security.NoSuchAlgorithmException; + +/** + * A SignRequesthandler that obtains hashdata inputs from a STAL webservice and + * displays these either within the applet or in a separate frame. + * The internal viewer displays plaintext data only, other mimetypes can be saved to disk. + * The standalone (frame) viewer displays all mimetypes. + * + * (This class depends on STALService and therefore is not part of BKUCommonGUI.) + * + * @author Clemens Orthacker + */ +public class AppletSecureViewer extends SignRequestHandler { + + private static final Log log = LogFactory.getLog(AppletSecureViewer.class); + protected STALPortType stalPort; + protected String sessId; + + public AppletSecureViewer(STALPortType stalPort, String sessId) { + if (stalPort == null || sessId == null) { + throw new NullPointerException("STAL port must not be null"); + } + this.sessId = sessId; + this.stalPort = stalPort; + } + + /** + * TODO don't throw exceptions + * @param signedReferences + * @throws java.security.DigestException + * @throws java.lang.Exception + */ + @Override + public void displayDataToBeSigned(List signedReferences) + throws DigestException, Exception { + + List hdi = getHashDataInput(signedReferences); + List verifiedHashDataInputs = verifyHashDataInput(signedReferences, hdi); + + if (verifiedHashDataInputs.size() > 0) { + gui.showSecureViewer(verifiedHashDataInputs, this, "hashDataDone"); + } else { + throw new Exception("No signature data (apart from any QualifyingProperties or a Manifest)"); + } + } + + /** + * Get all hashdata inputs that contain an ID attribute but no Type attribute. + * @param signedReferences + * @return + * @throws at.gv.egiz.stal.service.GetHashDataInputFault + */ + private List getHashDataInput(List signedReferences) + throws GetHashDataInputFault, Exception { + GetHashDataInputType request = new GetHashDataInputType(); + request.setSessionId(sessId); + +// HashMap idSignedRefMap = new HashMap(); + for (ReferenceType signedRef : signedReferences) { + //don't get Manifest, QualifyingProperties, ... + if (signedRef.getType() == null) { + String signedRefId = signedRef.getId(); + if (signedRefId != null) { + if (log.isTraceEnabled()) { + log.trace("requesting hashdata input for reference " + signedRefId); + } +// idSignedRefMap.put(signedRefId, signedRef); + GetHashDataInputType.Reference ref = new GetHashDataInputType.Reference(); + ref.setID(signedRefId); + request.getReference().add(ref); + + } else { + throw new Exception("Cannot resolve signature data for dsig:Reference without Id attribute"); + } + } + } + + if (request.getReference().size() < 1) { + log.error("No signature data (apart from any QualifyingProperties or a Manifest) for session " + sessId); + throw new Exception("No signature data (apart from any QualifyingProperties or a Manifest)"); + } + + if (log.isDebugEnabled()) { + log.debug("WebService call GetHashDataInput for " + request.getReference().size() + " references in session " + sessId); + } + GetHashDataInputResponseType response = stalPort.getHashDataInput(request); + return response.getReference(); + } + + /** + * Verifies all signed references and returns STAL HashDataInputs + * @param signedReferences + * @param hashDataInputs + * @return + * @throws java.security.DigestException + * @throws java.security.NoSuchAlgorithmException + * @throws Exception if no hashdata input is provided for a signed reference + */ + private List verifyHashDataInput(List signedReferences, List hashDataInputs) + throws DigestException, NoSuchAlgorithmException, Exception { + + ArrayList verifiedHashDataInputs = new ArrayList(); + + for (ReferenceType signedRef : signedReferences) { + if (signedRef.getType() == null) { + log.info("Verifying digest for signed reference " + signedRef.getId()); + + String signedRefId = signedRef.getId(); + byte[] signedDigest = signedRef.getDigestValue(); + String signedDigestAlg = null; + if (signedRef.getDigestMethod() != null) { + signedDigestAlg = signedRef.getDigestMethod().getAlgorithm(); + } else { + throw new NoSuchAlgorithmException("Failed to verify digest value for reference " + signedRefId + ": no digest algorithm"); + } + + // usually, there is just one item here + GetHashDataInputResponseType.Reference hashDataInput = null; + for (GetHashDataInputResponseType.Reference hdi : hashDataInputs) { + if (signedRefId.equals(hdi.getID())) { + hashDataInput = hdi; + break; + } + } + if (hashDataInput == null) { + throw new Exception("No hashdata input for reference " + signedRefId + " returned by service"); + } + + byte[] hdi = hashDataInput.getValue(); + String mimeType = hashDataInput.getMimeType(); + String encoding = hashDataInput.getEncoding(); + + if (hdi == null) { + throw new Exception("No hashdata input for reference " + signedRefId + " provided by service"); + } + if (log.isDebugEnabled()) { + log.debug("Got HashDataInput " + signedRefId + " (" + mimeType + ";" + encoding + ")"); + } + + byte[] hashDataInputDigest = digest(hdi, signedDigestAlg); + + if (log.isDebugEnabled()) { + log.debug("Comparing digest values... "); + } +// log.warn("***************** DISABLED HASHDATA VERIFICATION"); + if (!Arrays.equals(hashDataInputDigest, signedDigest)) { + log.error("Bad digest value for reference " + signedRefId); + throw new DigestException("Bad digest value for reference " + signedRefId); + } + + verifiedHashDataInputs.add(new ByteArrayHashDataInput(hdi, signedRefId, mimeType, encoding)); + } + } + + return verifiedHashDataInputs; + } + + //TODO + private byte[] digest(byte[] hashDataInput, String mdAlg) throws NoSuchAlgorithmException { + if ("http://www.w3.org/2000/09/xmldsig#sha1".equals(mdAlg)) { + mdAlg = "SHA-1"; + } else if ("http://www.w3.org/2001/04/xmlenc#sha256".equals(mdAlg)) { + mdAlg = "SHA-256"; + } else if ("http://www.w3.org/2001/04/xmlenc#sha224".equals(mdAlg)) { + mdAlg = "SHA-224"; + } else if ("http://www.w3.org/2001/04/xmldsig-more#sha224".equals(mdAlg)) { + mdAlg = "SHA-224"; + } else if ("http://www.w3.org/2001/04/xmldsig-more#sha384".equals(mdAlg)) { + mdAlg = "SHA-384"; + } else if ("http://www.w3.org/2001/04/xmlenc#sha512".equals(mdAlg)) { + mdAlg = "SHA-512"; + } else if ("http://www.w3.org/2001/04/xmldsig-more#md2".equals(mdAlg)) { + mdAlg = "MD2"; + } else if ("http://www.w3.org/2001/04/xmldsig-more#md5".equals(mdAlg)) { + mdAlg = "MD5"; + } else if ("http://www.w3.org/2001/04/xmlenc#ripemd160".equals(mdAlg)) { + mdAlg = "RipeMD-160"; + } else { + throw new NoSuchAlgorithmException("Failed to verify digest value: unsupported digest algorithm " + mdAlg); + } + + MessageDigest md = MessageDigest.getInstance(mdAlg); + return md.digest(hashDataInput); + } +} diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUI.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUI.java index c904be0c..159dd29d 100644 --- a/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUI.java +++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUI.java @@ -56,8 +56,6 @@ public class PINManagementGUI extends CardMgmtGUI implements PINManagementGUIFac /** remember the pinSpec to return to worker */ protected PINSpec pinSpec; - protected enum DIALOG { VERIFY, ACTIVATE, CHANGE, UNBLOCK }; - public PINManagementGUI(Container contentPane, Locale locale, Style guiStyle, @@ -235,43 +233,110 @@ public class PINManagementGUI extends CardMgmtGUI implements PINManagementGUIFac } @Override - public void showActivatePINDialog(final PINSpec pin, - final ActionListener okListener, final String okCommand, - final ActionListener cancelListener, final String cancelCommand) { - log.debug("scheduling activate pin dialog"); - showPINDialog(DIALOG.ACTIVATE, pin, okListener, okCommand, cancelListener, cancelCommand); + public void showPINDialog(DIALOG type, PINSpec pinSpec, + ActionListener okListener, String okCommand, + ActionListener cancelListener, String cancelCommand) { + showPINDialog(type, pinSpec, -1, false, + okListener, okCommand, cancelListener, cancelCommand); + } + + @Override + public void showPINDialog(DIALOG type, PINSpec pinSpec, int retries, + ActionListener okListener, String okCommand, + ActionListener cancelListener, String cancelCommand) { + showPINDialog(type, pinSpec, retries, false, + okListener, okCommand, cancelListener, cancelCommand); } + @Override + public void showPinpadPINDialog(DIALOG type, PINSpec pinSpec, int retries) { + String title, msg; + Object[] params; + if (retries < 0) { + params = new Object[2]; + if (shortText) { + params[0] = "PIN"; + } else { + params[0] = pinSpec.getLocalizedName(); + } + String pinSize = String.valueOf(pinSpec.getMinLength()); + if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { + pinSize += "-" + pinSpec.getMaxLength(); + } + params[1] = pinSize; + if (type == DIALOG.CHANGE) { + log.debug("show change pin dialog"); + title = TITLE_CHANGE_PIN; + msg = MESSAGE_CHANGEPIN_PINPAD; + } else if (type == DIALOG.ACTIVATE) { + log.debug("show activate pin dialog"); + title = TITLE_ACTIVATE_PIN; + msg = MESSAGE_ENTERPIN_PINPAD; + } else if (type == DIALOG.VERIFY) { + log.debug("show verify pin dialog"); + title = TITLE_VERIFY_PIN; + msg = MESSAGE_ENTERPIN_PINPAD; + } else { + log.debug("show unblock pin dialog"); + title = TITLE_UNBLOCK_PIN; + msg = MESSAGE_ENTERPIN_PINPAD; + } + + } else { + log.debug("show retry pin dialog"); + title = TITLE_RETRY; + msg = (retries < 2) ? + MESSAGE_LAST_RETRY : MESSAGE_RETRIES; + params = new Object[] {String.valueOf(retries)}; + } + showMessageDialog(title, msg, params); + } private void showPINDialog(final DIALOG type, final PINSpec pinSpec, + final int retries, final boolean pinpad, final ActionListener okListener, final String okCommand, final ActionListener cancelListener, final String cancelCommand) { + log.debug("scheduling pin dialog"); + SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - String HELP_TOPIC, TITLE, MESSAGE_MGMT; + String HELP_TOPIC, TITLE, MESSAGE_MGMT, MESSAGE_MGMT_PARAM; HELP_TOPIC = HELP_PINMGMT; - if (type == DIALOG.CHANGE) { - log.debug("show change pin dialog"); - TITLE = TITLE_CHANGE_PIN; - MESSAGE_MGMT = MESSAGE_CHANGE_PIN; - } else if (type == DIALOG.ACTIVATE) { - log.debug("show activate pin dialog"); - TITLE = TITLE_ACTIVATE_PIN; - MESSAGE_MGMT = MESSAGE_ACTIVATE_PIN; - oldPinField = null; - } else if (type == DIALOG.VERIFY) { - log.debug("show verify pin dialog"); - TITLE = TITLE_VERIFY_PIN; - MESSAGE_MGMT = MESSAGE_VERIFY_PIN; + if (retries < 0) { + if (type == DIALOG.CHANGE) { + log.debug("show change pin dialog"); + TITLE = TITLE_CHANGE_PIN; + MESSAGE_MGMT = MESSAGE_CHANGE_PIN; + } else if (type == DIALOG.ACTIVATE) { + log.debug("show activate pin dialog"); + TITLE = TITLE_ACTIVATE_PIN; + MESSAGE_MGMT = MESSAGE_ACTIVATE_PIN; + oldPinField = null; + } else if (type == DIALOG.VERIFY) { + log.debug("show verify pin dialog"); + TITLE = TITLE_VERIFY_PIN; + MESSAGE_MGMT = MESSAGE_VERIFY_PIN; + } else { + log.debug("show unblock pin dialog"); + TITLE = TITLE_UNBLOCK_PIN; + MESSAGE_MGMT = MESSAGE_UNBLOCK_PIN; + } + if (shortText) { + MESSAGE_MGMT_PARAM = "PIN"; + } else { + MESSAGE_MGMT_PARAM = pinSpec.getLocalizedName(); + } } else { - log.debug("show unblock pin dialog"); - TITLE = TITLE_UNBLOCK_PIN; - MESSAGE_MGMT = MESSAGE_UNBLOCK_PIN; + log.debug("show retry pin dialog"); + TITLE = TITLE_RETRY; + MESSAGE_MGMT = (retries < 2) ? + MESSAGE_LAST_RETRY : MESSAGE_RETRIES; + MESSAGE_MGMT_PARAM = String.valueOf(retries); } mainPanel.removeAll(); @@ -280,24 +345,67 @@ public class PINManagementGUI extends CardMgmtGUI implements PINManagementGUIFac helpListener.setHelpTopic(HELP_TOPIC); JLabel mgmtLabel = new JLabel(); - mgmtLabel.setFont(mgmtLabel.getFont().deriveFont(mgmtLabel.getFont().getStyle() & ~Font.BOLD)); + if (retries < 0) { + mgmtLabel.setFont(mgmtLabel.getFont().deriveFont(mgmtLabel.getFont().getStyle() & ~Font.BOLD)); + } else { + mgmtLabel.setFont(mgmtLabel.getFont().deriveFont(mgmtLabel.getFont().getStyle() | Font.BOLD)); + mgmtLabel.setForeground(ERROR_COLOR); + helpListener.setHelpTopic(HELP_RETRY); + } if (renderHeaderPanel) { titleLabel.setText(getMessage(TITLE)); String mgmtPattern = getMessage(MESSAGE_MGMT); - if (shortText) { - mgmtLabel.setText(MessageFormat.format(mgmtPattern, "PIN")); - } else { - mgmtLabel.setText(MessageFormat.format(mgmtPattern, pinSpec.getLocalizedName())); - } + mgmtLabel.setText(MessageFormat.format(mgmtPattern, MESSAGE_MGMT_PARAM)); } else { mgmtLabel.setText(getMessage(TITLE)); } + String pinSize = String.valueOf(pinSpec.getMinLength()); + if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { + pinSize += "-" + pinSpec.getMaxLength(); + } + + //////////////////////////////////////////////////////////////// + // COMMON LAYOUT SECTION + //////////////////////////////////////////////////////////////// + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + GroupLayout.SequentialGroup infoHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(mgmtLabel); + GroupLayout.ParallelGroup infoVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(mgmtLabel); + + if (!renderHeaderPanel) { + infoHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel); + infoVertical + .addComponent(helpLabel); + } + + GroupLayout.ParallelGroup pinHorizontal; + GroupLayout.SequentialGroup pinVertical; + + if (pinpad) { + JLabel pinpadLabel = new JLabel(); + pinpadLabel.setFont(mgmtLabel.getFont().deriveFont(mgmtLabel.getFont().getStyle() & ~Font.BOLD)); + String pinpadPattern = getMessage(MESSAGE_PINPAD); + pinpadLabel.setText(MessageFormat.format(pinpadPattern, + new Object[] { pinSpec.getLocalizedName(), pinSize })); + + pinHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(pinpadLabel); + pinVertical = mainPanelLayout.createSequentialGroup() + .addComponent(pinpadLabel); + } else { + JButton okButton = new JButton(); okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~Font.BOLD)); okButton.setText(getMessage(BUTTON_OK)); - okButton.setEnabled(type == DIALOG.VERIFY && pinSpec.getMinLength() == 0); + okButton.setEnabled(pinSpec.getMinLength() <= 0); okButton.setActionCommand(okCommand); okButton.addActionListener(okListener); @@ -334,7 +442,7 @@ public class PINManagementGUI extends CardMgmtGUI implements PINManagementGUIFac repeatPinLabel.setText(MessageFormat.format(repeatPinLabelPattern, new Object[]{pinSpec.getLocalizedName()})); repeatPinField.setText(""); - repeatPinField.setDocument(new PINDocument(pinSpec, okButton, pinField.getDocument())); +// repeatPinField.setDocument(new PINDocument(pinSpec, okButton, pinField.getDocument())); repeatPinField.setActionCommand(okCommand); repeatPinField.addActionListener(new ActionListener() { @@ -365,7 +473,15 @@ public class PINManagementGUI extends CardMgmtGUI implements PINManagementGUIFac } } }); - } // else -> ACTIVATE (not verify, not change) + + repeatPinField.setDocument(new PINDocument( + pinSpec, okButton, + pinField.getDocument(), oldPinField.getDocument())); + } else { + // else -> ACTIVATE (not verify, not change) + repeatPinField.setDocument(new PINDocument( + pinSpec, okButton, pinField.getDocument())); + } } else { pinField.setDocument(new PINDocument(pinSpec, okButton)); } @@ -373,30 +489,14 @@ public class PINManagementGUI extends CardMgmtGUI implements PINManagementGUIFac JLabel pinsizeLabel = new JLabel(); pinsizeLabel.setFont(pinsizeLabel.getFont().deriveFont(pinsizeLabel.getFont().getStyle() & ~Font.BOLD, pinsizeLabel.getFont().getSize()-2)); String pinsizePattern = getMessage(LABEL_PINSIZE); - String pinSize = String.valueOf(pinSpec.getMinLength()); - if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { - pinSize += "-" + pinSpec.getMaxLength(); - } pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - GroupLayout.SequentialGroup infoHorizontal = mainPanelLayout.createSequentialGroup() - .addComponent(mgmtLabel); - GroupLayout.ParallelGroup infoVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(mgmtLabel); - - if (!renderHeaderPanel) { - infoHorizontal - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel); - infoVertical - .addComponent(helpLabel); - } + //////////////////////////////////////////////////////////////// + // NON-PINPAD SPECIFIC LAYOUT SECTION + //////////////////////////////////////////////////////////////// - GroupLayout.ParallelGroup pinHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); - GroupLayout.SequentialGroup pinVertical = mainPanelLayout.createSequentialGroup(); + pinHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); + pinVertical = mainPanelLayout.createSequentialGroup(); // if (pinLabelPos == PinLabelPosition.ABOVE) { // if (changePin) { @@ -495,7 +595,38 @@ public class PINManagementGUI extends CardMgmtGUI implements PINManagementGUIFac .addComponent(pinsizeLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)); pinVertical .addComponent(pinsizeLabel); -// } + + GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); + buttonPanel.setLayout(buttonPanelLayout); + + GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup() + .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); + GroupLayout.Group buttonVertical; + + JButton cancelButton = new JButton(); + cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); + cancelButton.setText(getMessage(BUTTON_CANCEL)); + cancelButton.setActionCommand(cancelCommand); + cancelButton.addActionListener(cancelListener); + + buttonHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); + buttonVertical = buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(okButton) + .addComponent(cancelButton); + + buttonPanelLayout.setHorizontalGroup(buttonHorizontal); + buttonPanelLayout.setVerticalGroup(buttonVertical); + + if (oldPinField != null) { + oldPinField.requestFocusInWindow(); + } else { + pinField.requestFocusInWindow(); + } + + } // END NON-PINPAD SECTION mainPanelLayout.setHorizontalGroup( mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) @@ -508,132 +639,12 @@ public class PINManagementGUI extends CardMgmtGUI implements PINManagementGUIFac .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(pinVertical)); - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - - GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); - GroupLayout.Group buttonVertical; - - JButton cancelButton = new JButton(); - cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - cancelButton.setText(getMessage(BUTTON_CANCEL)); - cancelButton.setActionCommand(cancelCommand); - cancelButton.addActionListener(cancelListener); - - buttonHorizontal - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); - buttonVertical = buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(okButton) - .addComponent(cancelButton); - - buttonPanelLayout.setHorizontalGroup(buttonHorizontal); - buttonPanelLayout.setVerticalGroup(buttonVertical); - - if (oldPinField != null) { - oldPinField.requestFocusInWindow(); - } else { - pinField.requestFocusInWindow(); - } contentPanel.validate(); } }); } - @Override - public void showChangePINDialog(final PINSpec pin, - final ActionListener okListener, final String okCommand, - final ActionListener cancelListener, final String cancelCommand) { - - log.debug("scheduling change pin dialog"); - showPINDialog(DIALOG.CHANGE, pin, okListener, okCommand, cancelListener, cancelCommand); - } - - @Override - public void showUnblockPINDialog(final PINSpec pin, - final ActionListener okListener, final String okCommand, - final ActionListener cancelListener, final String cancelCommand) { - - log.debug("scheduling unblock PIN dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show unblock PIN dialog"); - - log.error("unblock pin not supported"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - if (renderHeaderPanel) { - titleLabel.setText(getMessage(TITLE_ERROR)); - } - - helpListener.setHelpTopic(HELP_PINMGMT); - - String errorMsgPattern = getMessage(ERR_UNBLOCK); - String errorMsg = MessageFormat.format(errorMsgPattern, pin.getLocalizedName()); - - JLabel errorMsgLabel = new JLabel(); - errorMsgLabel.setFont(errorMsgLabel.getFont().deriveFont(errorMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - errorMsgLabel.setText(errorMsg); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - GroupLayout.ParallelGroup mainHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); - GroupLayout.SequentialGroup mainVertical = mainPanelLayout.createSequentialGroup(); - - if (!renderHeaderPanel) { - JLabel errorTitleLabel = new JLabel(); - errorTitleLabel.setFont(errorTitleLabel.getFont().deriveFont(errorTitleLabel.getFont().getStyle() | java.awt.Font.BOLD)); - errorTitleLabel.setText(getMessage(TITLE_ERROR)); - errorTitleLabel.setForeground(ERROR_COLOR); - - mainHorizontal - .addGroup(mainPanelLayout.createSequentialGroup() - .addComponent(errorTitleLabel) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel)); - mainVertical - .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(errorTitleLabel) - .addComponent(helpLabel)); - } - - mainPanelLayout.setHorizontalGroup(mainHorizontal - .addComponent(errorMsgLabel)); - mainPanelLayout.setVerticalGroup(mainVertical - .addComponent(errorMsgLabel)); - - JButton okButton = new JButton(); - okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - okButton.setText(getMessage(BUTTON_OK)); - okButton.setActionCommand(cancelCommand); - okButton.addActionListener(cancelListener); - - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createSequentialGroup() - .addComponent(okButton)); - - contentPanel.validate(); - } - }); - } - @Override protected int initButtonSize() { int bs = super.initButtonSize(); @@ -659,8 +670,4 @@ public class PINManagementGUI extends CardMgmtGUI implements PINManagementGUIFac return bs; } - @Override - public void showVerifyPINDialog(PINSpec pin, ActionListener okListener, String okCmd, ActionListener cancelListener, String cancelCmd) { - showPINDialog(DIALOG.VERIFY, pin, okListener, okCmd, cancelListener, cancelCmd); - } } diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUIFacade.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUIFacade.java index 9c630431..45313f42 100644 --- a/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUIFacade.java +++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUIFacade.java @@ -35,13 +35,18 @@ public interface PINManagementGUIFacade extends BKUGUIFacade { public static final String TITLE_UNBLOCK_PIN = "title.unblock.pin"; public static final String TITLE_ACTIVATE_SUCCESS = "title.activate.success"; public static final String TITLE_CHANGE_SUCCESS = "title.change.success"; - public static final String MESSAGE_ACTIVATE_SUCCESS = "message.activate.success"; - public static final String MESSAGE_CHANGE_SUCCESS = "message.change.success"; - public static final String MESSAGE_PINMGMT = "message.pin.mgmt"; - public static final String MESSAGE_ACTIVATE_PIN = "message.activate.pin"; - public static final String MESSAGE_CHANGE_PIN = "message.change.pin"; - public static final String MESSAGE_VERIFY_PIN = "message.verify.pin"; - public static final String MESSAGE_UNBLOCK_PIN = "message.unblock.pin"; + + // removed message.* prefix to reuse keys as help keys + public static final String MESSAGE_ACTIVATE_SUCCESS = "activate.success"; + public static final String MESSAGE_CHANGE_SUCCESS = "change.success"; + public static final String MESSAGE_PINMGMT = "pin.mgmt"; + public static final String MESSAGE_PINPAD = "pinpad"; + public static final String MESSAGE_CHANGEPIN_PINPAD = "pinpad.change"; + public static final String MESSAGE_ACTIVATE_PIN = "activate.pin"; + public static final String MESSAGE_CHANGE_PIN = "change.pin"; + public static final String MESSAGE_VERIFY_PIN = "verify.pin"; + public static final String MESSAGE_UNBLOCK_PIN = "unblock.pin"; + public static final String LABEL_OLD_PIN = "label.old.pin"; public static final String LABEL_NEW_PIN = "label.new.pin"; public static final String LABEL_REPEAT_PIN = "label.repeat.pin"; @@ -66,26 +71,37 @@ public interface PINManagementGUIFacade extends BKUGUIFacade { public static final String STATUS_UNKNOWN = "status.unknown"; public enum STATUS { ACTIV, NOT_ACTIV, BLOCKED, UNKNOWN }; + public enum DIALOG { VERIFY, ACTIVATE, CHANGE, UNBLOCK }; public void showPINManagementDialog(Map pins, ActionListener activateListener, String activateCmd, String changeCmd, String unblockCmd, String verifyCmd, ActionListener cancelListener, String cancelCmd); - public void showActivatePINDialog(PINSpec pin, + public void showPINDialog(DIALOG type, PINSpec pin, ActionListener okListener, String okCmd, ActionListener cancelListener, String cancelCmd); - public void showChangePINDialog(PINSpec pin, + public void showPINDialog(DIALOG type, PINSpec pin, int retries, ActionListener okListener, String okCmd, ActionListener cancelListener, String cancelCmd); - public void showUnblockPINDialog(PINSpec pin, - ActionListener okListener, String okCmd, - ActionListener cancelListener, String cancelCmd); + public void showPinpadPINDialog(DIALOG type, PINSpec pin, int retries); - public void showVerifyPINDialog(PINSpec pin, - ActionListener okListener, String okCmd, - ActionListener cancelListener, String cancelCmd); +// public void showActivatePINDialog(PINSpec pin, +// ActionListener okListener, String okCmd, +// ActionListener cancelListener, String cancelCmd); +// +// public void showChangePINDialog(PINSpec pin, +// ActionListener okListener, String okCmd, +// ActionListener cancelListener, String cancelCmd); +// +// public void showUnblockPINDialog(PINSpec pin, +// ActionListener okListener, String okCmd, +// ActionListener cancelListener, String cancelCmd); +// +// public void showVerifyPINDialog(PINSpec pin, +// ActionListener okListener, String okCmd, +// ActionListener cancelListener, String cancelCmd); public char[] getOldPin(); diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/PINManagementBKUWorker.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/PINManagementBKUWorker.java index 85892026..81b635f8 100644 --- a/BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/PINManagementBKUWorker.java +++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/PINManagementBKUWorker.java @@ -42,7 +42,8 @@ public class PINManagementBKUWorker extends AppletBKUWorker { @Override public void run() { - gui.showWelcomeDialog(); + gui.showMessageDialog(BKUGUIFacade.TITLE_WELCOME, + BKUGUIFacade.MESSAGE_WELCOME); try { List responses = handleRequest(Collections.singletonList(new PINManagementRequest())); @@ -53,7 +54,6 @@ public class PINManagementBKUWorker extends AppletBKUWorker { log.debug("PIN management dialog terminated"); } else if (response instanceof ErrorResponse) { log.debug("PIN management dialog terminated with error"); - showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, null); } else { throw new RuntimeException("Invalid STAL response: " + response.getClass().getName()); } @@ -62,7 +62,11 @@ public class PINManagementBKUWorker extends AppletBKUWorker { } } catch (RuntimeException ex) { - log.error("unexpected error: " + ex.getMessage(), ex); + log.error(ex.getMessage()); + Throwable cause = ex.getCause(); + if (cause != null) { // && cause instanceof InterruptedException) { + log.info(cause.getMessage()); + } showErrorDialog(BKUGUIFacade.ERR_UNKNOWN, null); } catch (Exception ex) { log.error(ex.getMessage(), ex); diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/ManagementPINProviderFactory.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/ManagementPINProviderFactory.java new file mode 100644 index 00000000..b0dd8766 --- /dev/null +++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/ManagementPINProviderFactory.java @@ -0,0 +1,53 @@ +/* + * 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.ext; + +import at.gv.egiz.smcc.ChangePINProvider; +import at.gv.egiz.bku.gui.PINManagementGUIFacade; +import at.gv.egiz.smcc.PINProvider; +import at.gv.egiz.smcc.SignatureCard; + +/** + * + * @author Clemens Orthacker + */ +public abstract class ManagementPINProviderFactory { +// extends at.gv.egiz.bku.smccstal.PINProviderFactory { + + PINManagementGUIFacade gui; + + public static ManagementPINProviderFactory getInstance(SignatureCard forCard, + PINManagementGUIFacade gui) { +// if (forCard.ifdSupportsFeature(SignatureCard.FEATURE_VERIFY_PIN_DIRECT)) { +//// forCard.ifdSupportsFeature(SignatureCard.FEATURE_MODIFY_PIN_DIRECT) +// return new PinpadPINProviderFactory(gui); +// +// } else { + return new SoftwarePINProviderFactory(gui); +// } + } + + public abstract PINProvider getVerifyPINProvider(); + + public abstract PINProvider getActivatePINProvider(); + + public abstract ChangePINProvider getChangePINProvider(); + + public abstract PINProvider getUnblockPINProvider(); + +} diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PINManagementRequestHandler.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PINManagementRequestHandler.java index 66db0484..6b565b26 100644 --- a/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PINManagementRequestHandler.java +++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PINManagementRequestHandler.java @@ -18,13 +18,19 @@ package at.gv.egiz.bku.smccstal.ext; import at.gv.egiz.bku.gui.BKUGUIFacade; import at.gv.egiz.bku.gui.PINManagementGUIFacade; +import at.gv.egiz.bku.gui.PINManagementGUIFacade.DIALOG; import at.gv.egiz.bku.gui.PINManagementGUIFacade.STATUS; import at.gv.egiz.bku.smccstal.AbstractRequestHandler; +import at.gv.egiz.bku.smccstal.PINProviderFactory; +import at.gv.egiz.smcc.CancelledException; import at.gv.egiz.smcc.LockedException; import at.gv.egiz.smcc.NotActivatedException; +import at.gv.egiz.smcc.PINProvider; import at.gv.egiz.smcc.PINSpec; import at.gv.egiz.smcc.STARCOSCard; +import at.gv.egiz.smcc.SignatureCard; import at.gv.egiz.smcc.SignatureCardException; +import at.gv.egiz.smcc.TimeoutException; import at.gv.egiz.smcc.VerificationFailedException; import at.gv.egiz.smcc.util.SMCCHelper; import at.gv.egiz.stal.ErrorResponse; @@ -35,8 +41,6 @@ import at.gv.egiz.stal.ext.PINManagementResponse; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.smartcardio.Card; import javax.smartcardio.CardChannel; import javax.smartcardio.CardException; @@ -53,7 +57,8 @@ public class PINManagementRequestHandler extends AbstractRequestHandler { protected static final Log log = LogFactory.getLog(PINManagementRequestHandler.class); - Map pinStatuses; + protected Map pinStatuses; + private ManagementPINProviderFactory pinProviderFactory; @Override public STALResponse handleRequest(STALRequest request) throws InterruptedException { @@ -61,9 +66,12 @@ public class PINManagementRequestHandler extends AbstractRequestHandler { PINManagementGUIFacade gui = (PINManagementGUIFacade) this.gui; + PINSpec selectedPIN = null; + try { - pinStatuses = getPINStatuses(); + pinStatuses = getPINStatuses(); + gui.showPINManagementDialog(pinStatuses, this, "activate_enterpin", "change_enterpin", "unblock_enterpuk", "verify_enterpin", this, "cancel"); @@ -74,175 +82,100 @@ public class PINManagementRequestHandler extends AbstractRequestHandler { if ("cancel".equals(actionCommand)) { return new PINManagementResponse(); - } else if ("back".equals(actionCommand)) { - gui.showPINManagementDialog(pinStatuses, - this, "activate_enterpin", "change_enterpin", "unblock_enterpuk", "verify_enterpin", - this, "cancel"); } else { - PINSpec selectedPIN = gui.getSelectedPINSpec(); + selectedPIN = gui.getSelectedPINSpec(); if (selectedPIN == null) { - throw new RuntimeException("no PIN selected for activation/change"); + throw new NullPointerException("no PIN selected for activation/change"); } - if ("activate_enterpin".equals(actionCommand)) { - gui.showActivatePINDialog(selectedPIN, - this, "activate", this, "back"); - } else if ("change_enterpin".equals(actionCommand)) { - gui.showChangePINDialog(selectedPIN, - this, "change", this, "back"); - } else if ("unblock_enterpuk".equals(actionCommand)) { - gui.showUnblockPINDialog(selectedPIN, - this, "unblock", this, "back"); - } else if ("verify_enterpin".equals(actionCommand)) { - gui.showVerifyPINDialog(selectedPIN, - this, "verify", this, "back"); - } else if ("activate".equals(actionCommand)) { - try { - log.debug("activate " + selectedPIN.getLocalizedName()); - card.activatePIN(selectedPIN, - String.valueOf(gui.getPin())); + if (pinProviderFactory == null) { + pinProviderFactory = + ManagementPINProviderFactory.getInstance(card, gui); + } + + try { + if ("activate_enterpin".equals(actionCommand)) { + log.info("activate " + selectedPIN.getLocalizedName()); + card.activatePIN(selectedPIN, + pinProviderFactory.getActivatePINProvider()); updatePINStatus(selectedPIN, STATUS.ACTIV); gui.showMessageDialog(PINManagementGUIFacade.TITLE_ACTIVATE_SUCCESS, PINManagementGUIFacade.MESSAGE_ACTIVATE_SUCCESS, new Object[] {selectedPIN.getLocalizedName()}, - this, "ok"); + BKUGUIFacade.BUTTON_OK, this, "ok"); waitForAction(); - gui.showPINManagementDialog(pinStatuses, - this, "activate_enterpin", "change_enterpin", "unblock_enterpuk", "verify_enterpin", - this, "cancel"); - } catch (GetPINStatusException ex) { - log.error("failed to get " + selectedPIN.getLocalizedName() + - " status: " + ex.getMessage()); - gui.showErrorDialog(PINManagementGUIFacade.ERR_STATUS, null, - this, "cancel"); - } catch (SignatureCardException ex) { - log.error("failed to activate " + selectedPIN.getLocalizedName() + - ": " + ex.getMessage()); - gui.showErrorDialog(PINManagementGUIFacade.ERR_ACTIVATE, - new Object[] {selectedPIN.getLocalizedName()}, - this, "cancel"); - } - } else if ("change".equals(actionCommand)) { - log.info("change " + selectedPIN.getLocalizedName()); - try { - card.changePIN(selectedPIN, - String.valueOf(gui.getOldPin()), - String.valueOf(gui.getPin())); + } else if ("change_enterpin".equals(actionCommand)) { + log.info("change " + selectedPIN.getLocalizedName()); + card.changePIN(selectedPIN, + pinProviderFactory.getChangePINProvider()); updatePINStatus(selectedPIN, STATUS.ACTIV); gui.showMessageDialog(PINManagementGUIFacade.TITLE_CHANGE_SUCCESS, PINManagementGUIFacade.MESSAGE_CHANGE_SUCCESS, new Object[] {selectedPIN.getLocalizedName()}, - this, "ok"); - waitForAction(); - gui.showPINManagementDialog(pinStatuses, - this, "activate_enterpin", "change_enterpin", "unblock_enterpuk", "verify_enterpin", - this, "cancel"); - } catch (GetPINStatusException ex) { - log.error("failed to get " + selectedPIN.getLocalizedName() + - " status: " + ex.getMessage()); - gui.showErrorDialog(PINManagementGUIFacade.ERR_STATUS, null, - this, "cancel"); - } catch (LockedException ex) { - log.error("failed to change " + selectedPIN.getLocalizedName() + - ": PIN locked"); - updatePINStatus(selectedPIN, STATUS.BLOCKED); - gui.showErrorDialog(PINManagementGUIFacade.ERR_LOCKED, - new Object[] {selectedPIN.getLocalizedName()}, - this, "ok"); - waitForAction(); - gui.showPINManagementDialog(pinStatuses, - this, "activate_enterpin", "change_enterpin", "unblock_enterpuk", "verify_enterpin", - this, "cancel"); - } catch (VerificationFailedException ex) { - log.error("failed to change " + selectedPIN.getLocalizedName() + - ": " + ex.getMessage()); - gui.showErrorDialog(PINManagementGUIFacade.ERR_RETRIES, - new Object[] {selectedPIN.getLocalizedName(), ex.getRetries()}, - this, "change_enterpin"); - } catch (NotActivatedException ex) { - log.error("failed to change " + selectedPIN.getLocalizedName() + - ": PIN not active"); - updatePINStatus(selectedPIN, STATUS.NOT_ACTIV); - gui.showErrorDialog(PINManagementGUIFacade.ERR_NOT_ACTIVE, - new Object[] {selectedPIN.getLocalizedName()}, - this, "ok"); + BKUGUIFacade.BUTTON_OK, this, "ok"); waitForAction(); - gui.showPINManagementDialog(pinStatuses, - this, "activate_enterpin", "change_enterpin", "unblock_enterpuk", "verify_enterpin", - this, "cancel"); - } catch (SignatureCardException ex) { - log.error("failed to change " + selectedPIN.getLocalizedName() + - ": " + ex.getMessage()); - gui.showErrorDialog(PINManagementGUIFacade.ERR_CHANGE, - new Object[] {selectedPIN.getLocalizedName()}, - this, "cancel"); - } - } else if ("unblock".equals(actionCommand)) { - log.info("unblock " + selectedPIN.getLocalizedName()); - log.error("unblock PIN not implemented"); - gui.showErrorDialog(PINManagementGUIFacade.ERR_UNBLOCK, null, this, "cancel"); - } else if ("verify".equals(actionCommand)) { - try { + + } else if ("unblock_enterpuk".equals(actionCommand)) { + log.info("unblock " + selectedPIN.getLocalizedName()); + card.unblockPIN(selectedPIN, + pinProviderFactory.getUnblockPINProvider()); + } else if ("verify_enterpin".equals(actionCommand)) { log.info("verify " + selectedPIN.getLocalizedName()); - int retries = card.verifyPIN(selectedPIN, String.valueOf(gui.getPin())); - log.trace(retries + " retries"); - if (retries < 0) { - updatePINStatus(selectedPIN, STATUS.ACTIV); - gui.showPINManagementDialog(pinStatuses, - this, "activate_enterpin", "change_enterpin", "unblock_enterpuk", "verify_enterpin", - this, "cancel"); - } else { - log.error("failed to verify " + selectedPIN.getLocalizedName() + - ": " + retries + " retries left"); - gui.showErrorDialog(PINManagementGUIFacade.ERR_RETRIES, - new Object[] {selectedPIN.getLocalizedName(), retries}, - this, "verify_enterpin"); - } - } catch (GetPINStatusException ex) { - log.error("failed to get " + selectedPIN.getLocalizedName() + - " status: " + ex.getMessage()); - gui.showErrorDialog(PINManagementGUIFacade.ERR_STATUS, null, - this, "cancel"); - } catch (LockedException ex) { - log.error("failed to verify " + selectedPIN.getLocalizedName() + - ": PIN locked"); - updatePINStatus(selectedPIN, STATUS.BLOCKED); - gui.showPINManagementDialog(pinStatuses, - this, "activate_enterpin", "change_enterpin", "unblock_enterpuk", "verify_enterpin", - this, "cancel"); - } catch (NotActivatedException ex) { - log.error("failed to verify " + selectedPIN.getLocalizedName() + - ": PIN not active"); - updatePINStatus(selectedPIN, STATUS.NOT_ACTIV); - gui.showPINManagementDialog(pinStatuses, - this, "activate_enterpin", "change_enterpin", "unblock_enterpuk", "verify_enterpin", - this, "cancel"); - } catch (SignatureCardException ex) { - log.error("failed to verify " + selectedPIN.getLocalizedName() + - ": " + ex.getMessage()); - gui.showErrorDialog(PINManagementGUIFacade.ERR_STATUS, - new Object[] {selectedPIN.getLocalizedName()}, - this, "cancel"); + card.verifyPIN(selectedPIN, + pinProviderFactory.getVerifyPINProvider()); + updatePINStatus(selectedPIN, STATUS.ACTIV); } - - } else { - throw new RuntimeException("unsupported action " + actionCommand); + } catch (CancelledException ex) { + log.trace("cancelled"); + } catch (TimeoutException ex) { + log.error("Timeout during pin entry"); + gui.showMessageDialog(BKUGUIFacade.TITLE_ENTRY_TIMEOUT, + BKUGUIFacade.ERR_PIN_TIMEOUT, + new Object[] {selectedPIN.getLocalizedName()}, + BKUGUIFacade.BUTTON_OK, this, null); + waitForAction(); + } catch (LockedException ex) { + log.error(selectedPIN.getLocalizedName() + " locked"); + updatePINStatus(selectedPIN, STATUS.BLOCKED); + gui.showErrorDialog(PINManagementGUIFacade.ERR_LOCKED, + new Object[] {selectedPIN.getLocalizedName()}, + this, null); + waitForAction(); + } catch (NotActivatedException ex) { + log.error(selectedPIN.getLocalizedName() + " not active"); + updatePINStatus(selectedPIN, STATUS.NOT_ACTIV); + gui.showErrorDialog(PINManagementGUIFacade.ERR_NOT_ACTIVE, + new Object[] {selectedPIN.getLocalizedName()}, + this, null); + waitForAction(); } - } - } + } // end if + + selectedPIN = null; + gui.showPINManagementDialog(pinStatuses, + this, "activate_enterpin", "change_enterpin", "unblock_enterpuk", "verify_enterpin", + this, "cancel"); + } // end while + } catch (GetPINStatusException ex) { - log.error("Failed to get PIN statuses: " + ex.getMessage()); + String pin = (selectedPIN != null) ? selectedPIN.getLocalizedName() : "pin"; + log.error("failed to get " + pin + " status: " + ex.getMessage()); gui.showErrorDialog(PINManagementGUIFacade.ERR_STATUS, null, this, "ok"); waitForAction(); return new ErrorResponse(1000); + } catch (SignatureCardException ex) { + log.error(ex.getMessage(), ex); + gui.showErrorDialog(PINManagementGUIFacade.ERR_UNKNOWN, null, + this, "ok"); + waitForAction(); + return new ErrorResponse(1000); } } else { log.error("Got unexpected STAL request: " + request); return new ErrorResponse(1000); } - } @Override @@ -375,4 +308,100 @@ public class PINManagementRequestHandler extends AbstractRequestHandler { pinStatuses.put(pinSpec, status); } } + +// /** +// * provides oldPin and newPin from one dialog, +// * and don't know whether providePIN() or provideOldPIN() is called first. +// */ +// class SoftwarePinProvider implements PINProvider { +// +// private PINManagementGUIFacade.DIALOG type; +// private boolean retry = false; +// +// private char[] newPin; +// private char[] oldPin; +// +// public SoftwarePinProvider(DIALOG type) { +// this.type = type; +// } +// +// @Override +// public char[] providePIN(PINSpec spec, int retries) +// throws CancelledException, InterruptedException { +// if (newPin == null) { +// getPINs(spec, retries); +// } +// char[] pin = newPin; +// newPin = null; +// return pin; +// } +// +// @Override +// public char[] provideOldPIN(PINSpec spec, int retries) +// throws CancelledException, InterruptedException { +// if (oldPin == null) { +// getPINs(spec, retries); +// } +// char[] pin = oldPin; +// oldPin = null; +// return pin; +// } +// +// private void getPINs(PINSpec spec, int retries) +// throws InterruptedException, CancelledException { +// PINManagementGUIFacade gui = +// (PINManagementGUIFacade) PINManagementRequestHandler.this.gui; +// +// if (retry) { +// gui.showPINDialog(type, spec, retries, +// PINManagementRequestHandler.this, "exec", +// PINManagementRequestHandler.this, "back"); +// } else { +// gui.showPINDialog(type, spec, +// PINManagementRequestHandler.this, "exec", +// PINManagementRequestHandler.this, "back"); +// } +// waitForAction(); +// +// if (actionCommand.equals("exec")) { +// gui.showWaitDialog(null); +// retry = true; +// oldPin = gui.getOldPin(); +// newPin = gui.getPin(); +// } else if (actionCommand.equals("back")) { +// throw new CancelledException(); +// } else { +// log.error("unsupported command " + actionCommand); +// throw new CancelledException(); +// } +// } +// } +// +// +// class PinpadPinProvider implements PINProvider { +// +// private PINManagementGUIFacade.DIALOG type; +// private boolean retry = false; +// +// public PinpadPinProvider(DIALOG type) { +// this.type = type; +// } +// +// @Override +// public char[] providePIN(PINSpec spec, int retries) { +// log.debug("provide pin for " + type); +// if (retry) { +// ((PINManagementGUIFacade) gui).showPinpadPINDialog(type, spec, retries); +// } else { +// ((PINManagementGUIFacade) gui).showPinpadPINDialog(type, spec, -1); +// retry = true; +// } +// return null; +// } +// +// @Override +// public char[] provideOldPIN(PINSpec spec, int retries) { +// return null; +// } +// } } diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PinpadPINProviderFactory.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PinpadPINProviderFactory.java new file mode 100644 index 00000000..4176e0a9 --- /dev/null +++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PinpadPINProviderFactory.java @@ -0,0 +1,126 @@ +/* + * 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.ext; + +import at.gv.egiz.smcc.ChangePINProvider; +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.bku.gui.PINManagementGUIFacade; +import at.gv.egiz.bku.gui.PINManagementGUIFacade.DIALOG; +import at.gv.egiz.bku.smccstal.AbstractPINProvider; +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.PINProvider; +import at.gv.egiz.smcc.PINSpec; + +/** + * + * @author Clemens Orthacker + */ +public class PinpadPINProviderFactory extends ManagementPINProviderFactory { + + protected PinpadPINProviderFactory(PINManagementGUIFacade gui) { + this.gui = gui; + } + + @Override + public PINProvider getVerifyPINProvider() { + return new SimplePinProvider(DIALOG.VERIFY); + } + + @Override + public PINProvider getActivatePINProvider() { + return new SimplePinProvider(DIALOG.ACTIVATE); + } + + @Override + public ChangePINProvider getChangePINProvider() { + return new SimplePinProvider(DIALOG.CHANGE); + } + + @Override + public PINProvider getUnblockPINProvider() { + return new SimplePinProvider(DIALOG.UNBLOCK); + } + + + class SimplePinProvider extends AbstractPINProvider + implements ChangePINProvider { + +// protected PINManagementGUIFacade gui; + protected PINManagementGUIFacade.DIALOG type; + + private SimplePinProvider(PINManagementGUIFacade.DIALOG type) { + this.type = type; + } + + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + + showPinpadPINDialog(retries, spec); + retry = true; + return null; + +// gui.showPINDialog(type, spec, (retry) ? retries : -1, +// this, "exec", +// this, "back"); +// +// waitForAction(); +// +// if ("exec".equals(action)) { +// gui.showWaitDialog(null); +// retry = true; +// return gui.getPin(); +// } else if ("back".equals(action)) { +// throw new CancelledException(); +// } else { +// log.error("unsupported command " + action); +// throw new CancelledException(); +// } + } + + /** + * do not call this method without calling providePIN() + * (no message is displayed) + * @param spec + * @param retries + * @return + */ + @Override + public char[] provideOldPIN(PINSpec spec, int retries) { + return null; + } + + private void showPinpadPINDialog(int retries, PINSpec pinSpec) { + String title, message; + Object[] params; + if (retry) { + title = BKUGUIFacade.TITLE_RETRY; + message = BKUGUIFacade.MESSAGE_RETRIES; + params = new Object[]{String.valueOf(retries)}; + } else { + title = BKUGUIFacade.TITLE_SIGN; + message = BKUGUIFacade.MESSAGE_ENTERPIN_PINPAD; + String pinSize = String.valueOf(pinSpec.getMinLength()); + if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { + pinSize += "-" + pinSpec.getMaxLength(); + } + params = new Object[]{pinSpec.getLocalizedName(), pinSize}; + } + gui.showMessageDialog(title, message, params); + } + } +} diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/SoftwarePINProviderFactory.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/SoftwarePINProviderFactory.java new file mode 100644 index 00000000..e87512d0 --- /dev/null +++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/SoftwarePINProviderFactory.java @@ -0,0 +1,148 @@ +/* + * 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.ext; + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.smcc.ChangePINProvider; +import at.gv.egiz.bku.gui.PINManagementGUIFacade; +import at.gv.egiz.bku.gui.PINManagementGUIFacade.DIALOG; +import at.gv.egiz.bku.smccstal.AbstractPINProvider; +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.PINProvider; +import at.gv.egiz.smcc.PINSpec; + +/** + * + * @author Clemens Orthacker + */ +public class SoftwarePINProviderFactory extends ManagementPINProviderFactory { + + protected SoftwarePINProviderFactory(PINManagementGUIFacade gui) { + this.gui = gui; + } + + @Override + public PINProvider getVerifyPINProvider() { + return new SimplePinProvider(DIALOG.VERIFY); + } + + @Override + public PINProvider getActivatePINProvider() { + return new SimplePinProvider(DIALOG.ACTIVATE); + } + + @Override + public ChangePINProvider getChangePINProvider() { + return new ChangePinProvider(); + } + + @Override + public PINProvider getUnblockPINProvider() { + return new SimplePinProvider(DIALOG.UNBLOCK); + } + + class SimplePinProvider extends AbstractPINProvider { + +// protected PINManagementGUIFacade gui; + protected PINManagementGUIFacade.DIALOG type; + + private SimplePinProvider(DIALOG type) { + this.type = type; + } + + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + + gui.showPINDialog(type, spec, (retry) ? retries : -1, + this, "exec", + this, "back"); + + waitForAction(); + + if ("exec".equals(action)) { + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); + retry = true; + return gui.getPin(); + } else if ("back".equals(action)) { + throw new CancelledException(); + } else { + log.error("unsupported command " + action); + throw new CancelledException(); + } + } + } + + class ChangePinProvider extends AbstractPINProvider + implements ChangePINProvider { + +// protected PINManagementGUIFacade gui; + + private char[] oldPin; + private char[] newPin; + + private ChangePinProvider() { + } + + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + if (newPin == null) { + getPINs(spec, retries); + } + char[] pin = newPin; + newPin = null; + return pin; + } + + @Override + public char[] provideOldPIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + if (oldPin == null) { + getPINs(spec, retries); + } + char[] pin = oldPin; + oldPin = null; + return pin; + } + + private void getPINs(PINSpec spec, int retries) + throws InterruptedException, CancelledException { + + gui.showPINDialog(PINManagementGUIFacade.DIALOG.CHANGE, spec, + (retry) ? retries : -1, + this, "exec", + this, "back"); + + waitForAction(); + + if ("exec".equals(action)) { + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); + retry = true; + oldPin = gui.getOldPin(); + newPin = gui.getPin(); + } else if ("back".equals(action)) { + throw new CancelledException(); + } else { + log.error("unsupported command " + action); + throw new CancelledException(); + } + } + } +} diff --git a/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages.properties b/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages.properties index 69d231f7..4ceacb21 100644 --- a/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages.properties +++ b/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages.properties @@ -22,13 +22,16 @@ title.verify.pin=PIN Eingeben title.activate.success=Erfolg title.change.success=Erfolg -message.pin.mgmt=Die Karte verf\u00FCgt \u00FCber {0} PINs -message.activate.pin={0} eingeben und best\u00E4tigen -message.change.pin={0} eingeben und best\u00E4tigen -message.unblock.pin=PUK zu {0} eingeben -message.verify.pin={0} eingeben (TODO: Warning not activated) -message.activate.success={0} wurde erfolgreich aktiviert. -message.change.success={0} wurde erfolgreich ge\u00E4ndert. +# removed message.* prefix to reuse keys as help keys +pin.mgmt=Die Karte verf\u00FCgt \u00FCber {0} PINs +pinpad={0} ({1} stellig) am Kartenleser eingeben und best\u00E4tigen. +pinpad.change={0} ({1} stellig) am Kartenleser eingeben und best\u00E4tigen. +activate.pin={0} eingeben und best\u00E4tigen +change.pin={0} eingeben und best\u00E4tigen +unblock.pin=PUK zu {0} eingeben +verify.pin={0} eingeben (TODO: Warning not activated) +activate.success={0} wurde erfolgreich aktiviert. +change.success={0} wurde erfolgreich ge\u00E4ndert. label.activation=e-card Aktivierungsprozess label.activation.step=Schritt {0} diff --git a/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages_en.properties b/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages_en.properties index 920f7d5b..9178d65c 100644 --- a/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages_en.properties +++ b/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages_en.properties @@ -21,12 +21,15 @@ title.unblock.pin=Unblock PIN title.activate.success=Success title.change.success=Success -message.pin.mgmt=The smartcard has {0} PINs -message.activate.pin=Enter and confirm {0} -message.change.pin=Enter and confirm {0} -message.unblock.pin=Enter PUK for {0} -message.activate.success={0} successfully activated -message.change.success={0} successfully changed +# removed message.* prefix to reuse keys as help keys +pin.mgmt=The smartcard has {0} PINs +pinpad=Enter {0} ({1} digits) on pinpad and confirm. +pinpad.change=Enter {0} ({1} digits) on pinpad and confirm. +activate.pin=Enter and confirm {0} +change.pin=Enter and confirm {0} +unblock.pin=Enter PUK for {0} +activate.success={0} successfully activated +change.success={0} successfully changed label.activation=e-card activation process label.activation.step=Step {0} diff --git a/BKUAppletExt/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java b/BKUAppletExt/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java index ef8c87e4..b01abe72 100644 --- a/BKUAppletExt/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java +++ b/BKUAppletExt/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java @@ -74,7 +74,7 @@ public class BKUGUIWorker implements Runnable { @Override public void actionPerformed(ActionEvent e) { - gui.showSignaturePINDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", null, "hashdata"); + gui.showSignaturePINDialog(signPinSpec, -1, signListener, "sign", cancelListener, "cancel", null, "hashdata"); } }; HashDataInput signedRef1 = new ByteArrayHashDataInput( @@ -112,7 +112,7 @@ public class BKUGUIWorker implements Runnable { // signedRefs.add(signedRef4); // signedRefs.add(signedRef4); // signedRefs = Collections.singletonList(signedRef1); - gui.showHashDataInputDialog(signedRefs, returnListener, "return"); + gui.showSecureViewer(signedRefs, returnListener, "return"); } }; diff --git a/BKUAppletExt/src/test/java/at/gv/egiz/bku/smccstal/ext/FileSystemTest.java b/BKUAppletExt/src/test/java/at/gv/egiz/bku/smccstal/ext/FileSystemTest.java deleted file mode 100644 index 5fa3cbd7..00000000 --- a/BKUAppletExt/src/test/java/at/gv/egiz/bku/smccstal/ext/FileSystemTest.java +++ /dev/null @@ -1,435 +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.smccstal.ext; - -import at.gv.egiz.smcc.FileNotFoundException; -import at.gv.egiz.smcc.LockedException; -import at.gv.egiz.smcc.NotActivatedException; -import at.gv.egiz.smcc.PINProvider; -import at.gv.egiz.smcc.PINSpec; -import at.gv.egiz.smcc.SignatureCard; -import at.gv.egiz.smcc.SignatureCardException; -import at.gv.egiz.smcc.util.SMCCHelper; -import at.gv.egiz.smcc.util.SmartCardIO; -import java.math.BigInteger; -import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.Locale; -import java.util.Map; -import javax.smartcardio.Card; -import javax.smartcardio.CardChannel; -import javax.smartcardio.CardException; -import javax.smartcardio.CardTerminal; -import javax.smartcardio.CommandAPDU; -import javax.smartcardio.ResponseAPDU; -import org.junit.Ignore; -import org.junit.Test; -import static org.junit.Assert.*; - -/** - * - * @author Clemens Orthacker - */ -@Ignore -public class FileSystemTest { - - /** asign premium */ - public static final byte[] AID_DEC = new byte[] { (byte) 0xA0, (byte) 0x00, - (byte) 0x00, (byte) 0x01, (byte) 0x18, (byte) 0x45, (byte) 0x4E }; - - @Test -// @Ignore - public void testCard() throws CardException, SignatureCardException, InterruptedException { - - SMCCHelper smccHelper = new SMCCHelper(); - switch (smccHelper.getResultCode()) { - case SMCCHelper.CARD_FOUND: - System.out.println("card found "); - } - SignatureCard signatureCard = smccHelper.getSignatureCard(new Locale("de")); - Card card = signatureCard.getCard(); - -// SmartCardIO scIO = new SmartCardIO(); -// Map terminalCardMap = scIO.getCards(); -// -// for (CardTerminal ct : terminalCardMap.keySet()) { -// Card card = terminalCardMap.get(ct); -// System.out.println("found card (" + ct.getName() + "): " + Formatter.byteArrayToHexString(card.getATR().getBytes())); - - System.out.println("found card " + Formatter.byteArrayToHexString(card.getATR().getBytes())); - - CardChannel cardchannel; - - //RESET - System.out.println("RESET"); - signatureCard.reset(); - card = signatureCard.getCard(); -// card.disconnect(true); -// card = ct.connect("*"); - - System.out.println("begin exclusive"); - card.beginExclusive(); - System.out.println("get cardchannel"); - cardchannel = card.getBasicChannel(); - - testECard(cardchannel, signatureCard, card); -// testASignPremium(cardchannel, signatureCard, card); - -// } - - } - - public static class TestCard { - - protected CardChannel channel; - protected int ifs_ = 254; - - public TestCard(CardChannel channel) { - this.channel = channel; - } - - protected byte[] readTLVFile(byte[] aid, byte[] ef, String pin, byte kid, int maxLength) - throws SignatureCardException, InterruptedException, CardException { - - - // SELECT FILE (AID) - selectFileAID(aid); - - // SELECT FILE (EF) - ResponseAPDU resp = selectFileFID(ef); - if (resp.getSW() == 0x6a82) { - // EF not found - throw new FileNotFoundException("EF " + toString(ef) + " not found."); - } else if (resp.getSW() != 0x9000) { - throw new SignatureCardException("SELECT FILE with " + "FID=" + toString(ef) + " failed (" + "SW=" + Integer.toHexString(resp.getSW()) + ")."); - } - - // VERIFY - if (pin != null) { - int retries = verifyPIN(pin, kid); - if (retries != -1) { - throw new at.gv.egiz.smcc.VerificationFailedException(retries); - } - } - - return readBinaryTLV(maxLength, (byte) 0x30); - } - - protected byte[] readBinary(CardChannel channel, int offset, int len) - throws CardException, SignatureCardException { - - //transmit(channel,apdu) - ResponseAPDU resp = channel.transmit(new CommandAPDU(0x00, 0xB0, - 0x7F & (offset >> 8), offset & 0xFF, len)); - if (resp.getSW() == 0x9000) { - return resp.getData(); - } else if (resp.getSW() == 0x6982) { - throw new at.gv.egiz.smcc.SecurityStatusNotSatisfiedException(); - } else { - throw new SignatureCardException("Failed to read bytes (" + offset + "+" + len + "): SW=" + Integer.toHexString(resp.getSW())); - } - - } - - protected byte[] readBinaryTLV(int maxSize, byte expectedType) throws CardException, - SignatureCardException { - -// CardChannel channel = getCardChannel(); - - // read first chunk - int len = Math.min(maxSize, ifs_); - byte[] chunk = readBinary(channel, 0, len); - if (chunk.length > 0 && chunk[0] != expectedType) { - return null; - } - int offset = chunk.length; - int actualSize = maxSize; - if (chunk.length > 3) { - if ((chunk[1] & 0x80) > 0) { - int octets = (0x0F & chunk[1]); - actualSize = 2 + octets; - for (int i = 1; i <= octets; i++) { - actualSize += (0xFF & chunk[i + 1]) << ((octets - i) * 8); - } - } else { - actualSize = 2 + chunk[1]; - } - } - ByteBuffer buffer = ByteBuffer.allocate(actualSize); - buffer.put(chunk, 0, Math.min(actualSize, chunk.length)); - while (offset < actualSize) { - len = Math.min(ifs_, actualSize - offset); - chunk = readBinary(channel, offset, len); - buffer.put(chunk); - offset += chunk.length; - } - return buffer.array(); - - } - - protected byte[] selectFileAID(byte[] dfName) throws CardException, SignatureCardException { -// CardChannel channel = getCardChannel(); - ResponseAPDU resp = channel.transmit(new CommandAPDU(0x00, 0xA4, 0x04, - 0x00, dfName, 256)); - if (resp.getSW() != 0x9000) { - throw new SignatureCardException("Failed to select application AID=" + toString(dfName) + ": SW=" + Integer.toHexString(resp.getSW()) + "."); - } else { - return resp.getBytes(); - } - } - - protected ResponseAPDU selectFileFID(byte[] fid) throws CardException, SignatureCardException { -// CardChannel channel = getCardChannel(); - return channel.transmit(new CommandAPDU(0x00, 0xA4, 0x02, - 0x04, fid, 256)); - } - - protected String toString(byte[] b) { - StringBuffer sb = new StringBuffer(); - if (b != null && b.length > 0) { - sb.append(Integer.toHexString((b[0] & 240) >> 4)); - sb.append(Integer.toHexString(b[0] & 15)); - } - for (int i = 1; i < b.length; i++) { - sb.append(':'); - sb.append(Integer.toHexString((b[i] & 240) >> 4)); - sb.append(Integer.toHexString(b[i] & 15)); - } - return sb.toString(); - } - - protected int verifyPIN(String pin, byte kid) throws CardException, SignatureCardException { - -// CardChannel channel = getCardChannel(); - - ResponseAPDU resp; - if (pin == null) { - // - resp = channel.transmit(new CommandAPDU(0x00, 0x20, 0x00, kid)); - } else { - // PIN length in bytes - int len = (int) Math.ceil(pin.length() / 2); - - // BCD encode PIN and marshal PIN block - byte[] pinBytes = new BigInteger(pin, 16).toByteArray(); - byte[] pinBlock = new byte[8]; - if (len < pinBytes.length) { - System.arraycopy(pinBytes, pinBytes.length - len, pinBlock, 1, len); - } else { - System.arraycopy(pinBytes, 0, pinBlock, len - pinBytes.length + 1, - pinBytes.length); - } - pinBlock[0] = (byte) (0x20 + len * 2); - Arrays.fill(pinBlock, len + 1, 8, (byte) 0xff); - - resp = channel.transmit(new CommandAPDU(0x00, 0x20, 0x00, kid, pinBlock));//, false); - - } - - if (resp.getSW() == 0x63c0) { - throw new LockedException("PIN locked."); - } else if (resp.getSW1() == 0x63 && resp.getSW2() >> 4 == 0xc) { - // return number of possible retries - return resp.getSW2() & 0x0f; - } else if (resp.getSW() == 0x6983) { - throw new LockedException(); - } else if (resp.getSW() == 0x6984) { - // PIN LCS = "Initialized" (-> not activated) - throw new NotActivatedException("PIN not set."); - } else if (resp.getSW() == 0x9000) { - return -1; // success - } else { - throw new SignatureCardException("Failed to verify pin: SW=" + Integer.toHexString(resp.getSW())); - } - } - } - - public static class Formatter { - - private static String[] alphabet = {"0", "1", "2", - "3", "4", "5", "6", "7", "8", - "9", "A", "B", "C", "D", "E", - "F"}; - - public static String byteArrayToHexString(byte[] bytes) { - - if (bytes == null || bytes.length <= 0) { - return null; - } - - StringBuffer buf = new StringBuffer(2 * bytes.length); - - byte c = 0x00; - - for (int i = 0; i < bytes.length; i++) { - - // high nibble - c = (byte) (bytes[i] & 0xf0); - - // shift down - c = (byte) (c >>> 4); - - // cut high order bits - c = (byte) (c & 0x0f); - - buf.append(alphabet[(int) c]); - - // low nibble - c = (byte) (bytes[i] & 0x0f); - - buf.append(alphabet[(int) c]); - if (i < bytes.length - 1) { - buf.append(':'); - } - } - - return buf.toString(); - - } - } - - protected void testASignPremium(CardChannel cardchannel, SignatureCard signatureCard, Card card) throws CardException { - byte[] selectMF = new byte[]{(byte) 0x00, (byte) 0xA4, (byte) 0x00, (byte) 0x0C, (byte) 0x02, (byte) 0x3F, (byte) 0x00}; - byte[] selectDF_DEC = new byte[] { (byte) 0x00, (byte) 0xA4, (byte) 0x00, (byte) 0x0C, (byte) 0x02, (byte) 0xdf, (byte) 0x71 }; - byte[] selectAID_DEC = new byte[] { (byte) 0x00, (byte) 0xA4, (byte) 0x04, (byte) 0x00, (byte) 0x07, (byte) 0xA0, (byte) 0x00, - (byte) 0x00, (byte) 0x01, (byte) 0x18, (byte) 0x45, (byte) 0x4E }; - - CommandAPDU cAPDU; - ResponseAPDU rAPDU; - byte[] sw; - - cAPDU = new CommandAPDU(selectMF); - rAPDU = cardchannel.transmit(cAPDU); - sw = new byte[]{(byte) (0xFF & rAPDU.getSW1()), (byte) (0xFF & rAPDU.getSW2())}; - System.out.println("cAPDU: " + Formatter.byteArrayToHexString(cAPDU.getBytes())); - System.out.println("rAPDU (sw=" + Formatter.byteArrayToHexString(sw) + "): " + Formatter.byteArrayToHexString(rAPDU.getData())); - - cAPDU = new CommandAPDU(selectAID_DEC); - rAPDU = cardchannel.transmit(cAPDU); - sw = new byte[]{(byte) (0xFF & rAPDU.getSW1()), (byte) (0xFF & rAPDU.getSW2())}; - System.out.println("cAPDU: " + Formatter.byteArrayToHexString(cAPDU.getBytes())); - System.out.println("rAPDU (sw=" + Formatter.byteArrayToHexString(sw) + "): " + Formatter.byteArrayToHexString(rAPDU.getData())); - - cAPDU = new CommandAPDU(selectDF_DEC); - rAPDU = cardchannel.transmit(cAPDU); - sw = new byte[]{(byte) (0xFF & rAPDU.getSW1()), (byte) (0xFF & rAPDU.getSW2())}; - System.out.println("cAPDU: " + Formatter.byteArrayToHexString(cAPDU.getBytes())); - System.out.println("rAPDU (sw=" + Formatter.byteArrayToHexString(sw) + "): " + Formatter.byteArrayToHexString(rAPDU.getData())); - - - } - - protected void testECard(CardChannel cardchannel, SignatureCard signatureCard, Card card) throws CardException, InterruptedException, SignatureCardException { -// if (cardTerminal != null) { -// card_ = cardTerminal.connect("*"); -// } - byte[] selectMF = new byte[]{(byte) 0x00, (byte) 0xA4, (byte) 0x00, (byte) 0x0C, (byte) 0x02, (byte) 0x3F, (byte) 0x00}; - byte[] readEF_GDO = new byte[]{(byte) 0x00, (byte) 0xB0, (byte) 0x82, (byte) 0x00, (byte) 0x00}; - CommandAPDU cAPDU; - ResponseAPDU rAPDU; - byte[] sw; - cAPDU = new CommandAPDU(selectMF); - rAPDU = cardchannel.transmit(cAPDU); - sw = new byte[]{(byte) (0xFF & rAPDU.getSW1()), (byte) (0xFF & rAPDU.getSW2())}; - System.out.println("cAPDU: " + Formatter.byteArrayToHexString(cAPDU.getBytes())); - System.out.println("rAPDU (sw=" + Formatter.byteArrayToHexString(sw) + "): " + Formatter.byteArrayToHexString(rAPDU.getData())); - cAPDU = new CommandAPDU(readEF_GDO); - rAPDU = cardchannel.transmit(cAPDU); - sw = new byte[]{(byte) (0xFF & rAPDU.getSW1()), (byte) (0xFF & rAPDU.getSW2())}; - System.out.println("cAPDU: " + Formatter.byteArrayToHexString(cAPDU.getBytes())); - System.out.println("rAPDU (sw=" + Formatter.byteArrayToHexString(sw) + "): " + Formatter.byteArrayToHexString(rAPDU.getData())); - byte[] EF_GDO = rAPDU.getData(); - //RESET - System.out.println("RESET"); - signatureCard.reset(); - card = signatureCard.getCard(); -// card.disconnect(true); -// card = ct.connect("*"); - System.out.println("begin exclusive"); - card.beginExclusive(); - System.out.println("get cardchannel"); - cardchannel = card.getBasicChannel(); - byte[] getCLC = new byte[]{(byte) 0x00, (byte) 0xCA, (byte) 0xDF, (byte) 0x20, (byte) 0x00}; - byte[] verifyKartenPIN = new byte[]{(byte) 0x00, (byte) 0x20, (byte) 0x00, (byte) 0x01}; - byte[] selectDF_SichereSignatur = new byte[]{(byte) 0x00, (byte) 0xA4, (byte) 0x04, (byte) 0x00, (byte) 0x08, (byte) 0xD0, (byte) 0x40, (byte) 0x00, (byte) 0x00, (byte) 0x17, (byte) 0x00, (byte) 0x12, (byte) 0x01, (byte) 0x00}; - byte[] verifySignaturPIN = new byte[]{(byte) 0x00, (byte) 0x20, (byte) 0x00, (byte) 0x81}; - cAPDU = new CommandAPDU(getCLC); - rAPDU = cardchannel.transmit(cAPDU); - sw = new byte[]{(byte) (0xFF & rAPDU.getSW1()), (byte) (0xFF & rAPDU.getSW2())}; - System.out.println("cAPDU: " + Formatter.byteArrayToHexString(cAPDU.getBytes())); - System.out.println("rAPDU (sw=" + Formatter.byteArrayToHexString(sw) + "): " + Formatter.byteArrayToHexString(rAPDU.getData())); - byte[] clc = rAPDU.getData(); - cAPDU = new CommandAPDU(verifyKartenPIN); - rAPDU = cardchannel.transmit(cAPDU); - sw = new byte[]{(byte) (0xFF & rAPDU.getSW1()), (byte) (0xFF & rAPDU.getSW2())}; - System.out.println("cAPDU: " + Formatter.byteArrayToHexString(cAPDU.getBytes())); - System.out.println("rAPDU (sw=" + Formatter.byteArrayToHexString(sw) + "): " + Formatter.byteArrayToHexString(rAPDU.getData())); - cAPDU = new CommandAPDU(selectDF_SichereSignatur); - rAPDU = cardchannel.transmit(cAPDU); - sw = new byte[]{(byte) (0xFF & rAPDU.getSW1()), (byte) (0xFF & rAPDU.getSW2())}; - System.out.println("cAPDU: " + Formatter.byteArrayToHexString(cAPDU.getBytes())); - System.out.println("rAPDU (sw=" + Formatter.byteArrayToHexString(sw) + "): " + Formatter.byteArrayToHexString(rAPDU.getData())); - cAPDU = new CommandAPDU(verifySignaturPIN); - rAPDU = cardchannel.transmit(cAPDU); - sw = new byte[]{(byte) (0xFF & rAPDU.getSW1()), (byte) (0xFF & rAPDU.getSW2())}; - System.out.println("cAPDU: " + Formatter.byteArrayToHexString(cAPDU.getBytes())); - System.out.println("rAPDU (sw=" + Formatter.byteArrayToHexString(sw) + "): " + Formatter.byteArrayToHexString(rAPDU.getData())); - //RESET - System.out.println("RESET"); - signatureCard.reset(); - card = signatureCard.getCard(); - System.out.println("InfoboxReadRequests..."); - PINProvider pinProvider = new PINProvider() { - - @Override - public String providePIN(PINSpec spec, int retries) throws InterruptedException { - if (retries >= 3) { - return "2540"; - } else { - throw new InterruptedException("TOO FEW PIN RETRIES LEFT, ABORTING"); - } - } - }; - byte[] ehic = signatureCard.getInfobox("EHIC", pinProvider, null); - System.out.println("EHIC: " + Formatter.byteArrayToHexString(ehic)); - byte[] grunddaten = signatureCard.getInfobox("Grunddaten", pinProvider, null); - System.out.println("Grunddaten: " + Formatter.byteArrayToHexString(grunddaten)); - //RESET - System.out.println("RESET"); - signatureCard.reset(); - card = signatureCard.getCard(); -// card.disconnect(true); -// card = ct.connect("*"); - System.out.println("begin exclusive"); - card.beginExclusive(); - System.out.println("get cardchannel"); - cardchannel = card.getBasicChannel(); - cAPDU = new CommandAPDU(getCLC); - rAPDU = cardchannel.transmit(cAPDU); - sw = new byte[]{(byte) (0xFF & rAPDU.getSW1()), (byte) (0xFF & rAPDU.getSW2())}; - System.out.println("cAPDU: " + Formatter.byteArrayToHexString(cAPDU.getBytes())); - System.out.println("rAPDU (sw=" + Formatter.byteArrayToHexString(sw) + "): " + Formatter.byteArrayToHexString(rAPDU.getData())); - assertTrue(Arrays.equals(clc, rAPDU.getData())); - cAPDU = new CommandAPDU(readEF_GDO); - rAPDU = cardchannel.transmit(cAPDU); - sw = new byte[]{(byte) (0xFF & rAPDU.getSW1()), (byte) (0xFF & rAPDU.getSW2())}; - System.out.println("cAPDU: " + Formatter.byteArrayToHexString(cAPDU.getBytes())); - System.out.println("rAPDU (sw=" + Formatter.byteArrayToHexString(sw) + "): " + Formatter.byteArrayToHexString(rAPDU.getData())); - assertTrue(Arrays.equals(EF_GDO, rAPDU.getData())); -// } - } -} 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 be5e3fc8..1043b6a1 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 @@ -36,6 +36,7 @@ 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_PIN_TIMEOUT = "error.pin.timeout"; public static final String ERR_VIEWER = "error.viewer"; public static final String ERR_EXTERNAL_LINK = "error.external.link"; public static final String ERR_CONFIG = "error.config"; @@ -52,6 +53,7 @@ public interface BKUGUIFacade { 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_ENTRY_TIMEOUT = "title.entry.timeout"; public static final String TITLE_RETRY = "title.retry"; public static final String TITLE_WAIT = "title.wait"; public static final String TITLE_HASHDATA = "title.hashdata"; @@ -60,17 +62,22 @@ public interface BKUGUIFacade { 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_HASHDATALINK_TINY = "message.hashdatalink.tiny"; -// 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_LAST_RETRY = "message.retries.last"; - public static final String MESSAGE_OVERWRITE = "message.overwrite"; - public static final String MESSAGE_HELP = "message.help"; + + // removed message.* prefix to reuse keys as help keys + public static final String MESSAGE_WELCOME = "welcome"; + public static final String MESSAGE_WAIT = "wait"; + public static final String MESSAGE_INSERTCARD = "insertcard"; + public static final String MESSAGE_CARD_NOT_SUPPORTED = "cardnotsupported"; + public static final String MESSAGE_ENTERPIN = "enterpin"; + public static final String MESSAGE_ENTERPIN_PINPAD = "enterpin.pinpad"; + public static final String MESSAGE_HASHDATALINK = "hashdatalink"; + public static final String MESSAGE_HASHDATALINK_TINY = "hashdatalink.tiny"; + public static final String MESSAGE_HASHDATALIST = "hashdatalist"; + public static final String MESSAGE_RETRIES = "retries"; + public static final String MESSAGE_LAST_RETRY = "retries.last"; + public static final String MESSAGE_OVERWRITE = "overwrite"; + public static final String MESSAGE_HELP = "help"; + public static final String WARNING_XHTML = "warning.xhtml"; public static final String LABEL_PIN = "label.pin"; public static final String LABEL_PINSIZE = "label.pinsize"; @@ -103,33 +110,48 @@ public interface BKUGUIFacade { */ public Locale getLocale(); - public void showWelcomeDialog(); +// public void showWelcomeDialog(); /** * * @param waitMessage if null, a simple 'please wait' text is displayed */ - public void showWaitDialog(String waitMessage); +// public void showWaitDialog(String waitMessage); + +// public void showInsertCardDialog(ActionListener cancelListener, String actionCommand); - public void showInsertCardDialog(ActionListener cancelListener, String actionCommand); +// public void showCardNotSupportedDialog(ActionListener cancelListener, String actionCommand); - public void showCardNotSupportedDialog(ActionListener cancelListener, String actionCommand); + public void showCardPINDialog(PINSpec pinSpec, int numRetries, + ActionListener okListener, String okCommand, + ActionListener cancelListener, String cancelCommand); - 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 showCardPINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand); + public void showSignaturePINDialog(PINSpec pinSpec, int numRetries, ActionListener signListener, String signCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand); - 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 void showSignaturePINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand); +// public void showPinpadSignaturePINDialog(PINSpec pinSpec, int retries); public char[] getPin(); - public void showHashDataInputDialog(List signedReferences, ActionListener okListener, String okCommand); + public void showSecureViewer(List signedReferences, + ActionListener okListener, String okCommand); - public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams, ActionListener okListener, String okCommand); + public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams, + ActionListener okListener, String okCommand); public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams); - public void showMessageDialog(String titleKey, String msgKey, Object[] msgParams, ActionListener okListener, String okCommand); + public void showMessageDialog(String titleKey, + String msgKey, Object[] msgParams, + String buttonKey, + ActionListener okListener, String okCommand); + + public void showMessageDialog(String titleKey, + String msgKey, Object[] msgParams); + + public void showMessageDialog(String titleKey, + String msgKey); } 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 76b1d795..928be249 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 @@ -315,200 +315,204 @@ public class BKUGUIImpl implements BKUGUIFacade { return messages.containsKey(key); } - @Override - public void showWelcomeDialog() { - - log.debug("scheduling welcome dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show welcome dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - helpListener.setHelpTopic(HELP_WELCOME); - - JLabel welcomeMsgLabel = new JLabel(); - welcomeMsgLabel.setFont(welcomeMsgLabel.getFont().deriveFont(welcomeMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - - if (renderHeaderPanel) { - titleLabel.setText(getMessage(TITLE_WELCOME)); - welcomeMsgLabel.setText(getMessage(MESSAGE_WAIT)); - } else { - welcomeMsgLabel.setText(getMessage(TITLE_WELCOME)); - } - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() - .addComponent(welcomeMsgLabel); - GroupLayout.Group messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(welcomeMsgLabel); - if (!renderHeaderPanel) { - messageHorizontal - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel); - messageVertical - .addComponent(helpLabel); - } - - mainPanelLayout.setHorizontalGroup(messageHorizontal); - mainPanelLayout.setVerticalGroup(messageVertical); - - contentPanel.validate(); - - } - }); - } - - @Override - public void showInsertCardDialog(final ActionListener cancelListener, final String cancelCommand) { - - log.debug("scheduling insert card dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show insert card dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - if (renderHeaderPanel) { - titleLabel.setText(getMessage(TITLE_INSERTCARD)); - } - - helpListener.setHelpTopic(HELP_INSERTCARD); - - JLabel insertCardMsgLabel = new JLabel(); - insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - insertCardMsgLabel.setText(getMessage(MESSAGE_INSERTCARD)); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() - .addComponent(insertCardMsgLabel); - GroupLayout.ParallelGroup messageVertical = mainPanelLayout.createParallelGroup() - .addComponent(insertCardMsgLabel); - - if (!renderHeaderPanel) { - messageHorizontal - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel); - messageVertical - .addComponent(helpLabel); - } - - mainPanelLayout.setHorizontalGroup(messageHorizontal); - mainPanelLayout.setVerticalGroup(messageVertical); - - if (renderCancelButton) { - JButton cancelButton = new JButton(); - cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - cancelButton.setText(getMessage(BUTTON_CANCEL)); - cancelButton.addActionListener(cancelListener); - cancelButton.setActionCommand(cancelCommand); - - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createSequentialGroup() - .addComponent(cancelButton)); - } - - contentPanel.validate(); - } - }); - } +// @Override +// public void showWelcomeDialog() { +// +// log.debug("scheduling welcome dialog"); +// +// SwingUtilities.invokeLater(new Runnable() { +// +// @Override +// public void run() { +// +// log.debug("show welcome dialog"); +// +// mainPanel.removeAll(); +// buttonPanel.removeAll(); +// +// helpListener.setHelpTopic(HELP_WELCOME); +// +// JLabel welcomeMsgLabel = new JLabel(); +// welcomeMsgLabel.setFont(welcomeMsgLabel.getFont().deriveFont(welcomeMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); +// +// if (renderHeaderPanel) { +// titleLabel.setText(getMessage(TITLE_WELCOME)); +// welcomeMsgLabel.setText(getMessage(MESSAGE_WAIT)); +// } else { +// welcomeMsgLabel.setText(getMessage(TITLE_WELCOME)); +// } +// +// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); +// mainPanel.setLayout(mainPanelLayout); +// +// GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() +// .addComponent(welcomeMsgLabel); +// GroupLayout.Group messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addComponent(welcomeMsgLabel); +// if (!renderHeaderPanel) { +// messageHorizontal +// .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) +// .addComponent(helpLabel); +// messageVertical +// .addComponent(helpLabel); +// } +// +// mainPanelLayout.setHorizontalGroup(messageHorizontal); +// mainPanelLayout.setVerticalGroup(messageVertical); +// +// contentPanel.validate(); +// +// } +// }); +// } + +// @Override +// public void showInsertCardDialog( +// final ActionListener cancelListener, final String cancelCommand) { +// +// log.debug("scheduling insert card dialog"); +// +// SwingUtilities.invokeLater(new Runnable() { +// +// @Override +// public void run() { +// +// log.debug("show insert card dialog"); +// +// mainPanel.removeAll(); +// buttonPanel.removeAll(); +// +// if (renderHeaderPanel) { +// titleLabel.setText(getMessage(TITLE_INSERTCARD)); +// } +// +// helpListener.setHelpTopic(HELP_INSERTCARD); +// +// JLabel insertCardMsgLabel = new JLabel(); +// insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); +// insertCardMsgLabel.setText(getMessage(MESSAGE_INSERTCARD)); +// +// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); +// mainPanel.setLayout(mainPanelLayout); +// +// GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() +// .addComponent(insertCardMsgLabel); +// GroupLayout.ParallelGroup messageVertical = mainPanelLayout.createParallelGroup() +// .addComponent(insertCardMsgLabel); +// +// if (!renderHeaderPanel) { +// messageHorizontal +// .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) +// .addComponent(helpLabel); +// messageVertical +// .addComponent(helpLabel); +// } +// +// mainPanelLayout.setHorizontalGroup(messageHorizontal); +// mainPanelLayout.setVerticalGroup(messageVertical); +// +// if (renderCancelButton) { +// JButton cancelButton = new JButton(); +// cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); +// cancelButton.setText(getMessage(BUTTON_CANCEL)); +// cancelButton.addActionListener(cancelListener); +// cancelButton.setActionCommand(cancelCommand); +// +// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); +// buttonPanel.setLayout(buttonPanelLayout); +// +// buttonPanelLayout.setHorizontalGroup( +// buttonPanelLayout.createSequentialGroup() +// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) +// .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); +// buttonPanelLayout.setVerticalGroup( +// buttonPanelLayout.createSequentialGroup() +// .addComponent(cancelButton)); +// } +// +// contentPanel.validate(); +// } +// }); +// } /** * only difference to showInsertCard: title text: card not supported * @param cancelListener * @param cancelCommand */ - @Override - public void showCardNotSupportedDialog(final ActionListener cancelListener, final String cancelCommand) { - - log.debug("scheduling card not supported dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show card not supported dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - JLabel insertCardMsgLabel = new JLabel(); - insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - - if (renderHeaderPanel) { - titleLabel.setText(getMessage(TITLE_CARD_NOT_SUPPORTED)); - insertCardMsgLabel.setText(getMessage(MESSAGE_INSERTCARD)); - } else { - insertCardMsgLabel.setText(getMessage(TITLE_CARD_NOT_SUPPORTED)); - } - - helpListener.setHelpTopic(HELP_CARDNOTSUPPORTED); - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() - .addComponent(insertCardMsgLabel); - GroupLayout.Group messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(insertCardMsgLabel); - if (!renderHeaderPanel) { - messageHorizontal - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel); - messageVertical - .addComponent(helpLabel); - } - - mainPanelLayout.setHorizontalGroup(messageHorizontal); - mainPanelLayout.setVerticalGroup(messageVertical); - - if (renderCancelButton) { - JButton cancelButton = new JButton(); - cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - cancelButton.setText(getMessage(BUTTON_CANCEL)); - cancelButton.addActionListener(cancelListener); - cancelButton.setActionCommand(cancelCommand); - - GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); - buttonPanel.setLayout(buttonPanelLayout); - - buttonPanelLayout.setHorizontalGroup( - buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup( - buttonPanelLayout.createSequentialGroup() - .addComponent(cancelButton)); - } - - contentPanel.validate(); - } - }); - } - - private void showCardPINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener okListener, final String okCommand, final ActionListener cancelListener, final String cancelCommand) { +// @Override +// public void showCardNotSupportedDialog(final ActionListener cancelListener, final String cancelCommand) { +// +// log.debug("scheduling card not supported dialog"); +// +// SwingUtilities.invokeLater(new Runnable() { +// +// @Override +// public void run() { +// +// log.debug("show card not supported dialog"); +// +// mainPanel.removeAll(); +// buttonPanel.removeAll(); +// +// JLabel insertCardMsgLabel = new JLabel(); +// insertCardMsgLabel.setFont(insertCardMsgLabel.getFont().deriveFont(insertCardMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); +// +// if (renderHeaderPanel) { +// titleLabel.setText(getMessage(TITLE_CARD_NOT_SUPPORTED)); +// insertCardMsgLabel.setText(getMessage(MESSAGE_INSERTCARD)); +// } else { +// insertCardMsgLabel.setText(getMessage(TITLE_CARD_NOT_SUPPORTED)); +// } +// +// helpListener.setHelpTopic(HELP_CARDNOTSUPPORTED); +// +// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); +// mainPanel.setLayout(mainPanelLayout); +// +// GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() +// .addComponent(insertCardMsgLabel); +// GroupLayout.Group messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addComponent(insertCardMsgLabel); +// if (!renderHeaderPanel) { +// messageHorizontal +// .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) +// .addComponent(helpLabel); +// messageVertical +// .addComponent(helpLabel); +// } +// +// mainPanelLayout.setHorizontalGroup(messageHorizontal); +// mainPanelLayout.setVerticalGroup(messageVertical); +// +// if (renderCancelButton) { +// JButton cancelButton = new JButton(); +// cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); +// cancelButton.setText(getMessage(BUTTON_CANCEL)); +// cancelButton.addActionListener(cancelListener); +// cancelButton.setActionCommand(cancelCommand); +// +// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); +// buttonPanel.setLayout(buttonPanelLayout); +// +// buttonPanelLayout.setHorizontalGroup( +// buttonPanelLayout.createSequentialGroup() +// .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) +// .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); +// buttonPanelLayout.setVerticalGroup( +// buttonPanelLayout.createSequentialGroup() +// .addComponent(cancelButton)); +// } +// +// contentPanel.validate(); +// } +// }); +// } + + @Override + public void showCardPINDialog(final PINSpec pinSpec, final int numRetries, + final ActionListener okListener, final String okCommand, + final ActionListener cancelListener, final String cancelCommand) { log.debug("scheduling card-pin dialog"); @@ -534,7 +538,7 @@ public class BKUGUIImpl implements BKUGUIFacade { JButton okButton = new JButton(); okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); okButton.setText(getMessage(BUTTON_OK)); - okButton.setEnabled(false); + okButton.setEnabled(pinSpec.getMinLength() <= 0); okButton.setActionCommand(okCommand); okButton.addActionListener(okListener); @@ -681,27 +685,30 @@ public class BKUGUIImpl implements BKUGUIFacade { }); } - @Override - public void showCardPINDialog(PINSpec pinSpec, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand) { - showCardPINDialog(pinSpec, -1, okListener, okCommand, cancelListener, cancelCommand); - } - - @Override - public void showCardPINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand) { - showCardPINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand); - } - - @Override - public void showSignaturePINDialog(PINSpec pinSpec, ActionListener signListener, String signCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand) { - showSignaturePINDialog(pinSpec, -1, signListener, signCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); - } +// @Override +// public void showCardPINDialog(PINSpec pinSpec, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand) { +// showCardPINDialog(pinSpec, -1, okListener, okCommand, cancelListener, cancelCommand); +// } +// +// @Override +// public void showCardPINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand) { +// showCardPINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand); +// } + +// @Override +// public void showSignaturePINDialog(PINSpec pinSpec, ActionListener signListener, String signCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand) { +// showSignaturePINDialog(pinSpec, -1, signListener, signCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); +// } @Override - public void showSignaturePINRetryDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand) { - showSignaturePINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); - } - - private void showSignaturePINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener signListener, final String signCommand, final ActionListener cancelListener, final String cancelCommand, final ActionListener hashdataListener, final String hashdataCommand) { + public void showSignaturePINDialog(final PINSpec pinSpec, final int numRetries, + final ActionListener signListener, final String signCommand, + final ActionListener cancelListener, final String cancelCommand, + final ActionListener hashdataListener, final String hashdataCommand) { +// showSignaturePINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); +// } +// +// private void showSignaturePINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener signListener, final String signCommand, final ActionListener cancelListener, final String cancelCommand, final ActionListener hashdataListener, final String hashdataCommand) { log.debug("scheduling signature-pin dialog"); @@ -726,7 +733,7 @@ public class BKUGUIImpl implements BKUGUIFacade { JButton signButton = new JButton(); signButton.setFont(signButton.getFont().deriveFont(signButton.getFont().getStyle() & ~java.awt.Font.BOLD)); signButton.setText(getMessage(BUTTON_SIGN)); - signButton.setEnabled(false); + signButton.setEnabled(pinSpec.getMinLength() <= 0); signButton.setActionCommand(signCommand); signButton.addActionListener(signListener); @@ -888,7 +895,7 @@ public class BKUGUIImpl implements BKUGUIFacade { final ActionListener okListener, final String okCommand) { showMessageDialog(TITLE_ERROR, ERROR_COLOR, - errorMsgKey, errorMsgParams, okListener, okCommand); + errorMsgKey, errorMsgParams, BUTTON_OK, okListener, okCommand); } @Override @@ -896,22 +903,45 @@ public class BKUGUIImpl implements BKUGUIFacade { final String errorMsgKey, final Object[] errorMsgParams) { showMessageDialog(TITLE_ERROR, ERROR_COLOR, - errorMsgKey, errorMsgParams, null, null); + errorMsgKey, errorMsgParams, null, null, null); } @Override public void showMessageDialog( final String titleKey, final String msgKey, final Object[] msgParams, + final String buttonKey, final ActionListener okListener, final String okCommand) { showMessageDialog(titleKey, null, - msgKey, msgParams, okListener, okCommand); + msgKey, msgParams, buttonKey, okListener, okCommand); + } + + @Override + public void showMessageDialog( + final String titleKey, + final String msgKey, final Object[] msgParams) { + + showMessageDialog(titleKey, null, + msgKey, msgParams, null, null, null); + } + + @Override + public void showMessageDialog( + final String titleKey, final String msgKey) { + + showMessageDialog(titleKey, null, + msgKey, null, null, null, null); } + /** + * + * @param buttonKey if null defaults to BUTTON_OK + */ private void showMessageDialog( final String titleKey, final Color titleColor, final String msgKey, final Object[] msgParams, + final String buttonKey, final ActionListener okListener, final String okCommand) { log.debug("scheduling message dialog"); @@ -972,7 +1002,7 @@ public class BKUGUIImpl implements BKUGUIFacade { if (okListener != null) { JButton okButton = new JButton(); okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() & ~java.awt.Font.BOLD)); - okButton.setText(getMessage(BUTTON_OK)); + okButton.setText(getMessage((buttonKey != null) ? buttonKey : BUTTON_OK)); okButton.setActionCommand(okCommand); okButton.addActionListener(okListener); @@ -993,57 +1023,57 @@ public class BKUGUIImpl implements BKUGUIFacade { }); } - @Override - public void showWaitDialog(final String waitMessage) { - - log.debug("scheduling wait dialog"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - - log.debug("show wait dialog"); - - mainPanel.removeAll(); - buttonPanel.removeAll(); - - if (renderHeaderPanel) { - titleLabel.setText(getMessage(TITLE_WAIT)); - } - - helpListener.setHelpTopic(HELP_WAIT); - - JLabel waitMsgLabel = new JLabel(); - waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - if (waitMessage != null) { - waitMsgLabel.setText("" + waitMessage + ""); - } else { - waitMsgLabel.setText(getMessage(MESSAGE_WAIT)); - } - - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); - mainPanel.setLayout(mainPanelLayout); - - GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() - .addComponent(waitMsgLabel); - GroupLayout.ParallelGroup messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(waitMsgLabel); - - if (!renderHeaderPanel) { - messageHorizontal - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel); - messageVertical - .addComponent(helpLabel); - } - mainPanelLayout.setHorizontalGroup(messageHorizontal); - mainPanelLayout.setVerticalGroup(messageVertical); - - contentPanel.validate(); - } - }); - } +// @Override +// public void showWaitDialog(final String waitMessage) { +// +// log.debug("scheduling wait dialog"); +// +// SwingUtilities.invokeLater(new Runnable() { +// +// @Override +// public void run() { +// +// log.debug("show wait dialog"); +// +// mainPanel.removeAll(); +// buttonPanel.removeAll(); +// +// if (renderHeaderPanel) { +// titleLabel.setText(getMessage(TITLE_WAIT)); +// } +// +// helpListener.setHelpTopic(HELP_WAIT); +// +// JLabel waitMsgLabel = new JLabel(); +// waitMsgLabel.setFont(waitMsgLabel.getFont().deriveFont(waitMsgLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); +// if (waitMessage != null) { +// waitMsgLabel.setText("" + waitMessage + ""); +// } else { +// waitMsgLabel.setText(getMessage(MESSAGE_WAIT)); +// } +// +// GroupLayout mainPanelLayout = new GroupLayout(mainPanel); +// mainPanel.setLayout(mainPanelLayout); +// +// GroupLayout.SequentialGroup messageHorizontal = mainPanelLayout.createSequentialGroup() +// .addComponent(waitMsgLabel); +// GroupLayout.ParallelGroup messageVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) +// .addComponent(waitMsgLabel); +// +// if (!renderHeaderPanel) { +// messageHorizontal +// .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) +// .addComponent(helpLabel); +// messageVertical +// .addComponent(helpLabel); +// } +// mainPanelLayout.setHorizontalGroup(messageHorizontal); +// mainPanelLayout.setVerticalGroup(messageVertical); +// +// contentPanel.validate(); +// } +// }); +// } @Override public char[] getPin() { @@ -1062,7 +1092,7 @@ public class BKUGUIImpl implements BKUGUIFacade { * @param okCommand */ @Override - public void showHashDataInputDialog(final List signedReferences, + public void showSecureViewer(final List signedReferences, final ActionListener okListener, final String okCommand) { diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java index 87b636f0..13aaf870 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java @@ -35,6 +35,7 @@ class PINDocument extends PlainDocument { protected Pattern pinPattern; protected JButton enterButton; protected Document compareTo; + protected Document oldPin; public PINDocument(PINSpec pinSpec, JButton enterButton) { this.pinSpec = pinSpec; @@ -46,11 +47,30 @@ class PINDocument extends PlainDocument { this.enterButton = enterButton; } + /** + * + * @param pinSpec + * @param enterButton + * @param compareTo enable enterButton iff this pinDocument's pin equals to compareTo's pin. may be null + */ public PINDocument(PINSpec pinSpec, JButton enterButton, Document compareTo) { this(pinSpec, enterButton); this.compareTo = compareTo; } + /** + * + * @param pinSpec + * @param enterButton may be null + * @param compareTo enable enterButton iff this pinDocument's pin equals to compareTo's pin. may be null + * @param oldPin enable enterButton iff oldPin meets the pinSpec pin length requirements, may be null + */ + public PINDocument(PINSpec pinSpec, JButton enterButton, Document compareTo, Document oldPin) { + this(pinSpec, enterButton); + this.compareTo = compareTo; + this.oldPin = oldPin; + } + @Override public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { if (pinSpec.getMaxLength() < 0 || pinSpec.getMaxLength() >= (getLength() + str.length())) { @@ -66,7 +86,10 @@ class PINDocument extends PlainDocument { } } if (enterButton != null) { - enterButton.setEnabled(getLength() >= pinSpec.getMinLength() && compare()); + enterButton.setEnabled( + (oldPin == null || oldPin.getLength() >= pinSpec.getMinLength()) && + getLength() >= pinSpec.getMinLength() && + compare()); } } @@ -74,7 +97,10 @@ class PINDocument extends PlainDocument { public void remove(int offs, int len) throws BadLocationException { super.remove(offs, len); if (enterButton != null) { - enterButton.setEnabled(getLength() >= pinSpec.getMinLength() && compare()); + enterButton.setEnabled( + (oldPin == null || oldPin.getLength() >= pinSpec.getMinLength()) && + getLength() >= pinSpec.getMinLength() && + compare()); } } 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 1e0bc9f5..6d651b2d 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 @@ -20,6 +20,7 @@ title.cardnotsupported=Die Karte wird nicht unterst\u00FCtzt title.cardpin=Karte wird gelesen title.sign=Signatur erstellen title.error=Fehler +title.entry.timeout=Zeit\u00FCberschreitung title.retry=Falsche PIN title.wait=Bitte warten title.hashdata=Signaturdaten @@ -28,19 +29,25 @@ windowtitle.savedir=Signaturdaten in Verzeichnis speichern windowtitle.overwrite=Datei \u00FCberschreiben? windowtitle.viewer=Signaturdaten windowtitle.help=Hilfe zur B\u00FCrgerkarte -message.wait=Bitte warten... -message.insertcard=Bitte die B\u00FCrgerkarte in den Kartenleser stecken -message.enterpin={0} eingeben -message.hashdatalink=Signaturdaten anzeigen -message.hashdatalink.tiny=Signaturdaten + +# removed message.* prefix to reuse keys as help keys +welcome=Bitte warten... +wait=Bitte warten... +cardnotsupported=Bitte die B\u00FCrgerkarte in den Kartenleser stecken +insertcard=Bitte die B\u00FCrgerkarte in den Kartenleser stecken +enterpin={0} eingeben +enterpin.pinpad={0} ({1} stellig) am Kartenleser eingeben +hashdatalink=Signaturdaten anzeigen +hashdatalink.tiny=Signaturdaten #message.hashdata=Hinweis: Dies ist eine Voransicht des zu signierenden Inhalts. F\u00FCr eine standardkonforme Darstellung siehe Hilfe (i). #message.hashdata=Dies ist eine Voransicht des zu signierenden Inhaltes. F\u00FCr Details siehe Hilfe (i). #verwenden sie bitte die von ihrem System zur Verf\u00FCgung gestellte {0} Anwendung. -message.hashdatalist={0} Signaturdaten: -message.retries.last=Letzter Versuch! -message.retries=Noch {0} Versuche -message.overwrite=M\u00F6chten Sie das existierende Dokument {0} \u00FCberschreiben? -message.help=Hilfe zu {0} +hashdatalist={0} Signaturdaten: +retries.last=Letzter Versuch! +retries=Noch {0} Versuche +overwrite=M\u00F6chten Sie das existierende Dokument {0} \u00FCberschreiben? +help=Hilfe zu {0} + warning.xhtml=Hinweis: Dies ist eine Voransicht des zu signierenden Inhalts. F\u00FCr eine standardkonforme Darstellung siehe Hilfe (i). label.pin={0}: label.pinsize=({0} stellig) @@ -73,6 +80,7 @@ error.unknown=Ein Fehler trat auf error.test=Fehler1 {0} - Fehler2 {1} error.card.locked=B\u00FCrgerkarte ist gesperrt error.card.notactivated=B\u00FCrgerkartenfunktion ist nicht aktiviert +error.pin.timeout=Zeit\u00FCberschreitung bei Eingabe der PIN error.viewer=Der Inhalt kann nicht dargestellt werden: {0} error.external.link=Externer Link {0} wird nicht ge\u00F6ffnet error.config=Fehlerhafte Konfiguration des Systems: {0} 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 4fbccd5b..2fb66969 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 @@ -20,6 +20,7 @@ title.cardnotsupported=This card is not supported title.cardpin=Reading card title.sign=Create signature title.error=Error +title.entry.timeout=Timeout title.retry=Wrong PIN title.wait=Please wait title.hashdata=Signature data @@ -28,17 +29,23 @@ windowtitle.savedir=Save signature data to directory windowtitle.overwrite=Overwrite file? windowtitle.viewer=Signature data windowtitle.help=Citizen card help -message.wait=Please wait... -message.insertcard=Please insert your citizen card into the reader -message.enterpin=Enter {0} -message.hashdatalink=Display signature data -message.hashdatalink.tiny=signature data + +# removed message.* prefix to reuse keys as help keys +welcome=Please wait... +wait=Please wait... +insertcard=Please insert your citizen card into the reader +cardnotsupported=Please insert your citizen card into the reader +enterpin=Enter {0} +enterpin.pinpad=Enter {0} ({1} digits) on card reader pinpad +hashdatalink=Display signature data +hashdatalink.tiny=signature data #message.hashdata=Remark: This is a preview of the data to-be signed. For standards compliant display see help. -message.hashdatalist={0} signature data objects: -message.retries.last=Last try! -message.retries={0} tries left -message.overwrite=Overwrite {0}? -message.help=Help topic {0} +hashdatalist={0} signature data objects: +retries.last=Last try! +retries={0} tries left +overwrite=Overwrite {0}? +help=Help topic {0} + warning.xhtml=Remark: This is a preview of the data to-be signed. For standards compliant display see help. label.pin={0}: label.pinsize=({0} digits) @@ -71,6 +78,7 @@ error.unknown=An error occured error.test=Error1 {0} - Error2 {1} error.card.locked=Citizen card is locked error.card.notactivated=Citizen card not activated +error.pin.timeout=Timeout during PIN entry error.viewer=Failed to display contents: {0} error.external.link=Cannot open external link {0} error.config=Incorrect system configuration: {0} 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 ef64ac59..194e18b0 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 @@ -78,7 +78,7 @@ public class BKUGUIWorker implements Runnable { @Override public void actionPerformed(ActionEvent e) { - gui.showSignaturePINDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", null, "hashdata"); + gui.showSignaturePINDialog(signPinSpec, -1, signListener, "sign", cancelListener, "cancel", null, "hashdata"); } }; HashDataInput signedRef1 = new ByteArrayHashDataInput( @@ -116,7 +116,7 @@ public class BKUGUIWorker implements Runnable { // signedRefs.add(signedRef4); // signedRefs.add(signedRef4); // signedRefs = Collections.singletonList(signedRef1); - gui.showHashDataInputDialog(signedRefs, returnListener, "return"); + gui.showSecureViewer(signedRefs, returnListener, "return"); } }; @@ -149,7 +149,7 @@ public class BKUGUIWorker implements Runnable { // // Thread.sleep(2000); // - gui.showSignaturePINDialog(signPinSpec, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); + gui.showSignaturePINDialog(signPinSpec, -1, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); // // Thread.sleep(4000); // 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 1714017e..5a0ba84a 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 @@ -40,27 +40,27 @@ public class BKUGuiProxy implements BKUGUIFacade { return delegate.getLocale(); } +// @Override +// public void showCardNotSupportedDialog(ActionListener cancelListener, +// String actionCommand) { +// showDialog(); +// delegate.showCardNotSupportedDialog(cancelListener, actionCommand); +// } +// +// @Override +// public void showCardPINDialog(PINSpec pinSpec, ActionListener okListener, +// String okCommand, ActionListener cancelListener, String cancelCommand) { +// showDialog(); +// delegate.showCardPINDialog(pinSpec, okListener, okCommand, cancelListener, +// cancelCommand); +// } +// @Override - public void showCardNotSupportedDialog(ActionListener cancelListener, - String actionCommand) { - showDialog(); - delegate.showCardNotSupportedDialog(cancelListener, actionCommand); - } - - @Override - public void showCardPINDialog(PINSpec pinSpec, ActionListener okListener, - String okCommand, ActionListener cancelListener, String cancelCommand) { - showDialog(); - delegate.showCardPINDialog(pinSpec, okListener, okCommand, cancelListener, - cancelCommand); - } - - @Override - public void showCardPINRetryDialog(PINSpec pinSpec, int numRetries, + public void showCardPINDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand) { showDialog(); - delegate.showCardPINRetryDialog(pinSpec, numRetries, okListener, okCommand, + delegate.showCardPINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand); } @@ -77,57 +77,71 @@ public class BKUGuiProxy implements BKUGUIFacade { delegate.showErrorDialog(errorMsgKey, errorMsgParams); } +// @Override +// public void showInsertCardDialog(ActionListener cancelListener, +// String actionCommand) { +// showDialog(); +// delegate.showInsertCardDialog(cancelListener, actionCommand); +// } +// +// @Override +// public void showSignaturePINDialog(PINSpec pinSpec, +// ActionListener signListener, String signCommand, +// ActionListener cancelListener, String cancelCommand, +// ActionListener hashdataListener, String hashdataCommand) { +// showDialog(); +// delegate.showSignaturePINDialog(pinSpec, signListener, signCommand, +// cancelListener, cancelCommand, hashdataListener, hashdataCommand); +// } +// @Override - public void showInsertCardDialog(ActionListener cancelListener, - String actionCommand) { - showDialog(); - delegate.showInsertCardDialog(cancelListener, actionCommand); - } - - @Override - public void showSignaturePINDialog(PINSpec pinSpec, - ActionListener signListener, String signCommand, - ActionListener cancelListener, String cancelCommand, - ActionListener hashdataListener, String hashdataCommand) { - showDialog(); - delegate.showSignaturePINDialog(pinSpec, signListener, signCommand, - cancelListener, cancelCommand, hashdataListener, hashdataCommand); - } - - @Override - public void showSignaturePINRetryDialog(PINSpec pinSpec, int numRetries, + public void showSignaturePINDialog(PINSpec pinSpec, int numRetries, ActionListener okListener, String okCommand, ActionListener cancelListener, String cancelCommand, ActionListener hashdataListener, String hashdataCommand) { showDialog(); - delegate.showSignaturePINRetryDialog(pinSpec, numRetries, okListener, + delegate.showSignaturePINDialog(pinSpec, numRetries, okListener, okCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); } +// +// @Override +// public void showWaitDialog(String waitMessage) { +// showDialog(); +// delegate.showWaitDialog(waitMessage); +// } +// +// @Override +// public void showWelcomeDialog() { +// showDialog(); +// delegate.showWelcomeDialog(); +// } @Override - public void showWaitDialog(String waitMessage) { + public void showSecureViewer(List signedReferences, + ActionListener okListener, + String okCommand) { showDialog(); - delegate.showWaitDialog(waitMessage); + delegate.showSecureViewer(signedReferences, okListener, okCommand); } @Override - public void showWelcomeDialog() { + public void showMessageDialog(String titleKey, + String msgKey, Object[] msgParams, + String buttonKey, ActionListener okListener, String okCommand) { showDialog(); - delegate.showWelcomeDialog(); + delegate.showMessageDialog(titleKey, msgKey, msgParams, buttonKey, okListener, okCommand); } @Override - public void showHashDataInputDialog(List signedReferences, - ActionListener okListener, - String okCommand) { + public void showMessageDialog(String titleKey, String msgKey, Object[] msgParams) { showDialog(); - delegate.showHashDataInputDialog(signedReferences, okListener, okCommand); + delegate.showMessageDialog(titleKey, msgKey, msgParams); } @Override - public void showMessageDialog(String titleKey, String msgKey, Object[] msgParams, ActionListener okListener, String okCommand) { + public void showMessageDialog(String titleKey, String msgKey) { showDialog(); - delegate.showMessageDialog(titleKey, msgKey, msgParams, okListener, okCommand); + delegate.showMessageDialog(titleKey, msgKey); } } diff --git a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSignRequestHandler.java b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSignRequestHandler.java index 46f915a9..531e6591 100644 --- a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSignRequestHandler.java +++ b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSignRequestHandler.java @@ -67,7 +67,7 @@ public class LocalSignRequestHandler extends SignRequestHandler { * @throws java.lang.Exception */ @Override - public void displayHashDataInputs(List dsigReferences) throws Exception { + public void displayDataToBeSigned(List dsigReferences) throws Exception { if (dsigReferences == null || dsigReferences.size() < 1) { log.error("No hashdata input selected to be displayed: null"); throw new Exception("No HashData Input selected to be displayed"); @@ -109,7 +109,7 @@ public class LocalSignRequestHandler extends SignRequestHandler { log.error("dsig:SignedInfo does not contain a data reference"); throw new Exception("dsig:SignedInfo does not contain a data reference"); } - gui.showHashDataInputDialog(selectedHashDataInputs, this, "hashDataDone"); + gui.showSecureViewer(selectedHashDataInputs, this, "hashDataDone"); } private ByteArrayHashDataInput getByteArrayHashDataInput(HashDataInput hashDataInput) throws IOException { diff --git a/BKULocalApp/src/main/java/at/gv/egiz/bku/local/app/Container.java b/BKULocalApp/src/main/java/at/gv/egiz/bku/local/app/Container.java index d15d2c1b..833dbf4d 100644 --- a/BKULocalApp/src/main/java/at/gv/egiz/bku/local/app/Container.java +++ b/BKULocalApp/src/main/java/at/gv/egiz/bku/local/app/Container.java @@ -1,10 +1,5 @@ package at.gv.egiz.bku.local.app; -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.net.URLClassLoader; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.mortbay.jetty.Connector; diff --git a/BKUOnline/src/main/webapp/helpfiles/de/cardnotsupported.html b/BKUOnline/src/main/webapp/helpfiles/de/cardnotsupported.html new file mode 100644 index 00000000..021ddfa7 --- /dev/null +++ b/BKUOnline/src/main/webapp/helpfiles/de/cardnotsupported.html @@ -0,0 +1,47 @@ + + + + +Untitled Document + + + + + + +

+ +
+

Bildschirmfoto des Applets

+

Hinweis: Das Bildschirmfoto oben kann von der Darstellung in der Webseite abweichen.

+
+
+

Die Karte wird nicht unterstützt

+

Die im Kartenleser gesteckte Chipkarte wird nicht unterstützt.

+

Bitte stecken Sie eine unterstützte Chipkarte (Bürgerkarte) in den Kartenleser. Derzeit werden die folgenden Chipkarten unterstützt:

+ +

Sind mehrere unterstützte Kartenleser angeschlossen, stecken sie eine unterstützte Chipkarte (Bürgerkarte) in einen der angeschlossenen Kartenleser. Wird die Chipkarte erkannt wechselt die Bildschirmanzeige. Wird die Chipkarte nicht erkannt, wird der Kartenleser möglicherweise nicht unterstützt. Stecken Sie die Chipkarte daher in einen anderen Kartenleser.

+


+
+ +
+ + diff --git a/BKUOnline/src/main/webapp/helpfiles/de/cardnotsupported.png b/BKUOnline/src/main/webapp/helpfiles/de/cardnotsupported.png new file mode 100644 index 00000000..c3b7ce6b Binary files /dev/null and b/BKUOnline/src/main/webapp/helpfiles/de/cardnotsupported.png differ diff --git a/BKUOnline/src/main/webapp/helpfiles/de/help.cardnotsupported.html b/BKUOnline/src/main/webapp/helpfiles/de/help.cardnotsupported.html deleted file mode 100644 index c647bf72..00000000 --- a/BKUOnline/src/main/webapp/helpfiles/de/help.cardnotsupported.html +++ /dev/null @@ -1,47 +0,0 @@ - - - - -Untitled Document - - - - - - -
- -
-

Bildschirmfoto des Applets

-

Hinweis: Das Bildschirmfoto oben kann von der Darstellung in der Webseite abweichen.

-
-
-

Die Karte wird nicht unterstützt

-

Die im Kartenleser gesteckte Chipkarte wird nicht unterstützt.

-

Bitte stecken Sie eine unterstützte Chipkarte (Bürgerkarte) in den Kartenleser. Derzeit werden die folgenden Chipkarten unterstützt:

- -

Sind mehrere unterstützte Kartenleser angeschlossen, stecken sie eine unterstützte Chipkarte (Bürgerkarte) in einen der angeschlossenen Kartenleser. Wird die Chipkarte erkannt wechselt die Bildschirmanzeige. Wird die Chipkarte nicht erkannt, wird der Kartenleser möglicherweise nicht unterstützt. Stecken Sie die Chipkarte daher in einen anderen Kartenleser.

-


-
- -
- - diff --git a/BKUOnline/src/main/webapp/helpfiles/de/help.cardnotsupported.png b/BKUOnline/src/main/webapp/helpfiles/de/help.cardnotsupported.png deleted file mode 100644 index c3b7ce6b..00000000 Binary files a/BKUOnline/src/main/webapp/helpfiles/de/help.cardnotsupported.png and /dev/null differ diff --git a/BKUOnline/src/main/webapp/helpfiles/de/help.insertcard.html b/BKUOnline/src/main/webapp/helpfiles/de/help.insertcard.html deleted file mode 100644 index 0bfc6230..00000000 --- a/BKUOnline/src/main/webapp/helpfiles/de/help.insertcard.html +++ /dev/null @@ -1,42 +0,0 @@ - - - - -Untitled Document - - - - - - -
- -
-

Bildschirmfoto des Applets

-

Hinweis: Das Bildschirmfoto oben kann von der Darstellung in der Webseite abweichen.

-
-
-

Bitte die Bürgerkarte in den Kartenleser stecken

-

Die Software für den Zugriff auf die Bürgerkarte hat einen oder mehrere unterstützte Kartenleser gefunden.

-

Bitte stecken Sie nun ihre Bürgerkarte in den Kartenleser. Wird die Karte erkannt, welchselt die Bildschirmanzeige.

-

Sollten Sie mehrere Kartenleser angeschlossen haben, wählen Sie einen beliebigen aus. Wird die Karte im ausgewählten Kartenleser nicht erkannt, wird dieser Kartenleser eventuell nicht unterstützt. Probieren Sie es daher in einem anderen Kartenleser nochmal. -

-


-
- -
- - diff --git a/BKUOnline/src/main/webapp/helpfiles/de/help.insertcard.png b/BKUOnline/src/main/webapp/helpfiles/de/help.insertcard.png deleted file mode 100644 index 62a22975..00000000 Binary files a/BKUOnline/src/main/webapp/helpfiles/de/help.insertcard.png and /dev/null differ diff --git a/BKUOnline/src/main/webapp/helpfiles/de/help.wait.html b/BKUOnline/src/main/webapp/helpfiles/de/help.wait.html deleted file mode 100644 index ed3db1b8..00000000 --- a/BKUOnline/src/main/webapp/helpfiles/de/help.wait.html +++ /dev/null @@ -1,39 +0,0 @@ - - - - -Untitled Document - - - - - - -
- -
-

Bildschirmfoto des Applets

-

Hinweis: Das Bildschirmfoto oben kann von der Darstellung in der Webseite abweichen.

-
-
-

Bitte warten ...

-

Die Software für den Zugriff auf die Bürgerkarte ist damit beschäftigt, einen Befehl auszuführen bzw. auf einen neuen Befehl vom Server zu warten.

-


-
- -
- - diff --git a/BKUOnline/src/main/webapp/helpfiles/de/help.wait.png b/BKUOnline/src/main/webapp/helpfiles/de/help.wait.png deleted file mode 100644 index 63a38fbf..00000000 Binary files a/BKUOnline/src/main/webapp/helpfiles/de/help.wait.png and /dev/null differ diff --git a/BKUOnline/src/main/webapp/helpfiles/de/help.welcome.html b/BKUOnline/src/main/webapp/helpfiles/de/help.welcome.html deleted file mode 100644 index 9796a206..00000000 --- a/BKUOnline/src/main/webapp/helpfiles/de/help.welcome.html +++ /dev/null @@ -1,40 +0,0 @@ - - - - -Untitled Document - - - - - - -
- -
-

Bildschirmfoto des Applets

-

Hinweis: Das Bildschirmfoto oben kann von der Darstellung in der Webseite abweichen.

-
-
-

Willkommen

-

Die Anzeige "Willkommen" erfolgt unmittelbar nachdem die Software für den Zugriff auf die Bürgerkarte erfolgreich im Browser geladen wurde.

-

Die Software versucht nun eine Verbindung mit dem Server aufzunehmen um Befehle für den Zugriff auf die Bürgerkarte zu erhalten.

-


-
- -
- - diff --git a/BKUOnline/src/main/webapp/helpfiles/de/help.welcome.png b/BKUOnline/src/main/webapp/helpfiles/de/help.welcome.png deleted file mode 100644 index 78133b4d..00000000 Binary files a/BKUOnline/src/main/webapp/helpfiles/de/help.welcome.png and /dev/null differ diff --git a/BKUOnline/src/main/webapp/helpfiles/de/insertcard.html b/BKUOnline/src/main/webapp/helpfiles/de/insertcard.html new file mode 100644 index 00000000..f7f1a28a --- /dev/null +++ b/BKUOnline/src/main/webapp/helpfiles/de/insertcard.html @@ -0,0 +1,42 @@ + + + + +Untitled Document + + + + + + +
+ +
+

Bildschirmfoto des Applets

+

Hinweis: Das Bildschirmfoto oben kann von der Darstellung in der Webseite abweichen.

+
+
+

Bitte die Bürgerkarte in den Kartenleser stecken

+

Die Software für den Zugriff auf die Bürgerkarte hat einen oder mehrere unterstützte Kartenleser gefunden.

+

Bitte stecken Sie nun ihre Bürgerkarte in den Kartenleser. Wird die Karte erkannt, welchselt die Bildschirmanzeige.

+

Sollten Sie mehrere Kartenleser angeschlossen haben, wählen Sie einen beliebigen aus. Wird die Karte im ausgewählten Kartenleser nicht erkannt, wird dieser Kartenleser eventuell nicht unterstützt. Probieren Sie es daher in einem anderen Kartenleser nochmal. +

+


+
+ +
+ + diff --git a/BKUOnline/src/main/webapp/helpfiles/de/insertcard.png b/BKUOnline/src/main/webapp/helpfiles/de/insertcard.png new file mode 100644 index 00000000..62a22975 Binary files /dev/null and b/BKUOnline/src/main/webapp/helpfiles/de/insertcard.png differ diff --git a/BKUOnline/src/main/webapp/helpfiles/de/wait.html b/BKUOnline/src/main/webapp/helpfiles/de/wait.html new file mode 100644 index 00000000..8561ff35 --- /dev/null +++ b/BKUOnline/src/main/webapp/helpfiles/de/wait.html @@ -0,0 +1,39 @@ + + + + +Untitled Document + + + + + + +
+ +
+

Bildschirmfoto des Applets

+

Hinweis: Das Bildschirmfoto oben kann von der Darstellung in der Webseite abweichen.

+
+
+

Bitte warten ...

+

Die Software für den Zugriff auf die Bürgerkarte ist damit beschäftigt, einen Befehl auszuführen bzw. auf einen neuen Befehl vom Server zu warten.

+


+
+ +
+ + diff --git a/BKUOnline/src/main/webapp/helpfiles/de/wait.png b/BKUOnline/src/main/webapp/helpfiles/de/wait.png new file mode 100644 index 00000000..63a38fbf Binary files /dev/null and b/BKUOnline/src/main/webapp/helpfiles/de/wait.png differ diff --git a/BKUOnline/src/main/webapp/helpfiles/de/welcome.html b/BKUOnline/src/main/webapp/helpfiles/de/welcome.html new file mode 100644 index 00000000..6c5463e5 --- /dev/null +++ b/BKUOnline/src/main/webapp/helpfiles/de/welcome.html @@ -0,0 +1,40 @@ + + + + +Untitled Document + + + + + + +
+ +
+

Bildschirmfoto des Applets

+

Hinweis: Das Bildschirmfoto oben kann von der Darstellung in der Webseite abweichen.

+
+
+

Willkommen

+

Die Anzeige "Willkommen" erfolgt unmittelbar nachdem die Software für den Zugriff auf die Bürgerkarte erfolgreich im Browser geladen wurde.

+

Die Software versucht nun eine Verbindung mit dem Server aufzunehmen um Befehle für den Zugriff auf die Bürgerkarte zu erhalten.

+


+
+ +
+ + diff --git a/BKUOnline/src/main/webapp/helpfiles/de/welcome.png b/BKUOnline/src/main/webapp/helpfiles/de/welcome.png new file mode 100644 index 00000000..78133b4d Binary files /dev/null and b/BKUOnline/src/main/webapp/helpfiles/de/welcome.png differ diff --git a/smcc/src/main/java/at/gv/egiz/smcc/ACOS04Card.java b/smcc/src/main/java/at/gv/egiz/smcc/ACOS04Card.java new file mode 100644 index 00000000..9fca6ab9 --- /dev/null +++ b/smcc/src/main/java/at/gv/egiz/smcc/ACOS04Card.java @@ -0,0 +1,30 @@ +/* + * 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.smcc; + +/** + * + * @author Clemens Orthacker + */ +public class ACOS04Card extends ACOSCard { + + public ACOS04Card() { + pinSpecs.remove(PINSPEC_INF); + } + +} diff --git a/smcc/src/main/java/at/gv/egiz/smcc/ACOSCard.java b/smcc/src/main/java/at/gv/egiz/smcc/ACOSCard.java index c2c62fd8..01b9155b 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/ACOSCard.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/ACOSCard.java @@ -29,9 +29,10 @@ package at.gv.egiz.smcc; import at.gv.egiz.smcc.util.SMCCHelper; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; import java.nio.charset.Charset; -import javax.smartcardio.Card; import javax.smartcardio.CardChannel; import javax.smartcardio.CardException; import javax.smartcardio.CommandAPDU; @@ -100,9 +101,9 @@ public class ACOSCard extends AbstractSignatureCard implements SignatureCard { (byte) 0x01 // RSA // TODO: Not verified yet }; - private static final int PINSPEC_INF = 0; - private static final int PINSPEC_DEC = 1; - private static final int PINSPEC_SIG = 2; + protected static final int PINSPEC_INF = 0; + protected static final int PINSPEC_DEC = 1; + protected static final int PINSPEC_SIG = 2; public ACOSCard() { super("at/gv/egiz/smcc/ACOSCard"); @@ -179,15 +180,12 @@ public class ACOSCard extends AbstractSignatureCard implements SignatureCard { //new PINSpec(4, 4, "[0-9]", getResourceBundle().getString("inf.pin.name")); int retries = -1; - String pin = null; + char[] pin = null; boolean pinRequiered = false; do { if (pinRequiered) { pin = provider.providePIN(spec, retries); - if (pin == null) { - throw new CancelledException(); - } } try { getCard().beginExclusive(); @@ -234,20 +232,17 @@ public class ACOSCard extends AbstractSignatureCard implements SignatureCard { //new PINSpec(6, 10, "[0-9]", getResourceBundle().getString("sig.pin.name")); int retries = -1; - String pin = null; + char[] pin = null; do { pin = provider.providePIN(spec, retries); - if (pin == null) { - throw new CancelledException(); - } try { getCard().beginExclusive(); // SELECT DF selectFileFID(DF_SIG); // VERIFY - retries = verifyPIN(pin, KID_PIN_SIG); + retries = verifyPIN(KID_PIN_SIG, pin); if (retries != -1) { throw new VerificationFailedException(retries); } @@ -259,7 +254,7 @@ public class ACOSCard extends AbstractSignatureCard implements SignatureCard { return psoComputDigitalSiganture(); } catch (SecurityStatusNotSatisfiedException e) { - retries = verifyPIN(null, KID_PIN_SIG); + retries = verifyPIN(KID_PIN_SIG); } catch (VerificationFailedException e) { retries = e.getRetries(); } finally { @@ -276,15 +271,12 @@ public class ACOSCard extends AbstractSignatureCard implements SignatureCard { //new PINSpec(4, 4, "[0-9]", getResourceBundle().getString("dec.pin.name")); int retries = -1; - String pin = null; - boolean pinRequiered = false; + char[] pin = null; + boolean pinRequired = false; do { - if (pinRequiered) { + if (pinRequired) { pin = provider.providePIN(spec, retries); - if (pin == null) { - throw new CancelledException(); - } } try { getCard().beginExclusive(); @@ -292,7 +284,7 @@ public class ACOSCard extends AbstractSignatureCard implements SignatureCard { // SELECT DF selectFileFID(DF_DEC); // VERIFY - retries = verifyPIN(pin, KID_PIN_DEC); + retries = verifyPIN(KID_PIN_DEC, pin); if (retries != -1) { throw new VerificationFailedException(retries); } @@ -304,10 +296,10 @@ public class ACOSCard extends AbstractSignatureCard implements SignatureCard { } catch (FileNotFoundException e) { throw new NotActivatedException(); } catch (SecurityStatusNotSatisfiedException e) { - pinRequiered = true; - retries = verifyPIN(null, KID_PIN_DEC); + pinRequired = true; + retries = verifyPIN(KID_PIN_DEC); } catch (VerificationFailedException e) { - pinRequiered = true; + pinRequired = true; retries = e.getRetries(); } finally { getCard().endExclusive(); @@ -328,48 +320,16 @@ public class ACOSCard extends AbstractSignatureCard implements SignatureCard { } + //////////////////////////////////////////////////////////////////////// + // PROTECTED METHODS (assume exclusive card access) + //////////////////////////////////////////////////////////////////////// + protected ResponseAPDU selectFileFID(byte[] fid) throws CardException, SignatureCardException { CardChannel channel = getCardChannel(); return transmit(channel, new CommandAPDU(0x00, 0xA4, 0x00, 0x00, fid, 256)); } - @Override - protected int verifyPIN(String pin, byte kid) throws LockedException, NotActivatedException, SignatureCardException { - - CardChannel channel = getCardChannel(); - - ResponseAPDU resp; - try { - if (pin != null) { - resp = transmit(channel, new CommandAPDU(0x00, 0x20, 0x00, kid, encodePINBlock(pin)), false); - } else { - //TODO this is not supported - resp = transmit(channel, new CommandAPDU(0x00, 0x20, 0x00, kid), false); - } - } catch (CardException ex) { - log.error("smart card communication failed: " + ex.getMessage()); - throw new SignatureCardException("smart card communication failed: " + ex.getMessage(), ex); - } - - //6A 00 (falshe P1/P2) nicht in contextAID - //69 85 (nutzungsbedingungen nicht erfüllt) in DF_Sig und nicht sigpin - - if (resp.getSW() == 0x63c0) { - throw new LockedException("PIN locked."); - } else if (resp.getSW1() == 0x63 && resp.getSW2() >> 4 == 0xc) { - // return number of possible retries - return resp.getSW2() & 0x0f; - } else if (resp.getSW() == 0x6983) { - throw new NotActivatedException(); - } else if (resp.getSW() == 0x9000) { - return -1; - } else { - throw new SignatureCardException("Failed to verify pin: SW=" - + Integer.toHexString(resp.getSW()) + "."); - } - } - private void mseSetDST(int p1, int p2, byte[] dst) throws CardException, SignatureCardException { CardChannel channel = getCardChannel(); ResponseAPDU resp = transmit(channel, new CommandAPDU(0x00, 0x22, p1, @@ -426,92 +386,294 @@ public class ACOSCard extends AbstractSignatureCard implements SignatureCard { } } - @Override - public String toString() { - return "a-sign premium"; - } - /** - * ASCII encoded pin, padded with 0x00 - * @param pin - * @return a 8 byte pin block + * + * @param kid + * @return -1 */ - private byte[] encodePINBlock(String pin) { - byte[] asciiPIN = pin.getBytes(Charset.forName("ASCII")); - byte[] encodedPIN = new byte[8]; - System.arraycopy(asciiPIN, 0, encodedPIN, 0, Math.min(asciiPIN.length, - encodedPIN.length)); -// System.out.println("ASCII encoded PIN block: " + SMCCHelper.toString(encodedPIN)); - return encodedPIN; + @Override + protected int verifyPIN(byte kid) { + log.debug("VERIFY PIN without PIN BLOCK not supported by ACOS"); + return -1; } @Override - public void activatePIN(PINSpec pinSpec, String pin) throws SignatureCardException { - throw new SignatureCardException("PIN activation not supported by this card"); + protected int verifyPIN(byte kid, char[] pin) + throws LockedException, NotActivatedException, CancelledException, TimeoutException, SignatureCardException { + try { + byte[] sw; + if (ifdSupportsFeature(FEATURE_VERIFY_PIN_DIRECT)) { + log.debug("verify PIN on IFD"); + sw = transmitControlCommand( + ifdCtrlCmds.get(FEATURE_VERIFY_PIN_DIRECT), + getPINVerifyStructure(kid)); +// int sw = (resp[resp.length-2] & 0xff) << 8 | resp[resp.length-1] & 0xff; + } else { + byte[] pinBlock = encodePINBlock(pin); + CardChannel channel = getCardChannel(); + ResponseAPDU resp = transmit(channel, + new CommandAPDU(0x00, 0x20, 0x00, kid, pinBlock), false); + sw = new byte[2]; + sw[0] = (byte) resp.getSW1(); + sw[1] = (byte) resp.getSW2(); + } + + //6A 00 (falshe P1/P2) nicht in contextAID + //69 85 (nutzungsbedingungen nicht erfüllt) in DF_Sig und nicht sigpin + + if (sw[0] == (byte) 0x90 && sw[1] == (byte) 0x00) { + return -1; + } else if (sw[0] == (byte) 0x63 && sw[1] == (byte) 0xc0) { + throw new LockedException("[63:c0]"); + } else if (sw[0] == (byte) 0x63 && (sw[1] & 0xf0) >> 4 == 0xc) { + return sw[1] & 0x0f; + } else if (sw[0] == (byte) 0x69 && sw[1] == (byte) 0x83) { + //Authentisierungsmethode gesperrt + throw new NotActivatedException("[69:83]"); +// } else if (sw[0] == (byte) 0x69 && sw[1] == (byte) 0x84) { +// //referenzierte Daten sind reversibel gesperrt (invalidated) +// throw new NotActivatedException("[69:84]"); +// } else if (sw[0] == (byte) 0x69 && sw[1] == (byte) 0x85) { +// //Benutzungsbedingungen nicht erfüllt +// throw new NotActivatedException("[69:85]"); + } else if (sw[0] == (byte) 0x64 && sw[1] == (byte) 0x00) { + throw new TimeoutException("[64:00]"); + } else if (sw[0] == (byte) 0x64 && sw[1] == (byte) 0x01) { + throw new CancelledException("[64:01]"); + } + log.error("Failed to verify pin: SW=" + + SMCCHelper.toString(sw)); + throw new SignatureCardException(SMCCHelper.toString(sw)); + + } catch (CardException ex) { + log.error("smart card communication failed: " + ex.getMessage()); + throw new SignatureCardException("smart card communication failed: " + ex.getMessage(), ex); + } } /** * SCARD_E_NOT_TRANSACTED inf/dec PIN not active (pcsc crash) - * @param pinSpec - * @param oldPIN - * @param newPIN + * @param kid + * @param oldPin + * @param newPin + * @return * @throws at.gv.egiz.smcc.LockedException - * @throws at.gv.egiz.smcc.VerificationFailedException * @throws at.gv.egiz.smcc.NotActivatedException * @throws at.gv.egiz.smcc.SignatureCardException */ @Override - public void changePIN(PINSpec pinSpec, String oldPIN, String newPIN) - throws LockedException, VerificationFailedException, NotActivatedException, SignatureCardException { - Card icc = getCard(); + protected int changePIN(byte kid, char[] oldPin, char[] newPin) + throws LockedException, NotActivatedException, CancelledException, TimeoutException, SignatureCardException { try { - icc.beginExclusive(); - CardChannel channel = icc.getBasicChannel(); - - if (pinSpec.getContextAID() != null) { - ResponseAPDU responseAPDU = transmit(channel, - new CommandAPDU(0x00, 0xa4, 0x04, 0x0c, pinSpec.getContextAID())); - if (responseAPDU.getSW() != 0x9000) { - icc.endExclusive(); - String msg = "Select AID " + SMCCHelper.toString(pinSpec.getContextAID()) + - ": SW=" + Integer.toHexString(responseAPDU.getSW()); - log.error(msg); - throw new SignatureCardException(msg); - } - } - - byte[] cmd = new byte[16]; - System.arraycopy(encodePINBlock(oldPIN), 0, cmd, 0, 8); - System.arraycopy(encodePINBlock(newPIN), 0, cmd, 8, 8); + byte[] sw; + if (ifdSupportsFeature(FEATURE_MODIFY_PIN_DIRECT)) { + log.debug("modify PIN on IFD"); + sw = transmitControlCommand( + ifdCtrlCmds.get(FEATURE_MODIFY_PIN_DIRECT), + getPINModifyStructure(kid)); +// int sw = (resp[resp.length-2] & 0xff) << 8 | resp[resp.length-1] & 0xff; + } else { + byte[] cmd = new byte[16]; + System.arraycopy(encodePINBlock(oldPin), 0, cmd, 0, 8); + System.arraycopy(encodePINBlock(newPin), 0, cmd, 8, 8); - ResponseAPDU responseAPDU = transmit(channel, - new CommandAPDU(0x00, 0x24, 0x00, pinSpec.getKID(), cmd), false); + CardChannel channel = getCardChannel(); - icc.endExclusive(); + ResponseAPDU resp = transmit(channel, + new CommandAPDU(0x00, 0x24, 0x00, kid, cmd), false); - log.debug("change pin returned SW=" + Integer.toHexString(responseAPDU.getSW())); + sw = new byte[2]; + sw[0] = (byte) resp.getSW1(); + sw[1] = (byte) resp.getSW2(); + } - if (responseAPDU.getSW() == 0x63c0) { - log.error(pinSpec.getLocalizedName() + " locked"); - throw new LockedException(); - } else if (responseAPDU.getSW1() == 0x63 && responseAPDU.getSW2() >> 4 == 0xc) { - int retries = responseAPDU.getSW2() & 0x0f; - log.error("wrong " + pinSpec.getLocalizedName() + ", " + retries + " retries"); - throw new VerificationFailedException(retries); - } else if (responseAPDU.getSW() == 0x6983) { + // activates pin (newPIN) if not active + if (sw[0] == (byte) 0x90 && sw[1] == (byte) 0x00) { + return -1; + } else if (sw[0] == (byte) 0x63 && sw[1] == (byte) 0xc0) { + throw new LockedException("[63:c0]"); + } else if (sw[0] == (byte) 0x63 && (sw[1] & 0xf0) >> 4 == 0xc) { + return sw[1] & 0x0f; + } else if (sw[0] == (byte) 0x69 && sw[1] == (byte) 0x83) { + //Authentisierungsmethode gesperrt // sig-pin only (card not transacted for inf/dec pin) - log.error(pinSpec.getLocalizedName() + " not activated"); - throw new NotActivatedException(); - } else if (responseAPDU.getSW() != 0x9000) { - String msg = "Failed to change " + pinSpec.getLocalizedName() + - ": SW=" + Integer.toHexString(responseAPDU.getSW()); - log.error(msg); - throw new SignatureCardException(msg); + throw new NotActivatedException("[69:83]"); + } else if (sw[0] == (byte) 0x64 && sw[1] == (byte) 0x00) { + throw new TimeoutException("[64:00]"); + } else if (sw[0] == (byte) 0x64 && sw[1] == (byte) 0x01) { + throw new CancelledException("[64:01]"); } + log.error("Failed to change pin: SW=" + + SMCCHelper.toString(sw)); + throw new SignatureCardException(SMCCHelper.toString(sw)); + } catch (CardException ex) { - log.error("Failed to change " + pinSpec.getLocalizedName() + - ": " + ex.getMessage()); - throw new SignatureCardException(ex.getMessage(), ex); + log.error("smart card communication failed: " + ex.getMessage()); + throw new SignatureCardException("smart card communication failed: " + ex.getMessage(), ex); } } + + /** + * throws SignatureCardException (PIN activation not supported by ACOS) + * @throws at.gv.egiz.smcc.SignatureCardException + */ + @Override + public void activatePIN(byte kid, char[] pin) + throws SignatureCardException { + log.error("ACTIVATE PIN not supported by ACOS"); + throw new SignatureCardException("PIN activation not supported by this card"); + } + + /** + * ASCII encoded pin, padded with 0x00 + * @param pin + * @return a 8 byte pin block + */ + @Override + protected byte[] encodePINBlock(char[] pin) { +// byte[] asciiPIN = new String(pin).getBytes(Charset.forName("ASCII")); + CharBuffer chars = CharBuffer.wrap(pin); + ByteBuffer bytes = Charset.forName("ASCII").encode(chars); + byte[] asciiPIN = bytes.array(); + byte[] encodedPIN = new byte[8]; + System.arraycopy(asciiPIN, 0, encodedPIN, 0, Math.min(asciiPIN.length, + encodedPIN.length)); +// System.out.println("ASCII encoded PIN block: " + SMCCHelper.toString(encodedPIN)); + return encodedPIN; + } + + private byte[] getPINVerifyStructure(byte kid) { + + byte bTimeOut = (byte) 00; // Default time out + byte bTimeOut2 = (byte) 00; // Default time out + byte bmFormatString = (byte) 0x82; // 1 0001 0 01 + // ^------------ System unit = byte + // ^^^^------- PIN position in the frame = 1 byte + // ^----- PIN justification left + // ^^-- BCD format + // 1 0000 0 10 + // ^^-- ASCII format + byte bmPINBlockString = (byte) 0x08; // 0100 0111 + // ^^^^--------- PIN length size: 4 bits + // ^^^^---- Length PIN = 7 bytes + byte bmPINLengthFormat = (byte) 0x04; // 000 0 0100 + // ^-------- System bit units is bit + // ^^^^--- PIN length is at the 4th position bit + byte wPINMaxExtraDigitL = (byte) 0x04; // Max=4 digits + byte wPINMaxExtraDigitH = (byte) 0x04; // Min=4 digits + byte bEntryValidationCondition = 0x02; // Max size reach or Validation key pressed + byte bNumberMessage = (byte) 0x00; // No message + byte wLangIdL = (byte) 0x0C; // - English? + byte wLangIdH = (byte) 0x04; // \ + byte bMsgIndex = (byte) 0x00; // Default Msg + + byte[] apdu = new byte[] { + (byte) 0x00, (byte) 0x20, (byte) 0x00, kid, (byte) 0x08, // CLA INS P1 P2 LC + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, // Data + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 // Data + }; + + int offset = 0; + byte[] pinVerifyStructure = new byte[offset + 19 + apdu.length]; + pinVerifyStructure[offset++] = bTimeOut; + pinVerifyStructure[offset++] = bTimeOut2; + pinVerifyStructure[offset++] = bmFormatString; + pinVerifyStructure[offset++] = bmPINBlockString; + pinVerifyStructure[offset++] = bmPINLengthFormat; + pinVerifyStructure[offset++] = wPINMaxExtraDigitL; + pinVerifyStructure[offset++] = wPINMaxExtraDigitH; + pinVerifyStructure[offset++] = bEntryValidationCondition; + pinVerifyStructure[offset++] = bNumberMessage; + pinVerifyStructure[offset++] = wLangIdL; + pinVerifyStructure[offset++] = wLangIdH; + pinVerifyStructure[offset++] = bMsgIndex; + + pinVerifyStructure[offset++] = 0x00; + pinVerifyStructure[offset++] = 0x00; + pinVerifyStructure[offset++] = 0x00; + + pinVerifyStructure[offset++] = (byte) apdu.length; + pinVerifyStructure[offset++] = 0x00; + pinVerifyStructure[offset++] = 0x00; + pinVerifyStructure[offset++] = 0x00; + System.arraycopy(apdu, 0, pinVerifyStructure, offset, apdu.length); + + return pinVerifyStructure; + } + + public byte[] getPINModifyStructure(byte kid) { + + byte bTimeOut = (byte) 00; // Default time out + byte bTimeOut2 = (byte) 00; // Default time out + byte bmFormatString = (byte) 0x82; // 1 0001 0 01 + // ^------------ System unit = byte + // ^^^^------- PIN position in the frame = 1 byte + // ^----- PIN justification left + // ^^-- BCD format + // 1 0000 0 10 + // ^^-- ASCII format + byte bmPINBlockString = (byte) 0x08; // 0100 0111 + // ^^^^--------- PIN length size: 4 bits + // ^^^^---- Length PIN = 7 bytes + byte bmPINLengthFormat = (byte) 0x00; // 000 0 0100 + // ^-------- System bit units is bit + // ^^^^--- PIN length is at the 4th position bit + byte bInsertionOffsetOld = (byte) 0x00; // insertion position offset in bytes + byte bInsertionOffsetNew = (byte) 0x00; // insertion position offset in bytes + byte wPINMaxExtraDigitL = (byte) 0x04; // Min=4 digits + byte wPINMaxExtraDigitH = (byte) 0x04; // Max=12 digits + byte bConfirmPIN = (byte) 0x00; // ??? need for confirm pin + byte bEntryValidationCondition = 0x02; // Max size reach or Validation key pressed + byte bNumberMessage = (byte) 0x00; // No message + byte wLangIdL = (byte) 0x0C; // - English? + byte wLangIdH = (byte) 0x04; // \ + byte bMsgIndex1 = (byte) 0x00; // Default Msg + byte bMsgIndex2 = (byte) 0x00; // Default Msg + byte bMsgIndex3 = (byte) 0x00; // Default Msg + + byte[] apdu = new byte[] { + (byte) 0x00, (byte) 0x24, (byte) 0x00, kid, (byte) 0x10, // CLA INS P1 P2 LC + (byte) 0x20, (byte) 0xff, (byte) 0xff, (byte) 0xff, // Data + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, // ... + (byte) 0x20, (byte) 0xff, (byte) 0xff, (byte) 0xff, // Data + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff // ... + }; + + int offset = 0; + byte[] pinModifyStructure = new byte[offset + 24 + apdu.length]; + pinModifyStructure[offset++] = bTimeOut; + pinModifyStructure[offset++] = bTimeOut2; + pinModifyStructure[offset++] = bmFormatString; + pinModifyStructure[offset++] = bmPINBlockString; + pinModifyStructure[offset++] = bmPINLengthFormat; + pinModifyStructure[offset++] = bInsertionOffsetOld; + pinModifyStructure[offset++] = bInsertionOffsetNew; + pinModifyStructure[offset++] = wPINMaxExtraDigitL; + pinModifyStructure[offset++] = wPINMaxExtraDigitH; + pinModifyStructure[offset++] = bConfirmPIN; + pinModifyStructure[offset++] = bEntryValidationCondition; + pinModifyStructure[offset++] = bNumberMessage; + pinModifyStructure[offset++] = wLangIdL; + pinModifyStructure[offset++] = wLangIdH; + pinModifyStructure[offset++] = bMsgIndex1; + pinModifyStructure[offset++] = bMsgIndex2; + pinModifyStructure[offset++] = bMsgIndex3; + + pinModifyStructure[offset++] = 0x00; + pinModifyStructure[offset++] = 0x00; + pinModifyStructure[offset++] = 0x00; + + pinModifyStructure[offset++] = (byte) apdu.length; + pinModifyStructure[offset++] = 0x00; + pinModifyStructure[offset++] = 0x00; + pinModifyStructure[offset++] = 0x00; + System.arraycopy(apdu, 0, pinModifyStructure, offset, apdu.length); + + return pinModifyStructure; + } + + @Override + public String toString() { + return "a-sign premium"; + } } diff --git a/smcc/src/main/java/at/gv/egiz/smcc/AbstractSignatureCard.java b/smcc/src/main/java/at/gv/egiz/smcc/AbstractSignatureCard.java index 39952bb9..6587aaf9 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/AbstractSignatureCard.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/AbstractSignatureCard.java @@ -33,12 +33,12 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.ResourceBundle; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.smartcardio.ATR; import javax.smartcardio.Card; import javax.smartcardio.CardChannel; @@ -54,6 +54,14 @@ public abstract class AbstractSignatureCard implements SignatureCard { private static Log log = LogFactory.getLog(AbstractSignatureCard.class); + static final short GET_FEATURE_REQUEST = 3400; + + private static int getCtrlCode(short function) { + return 0x310000 | ((0xFFFF & function) << 2); + } + + protected Map ifdCtrlCmds; + protected List pinSpecs = new ArrayList(); private ResourceBundle i18n; @@ -106,11 +114,14 @@ public abstract class AbstractSignatureCard implements SignatureCard { */ protected byte[] selectFileAID(byte[] dfName) throws CardException, SignatureCardException { CardChannel channel = getCardChannel(); - ResponseAPDU resp = transmit(channel, new CommandAPDU(0x00, 0xA4, 0x04, - 0x00, dfName, 256)); + ResponseAPDU resp = transmit(channel, + new CommandAPDU(0x00, 0xA4, 0x04, 0x00, dfName, 256)); +// new CommandAPDU(0x00, 0xa4, 0x04, 0x0c, dfName)); if (resp.getSW() != 0x9000) { - throw new SignatureCardException("Failed to select application AID=" - + toString(dfName) + ": SW=" + Integer.toHexString(resp.getSW()) + "."); + String msg = "Failed to select application AID=" + SMCCHelper.toString(dfName) + + ": SW=" + Integer.toHexString(resp.getSW()); + log.error(msg); + throw new SignatureCardException(msg); } else { return resp.getBytes(); } @@ -119,10 +130,63 @@ public abstract class AbstractSignatureCard implements SignatureCard { protected abstract ResponseAPDU selectFileFID(byte[] fid) throws CardException, SignatureCardException; - protected abstract int verifyPIN(String pin, byte kid) + /** + * VERIFY APDU without PIN BLOCK + * Not supported by ACOS cards (and GemPC Pinpad?) + * @param kid + * @return the number of possible tries until card is blocked or -1 if unknown + * (ACOS does not support this VERIFY APDU type) + * @throws at.gv.egiz.smcc.LockedException + * @throws at.gv.egiz.smcc.NotActivatedException + * @throws at.gv.egiz.smcc.SignatureCardException + */ + protected abstract int verifyPIN(byte kid) throws LockedException, NotActivatedException, SignatureCardException; - + /** + * VERIFY APDU with PIN BLOCK + * If IFD supports VERIFY_PIN on pinpad, parameter pin may be empty. + * @param kid + * @param pin to be encoded in the PIN BLOCK + * @return -1 if VERIFY PIN was successful, or the number of possible retries + * @throws at.gv.egiz.smcc.LockedException + * @throws at.gv.egiz.smcc.NotActivatedException + * @throws at.gv.egiz.smcc.SignatureCardException + */ + protected abstract int verifyPIN(byte kid, char[] pin) + throws LockedException, NotActivatedException, CancelledException, TimeoutException, SignatureCardException; + + /** + * CHANGE(?) APDU + * If IFD supports VERIFY_PIN on pinpad, parameter pin may be empty. + * @param kid + * @param pin + * @throws at.gv.egiz.smcc.SignatureCardException if activation fails + */ + protected abstract void activatePIN(byte kid, char[] pin) + throws CancelledException, TimeoutException, SignatureCardException; + + /** + * CHANGE(?) APDU + * If IFD supports VERIFY_PIN on pinpad, parameter pin may be empty. + * @param kid + * @param pin + * @return -1 if CHANGE PIN was successful, or the number of possible retries + * @throws at.gv.egiz.smcc.SignatureCardException if change fails + */ + protected abstract int changePIN(byte kid, char[] oldPin, char[] newPin) + throws CancelledException, TimeoutException, SignatureCardException; + + /** + * encode the pin as needed in VERIFY/CHANGE APDUs + * @param pin + * @return + * @throws at.gv.egiz.smcc.SignatureCardException if the provided pin does + * not meet the restrictions imposed by the encoding (not the pinSpec!), + * such as maximum Length + */ + protected abstract byte[] encodePINBlock(char[] pin) throws SignatureCardException; + protected byte[] readRecord(int recordNumber) throws SignatureCardException, CardException { return readRecord(getCardChannel(), recordNumber); } @@ -295,7 +359,7 @@ public abstract class AbstractSignatureCard implements SignatureCard { * @throws SignatureCardException * @throws CardException */ - protected byte[] readTLVFile(byte[] aid, byte[] ef, String pin, byte kid, int maxLength) + protected byte[] readTLVFile(byte[] aid, byte[] ef, char[] pin, byte kid, int maxLength) throws SignatureCardException, InterruptedException, CardException { @@ -318,7 +382,7 @@ public abstract class AbstractSignatureCard implements SignatureCard { // VERIFY if (pin != null) { - int retries = verifyPIN(pin, kid); + int retries = verifyPIN(kid, pin); if (retries != -1) { throw new VerificationFailedException(retries); } @@ -388,6 +452,7 @@ public abstract class AbstractSignatureCard implements SignatureCard { ifs_ = 0xFF & atr.getBytes()[6]; log.trace("Setting IFS (information field size) to " + ifs_); } + ifdCtrlCmds = queryIFDFeatures(); } @Override @@ -446,39 +511,266 @@ public abstract class AbstractSignatureCard implements SignatureCard { } @Override - public int verifyPIN(PINSpec pinSpec, String pin) throws LockedException, NotActivatedException, SignatureCardException { - - Card icc = getCard(); + public void verifyPIN(PINSpec pinSpec, PINProvider pinProvider) + throws LockedException, NotActivatedException, CancelledException, TimeoutException, SignatureCardException, InterruptedException { try { - icc.beginExclusive(); - CardChannel channel = icc.getBasicChannel(); + getCard().beginExclusive(); if (pinSpec.getContextAID() != null) { - ResponseAPDU responseAPDU = transmit(channel, - new CommandAPDU(0x00, 0xa4, 0x04, 0x0c, pinSpec.getContextAID())); - if (responseAPDU.getSW() != 0x9000) { - icc.endExclusive(); - String msg = "Failed to verify PIN " + - SMCCHelper.toString(new byte[]{pinSpec.getKID()}) + - ": Failed to verify AID " + - SMCCHelper.toString(pinSpec.getContextAID()) + - ": " + SMCCHelper.toString(responseAPDU.getBytes()); - log.error(msg); - throw new SignatureCardException(msg); - } + selectFileAID(pinSpec.getContextAID()); } - return verifyPIN(pin, pinSpec.getKID()); + + int retries = verifyPIN(pinSpec.getKID()); + do { + char[] pin = pinProvider.providePIN(pinSpec, retries); + retries = verifyPIN(pinSpec.getKID(), pin); + } while (retries > 0); + //return on -1, 0 never reached: verifyPIN throws LockedEx } catch (CardException ex) { - log.error("failed to verify pinspec: " + ex.getMessage(), ex); + log.error("failed to verify " + pinSpec.getLocalizedName() + + ": " + ex.getMessage(), ex); throw new SignatureCardException(ex); } finally { try { - icc.endExclusive(); + getCard().endExclusive(); + } catch (CardException ex) { + log.trace("failed to end exclusive card access: " + ex.getMessage()); + } + } + } + + @Override + public void activatePIN(PINSpec pinSpec, PINProvider pinProvider) + throws CancelledException, SignatureCardException, CancelledException, TimeoutException, InterruptedException { + try { + getCard().beginExclusive(); + + if (pinSpec.getContextAID() != null) { + selectFileAID(pinSpec.getContextAID()); + } + char[] pin = pinProvider.providePIN(pinSpec, -1); + activatePIN(pinSpec.getKID(), pin); + + } catch (CardException ex) { + log.error("Failed to activate " + pinSpec.getLocalizedName() + + ": " + ex.getMessage()); + throw new SignatureCardException(ex.getMessage(), ex); + } finally { + try { + getCard().endExclusive(); } catch (CardException ex) { log.trace("failed to end exclusive card access: " + ex.getMessage()); } + } + } + + /** + * activates pin (newPIN) if not active + * @param pinSpec + * @param oldPIN + * @param newPIN + * @throws at.gv.egiz.smcc.LockedException + * @throws at.gv.egiz.smcc.VerificationFailedException + * @throws at.gv.egiz.smcc.NotActivatedException + * @throws at.gv.egiz.smcc.SignatureCardException + */ + @Override + public void changePIN(PINSpec pinSpec, ChangePINProvider pinProvider) + throws LockedException, NotActivatedException, CancelledException, TimeoutException, SignatureCardException, InterruptedException { + try { + getCard().beginExclusive(); + + if (pinSpec.getContextAID() != null) { + selectFileAID(pinSpec.getContextAID()); + } + + int retries = verifyPIN(pinSpec.getKID()); + do { + char[] newPin = pinProvider.providePIN(pinSpec, retries); + char[] oldPin = pinProvider.provideOldPIN(pinSpec, retries); + retries = changePIN(pinSpec.getKID(), oldPin, newPin); + } while (retries > 0); + //return on -1, 0 never reached: verifyPIN throws LockedEx + } catch (CardException ex) { + log.error("Failed to change " + pinSpec.getLocalizedName() + + ": " + ex.getMessage()); + throw new SignatureCardException(ex.getMessage(), ex); + } finally { + try { + getCard().endExclusive(); + } catch (CardException ex) { + log.trace("failed to end exclusive card access: " + ex.getMessage()); + } } } + + @Override + public void unblockPIN(PINSpec pinSpec, PINProvider pinProvider) + throws CancelledException, SignatureCardException, InterruptedException { + throw new SignatureCardException("Unblock not supported yet"); + } + + ///////////////////////////////////////////////////////////////////////////// + // IFD related code + ///////////////////////////////////////////////////////////////////////////// + + /** + * TODO implement VERIFY_PIN_START/FINISH (feature 0x01/0x02) + * @return + */ + @Override + public boolean ifdSupportsFeature(byte feature) { + if (ifdCtrlCmds != null) { + return ifdCtrlCmds.containsKey(feature); + } + return false; + } + + protected Map queryIFDFeatures() { + + if (card_ == null) { + throw new NullPointerException("Need connected smart card to query IFD features"); + } + + Map ifdFeatures = new HashMap(); + + try { + if (log.isTraceEnabled()) { + log.trace("GET_FEATURE_REQUEST CtrlCode " + Integer.toHexString(getCtrlCode(GET_FEATURE_REQUEST))); + } + byte[] resp = card_.transmitControlCommand(getCtrlCode(GET_FEATURE_REQUEST), new byte[]{}); + + if (log.isTraceEnabled()) { + log.trace("GET_FEATURE_REQUEST Response " + SMCCHelper.toString(resp)); + } + + for (int i = 0; i + 5 < resp.length; i += 6) { + Byte feature = new Byte(resp[i]); + Long ctrlCode = new Long( + ((0xFF & resp[i + 2]) << 24) | + ((0xFF & resp[i + 3]) << 16) | + ((0xFF & resp[i + 4]) << 8) | + (0xFF & resp[i + 5])); + if (log.isInfoEnabled()) { + log.info("IFD supports feature " + Integer.toHexString(feature.byteValue()) + + ": " + Long.toHexString(ctrlCode.longValue())); + } + ifdFeatures.put(feature, ctrlCode); + } + + } catch (CardException ex) { + log.debug("Failed to query IFD features: " + ex.getMessage()); + log.trace(ex); + log.info("IFD does not support PINPad"); + return null; + } + return ifdFeatures; + } + + + protected byte ifdGetKeyPressed() throws CardException { + if (ifdSupportsFeature(FEATURE_VERIFY_PIN_DIRECT)) { + + Long controlCode = (Long) ifdCtrlCmds.get(new Byte((byte) 0x05)); + + byte key = 0x00; + while (key == 0x00) { + + byte[] resp = card_.transmitControlCommand(controlCode.intValue(), new byte[] {}); + + if (resp != null && resp.length > 0) { + key = resp[0]; + } + } + + System.out.println("Key: " + key); + + } + + return 0x00; + } + + protected byte[] ifdVerifyPINFinish() throws CardException { + if (ifdSupportsFeature(FEATURE_VERIFY_PIN_DIRECT)) { + + Long controlCode = (Long) ifdCtrlCmds.get(new Byte((byte) 0x02)); + + byte[] resp = card_.transmitControlCommand(controlCode.intValue(), new byte[] {}); + + System.out.println("CommandResp: " + toString(resp)); + + return resp; + + } + + return null; + } + + + /** + * assumes ifdSupportsVerifyPIN() == true + * @param pinVerifyStructure + * @return + * @throws javax.smartcardio.CardException + */ +// protected byte[] ifdVerifyPIN(byte[] pinVerifyStructure) throws CardException { +// +//// Long ctrlCode = (Long) ifdFeatures.get(FEATURE_IFD_PIN_PROPERTIES); +//// if (ctrlCode != null) { +//// if (log.isTraceEnabled()) { +//// log.trace("PIN_PROPERTIES CtrlCode " + Integer.toHexString(ctrlCode.intValue())); +//// } +//// byte[] resp = card_.transmitControlCommand(ctrlCode.intValue(), new byte[] {}); +//// +//// if (log.isTraceEnabled()) { +//// log.trace("PIN_PROPERTIES Response " + SMCCHelper.toString(resp)); +//// } +//// } +// +// +// Long ctrlCode = (Long) ifdFeatures.get(FEATURE_VERIFY_PIN_DIRECT); +// if (ctrlCode == null) { +// throw new NullPointerException("no CtrlCode for FEATURE_VERIFY_PIN_DIRECT"); +// } +// +// if (log.isTraceEnabled()) { +// log.trace("VERIFY_PIN_DIRECT CtrlCode " + Integer.toHexString(ctrlCode.intValue()) + +// ", PIN_VERIFY_STRUCTURE " + SMCCHelper.toString(pinVerifyStructure)); +// } +// byte[] resp = card_.transmitControlCommand(ctrlCode.intValue(), pinVerifyStructure); +// +// if (log.isTraceEnabled()) { +// log.trace("VERIFY_PIN_DIRECT Response " + SMCCHelper.toString(resp)); +// } +// return resp; +// } + +// protected Long getControlCode(Byte feature) { +// if (ifdFeatures != null) { +// return ifdFeatures.get(feature); +// } +// return null; +// } + + protected byte[] transmitControlCommand(Long ctrlCode, byte[] ctrlCommand) + throws CardException { +// Long ctrlCode = (Long) ifdFeatures.get(feature); + if (ctrlCode == null) { + throw new NullPointerException("ControlCode " + + Integer.toHexString(ctrlCode.intValue()) + " not supported"); + } + if (log.isTraceEnabled()) { + log.trace("CtrlCommand (" + Integer.toHexString(ctrlCode.intValue()) + + ") " + SMCCHelper.toString(ctrlCommand)); + } + byte[] resp = card_.transmitControlCommand(ctrlCode.intValue(), ctrlCommand); + + if (log.isTraceEnabled()) { + log.trace("CtrlCommand Response " + SMCCHelper.toString(resp)); + } + return resp; + } + } diff --git a/smcc/src/main/java/at/gv/egiz/smcc/ChangePINProvider.java b/smcc/src/main/java/at/gv/egiz/smcc/ChangePINProvider.java new file mode 100644 index 00000000..d0622aa4 --- /dev/null +++ b/smcc/src/main/java/at/gv/egiz/smcc/ChangePINProvider.java @@ -0,0 +1,39 @@ +/* + * 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.smcc; + +import at.gv.egiz.smcc.*; + +/** + * + * @author Clemens Orthacker + */ +public interface ChangePINProvider extends PINProvider { + + /** + * + * @param spec + * @param retries + * @return null if no old value for this pin + * @throws at.gv.egiz.smcc.CancelledException if cancelled by user + * @throws java.lang.InterruptedException + */ + public char[] provideOldPIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException; + +} diff --git a/smcc/src/main/java/at/gv/egiz/smcc/PINProvider.java b/smcc/src/main/java/at/gv/egiz/smcc/PINProvider.java index e0104618..8fa80dcb 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/PINProvider.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/PINProvider.java @@ -28,8 +28,30 @@ // package at.gv.egiz.smcc; +/** + * The number of retries is not fixed and there is no way (?) to obtain this value. + * A PINProvider should therefore maintain an internal retry counter or flag + * to decide whether or not to warn the user (num retries passed in providePIN). + * + * Therefore PINProvider objects should not be reused. + * + * (ACOS: reload counter: between 0 and 15, where 15 meens deactivated) + * + * @author Clemens Orthacker + */ public interface PINProvider { - - public String providePIN(PINSpec spec, int retries) throws InterruptedException; + + /** + * + * @param spec + * @param retries num of remaining retries or -1 if unknown + * (a positive value does not necessarily signify that there was + * already an unsuccessful PIN verification) + * @return pin != null + * @throws at.gv.egiz.smcc.CancelledException + * @throws java.lang.InterruptedException + */ + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException; } diff --git a/smcc/src/main/java/at/gv/egiz/smcc/STARCOSCard.java b/smcc/src/main/java/at/gv/egiz/smcc/STARCOSCard.java index 3c5f38a2..91245c50 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/STARCOSCard.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/STARCOSCard.java @@ -30,7 +30,6 @@ package at.gv.egiz.smcc; import at.gv.egiz.smcc.util.SMCCHelper; import java.util.Arrays; -import javax.smartcardio.Card; import javax.smartcardio.CardChannel; import javax.smartcardio.CardException; import javax.smartcardio.CommandAPDU; @@ -223,15 +222,12 @@ public class STARCOSCard extends AbstractSignatureCard implements SignatureCard //new PINSpec(4, 4, "[0-9]", getResourceBundle().getString("card.pin.name")); int retries = -1; - String pin = null; + char[] pin = null; boolean pinRequiered = false; do { if (pinRequiered) { pin = provider.providePIN(spec, retries); - if (pin == null) { - throw new CancelledException(); - } } try { getCard().beginExclusive(); @@ -240,7 +236,7 @@ public class STARCOSCard extends AbstractSignatureCard implements SignatureCard throw new NotActivatedException(); } catch (SecurityStatusNotSatisfiedException e) { pinRequiered = true; - retries = verifyPIN(null, KID_PIN_CARD); + retries = verifyPIN(KID_PIN_CARD); } catch (VerificationFailedException e) { pinRequiered = true; retries = e.getRetries(); @@ -316,20 +312,17 @@ public class STARCOSCard extends AbstractSignatureCard implements SignatureCard //new PINSpec(6, 10, "[0-9]", getResourceBundle().getString("sig.pin.name")); int retries = -1; - String pin = null; + char[] pin = null; do { try { getCard().beginExclusive(); selectFileAID(AID_DF_SS); - retries = verifyPIN(null, KID_PIN_SS); + retries = verifyPIN(KID_PIN_SS); //, null); } finally { getCard().endExclusive(); } pin = provider.providePIN(spec, retries); - if (pin == null) { - throw new CancelledException(); - } try { getCard().beginExclusive(); return createSignature(hash, AID_DF_SS, pin, KID_PIN_SS, DST_SS); @@ -349,15 +342,12 @@ public class STARCOSCard extends AbstractSignatureCard implements SignatureCard //new PINSpec(4, 4, "[0-9]", getResourceBundle().getString("card.pin.name")); int retries = -1; - String pin = null; + char[] pin = null; boolean pinRequiered = false; do { if (pinRequiered) { pin = provider.providePIN(spec, retries); - if (pin == null) { - throw new CancelledException(); - } } try { getCard().beginExclusive(); @@ -366,7 +356,7 @@ public class STARCOSCard extends AbstractSignatureCard implements SignatureCard throw new NotActivatedException(); } catch (SecurityStatusNotSatisfiedException e) { pinRequiered = true; - retries = verifyPIN(null, KID_PIN_CARD); + retries = verifyPIN(KID_PIN_CARD); } catch (VerificationFailedException e) { pinRequiered = true; retries = e.getRetries(); @@ -389,13 +379,18 @@ public class STARCOSCard extends AbstractSignatureCard implements SignatureCard } + + //////////////////////////////////////////////////////////////////////// + // PROTECTED METHODS (assume exclusive card access) + //////////////////////////////////////////////////////////////////////// + protected ResponseAPDU selectFileFID(byte[] fid) throws CardException, SignatureCardException { CardChannel channel = getCardChannel(); return transmit(channel, new CommandAPDU(0x00, 0xA4, 0x02, 0x04, fid, 256)); } - private byte[] createSignature(byte[] hash, byte[] aid, String pin, byte kid, + private byte[] createSignature(byte[] hash, byte[] aid, char[] pin, byte kid, byte[] dst) throws CardException, SignatureCardException { // SELECT MF @@ -403,7 +398,7 @@ public class STARCOSCard extends AbstractSignatureCard implements SignatureCard // SELECT DF selectFileAID(aid); // VERIFY - int retries = verifyPIN(pin, kid); + int retries = verifyPIN(kid, pin); if (retries != -1) { throw new VerificationFailedException(retries); } @@ -417,7 +412,6 @@ public class STARCOSCard extends AbstractSignatureCard implements SignatureCard } - private void selectMF() throws CardException, SignatureCardException { CardChannel channel = getCardChannel(); ResponseAPDU resp = transmit(channel, new CommandAPDU(0x00, 0xA4, 0x00, @@ -467,58 +461,85 @@ public class STARCOSCard extends AbstractSignatureCard implements SignatureCard } } - /** - * VERIFY PIN - *

- * If pin is null only the PIN status is checked and - * returned. - *

- * - * @param pin - * the PIN (may be null) - * @param kid - * the KID of the PIN to be verified - * - * @return -1 if VERIFY PIN was successful, or the number of possible retries - * - * @throws LockedException - * if the pin is locked - * @throws NotActivatedException - * if the card application has not been activated - * @throws SignatureCardException - * if VERIFY PIN fails for some other reason (card communication error) - */ @Override - public int verifyPIN(String pin, byte kid) throws LockedException, NotActivatedException, SignatureCardException { + protected int verifyPIN(byte kid, char[] pin) + throws LockedException, NotActivatedException, SignatureCardException { try { - CardChannel channel = getCardChannel(); - - ResponseAPDU resp; - if (pin == null) { - resp = transmit(channel, new CommandAPDU(0x00, 0x20, 0x00, kid)); + byte[] sw; + if (ifdSupportsFeature(FEATURE_VERIFY_PIN_DIRECT)) { + log.debug("verify PIN on IFD"); + sw = transmitControlCommand( + ifdCtrlCmds.get(FEATURE_VERIFY_PIN_DIRECT), + getPINVerifyStructure(kid)); +// int sw = (resp[resp.length-2] & 0xff) << 8 | resp[resp.length-1] & 0xff; } else { - // BCD encode PIN and marshal PIN block byte[] pinBlock = encodePINBlock(pin); - resp = transmit(channel, new CommandAPDU(0x00, 0x20, 0x00, kid, pinBlock), false); + CardChannel channel = getCardChannel(); + ResponseAPDU resp = transmit(channel, + new CommandAPDU(0x00, 0x20, 0x00, kid, pinBlock), false); + sw = new byte[2]; + sw[0] = (byte) resp.getSW1(); + sw[1] = (byte) resp.getSW2(); + } + if (sw[0] == (byte) 0x90 && sw[1] == (byte) 0x00) { + return -1; + } else if (sw[0] == (byte) 0x63 && sw[1] == (byte) 0xc0) { + throw new LockedException("[63:c0]"); + } else if (sw[0] == (byte) 0x63 && (sw[1] & 0xf0) >> 4 == 0xc) { + return sw[1] & 0x0f; + } else if (sw[0] == (byte) 0x69 && sw[1] == (byte) 0x83) { + //Authentisierungsmethode gesperrt + throw new LockedException("[69:83]"); + } else if (sw[0] == (byte) 0x69 && sw[1] == (byte) 0x84) { + //referenzierte Daten sind reversibel gesperrt (invalidated) + throw new NotActivatedException("[69:84]"); + } else if (sw[0] == (byte) 0x69 && sw[1] == (byte) 0x85) { + //Benutzungsbedingungen nicht erfüllt + throw new NotActivatedException("[69:85]"); + } else if (sw[0] == (byte) 0x64 && sw[1] == (byte) 0x00) { + throw new TimeoutException("[64:00]"); + } else if (sw[0] == (byte) 0x64 && sw[1] == (byte) 0x01) { + throw new CancelledException("[64:01]"); } + log.error("Failed to verify pin: SW=" + + SMCCHelper.toString(sw)); + throw new SignatureCardException(SMCCHelper.toString(sw)); + + } catch (CardException ex) { + log.error("smart card communication failed: " + ex.getMessage()); + throw new SignatureCardException("smart card communication failed: " + ex.getMessage(), ex); + } + } - if (resp.getSW() == 0x63c0) { - throw new LockedException("PIN locked."); - } else if (resp.getSW1() == 0x63 && resp.getSW2() >> 4 == 0xc) { - // return number of possible retries + @Override + protected int verifyPIN(byte kid) + throws LockedException, NotActivatedException, SignatureCardException { + try { + CardChannel channel = getCardChannel(); + ResponseAPDU resp = transmit(channel, + new CommandAPDU(0x00, 0x20, 0x00, kid), false); + + if (resp.getSW() == 0x9000) { + return -1; + } else if (resp.getSW() == 0x63c0) { + throw new LockedException("[63:c0]"); + } else if (resp.getSW1() == 0x63 && (resp.getSW2() & 0xf0) >> 4 == 0xc) { return resp.getSW2() & 0x0f; } else if (resp.getSW() == 0x6983) { - throw new LockedException(); + //Authentisierungsmethode gesperrt + throw new LockedException("[69:83]"); } else if (resp.getSW() == 0x6984) { - // PIN LCS = "Initialized" (-> not activated) - throw new NotActivatedException(); - } else if (resp.getSW() == 0x9000) { - return -1; // success - } else { - throw new SignatureCardException("Failed to verify pin: SW=" - + Integer.toHexString(resp.getSW())); + //referenzierte Daten sind reversibel gesperrt (invalidated) + throw new NotActivatedException("[69:84]"); + } else if (resp.getSW() == 0x6985) { + //Benutzungsbedingungen nicht erfüllt + throw new NotActivatedException("[69:85]"); } + log.error("Failed to verify pin: SW=" + + Integer.toHexString(resp.getSW())); + throw new SignatureCardException("[" + Integer.toHexString(resp.getSW()) + "]"); + } catch (CardException ex) { log.error("smart card communication failed: " + ex.getMessage()); throw new SignatureCardException("smart card communication failed: " + ex.getMessage(), ex); @@ -526,24 +547,95 @@ public class STARCOSCard extends AbstractSignatureCard implements SignatureCard } @Override - public void reset() throws SignatureCardException { + protected int changePIN(byte kid, char[] oldPin, char[] newPin) + throws LockedException, NotActivatedException, CancelledException, TimeoutException, SignatureCardException { try { - super.reset(); - log.debug("select MF (e-card workaround)"); - CardChannel channel = getCardChannel(); - ResponseAPDU resp = transmit(channel, new CommandAPDU(0x00, 0xA4, 0x00, 0x0C)); - if (resp.getSW() != 0x9000) { - throw new SignatureCardException("Failed to select MF after RESET: SW=" + Integer.toHexString(resp.getSW()) + "."); + byte[] sw; + if (ifdSupportsFeature(FEATURE_MODIFY_PIN_DIRECT)) { + log.debug("modify PIN on IFD"); + sw = transmitControlCommand( + ifdCtrlCmds.get(FEATURE_MODIFY_PIN_DIRECT), + getPINModifyStructure(kid)); +// int sw = (resp[resp.length-2] & 0xff) << 8 | resp[resp.length-1] & 0xff; + } else { + byte[] cmd = new byte[16]; + System.arraycopy(encodePINBlock(oldPin), 0, cmd, 0, 8); + System.arraycopy(encodePINBlock(newPin), 0, cmd, 8, 8); + + CardChannel channel = getCardChannel(); + + ResponseAPDU resp = transmit(channel, + new CommandAPDU(0x00, 0x24, 0x00, kid, cmd), false); + + sw = new byte[2]; + sw[0] = (byte) resp.getSW1(); + sw[1] = (byte) resp.getSW2(); + } + + // activates pin (newPIN) if not active + if (sw[0] == (byte) 0x90 && sw[1] == (byte) 0x00) { + return -1; + } else if (sw[0] == (byte) 0x63 && sw[1] == (byte) 0xc0) { + throw new LockedException("[63:c0]"); + } else if (sw[0] == (byte) 0x63 && (sw[1] & 0xf0) >> 4 == 0xc) { + return sw[1] & 0x0f; + } else if (sw[0] == (byte) 0x69 && sw[1] == (byte) 0x83) { + //Authentisierungsmethode gesperrt + throw new LockedException("[69:83]"); +// } else if (sw[0] == (byte) 0x69 && sw[1] == (byte) 0x84) { +// //referenzierte Daten sind reversibel gesperrt (invalidated) +// throw new NotActivatedException("[69:84]"); +// } else if (sw[0] == (byte) 0x69 && sw[1] == (byte) 0x85) { +// //Benutzungsbedingungen nicht erfüllt +// throw new NotActivatedException("[69:85]"); + } else if (sw[0] == (byte) 0x64 && sw[1] == (byte) 0x00) { + throw new TimeoutException("[64:00]"); + } else if (sw[0] == (byte) 0x64 && sw[1] == (byte) 0x01) { + throw new CancelledException("[64:01]"); } + log.error("Failed to change pin: SW=" + + SMCCHelper.toString(sw)); + throw new SignatureCardException(SMCCHelper.toString(sw)); } catch (CardException ex) { - log.error("Failed to select MF after RESET: " + ex.getMessage(), ex); - throw new SignatureCardException("Failed to select MF after RESET"); + log.error("smart card communication failed: " + ex.getMessage()); + throw new SignatureCardException("smart card communication failed: " + ex.getMessage(), ex); } } + @Override + protected void activatePIN(byte kid, char[] pin) + throws CancelledException, TimeoutException, SignatureCardException { + try { + CardChannel channel = getCardChannel(); + ResponseAPDU resp = transmit(channel, + new CommandAPDU(0x00, 0x24, 0x01, kid, encodePINBlock(pin)), false); + + log.trace("activate pin returned SW=" + Integer.toHexString(resp.getSW())); - public String toString() { - return "e-card"; + if (resp.getSW1() == 0x9000) { + return; + } else if (resp.getSW() == 0x6983) { + //Authentisierungsmethode gesperrt + throw new LockedException("[69:83]"); + } else if (resp.getSW() == 0x6984) { + //referenzierte Daten sind reversibel gesperrt (invalidated) + throw new NotActivatedException("[69:84]"); + } else if (resp.getSW() == 0x6985) { + //Benutzungsbedingungen nicht erfüllt + throw new NotActivatedException("[69:85]"); + } else if (resp.getSW() == 0x6400) { + throw new TimeoutException("[64:00]"); + } else if (resp.getSW() == 0x6401) { + throw new CancelledException("[64:01]"); + } + log.error("Failed to activate pin: SW=" + + Integer.toHexString(resp.getSW())); + throw new SignatureCardException("[" + Integer.toHexString(resp.getSW()) + "]"); + + } catch (CardException ex) { + log.error("smart card communication failed: " + ex.getMessage()); + throw new SignatureCardException("smart card communication failed: " + ex.getMessage(), ex); + } } /** @@ -552,17 +644,20 @@ public class STARCOSCard extends AbstractSignatureCard implements SignatureCard * @return a 8 byte pin block consisting of length byte (0x2X), * the BCD encoded pin and a 0xFF padding */ - private byte[] encodePINBlock(String pin) { - char[] pinChars = pin.toCharArray(); - int numDigits = pinChars.length; + @Override + protected byte[] encodePINBlock(char[] pin) throws SignatureCardException { + if (pin == null || pin.length > 12) { + throw new SignatureCardException("invalid pin: " + pin); + } + int numDigits = pin.length; int numBytes = (int) Math.ceil(numDigits/2.0); byte[] pinBlock = new byte[8]; pinBlock[0] = (byte) (0x20 | numDigits); for (int i = 0; i < numBytes; i++) { - int p1 = 16*Character.digit(pinChars[i*2], 16); - int p2 = (i*2+1 < numDigits) ? Character.digit(pinChars[i*2+1], 16) : 0xf; + int p1 = 16*Character.digit(pin[i*2], 16); + int p2 = (i*2+1 < numDigits) ? Character.digit(pin[i*2+1], 16) : 0xf; pinBlock[i+1] = (byte) (p1 + p2); } Arrays.fill(pinBlock, numBytes + 1, pinBlock.length, (byte) 0xff); @@ -570,111 +665,151 @@ public class STARCOSCard extends AbstractSignatureCard implements SignatureCard return pinBlock; } + + private byte[] getPINVerifyStructure(byte kid) { + + byte bTimeOut = (byte) 00; // Default time out + byte bTimeOut2 = (byte) 00; // Default time out + byte bmFormatString = (byte) 0x89; // 1 0001 0 01 + // ^------------ System unit = byte + // ^^^^------- PIN position in the frame = 1 byte + // ^----- PIN justification left + // ^^-- BCD format + byte bmPINBlockString = (byte) 0x47; // 0100 0111 + // ^^^^--------- PIN length size: 4 bits + // ^^^^---- Length PIN = 7 bytes + byte bmPINLengthFormat = (byte) 0x04; // 000 0 0100 + // ^-------- System bit units is bit + // ^^^^--- PIN length is at the 4th position bit + byte wPINMaxExtraDigitL = (byte) 0x04; // Max=4 digits + byte wPINMaxExtraDigitH = (byte) 0x04; // Min=4 digits + byte bEntryValidationCondition = 0x02; // Max size reach or Validation key pressed + byte bNumberMessage = (byte) 0x00; // No message + byte wLangIdL = (byte) 0x0C; // - English? + byte wLangIdH = (byte) 0x04; // \ + byte bMsgIndex = (byte) 0x00; // Default Msg + + byte[] apdu = new byte[] { + (byte) 0x00, (byte) 0x20, (byte) 0x00, kid, (byte) 0x08, // CLA INS P1 P2 LC + (byte) 0x20, (byte) 0xff, (byte) 0xff, (byte) 0xff, // Data + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff // ... + }; + + int offset = 0; + byte[] pinVerifyStructure = new byte[offset + 19 + apdu.length]; + pinVerifyStructure[offset++] = bTimeOut; + pinVerifyStructure[offset++] = bTimeOut2; + pinVerifyStructure[offset++] = bmFormatString; + pinVerifyStructure[offset++] = bmPINBlockString; + pinVerifyStructure[offset++] = bmPINLengthFormat; + pinVerifyStructure[offset++] = wPINMaxExtraDigitL; + pinVerifyStructure[offset++] = wPINMaxExtraDigitH; + pinVerifyStructure[offset++] = bEntryValidationCondition; + pinVerifyStructure[offset++] = bNumberMessage; + pinVerifyStructure[offset++] = wLangIdL; + pinVerifyStructure[offset++] = wLangIdH; + pinVerifyStructure[offset++] = bMsgIndex; + + pinVerifyStructure[offset++] = 0x00; + pinVerifyStructure[offset++] = 0x00; + pinVerifyStructure[offset++] = 0x00; + + pinVerifyStructure[offset++] = (byte) apdu.length; + pinVerifyStructure[offset++] = 0x00; + pinVerifyStructure[offset++] = 0x00; + pinVerifyStructure[offset++] = 0x00; + System.arraycopy(apdu, 0, pinVerifyStructure, offset, apdu.length); - @Override - public void activatePIN(PINSpec pinSpec, String pin) - throws SignatureCardException { - Card icc = getCard(); - try { - icc.beginExclusive(); - CardChannel channel = icc.getBasicChannel(); - - if (pinSpec.getContextAID() != null) { - ResponseAPDU responseAPDU = transmit(channel, - new CommandAPDU(0x00, 0xa4, 0x04, 0x0c, pinSpec.getContextAID())); - if (responseAPDU.getSW() != 0x9000) { - icc.endExclusive(); - String msg = "Select AID " + SMCCHelper.toString(pinSpec.getContextAID()) + - ": SW=" + Integer.toHexString(responseAPDU.getSW()); - log.error(msg); - throw new SignatureCardException(msg); - } - } - - ResponseAPDU responseAPDU = transmit(channel, - new CommandAPDU(0x00, 0x24, 0x01, pinSpec.getKID(), encodePINBlock(pin)), - false); - - icc.endExclusive(); - - log.debug("activate pin returned SW=" + Integer.toHexString(responseAPDU.getSW())); + return pinVerifyStructure; + } - if (responseAPDU.getSW() != 0x9000) { - String msg = "Failed to activate " + pinSpec.getLocalizedName() + - ": SW=" + Integer.toHexString(responseAPDU.getSW()); - log.error(msg); - throw new SignatureCardException(msg); - } - } catch (CardException ex) { - log.error("Failed to activate " + pinSpec.getLocalizedName() + - ": " + ex.getMessage()); - throw new SignatureCardException(ex.getMessage(), ex); - } + private byte[] getPINModifyStructure(byte kid) { + + byte bTimeOut = (byte) 00; // Default time out + byte bTimeOut2 = (byte) 00; // Default time out + byte bmFormatString = (byte) 0x89; // 1 0001 0 01 + // ^------------ System unit = byte + // ^^^^------- PIN position in the frame = 1 byte + // ^----- PIN justification left + // ^^-- BCD format + byte bmPINBlockString = (byte) 0x47; // 0100 0111 + // ^^^^--------- PIN length size: 4 bits + // ^^^^---- Length PIN = 7 bytes + byte bmPINLengthFormat = (byte) 0x04; // 000 0 0100 + // ^-------- System bit units is bit + // ^^^^--- PIN length is at the 4th position bit + byte bInsertionOffsetOld = (byte) 0x01; // insertion position offset in bytes + byte bInsertionOffsetNew = (byte) 0x08; // insertion position offset in bytes + byte wPINMaxExtraDigitL = (byte) 0x04; // Min=4 digits + byte wPINMaxExtraDigitH = (byte) 0x04; // Max=12 digits + byte bConfirmPIN = (byte) 0x00; // ??? need for confirm pin + byte bEntryValidationCondition = 0x02; // Max size reach or Validation key pressed + byte bNumberMessage = (byte) 0x00; // No message + byte wLangIdL = (byte) 0x0C; // - English? + byte wLangIdH = (byte) 0x04; // \ + byte bMsgIndex1 = (byte) 0x00; // Default Msg + byte bMsgIndex2 = (byte) 0x00; // Default Msg + byte bMsgIndex3 = (byte) 0x00; // Default Msg + + byte[] apdu = new byte[] { + (byte) 0x00, (byte) 0x24, (byte) 0x00, kid, (byte) 0x10, // CLA INS P1 P2 LC + (byte) 0x20, (byte) 0xff, (byte) 0xff, (byte) 0xff, // Data + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, // ... + (byte) 0x20, (byte) 0xff, (byte) 0xff, (byte) 0xff, // Data + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff // ... + }; + + int offset = 0; + byte[] pinModifyStructure = new byte[offset + 24 + apdu.length]; + pinModifyStructure[offset++] = bTimeOut; + pinModifyStructure[offset++] = bTimeOut2; + pinModifyStructure[offset++] = bmFormatString; + pinModifyStructure[offset++] = bmPINBlockString; + pinModifyStructure[offset++] = bmPINLengthFormat; + pinModifyStructure[offset++] = bInsertionOffsetOld; + pinModifyStructure[offset++] = bInsertionOffsetNew; + pinModifyStructure[offset++] = wPINMaxExtraDigitL; + pinModifyStructure[offset++] = wPINMaxExtraDigitH; + pinModifyStructure[offset++] = bConfirmPIN; + pinModifyStructure[offset++] = bEntryValidationCondition; + pinModifyStructure[offset++] = bNumberMessage; + pinModifyStructure[offset++] = wLangIdL; + pinModifyStructure[offset++] = wLangIdH; + pinModifyStructure[offset++] = bMsgIndex1; + pinModifyStructure[offset++] = bMsgIndex2; + pinModifyStructure[offset++] = bMsgIndex3; + + pinModifyStructure[offset++] = 0x00; + pinModifyStructure[offset++] = 0x00; + pinModifyStructure[offset++] = 0x00; + + pinModifyStructure[offset++] = (byte) apdu.length; + pinModifyStructure[offset++] = 0x00; + pinModifyStructure[offset++] = 0x00; + pinModifyStructure[offset++] = 0x00; + System.arraycopy(apdu, 0, pinModifyStructure, offset, apdu.length); + +// log.debug("PIN MODIFY " + SMCCHelper.toString(pinModifyStructure)); + return pinModifyStructure; } - /** - * activates pin (newPIN) if not active - * @param pinSpec - * @param oldPIN - * @param newPIN - * @throws at.gv.egiz.smcc.LockedException - * @throws at.gv.egiz.smcc.VerificationFailedException - * @throws at.gv.egiz.smcc.NotActivatedException - * @throws at.gv.egiz.smcc.SignatureCardException - */ @Override - public void changePIN(PINSpec pinSpec, String oldPIN, String newPIN) - throws LockedException, VerificationFailedException, NotActivatedException, SignatureCardException { - Card icc = getCard(); + public void reset() throws SignatureCardException { try { - icc.beginExclusive(); - CardChannel channel = icc.getBasicChannel(); - - if (pinSpec.getContextAID() != null) { - ResponseAPDU responseAPDU = transmit(channel, - new CommandAPDU(0x00, 0xa4, 0x04, 0x0c, pinSpec.getContextAID())); - if (responseAPDU.getSW() != 0x9000) { - icc.endExclusive(); - String msg = "Select AID " + SMCCHelper.toString(pinSpec.getContextAID()) + - ": SW=" + Integer.toHexString(responseAPDU.getSW()); - log.error(msg); - throw new SignatureCardException(msg); - } - } - - byte[] cmd = new byte[16]; - System.arraycopy(encodePINBlock(oldPIN), 0, cmd, 0, 8); - System.arraycopy(encodePINBlock(newPIN), 0, cmd, 8, 8); - - ResponseAPDU responseAPDU = transmit(channel, - new CommandAPDU(0x00, 0x24, 0x00, pinSpec.getKID(), cmd), false); - - icc.endExclusive(); - - log.debug("change pin returned SW=" + Integer.toHexString(responseAPDU.getSW())); - - // activates pin (newPIN) if not active - if (responseAPDU.getSW() == 0x63c0) { - log.error(pinSpec.getLocalizedName() + " locked"); - throw new LockedException(); - } else if (responseAPDU.getSW1() == 0x63 && responseAPDU.getSW2() >> 4 == 0xc) { - int retries = responseAPDU.getSW2() & 0x0f; - log.error("wrong " + pinSpec.getLocalizedName() + ", " + retries + " retries"); - throw new VerificationFailedException(retries); - } else if (responseAPDU.getSW() == 0x6983) { - log.error(pinSpec.getLocalizedName() + " locked"); - throw new LockedException(); - } else if (responseAPDU.getSW() != 0x9000) { - String msg = "Failed to change " + pinSpec.getLocalizedName() + - ": SW=" + Integer.toHexString(responseAPDU.getSW()); - log.error(msg); - throw new SignatureCardException(msg); + super.reset(); + log.debug("select MF (e-card workaround)"); + CardChannel channel = getCardChannel(); + ResponseAPDU resp = transmit(channel, new CommandAPDU(0x00, 0xA4, 0x00, 0x0C)); + if (resp.getSW() != 0x9000) { + throw new SignatureCardException("Failed to select MF after RESET: SW=" + Integer.toHexString(resp.getSW()) + "."); } } catch (CardException ex) { - log.error("Failed to change " + pinSpec.getLocalizedName() + - ": " + ex.getMessage()); - throw new SignatureCardException(ex.getMessage(), ex); + log.error("Failed to select MF after RESET: " + ex.getMessage(), ex); + throw new SignatureCardException("Failed to select MF after RESET"); } } + public String toString() { + return "e-card"; + } } diff --git a/smcc/src/main/java/at/gv/egiz/smcc/SWCard.java b/smcc/src/main/java/at/gv/egiz/smcc/SWCard.java index d7763be0..293b9c71 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/SWCard.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/SWCard.java @@ -77,11 +77,11 @@ public class SWCard implements SignatureCard { private KeyStore certifiedKeyStore; - private String certifiedKeyStorePassword; + private char[] certifiedKeyStorePassword; private KeyStore secureKeyStore; - private String secureKeyStorePassword; + private char[] secureKeyStorePassword; private Certificate certifiedCertificate; @@ -195,7 +195,7 @@ public class SWCard implements SignatureCard { } - private String loadKeyStorePassword(String passwordFileName) throws SignatureCardException { + private char[] loadKeyStorePassword(String passwordFileName) throws SignatureCardException { String fileName = getFileName(passwordFileName); FileInputStream keyStorePasswordFile; @@ -212,7 +212,7 @@ public class SWCard implements SignatureCard { for (int l; (l = reader.read(b)) != -1;) { sb.append(b, 0, l); } - return sb.toString(); + return sb.toString().toCharArray(); } catch (IOException e) { throw new SignatureCardException("Failed to read file '" + passwordFileName + "'."); } @@ -237,7 +237,7 @@ public class SWCard implements SignatureCard { } - private String getPassword(KeyboxName keyboxName) throws SignatureCardException { + private char[] getPassword(KeyboxName keyboxName) throws SignatureCardException { if (keyboxName == KeyboxName.CERITIFIED_KEYPAIR) { if (certifiedKeyStorePassword == null) { @@ -311,7 +311,7 @@ public class SWCard implements SignatureCard { public byte[] createSignature(byte[] hash, KeyboxName keyboxName, PINProvider provider) throws SignatureCardException, InterruptedException { // KeyStore password - String password = getPassword(keyboxName); + char[] password = getPassword(keyboxName); if (password == null) { @@ -325,7 +325,7 @@ public class SWCard implements SignatureCard { } - KeyStore keyStore = getKeyStore(keyboxName, password.toCharArray()); + KeyStore keyStore = getKeyStore(keyboxName, password); PrivateKey privateKey = null; @@ -338,7 +338,7 @@ public class SWCard implements SignatureCard { Key key = null; while (key == null) { try { - key = keyStore.getKey(alias, password.toCharArray()); + key = keyStore.getKey(alias, password); } catch (UnrecoverableKeyException e) { log.info("Failed to get Key from KeyStore. Wrong password?", e); } @@ -399,15 +399,27 @@ public class SWCard implements SignatureCard { } @Override - public int verifyPIN(PINSpec pinSpec, String pin) throws LockedException, NotActivatedException, SignatureCardException { - return -1; + public void verifyPIN(PINSpec pinSpec, PINProvider pinProvider) + throws LockedException, NotActivatedException, SignatureCardException { } @Override - public void changePIN(PINSpec pinSpec, String oldPIN, String newPIN) throws LockedException, VerificationFailedException, NotActivatedException, SignatureCardException { + public void activatePIN(PINSpec pinSpec, PINProvider pinProvider) throws SignatureCardException { + throw new UnsupportedOperationException("Not supported yet."); } @Override - public void activatePIN(PINSpec pinSpec, String pin) throws SignatureCardException { + public void unblockPIN(PINSpec pinSpec, PINProvider pukProvider) throws CancelledException, SignatureCardException, InterruptedException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void changePIN(PINSpec pinSpec, ChangePINProvider pinProvider) throws LockedException, NotActivatedException, CancelledException, SignatureCardException, InterruptedException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean ifdSupportsFeature(byte feature) { + return false; } } diff --git a/smcc/src/main/java/at/gv/egiz/smcc/SignatureCard.java b/smcc/src/main/java/at/gv/egiz/smcc/SignatureCard.java index 3c2273b9..2097e6d3 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/SignatureCard.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/SignatureCard.java @@ -36,6 +36,14 @@ import javax.smartcardio.CardTerminal; public interface SignatureCard { + /** + * IFD FEATURES + */ + static final Byte FEATURE_VERIFY_PIN_DIRECT = new Byte((byte) 0x06); + static final Byte FEATURE_MODIFY_PIN_DIRECT = new Byte((byte) 0x07); + static final Byte FEATURE_MCT_READER_DIRECT = new Byte((byte) 0x08); + static final Byte FEATURE_IFD_PIN_PROPERTIES = new Byte((byte) 0x0a); + public static class KeyboxName { public static KeyboxName SECURE_SIGNATURE_KEYPAIR = new KeyboxName( @@ -123,29 +131,29 @@ public interface SignatureCard { */ public List getPINSpecs(); - /** - * - * @param pinSpec descriptor which pin to verify - * @param pin may be null to test the PIN status - * @return the number of remaining retries or -1 - * @throws at.gv.egiz.smcc.LockedException - * @throws at.gv.egiz.smcc.NotActivatedException - * @throws at.gv.egiz.smcc.SignatureCardException - */ - public int verifyPIN(PINSpec pinSpec, String pin) - throws LockedException, NotActivatedException, SignatureCardException; + public void verifyPIN(PINSpec pinSpec, PINProvider pinProvider) + throws LockedException, NotActivatedException, CancelledException, SignatureCardException, InterruptedException; - public void changePIN(PINSpec pinSpec, String oldPIN, String newPIN) - throws LockedException, VerificationFailedException, NotActivatedException, SignatureCardException; + public void changePIN(PINSpec pinSpec, ChangePINProvider pinProvider) + throws LockedException, NotActivatedException, CancelledException, SignatureCardException, InterruptedException; - public void activatePIN(PINSpec pinSpec, String pin) - throws SignatureCardException; + public void activatePIN(PINSpec pinSpec, PINProvider pinProvider) + throws CancelledException, SignatureCardException, InterruptedException; + + public void unblockPIN(PINSpec pinSpec, PINProvider pukProvider) + throws CancelledException, SignatureCardException, InterruptedException; + + /** + * TODO + * @return + */ + public boolean ifdSupportsFeature(byte feature); /** * Sets the local for evtl. required callbacks (e.g. PINSpec) * @param locale must not be null; */ public void setLocale(Locale locale); - - + + } diff --git a/smcc/src/main/java/at/gv/egiz/smcc/SignatureCardFactory.java b/smcc/src/main/java/at/gv/egiz/smcc/SignatureCardFactory.java index ab66e9a1..5146c275 100644 --- a/smcc/src/main/java/at/gv/egiz/smcc/SignatureCardFactory.java +++ b/smcc/src/main/java/at/gv/egiz/smcc/SignatureCardFactory.java @@ -196,7 +196,7 @@ public class SignatureCardFactory { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }, "at.gv.egiz.smcc.ACOSCard")); - + } /** diff --git a/smcc/src/main/java/at/gv/egiz/smcc/TimeoutException.java b/smcc/src/main/java/at/gv/egiz/smcc/TimeoutException.java new file mode 100644 index 00000000..d14a4c15 --- /dev/null +++ b/smcc/src/main/java/at/gv/egiz/smcc/TimeoutException.java @@ -0,0 +1,39 @@ +/* +* 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.smcc; + +public class TimeoutException extends SignatureCardException { + + private static final long serialVersionUID = 1L; + + public TimeoutException() { + super(); + } + + public TimeoutException(String message, Throwable cause) { + super(message, cause); + } + + public TimeoutException(String message) { + super(message); + } + + public TimeoutException(Throwable cause) { + super(cause); + } + +} diff --git a/smcc/src/test/resources/log4j.properties b/smcc/src/test/resources/log4j.properties index 94662fd2..053eac17 100644 --- a/smcc/src/test/resources/log4j.properties +++ b/smcc/src/test/resources/log4j.properties @@ -1,5 +1,5 @@ # loglever DEBUG, appender STDOUT -log4j.rootLogger=DEBUG, STDOUT +log4j.rootLogger=TRACE, STDOUT #log4j.logger.at.gv.egiz.slbinding.RedirectEventFilter=DEBUG, STDOUT # STDOUT appender diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java index 23b71690..14b36e28 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractBKUWorker.java @@ -136,7 +136,9 @@ public abstract class AbstractBKUWorker extends AbstractSMCCSTAL implements Acti if (oldValue != SMCCHelper.CARD_NOT_SUPPORTED) { actionCommandList.clear(); actionCommandList.add("cancel"); - gui.showCardNotSupportedDialog(this, "cancel"); + gui.showMessageDialog(BKUGUIFacade.TITLE_CARD_NOT_SUPPORTED, + BKUGUIFacade.MESSAGE_CARD_NOT_SUPPORTED, null, + BKUGUIFacade.BUTTON_CANCEL, this, "cancel"); oldValue = SMCCHelper.CARD_NOT_SUPPORTED; } break; @@ -144,7 +146,9 @@ public abstract class AbstractBKUWorker extends AbstractSMCCSTAL implements Acti if (oldValue != SMCCHelper.NO_CARD) { actionCommandList.clear(); actionCommandList.add("cancel"); - gui.showInsertCardDialog(this, "cancel"); + gui.showMessageDialog(BKUGUIFacade.TITLE_INSERTCARD, + BKUGUIFacade.MESSAGE_INSERTCARD, null, + BKUGUIFacade.BUTTON_CANCEL, this, "cancel"); oldValue = SMCCHelper.NO_CARD; } break; diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractPINProvider.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractPINProvider.java new file mode 100644 index 00000000..e32f08d4 --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractPINProvider.java @@ -0,0 +1,67 @@ +/* + * 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; + +import at.gv.egiz.smcc.PINProvider; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author Clemens Orthacker + */ +public abstract class AbstractPINProvider implements PINProvider, ActionListener { + + protected static final Log log = LogFactory.getLog(AbstractPINProvider.class); + + protected boolean retry = false; + + protected String action; + + private boolean actionPerformed; + +// protected void waitForAction() throws InterruptedException { +// super.wait(); +// } + + protected synchronized void waitForAction() throws InterruptedException { + try { + while (!actionPerformed) { + this.wait(); + } + } catch (InterruptedException e) { + log.error("interrupt in waitForAction"); + throw e; + } + actionPerformed = false; + } + + private synchronized void actionPerformed() { + actionPerformed = true; + notify();//All(); + } + + @Override + public void actionPerformed(ActionEvent e) { + log.debug("command " + e.getActionCommand()); + action = e.getActionCommand(); + actionPerformed(); + } +} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java index 1cf81e05..71f35181 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/AbstractSMCCSTAL.java @@ -121,6 +121,12 @@ public abstract class AbstractSMCCSTAL implements STAL { return new ErrorResponse(6000); } + /** + * + * @param requestList + * @return + * @throws RuntimeException with cause InterruptedException if interrupted + */ @Override public List handleRequest(List requestList) { log.debug("Got request list containing " + requestList.size() diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java index 5a54e97f..94444922 100644 --- a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/InfoBoxReadRequestHandler.java @@ -33,23 +33,26 @@ import at.gv.egiz.stal.InfoboxReadResponse; import at.gv.egiz.stal.STALRequest; import at.gv.egiz.stal.STALResponse; -public class InfoBoxReadRequestHandler extends AbstractRequestHandler implements - PINProvider { +public class InfoBoxReadRequestHandler extends AbstractRequestHandler { private static Log log = LogFactory.getLog(InfoBoxReadRequestHandler.class); - private int retryCounter = 0; + protected PINProviderFactory pinProviderFactory; @Override public STALResponse handleRequest(STALRequest request) throws InterruptedException { if (request instanceof InfoboxReadRequest) { InfoboxReadRequest infoBox = (InfoboxReadRequest) request; + if (pinProviderFactory == null) { + pinProviderFactory = PINProviderFactory.getInstance(card, gui); + } try { if (infoBox.getInfoboxIdentifier().equals("IdentityLink")) { newSTALMessage("Message.RequestCaption", "Message.IdentityLink"); log.debug("Handling identitylink infobox"); - byte[] resp = card.getInfobox(infoBox.getInfoboxIdentifier(), this, - infoBox.getDomainIdentifier()); + byte[] resp = card.getInfobox(infoBox.getInfoboxIdentifier(), + pinProviderFactory.getCardPINProvider(), + infoBox.getDomainIdentifier()); if (resp == null) { log.info("Got null as result->user cancelled"); return new ErrorResponse(6001); @@ -94,8 +97,9 @@ public class InfoBoxReadRequestHandler extends AbstractRequestHandler implements newSTALMessage("Message.RequestCaption", "Message.InfoboxReadRequest"); log.warn("Unknown infobox identifier: " + infoBox.getInfoboxIdentifier() + " trying generic request"); - byte[] resp = card.getInfobox(infoBox.getInfoboxIdentifier(), this, - infoBox.getDomainIdentifier()); + byte[] resp = card.getInfobox(infoBox.getInfoboxIdentifier(), + pinProviderFactory.getCardPINProvider(), + infoBox.getDomainIdentifier()); if (resp == null) { return new ErrorResponse(6001); } @@ -110,13 +114,15 @@ public class InfoBoxReadRequestHandler extends AbstractRequestHandler implements log.info("Citizen card not activated.", e); gui.showErrorDialog(BKUGUIFacade.ERR_CARD_NOTACTIVATED, null, this, null); waitForAction(); - gui.showWaitDialog(null); + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); return new ErrorResponse(6001); } catch (LockedException e) { log.info("Citizen card locked.", e); gui.showErrorDialog(BKUGUIFacade.ERR_CARD_LOCKED, null, this, null); waitForAction(); - gui.showWaitDialog(null); + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); return new ErrorResponse(6001); } catch (CancelledException cx) { log.debug("User cancelled request", cx); @@ -135,20 +141,4 @@ public class InfoBoxReadRequestHandler extends AbstractRequestHandler implements public boolean requireCard() { return true; } - - @Override - public String providePIN(PINSpec spec, int retries) throws InterruptedException { - if (retryCounter++ > 0) { - log.info("PIN wrong retrying ..."); - gui.showCardPINRetryDialog(spec, retries, this, "ok", this, "cancel"); - } else { - gui.showCardPINDialog(spec, this, "ok", this, "cancel"); - } - waitForAction(); - gui.showWaitDialog(null); - if (actionCommand.equals("cancel")) { - return null; - } - return new String(gui.getPin()); - } } diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.java new file mode 100644 index 00000000..670b71dc --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PINProviderFactory.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.smccstal; + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.smcc.PINProvider; +import at.gv.egiz.smcc.SignatureCard; +import at.gv.egiz.stal.signedinfo.SignedInfoType; + +/** + * + * @author Clemens Orthacker + */ +public abstract class PINProviderFactory { + + BKUGUIFacade gui; + + public static PINProviderFactory getInstance(SignatureCard forCard, + BKUGUIFacade gui) { + if (forCard.ifdSupportsFeature(SignatureCard.FEATURE_VERIFY_PIN_DIRECT)) { + return new PinpadPINProviderFactory(gui); + } else { + return new SoftwarePINProviderFactory(gui); + } + } + + public abstract PINProvider getSignaturePINProvider(SecureViewer viewer, + SignedInfoType signedInfo); + + public abstract PINProvider getCardPINProvider(); + +} diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PinpadPINProviderFactory.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PinpadPINProviderFactory.java new file mode 100644 index 00000000..55321b72 --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/PinpadPINProviderFactory.java @@ -0,0 +1,155 @@ +/* + * 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; + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.smcc.CancelledException; +import at.gv.egiz.smcc.PINProvider; +import at.gv.egiz.smcc.PINSpec; +import at.gv.egiz.stal.HashDataInput; +import at.gv.egiz.stal.signedinfo.SignedInfoType; +import java.util.List; + +/** + * + * @author Clemens Orthacker + */ +public class PinpadPINProviderFactory extends PINProviderFactory { + + protected PinpadPINProviderFactory(BKUGUIFacade gui) { + this.gui = gui; + } + + @Override + public PINProvider getSignaturePINProvider(SecureViewer viewer, + SignedInfoType signedInfo) { + + return new SignaturePinProvider(viewer, signedInfo); + } + + @Override + public PINProvider getCardPINProvider() { + return new CardPinProvider(); + } + + class SignaturePinProvider extends AbstractPINProvider { + +// protected BKUGUIFacade gui; + protected SecureViewer viewer; + protected SignedInfoType signedInfo; + protected List hashDataInputs; + + private SignaturePinProvider(SecureViewer viewer, + SignedInfoType signedInfo) { + this.viewer = viewer; + this.signedInfo = signedInfo; + } + + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + + showPinpadPINDialog(retries, spec); + retry = true; + return null; + +// do { +// waitForAction(); +// gui.showWaitDialog(null); +// +// if ("hashData".equals(action)) { +// // show pin dialog in background +// gui.showSignaturePINDialog(spec, (retry) ? retries : -1, +// this, "sign", +// this, "cancel", +// this, "hashData"); +// +// viewer.displayDataToBeSigned(signedInfo.getReference()); +// +// } else if ("sign".equals(action)) { +// retry = true; +// return gui.getPin(); +// } else if ("hashDataDone".equals(action)) { +// gui.showSignaturePINDialog(spec, (retry) ? retries : -1, +// this, "sign", +// this, "cancel", +// this, "hashData"); +// } else if ("cancel".equals(action) || +// "error".equals(action)) { +// throw new CancelledException(spec.getLocalizedName() + +// " entry cancelled"); +// } +// } while (true); + } + + private void showPinpadPINDialog(int retries, PINSpec pinSpec) { + String title, message; + Object[] params; + if (retry) { + title = BKUGUIFacade.TITLE_RETRY; + message = BKUGUIFacade.MESSAGE_RETRIES; + params = new Object[]{String.valueOf(retries)}; + } else { + title = BKUGUIFacade.TITLE_SIGN; + message = BKUGUIFacade.MESSAGE_ENTERPIN_PINPAD; + String pinSize = String.valueOf(pinSpec.getMinLength()); + if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { + pinSize += "-" + pinSpec.getMaxLength(); + } + params = new Object[]{pinSpec.getLocalizedName(), pinSize}; + } + gui.showMessageDialog(title, message, params); + } + } + + class CardPinProvider extends AbstractPINProvider { + + private CardPinProvider() { + } + + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + + showPinpadPINDialog(retries, spec); + retry = true; + return null; + + } + + private void showPinpadPINDialog(int retries, PINSpec pinSpec) { + String title, message; + Object[] params; + if (retry) { + title = BKUGUIFacade.TITLE_RETRY; + message = BKUGUIFacade.MESSAGE_RETRIES; + params = new Object[]{String.valueOf(retries)}; + } else { + title = BKUGUIFacade.TITLE_CARDPIN; + message = BKUGUIFacade.MESSAGE_ENTERPIN_PINPAD; + String pinSize = String.valueOf(pinSpec.getMinLength()); + if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { + pinSize += "-" + pinSpec.getMaxLength(); + } + params = new Object[]{pinSpec.getLocalizedName(), pinSize}; + } + gui.showMessageDialog(title, message, params); + } + } +} + diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SecureViewer.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SecureViewer.java new file mode 100644 index 00000000..c395679a --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SecureViewer.java @@ -0,0 +1,44 @@ +/* + * 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; + +import at.gv.egiz.stal.signedinfo.ReferenceType; +import java.security.DigestException; +import java.util.List; + +/** + * + * @author Clemens Orthacker + */ +public interface SecureViewer { + + /** + * Displays the hashdata inputs for all provided dsig:SignedReferences. + * Implementations may verify the digest value if necessary. + * (LocalSignRequestHandler operates on DataObjectHashDataInput, + * other SignRequestHandlers should cache the HashDataInputs obtained by webservice calls, + * or simply forward to a HashDataInputServlet.) + * @param signedReferences The caller may select a subset of the references in SignedInfo to be displayed. + * @throws java.security.DigestException if digest values are verified and do not correspond + * (or any other digest computation error occurs) + * @throws java.lang.Exception + */ + void displayDataToBeSigned(List signedReferences) + throws DigestException, Exception; + +} 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 d041a8cb..ac510f38 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 @@ -17,7 +17,6 @@ package at.gv.egiz.bku.smccstal; import at.gv.egiz.bku.gui.BKUGUIFacade; -import java.awt.event.ActionEvent; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.security.MessageDigest; @@ -35,12 +34,11 @@ import at.gv.egiz.smcc.CancelledException; import at.gv.egiz.smcc.LockedException; import at.gv.egiz.smcc.NotActivatedException; import at.gv.egiz.smcc.PINProvider; -import at.gv.egiz.smcc.PINSpec; import at.gv.egiz.smcc.SignatureCard; import at.gv.egiz.smcc.SignatureCardException; import at.gv.egiz.smcc.SignatureCard.KeyboxName; +import at.gv.egiz.smcc.TimeoutException; import at.gv.egiz.stal.ErrorResponse; -import at.gv.egiz.stal.HashDataInput; import at.gv.egiz.stal.STALRequest; import at.gv.egiz.stal.STALResponse; import at.gv.egiz.stal.SignRequest; @@ -48,13 +46,12 @@ import at.gv.egiz.stal.SignResponse; import at.gv.egiz.stal.signedinfo.ObjectFactory; import at.gv.egiz.stal.signedinfo.SignedInfoType; import at.gv.egiz.stal.util.JCEAlgorithmNames; -import java.security.DigestException; -import java.util.List; -public abstract class SignRequestHandler extends AbstractRequestHandler implements HashDataInputDisplay { +public abstract class SignRequestHandler extends AbstractRequestHandler implements SecureViewer { private static Log log = LogFactory.getLog(SignRequestHandler.class); private static JAXBContext jaxbContext; + private PINProviderFactory pinProviderFactory; static { try { @@ -84,7 +81,14 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen MessageDigest md = MessageDigest.getInstance(jceName); md.update(signReq.getSignedInfo()); KeyboxName kb = SignatureCard.KeyboxName.getKeyboxName(signReq.getKeyIdentifier()); - byte[] resp = card.createSignature(md.digest(), kb, new STALPinProvider(si.getValue())); + + if (pinProviderFactory == null) { + pinProviderFactory = PINProviderFactory.getInstance(card, gui); + } + PINProvider pinProvider = pinProviderFactory. + getSignaturePINProvider(this, si.getValue()); + + byte[] resp = card.createSignature(md.digest(), kb, pinProvider); if (resp == null) { return new ErrorResponse(6001); } @@ -95,17 +99,28 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen log.info("Citizen card not activated.", e); gui.showErrorDialog(BKUGUIFacade.ERR_CARD_NOTACTIVATED, null, this, null); waitForAction(); - gui.showWaitDialog(null); + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); return new ErrorResponse(6001); } catch (LockedException e) { log.info("Citizen card locked.", e); gui.showErrorDialog(BKUGUIFacade.ERR_CARD_LOCKED, null, this, null); waitForAction(); - gui.showWaitDialog(null); + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); return new ErrorResponse(6001); } catch (CancelledException cx) { log.debug("User cancelled request"); return new ErrorResponse(6001); + } catch (TimeoutException ex) { + log.error("Timeout during pin entry"); + gui.showMessageDialog(BKUGUIFacade.TITLE_ENTRY_TIMEOUT, + BKUGUIFacade.ERR_PIN_TIMEOUT, null, + BKUGUIFacade.BUTTON_CANCEL, this, null); + waitForAction(); + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); + return new ErrorResponse(6001); } catch (SignatureCardException e) { log.error("Error while creating signature: " + e); return new ErrorResponse(4000); @@ -127,64 +142,64 @@ public abstract class SignRequestHandler extends AbstractRequestHandler implemen return true; } - class STALPinProvider implements PINProvider { - - protected SignedInfoType signedInfo; - protected List hashDataInputs; - private int retryCounter = 0; - - public STALPinProvider(SignedInfoType signedInfo) { - this.signedInfo = signedInfo; - } - - private void showSignaturePINDialog(PINSpec spec, int retries) { - if (retryCounter > 0) { - gui.showSignaturePINRetryDialog(spec, retries, SignRequestHandler.this, "sign", SignRequestHandler.this, - "cancel", SignRequestHandler.this, "hashData"); - } else { - gui.showSignaturePINDialog(spec, SignRequestHandler.this, "sign", SignRequestHandler.this, "cancel", SignRequestHandler.this, - "hashData"); - } - } - - @Override - public String providePIN(PINSpec spec, int retries) throws InterruptedException { - - showSignaturePINDialog(spec, retries); - - do { - waitForAction(); - gui.showWaitDialog(null); - if (actionCommand.equals("cancel")) { - return null; - } else if (actionCommand.equals("hashData")) { - - showSignaturePINDialog(spec, retries); - - try { - displayHashDataInputs(signedInfo.getReference()); - } catch (DigestException ex) { - log.error("Bad digest value: " + 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, "error"); - } - - } else if (actionCommand.equals("sign")) { - retryCounter++; - return new String(gui.getPin()); - } else if (actionCommand.equals("hashDataDone")) { - showSignaturePINDialog(spec, retries); - } else if (actionCommand.equals("error")) { - return null; - } - } while (true); - } - +// class SoftwarePinProvider implements PINProvider { +// +// protected SignedInfoType signedInfo; +// protected List hashDataInputs; +// private boolean retry = false; +// +// public SoftwarePinProvider(SignedInfoType signedInfo) { +// this.signedInfo = signedInfo; +// } +// +// private void showSignaturePINDialog(PINSpec spec, int retries) { +// if (retry) { +// gui.showSignaturePINRetryDialog(spec, retries, SignRequestHandler.this, "sign", SignRequestHandler.this, +// "cancel", SignRequestHandler.this, "hashData"); +// } else { +// gui.showSignaturePINDialog(spec, SignRequestHandler.this, "sign", SignRequestHandler.this, "cancel", SignRequestHandler.this, +// "hashData"); +// } +// } +// // @Override -// public void actionPerformed(ActionEvent e) { -// throw new UnsupportedOperationException("Not supported yet."); +// public char[] providePIN(PINSpec spec, int retries) +// throws CancelledException, InterruptedException { +// showSignaturePINDialog(spec, retries); +// +// do { +// waitForAction(); +// gui.showWaitDialog(null); +// if (actionCommand.equals("hashData")) { +// +// showSignaturePINDialog(spec, retries); +// +// try { +// displayHashDataInputs(signedInfo.getReference()); +// +// } catch (DigestException ex) { +// log.error("Bad digest value: " + 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, "error"); +// } +// } else if (actionCommand.equals("sign")) { +// retry = true; +// return gui.getPin(); +// } else if (actionCommand.equals("hashDataDone")) { +// showSignaturePINDialog(spec, retries); +// } else if (actionCommand.equals("cancel") || +// actionCommand.equals("error")) { +// throw new CancelledException(spec.getLocalizedName() + +// " entry cancelled"); +// } +// } while (true); // } - } +// } } diff --git a/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SoftwarePINProviderFactory.java b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SoftwarePINProviderFactory.java new file mode 100644 index 00000000..54a34280 --- /dev/null +++ b/smccSTAL/src/main/java/at/gv/egiz/bku/smccstal/SoftwarePINProviderFactory.java @@ -0,0 +1,140 @@ +/* + * 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; + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.smcc.*; +import at.gv.egiz.stal.HashDataInput; +import at.gv.egiz.stal.signedinfo.SignedInfoType; +import java.security.DigestException; +import java.util.List; + +/** + * + * @author Clemens Orthacker + */ +public class SoftwarePINProviderFactory extends PINProviderFactory { + + protected SoftwarePINProviderFactory(BKUGUIFacade gui) { + this.gui = gui; + } + + @Override + public PINProvider getSignaturePINProvider(SecureViewer viewer, + SignedInfoType signedInfo) { + return new SignaturePinProvider(viewer, signedInfo); + } + + @Override + public PINProvider getCardPINProvider() { + return new CardPinProvider(); + } + + class SignaturePinProvider extends AbstractPINProvider { + +// protected BKUGUIFacade gui; + protected SecureViewer viewer; + protected SignedInfoType signedInfo; + protected List hashDataInputs; + + private SignaturePinProvider(SecureViewer viewer, + SignedInfoType signedInfo) { + this.viewer = viewer; + this.signedInfo = signedInfo; + } + + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + + gui.showSignaturePINDialog(spec, (retry) ? retries : -1, + this, "sign", + this, "cancel", + this, "hashData"); + + do { + waitForAction(); + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); + + if ("hashData".equals(action)) { + // show pin dialog in background + gui.showSignaturePINDialog(spec, (retry) ? retries : -1, + this, "sign", + this, "cancel", + this, "hashData"); + + try { + viewer.displayDataToBeSigned(signedInfo.getReference()); + } catch (DigestException ex) { + log.error("Bad digest value: " + ex.getMessage()); + gui.showErrorDialog(BKUGUIFacade.ERR_INVALID_HASH, + new Object[]{ex.getMessage()}, + this, "error"); + } catch (Exception ex) { + log.error("Could not display hashdata inputs: " + + ex.getMessage()); + gui.showErrorDialog(BKUGUIFacade.ERR_DISPLAY_HASHDATA, + new Object[]{ex.getMessage()}, + this, "error"); + } + } else if ("sign".equals(action)) { + retry = true; + return gui.getPin(); + } else if ("hashDataDone".equals(action)) { + gui.showSignaturePINDialog(spec, (retry) ? retries : -1, + this, "sign", + this, "cancel", + this, "hashData"); + } else if ("cancel".equals(action) || + "error".equals(action)) { + throw new CancelledException(spec.getLocalizedName() + + " entry cancelled"); + } + } while (true); + } + } + + class CardPinProvider extends AbstractPINProvider { + +// protected BKUGUIFacade gui; + + private CardPinProvider() { + } + + @Override + public char[] providePIN(PINSpec spec, int retries) + throws CancelledException, InterruptedException { + + gui.showCardPINDialog(spec, (retry) ? retries : -1, + this, "ok", + this, "cancel"); + + waitForAction(); + + gui.showMessageDialog(BKUGUIFacade.TITLE_WAIT, + BKUGUIFacade.MESSAGE_WAIT); + + if ("cancel".equals(action)) { + throw new CancelledException(spec.getLocalizedName() + + " entry cancelled"); + } + retry = true; + return gui.getPin(); + } + } +} diff --git a/smccSTAL/src/test/java/at/gv/egiz/smcc/AbstractSMCCSTALTest.java b/smccSTAL/src/test/java/at/gv/egiz/smcc/AbstractSMCCSTALTest.java index b2a91784..51dfe0da 100644 --- a/smccSTAL/src/test/java/at/gv/egiz/smcc/AbstractSMCCSTALTest.java +++ b/smccSTAL/src/test/java/at/gv/egiz/smcc/AbstractSMCCSTALTest.java @@ -93,16 +93,24 @@ public class AbstractSMCCSTALTest extends AbstractSMCCSTAL implements } @Override - public int verifyPIN(PINSpec pinSpec, String pin) throws LockedException, NotActivatedException, SignatureCardException { - return -1; + public void verifyPIN(PINSpec pinSpec, PINProvider pinProvider) { } @Override - public void changePIN(PINSpec pinSpec, String oldPIN, String newPIN) throws LockedException, VerificationFailedException, NotActivatedException, SignatureCardException { + public void changePIN(PINSpec pinSpec, ChangePINProvider pinProvider) { } @Override - public void activatePIN(PINSpec pinSpec, String pin) throws SignatureCardException { + public void activatePIN(PINSpec pinSpec, PINProvider pinProvider) { + } + + @Override + public void unblockPIN(PINSpec pinSpec, PINProvider pukProvider) { + } + + @Override + public boolean ifdSupportsFeature(byte feature) { + return false; } }; -- cgit v1.2.3 From 616e06910051528674165319a1d6d161dff5859c Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 27 Mar 2009 17:33:11 +0000 Subject: 1.1-RC6 (pinpad, pinmgmt, secureviewer) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@323 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/bku/online/applet/AppletBKUWorker.java | 5 +- .../egiz/bku/online/applet/AppletSecureViewer.java | 79 +-- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 10 +- .../java/at/gv/egiz/bku/gui/PINManagementGUI.java | 26 +- .../at/gv/egiz/bku/gui/PINManagementGUIFacade.java | 9 +- .../java/at/gv/egiz/bku/gui/PINStatusRenderer.java | 2 - .../smccstal/ext/ManagementPINProviderFactory.java | 13 +- .../bku/smccstal/ext/PinpadPINProviderFactory.java | 45 +- .../gv/egiz/bku/gui/ActivationMessages.properties | 6 +- .../egiz/bku/gui/ActivationMessages_en.properties | 6 +- .../main/java/at/gv/egiz/bku/gui/BKUGUIFacade.java | 40 +- .../main/java/at/gv/egiz/bku/gui/BKUGUIImpl.java | 603 +++++++++++++-------- .../java/at/gv/egiz/bku/gui/HashDataViewer.java | 293 ---------- .../at/gv/egiz/bku/gui/SecureViewerDialog.java | 371 +++++++++++++ .../at/gv/egiz/bku/gui/Messages.properties | 3 +- .../at/gv/egiz/bku/gui/Messages_en.properties | 1 + .../src/main/resources/images/ChipperlingLogo.png | Bin 0 -> 4035 bytes .../test/java/at/gv/egiz/bku/gui/BKUGUITest.java | 5 +- .../test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java | 4 +- .../at/gv/egiz/bku/local/stal/BKUGuiProxy.java | 8 + .../at/gv/egiz/bku/local/stal/LocalBKUWorker.java | 3 +- .../gv/egiz/bku/local/stal/LocalSecureViewer.java | 109 ++++ .../bku/local/stal/LocalSignRequestHandler.java | 83 +-- .../gv/egiz/bku/online/conf/defaultConf.properties | 3 + BKUOnline/src/main/resources/log4j.properties | 2 +- BKUOnline/src/main/webapp/SLRequestForm.html | 27 + .../at/gv/egiz/bku/binding/ExpiryRemoverTest.java | 101 ++-- smcc/src/main/java/at/gv/egiz/smcc/ACOSCard.java | 130 ++--- .../at/gv/egiz/smcc/AbstractSignatureCard.java | 220 ++------ .../src/main/java/at/gv/egiz/smcc/STARCOSCard.java | 234 +++++--- smcc/src/main/java/at/gv/egiz/smcc/SWCard.java | 49 +- .../main/java/at/gv/egiz/smcc/SignatureCard.java | 15 +- smcc/src/main/java/at/gv/egiz/smcc/ccid/CCID.java | 77 +++ .../java/at/gv/egiz/smcc/ccid/DefaultReader.java | 264 +++++++++ .../at/gv/egiz/smcc/ccid/GemplusGemPCPinpad.java | 65 +++ .../java/at/gv/egiz/smcc/ccid/ReaderFactory.java | 35 ++ .../test/java/at/gv/egiz/smcc/ACOSCardTest.java | 135 +++++ .../test/java/at/gv/egiz/smcc/STARCOSCardTest.java | 267 +++++++++ .../gv/egiz/bku/smccstal/AbstractPINProvider.java | 2 +- .../gv/egiz/bku/smccstal/PINProviderFactory.java | 3 +- .../bku/smccstal/PinpadPINProviderFactory.java | 131 +++-- .../java/at/gv/egiz/bku/smccstal/SecureViewer.java | 11 +- .../gv/egiz/bku/smccstal/SignRequestHandler.java | 14 +- .../bku/smccstal/SoftwarePINProviderFactory.java | 25 +- .../java/at/gv/egiz/smcc/AbstractSMCCSTALTest.java | 7 +- 45 files changed, 2364 insertions(+), 1177 deletions(-) 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/SecureViewerDialog.java create mode 100644 BKUCommonGUI/src/main/resources/images/ChipperlingLogo.png create mode 100644 BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSecureViewer.java create mode 100644 smcc/src/main/java/at/gv/egiz/smcc/ccid/CCID.java create mode 100644 smcc/src/main/java/at/gv/egiz/smcc/ccid/DefaultReader.java create mode 100644 smcc/src/main/java/at/gv/egiz/smcc/ccid/GemplusGemPCPinpad.java create mode 100644 smcc/src/main/java/at/gv/egiz/smcc/ccid/ReaderFactory.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/ACOSCardTest.java create mode 100644 smcc/src/test/java/at/gv/egiz/smcc/STARCOSCardTest.java (limited to 'BKUCommonGUI/src/test/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 9b9735f6..e8d8976d 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletBKUWorker.java @@ -18,6 +18,7 @@ package at.gv.egiz.bku.online.applet; import at.gv.egiz.bku.smccstal.AbstractBKUWorker; import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.bku.smccstal.SignRequestHandler; import at.gv.egiz.stal.STALRequest; import at.gv.egiz.stal.STALResponse; import at.gv.egiz.stal.SignRequest; @@ -67,8 +68,10 @@ public class AppletBKUWorker extends AbstractBKUWorker implements Runnable { STALPortType stalPort = applet.getSTALPort(); STALTranslator stalTranslator = applet.getSTALTranslator(); + AppletSecureViewer secureViewer = + new AppletSecureViewer(gui, stalPort, sessionId); addRequestHandler(SignRequest.class, - new AppletSecureViewer(stalPort, sessionId)); + new SignRequestHandler(secureViewer)); GetNextRequestResponseType nextRequestResp = stalPort.connect(sessionId); diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java index e2551e2d..929cecb1 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/AppletSecureViewer.java @@ -16,17 +16,8 @@ */ package at.gv.egiz.bku.online.applet; +import at.gv.egiz.bku.gui.BKUGUIFacade; import at.gv.egiz.bku.smccstal.SecureViewer; -import java.security.DigestException; -import java.security.MessageDigest; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import at.gv.egiz.bku.smccstal.SignRequestHandler; import at.gv.egiz.stal.HashDataInput; import at.gv.egiz.stal.impl.ByteArrayHashDataInput; import at.gv.egiz.stal.service.GetHashDataInputFault; @@ -34,49 +25,73 @@ import at.gv.egiz.stal.service.STALPortType; import at.gv.egiz.stal.service.types.GetHashDataInputResponseType; import at.gv.egiz.stal.service.types.GetHashDataInputType; import at.gv.egiz.stal.signedinfo.ReferenceType; +import at.gv.egiz.stal.signedinfo.SignedInfoType; +import java.awt.event.ActionListener; +import java.security.DigestException; +import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** - * A SignRequesthandler that obtains hashdata inputs from a STAL webservice and - * displays these either within the applet or in a separate frame. - * The internal viewer displays plaintext data only, other mimetypes can be saved to disk. - * The standalone (frame) viewer displays all mimetypes. - * - * (This class depends on STALService and therefore is not part of BKUCommonGUI.) - * + * * @author Clemens Orthacker */ -public class AppletSecureViewer extends SignRequestHandler { +public class AppletSecureViewer implements SecureViewer { private static final Log log = LogFactory.getLog(AppletSecureViewer.class); + + protected BKUGUIFacade gui; protected STALPortType stalPort; protected String sessId; + protected List verifiedDataToBeSigned; - public AppletSecureViewer(STALPortType stalPort, String sessId) { - if (stalPort == null || sessId == null) { + public AppletSecureViewer(BKUGUIFacade gui, STALPortType stalPort, + String sessId) { + if (gui == null) { + throw new NullPointerException("GUI must not be null"); + } + if (stalPort == null) { throw new NullPointerException("STAL port must not be null"); } - this.sessId = sessId; + if (sessId == null) { + throw new NullPointerException("session id must not be null"); + } + this.gui = gui; this.stalPort = stalPort; + this.sessId = sessId; } /** - * TODO don't throw exceptions + * retrieves the data to be signed for * @param signedReferences + * @param okListener + * @param okCommand + * @param cancelListener + * @param cancelCommand * @throws java.security.DigestException * @throws java.lang.Exception */ @Override - public void displayDataToBeSigned(List signedReferences) + public void displayDataToBeSigned(SignedInfoType signedInfo, + ActionListener okListener, String okCommand) throws DigestException, Exception { - - List hdi = getHashDataInput(signedReferences); - List verifiedHashDataInputs = verifyHashDataInput(signedReferences, hdi); - - if (verifiedHashDataInputs.size() > 0) { - gui.showSecureViewer(verifiedHashDataInputs, this, "hashDataDone"); + + if (verifiedDataToBeSigned == null) { + log.info("retrieve data to be signed for dsig:SignedInfo " + + signedInfo.getId()); + List hdi = + getHashDataInput(signedInfo.getReference()); + verifiedDataToBeSigned = verifyHashDataInput(signedInfo.getReference(), + hdi); + } + if (verifiedDataToBeSigned.size() > 0) { + gui.showSecureViewer(verifiedDataToBeSigned, okListener, okCommand); } else { - throw new Exception("No signature data (apart from any QualifyingProperties or a Manifest)"); + throw new Exception("No data to be signed (apart from any QualifyingProperties or a Manifest)"); } } @@ -110,7 +125,7 @@ public class AppletSecureViewer extends SignRequestHandler { } } } - + if (request.getReference().size() < 1) { log.error("No signature data (apart from any QualifyingProperties or a Manifest) for session " + sessId); throw new Exception("No signature data (apart from any QualifyingProperties or a Manifest)"); @@ -187,7 +202,7 @@ public class AppletSecureViewer extends SignRequestHandler { verifiedHashDataInputs.add(new ByteArrayHashDataInput(hdi, signedRefId, mimeType, encoding)); } } - + return verifiedHashDataInputs; } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index a4337bbd..0ddb6dc6 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -34,6 +34,7 @@ import at.gv.egiz.bku.gui.BKUGUIFacade; import at.gv.egiz.bku.gui.BKUGUIImpl; import at.gv.egiz.stal.service.STALPortType; import at.gv.egiz.stal.service.STALService; +import java.applet.AppletContext; import java.awt.Container; import javax.xml.namespace.QName; @@ -207,14 +208,19 @@ public class BKUApplet extends JApplet { */ protected void sendRedirect(String sessionId) { try { + AppletContext ctx = getAppletContext(); + if (ctx == null) { + log.error("no applet context (applet might already have been destroyed)"); + return; + } URL redirectURL = getURLParameter(REDIRECT_URL, sessionId); String redirectTarget = getParameter(REDIRECT_TARGET); if (redirectTarget == null) { log.info("Done. Redirecting to " + redirectURL + " ..."); - getAppletContext().showDocument(redirectURL); + ctx.showDocument(redirectURL); } else { log.info("Done. Redirecting to " + redirectURL + " (target=" + redirectTarget + ") ..."); - getAppletContext().showDocument(redirectURL, redirectTarget); + ctx.showDocument(redirectURL, redirectTarget); } } catch (MalformedURLException ex) { log.warn("Failed to redirect: " + ex.getMessage(), ex); diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUI.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUI.java index 159dd29d..d1ca6c00 100644 --- a/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUI.java +++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUI.java @@ -118,18 +118,18 @@ public class PINManagementGUI extends CardMgmtGUI implements PINManagementGUIFac pinStatusTable.setDefaultRenderer(PINSpec.class, new PINSpecRenderer()); pinStatusTable.setDefaultRenderer(STATUS.class, new PINStatusRenderer(cardmgmtMessages)); pinStatusTable.setTableHeader(null); - - pinStatusTable.addMouseMotionListener(new MouseMotionAdapter() { - - @Override - public void mouseMoved(MouseEvent e) { - if (pinStatusTable.columnAtPoint(e.getPoint()) == 0) { - pinStatusTable.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - } else { - pinStatusTable.setCursor(Cursor.getDefaultCursor()); - } - } - }); + pinStatusTable.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); +// pinStatusTable.addMouseMotionListener(new MouseMotionAdapter() { +// +// @Override +// public void mouseMoved(MouseEvent e) { +// if (pinStatusTable.columnAtPoint(e.getPoint()) == 0) { +// pinStatusTable.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); +// } else { +// pinStatusTable.setCursor(Cursor.getDefaultCursor()); +// } +// } +// }); final JButton activateButton = new JButton(); activateButton.setFont(activateButton.getFont().deriveFont(activateButton.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -392,7 +392,7 @@ public class PINManagementGUI extends CardMgmtGUI implements PINManagementGUIFac if (pinpad) { JLabel pinpadLabel = new JLabel(); pinpadLabel.setFont(mgmtLabel.getFont().deriveFont(mgmtLabel.getFont().getStyle() & ~Font.BOLD)); - String pinpadPattern = getMessage(MESSAGE_PINPAD); + String pinpadPattern = getMessage(MESSAGE_VERIFYPIN_PINPAD); pinpadLabel.setText(MessageFormat.format(pinpadPattern, new Object[] { pinSpec.getLocalizedName(), pinSize })); diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUIFacade.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUIFacade.java index 45313f42..f0cc0a27 100644 --- a/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUIFacade.java +++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUIFacade.java @@ -40,13 +40,16 @@ public interface PINManagementGUIFacade extends BKUGUIFacade { public static final String MESSAGE_ACTIVATE_SUCCESS = "activate.success"; public static final String MESSAGE_CHANGE_SUCCESS = "change.success"; public static final String MESSAGE_PINMGMT = "pin.mgmt"; - public static final String MESSAGE_PINPAD = "pinpad"; - public static final String MESSAGE_CHANGEPIN_PINPAD = "pinpad.change"; +// public static final String MESSAGE_PINPAD = "pinpad"; public static final String MESSAGE_ACTIVATE_PIN = "activate.pin"; public static final String MESSAGE_CHANGE_PIN = "change.pin"; public static final String MESSAGE_VERIFY_PIN = "verify.pin"; public static final String MESSAGE_UNBLOCK_PIN = "unblock.pin"; - + public static final String MESSAGE_ACTIVATEPIN_PINPAD = "activate.pinpad"; + public static final String MESSAGE_CHANGEPIN_PINPAD = "change.pinpad"; + public static final String MESSAGE_VERIFYPIN_PINPAD = "verify.pinpad"; + public static final String MESSAGE_UNBLOCKPIN_PINPAD = "unblock.pinpad"; + public static final String LABEL_OLD_PIN = "label.old.pin"; public static final String LABEL_NEW_PIN = "label.new.pin"; public static final String LABEL_REPEAT_PIN = "label.repeat.pin"; diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINStatusRenderer.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINStatusRenderer.java index 4cb84b77..83ff74f2 100644 --- a/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINStatusRenderer.java +++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/gui/PINStatusRenderer.java @@ -22,8 +22,6 @@ import java.awt.Color; import java.awt.Font; import java.util.ResourceBundle; import javax.swing.table.DefaultTableCellRenderer; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; /** * diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/ManagementPINProviderFactory.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/ManagementPINProviderFactory.java index b0dd8766..d635b8df 100644 --- a/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/ManagementPINProviderFactory.java +++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/ManagementPINProviderFactory.java @@ -19,6 +19,7 @@ package at.gv.egiz.bku.smccstal.ext; import at.gv.egiz.smcc.ChangePINProvider; import at.gv.egiz.bku.gui.PINManagementGUIFacade; +import at.gv.egiz.smcc.ccid.CCID; import at.gv.egiz.smcc.PINProvider; import at.gv.egiz.smcc.SignatureCard; @@ -33,13 +34,13 @@ public abstract class ManagementPINProviderFactory { public static ManagementPINProviderFactory getInstance(SignatureCard forCard, PINManagementGUIFacade gui) { -// if (forCard.ifdSupportsFeature(SignatureCard.FEATURE_VERIFY_PIN_DIRECT)) { -//// forCard.ifdSupportsFeature(SignatureCard.FEATURE_MODIFY_PIN_DIRECT) -// return new PinpadPINProviderFactory(gui); -// -// } else { + if (forCard.getReader().hasFeature(CCID.FEATURE_VERIFY_PIN_DIRECT)) { +// forCard.ifdSupportsFeature(SignatureCard.FEATURE_MODIFY_PIN_DIRECT) + return new PinpadPINProviderFactory(gui); + + } else { return new SoftwarePINProviderFactory(gui); -// } + } } public abstract PINProvider getVerifyPINProvider(); diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PinpadPINProviderFactory.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PinpadPINProviderFactory.java index 4176e0a9..a9ad5ef8 100644 --- a/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PinpadPINProviderFactory.java +++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/smccstal/ext/PinpadPINProviderFactory.java @@ -73,23 +73,6 @@ public class PinpadPINProviderFactory extends ManagementPINProviderFactory { showPinpadPINDialog(retries, spec); retry = true; return null; - -// gui.showPINDialog(type, spec, (retry) ? retries : -1, -// this, "exec", -// this, "back"); -// -// waitForAction(); -// -// if ("exec".equals(action)) { -// gui.showWaitDialog(null); -// retry = true; -// return gui.getPin(); -// } else if ("back".equals(action)) { -// throw new CancelledException(); -// } else { -// log.error("unsupported command " + action); -// throw new CancelledException(); -// } } /** @@ -111,14 +94,38 @@ public class PinpadPINProviderFactory extends ManagementPINProviderFactory { title = BKUGUIFacade.TITLE_RETRY; message = BKUGUIFacade.MESSAGE_RETRIES; params = new Object[]{String.valueOf(retries)}; - } else { - title = BKUGUIFacade.TITLE_SIGN; + } else if (type == DIALOG.VERIFY) { + title = PINManagementGUIFacade.TITLE_VERIFY_PIN; message = BKUGUIFacade.MESSAGE_ENTERPIN_PINPAD; String pinSize = String.valueOf(pinSpec.getMinLength()); if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { pinSize += "-" + pinSpec.getMaxLength(); } params = new Object[]{pinSpec.getLocalizedName(), pinSize}; + } else if (type == DIALOG.ACTIVATE) { + title = PINManagementGUIFacade.TITLE_ACTIVATE_PIN; + message = PINManagementGUIFacade.MESSAGE_ACTIVATEPIN_PINPAD; + String pinSize = String.valueOf(pinSpec.getMinLength()); + if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { + pinSize += "-" + pinSpec.getMaxLength(); + } + params = new Object[]{pinSpec.getLocalizedName(), pinSize}; + } else if (type == DIALOG.CHANGE) { + title = PINManagementGUIFacade.TITLE_CHANGE_PIN; + message = PINManagementGUIFacade.MESSAGE_CHANGEPIN_PINPAD; + String pinSize = String.valueOf(pinSpec.getMinLength()); + if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { + pinSize += "-" + pinSpec.getMaxLength(); + } + params = new Object[]{pinSpec.getLocalizedName(), pinSize}; + } else { //if (type == DIALOG.UNBLOCK) { + title = PINManagementGUIFacade.TITLE_UNBLOCK_PIN; + message = PINManagementGUIFacade.MESSAGE_UNBLOCKPIN_PINPAD; + String pinSize = String.valueOf(pinSpec.getMinLength()); + if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { + pinSize += "-" + pinSpec.getMaxLength(); + } + params = new Object[]{pinSpec.getLocalizedName(), pinSize}; } gui.showMessageDialog(title, message, params); } diff --git a/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages.properties b/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages.properties index 4ceacb21..c6d219d4 100644 --- a/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages.properties +++ b/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages.properties @@ -24,12 +24,14 @@ title.change.success=Erfolg # removed message.* prefix to reuse keys as help keys pin.mgmt=Die Karte verf\u00FCgt \u00FCber {0} PINs -pinpad={0} ({1} stellig) am Kartenleser eingeben und best\u00E4tigen. -pinpad.change={0} ({1} stellig) am Kartenleser eingeben und best\u00E4tigen. activate.pin={0} eingeben und best\u00E4tigen change.pin={0} eingeben und best\u00E4tigen unblock.pin=PUK zu {0} eingeben verify.pin={0} eingeben (TODO: Warning not activated) +verify.pinpad={0} ({1} stellig) am Kartenleser eingeben (und best\u00E4tigen). +activate.pinpad={0} ({1} stellig) am Kartenleser eingeben und wiederholen (jeweils best\u00E4tigen). +change.pinpad=Alte {0} ({1} stellig) am Kartenleser eingeben, danach neue {0} eingeben und wiederholen (jeweils best\u00E4tigen). +unblock.pinpad={0} ({1} stellig) am Kartenleser eingeben (und best\u00E4tigen). activate.success={0} wurde erfolgreich aktiviert. change.success={0} wurde erfolgreich ge\u00E4ndert. diff --git a/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages_en.properties b/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages_en.properties index 9178d65c..b4bededf 100644 --- a/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages_en.properties +++ b/BKUAppletExt/src/main/resources/at/gv/egiz/bku/gui/ActivationMessages_en.properties @@ -23,11 +23,13 @@ title.change.success=Success # removed message.* prefix to reuse keys as help keys pin.mgmt=The smartcard has {0} PINs -pinpad=Enter {0} ({1} digits) on pinpad and confirm. -pinpad.change=Enter {0} ({1} digits) on pinpad and confirm. activate.pin=Enter and confirm {0} change.pin=Enter and confirm {0} unblock.pin=Enter PUK for {0} +verify.pinpad=Enter {0} ({1} digits) on cardreader (and confirm). +activate.pinpad=Enter {0} ({1} digits) on cardreader and repeat (confirm in each case). +change.pinpad=Enter old {0} ({1} digits) on cardreader, then enter new {0} and repeat (confirm in each case). +unblock.pinpad=Enter {0} ({1} digits) on cardreader (and confirm). activate.success={0} successfully activated change.success={0} successfully changed 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 1043b6a1..4b079428 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 @@ -43,6 +43,7 @@ public interface BKUGUIFacade { 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 DEFAULT_ICON = "/images/ChipperlingLogo.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; @@ -58,6 +59,7 @@ public interface BKUGUIFacade { 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_ERROR = "windowtitle.error"; public static final String WINDOWTITLE_SAVEDIR = "windowtitle.savedir"; public static final String WINDOWTITLE_OVERWRITE = "windowtitle.overwrite"; public static final String WINDOWTITLE_VIEWER = "windowtitle.viewer"; @@ -102,42 +104,36 @@ public interface BKUGUIFacade { public enum Style { tiny, simple, advanced }; -// public void init(Container contentPane, Locale locale, Style guiStyle, URL background, ActionListener helpListener); - /** * BKUWorker needs to init signature card with locale * @return */ public Locale getLocale(); -// public void showWelcomeDialog(); - - /** - * - * @param waitMessage if null, a simple 'please 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, int numRetries, 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, int numRetries, 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 void showSignaturePINDialog(PINSpec pinSpec, int numRetries, + ActionListener signListener, String signCommand, + ActionListener cancelListener, String cancelCommand, + ActionListener viewerListener, String viewerCommand); -// public void showPinpadSignaturePINDialog(PINSpec pinSpec, int retries); + public void showPinpadSignaturePINDialog(PINSpec pinSpec, int numRetries, + ActionListener viewerListener, String viewerCommand); public char[] getPin(); - public void showSecureViewer(List signedReferences, - ActionListener okListener, String okCommand); + /** + * + * @param dataToBeSigned + * @param backListener if list of references hides pin dialog, backListener + * receives an action when user hits 'back' button (i.e. whenever the pin-dialog + * needs to be re-paint) + * @param backCommand + */ + public void showSecureViewer(List dataToBeSigned, + ActionListener backListener, String backCommand); public void showErrorDialog(String errorMsgKey, Object[] errorMsgParams, ActionListener okListener, String okCommand); 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 928be249..a7eebbfd 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 @@ -71,6 +71,7 @@ public class BKUGUIImpl implements BKUGUIFacade { } protected HelpMouseListener helpListener; + protected SecureViewerDialog secureViewer; protected Container contentPane; protected ResourceBundle messages; @@ -145,13 +146,16 @@ public class BKUGUIImpl implements BKUGUIFacade { @Override public void run() { - log.debug("initializing gui"); + log.debug("initializing gui [" + Thread.currentThread().getName() + "]"); if (renderIconPanel) { initIconPanel(background); initContentPanel(null); } else { - initContentPanel(background); + initContentPanel((background == null) ? + getClass().getResource(DEFAULT_BACKGROUND) : + background + ); } GroupLayout layout = new GroupLayout(contentPane); @@ -159,15 +163,27 @@ public class BKUGUIImpl implements BKUGUIFacade { if (renderIconPanel) { layout.setHorizontalGroup(layout.createSequentialGroup() - .addComponent(iconPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); - layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(iconPanel, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); + .addContainerGap() + .addComponent(iconPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap()); + layout.setVerticalGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(iconPanel, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(contentPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()); } else { - layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(contentPanel)); - layout.setVerticalGroup(layout.createSequentialGroup().addComponent(contentPanel)); + layout.setHorizontalGroup(layout.createSequentialGroup() + // left border + .addContainerGap() + .addComponent(contentPanel) + .addContainerGap()); + layout.setVerticalGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(contentPanel) + .addContainerGap()); } } }); @@ -178,11 +194,12 @@ public class BKUGUIImpl implements BKUGUIFacade { protected void initIconPanel(URL background) { if (background == null) { - background = getClass().getResource(DEFAULT_BACKGROUND); + background = getClass().getResource(DEFAULT_ICON); } if ("file".equals(background.getProtocol())) { - log.warn("file:// background images not permitted: " + background); - background = getClass().getResource(DEFAULT_BACKGROUND); + log.warn("file:// background images not permitted: " + background + + ", loading default background"); + background = getClass().getResource(DEFAULT_ICON); } log.debug("loading icon panel background " + background); @@ -194,26 +211,24 @@ public class BKUGUIImpl implements BKUGUIFacade { iconPanel.setLayout(iconPanelLayout); iconPanelLayout.setHorizontalGroup( iconPanelLayout.createSequentialGroup() - .addContainerGap() .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)); - // no gap here (contentPanel has containerGap) iconPanelLayout.setVerticalGroup( iconPanelLayout.createSequentialGroup() - .addContainerGap() - .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); + .addComponent(iconLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)); } protected void initContentPanel(URL background) { +// if (background == null) { +// background = getClass().getResource(DEFAULT_BACKGROUND); +// } if (background == null) { - background = getClass().getResource(DEFAULT_BACKGROUND); - } - if (background == null) { + log.debug("no background image set"); contentPanel = new JPanel(); } else { if ("file".equals(background.getProtocol())) { - log.warn("file:// background images not permitted: " + background); + log.warn("file:// background images not permitted: " + background + + ", loading default background"); background = getClass().getResource(DEFAULT_BACKGROUND); } log.debug("loading background " + background); @@ -257,34 +272,29 @@ public class BKUGUIImpl implements BKUGUIFacade { GroupLayout contentPanelLayout = new GroupLayout(contentPanel); contentPanel.setLayout(contentPanelLayout); - GroupLayout.ParallelGroup horizontalContentInner = contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); + // align header, main and button to the right + GroupLayout.ParallelGroup horizontalContent = + contentPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING); //LEADING); + GroupLayout.SequentialGroup verticalContent = + contentPanelLayout.createSequentialGroup(); + if (renderHeaderPanel) { - horizontalContentInner + horizontalContent .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE); + verticalContent + .addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED); + } - horizontalContentInner + horizontalContent .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE); - GroupLayout.SequentialGroup horizontalContentOuter = contentPanelLayout.createSequentialGroup(); - if (!renderIconPanel) { - horizontalContentOuter - .addContainerGap(); - } - horizontalContentOuter - .addGroup(horizontalContentInner) - .addContainerGap(); - contentPanelLayout.setHorizontalGroup(horizontalContentOuter); - - GroupLayout.SequentialGroup verticalContent = contentPanelLayout.createSequentialGroup(); - verticalContent.addContainerGap(); - if (renderHeaderPanel) { - verticalContent.addComponent(headerPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED); - } - verticalContent.addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addContainerGap(); + .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); //Short.MAX_VALUE); + verticalContent + .addComponent(mainPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(buttonPanel, 0, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); + + contentPanelLayout.setHorizontalGroup(horizontalContent); //Outer); contentPanelLayout.setVerticalGroup(verticalContent); } @@ -521,7 +531,7 @@ public class BKUGUIImpl implements BKUGUIFacade { @Override public void run() { - log.debug("show card-pin dialog"); + log.debug("show card-pin dialog [" + Thread.currentThread().getName() + "]"); mainPanel.removeAll(); buttonPanel.removeAll(); @@ -653,7 +663,6 @@ public class BKUGUIImpl implements BKUGUIFacade { buttonPanel.setLayout(buttonPanelLayout); GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); GroupLayout.Group buttonVertical; @@ -700,6 +709,128 @@ public class BKUGUIImpl implements BKUGUIFacade { // showSignaturePINDialog(pinSpec, -1, signListener, signCommand, cancelListener, cancelCommand, hashdataListener, hashdataCommand); // } + @Override + public void showPinpadSignaturePINDialog(final PINSpec pinSpec, final int numRetries, +// final ActionListener cancelListener, final String cancelCommand, + final ActionListener hashdataListener, final String hashdataCommand) { + + log.debug("scheduling pinpad signature-pin dialog"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show pinpad signature-pin dialog [" + Thread.currentThread().getName() + "]"); + + mainPanel.removeAll(); + buttonPanel.removeAll(); + + if (renderHeaderPanel) { + if (numRetries < 0) { + titleLabel.setText(getMessage(TITLE_SIGN)); + } else { + titleLabel.setText(getMessage(TITLE_RETRY)); + } + } + + JLabel infoLabel = new JLabel(); + if (numRetries < 0) { + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + if (shortText) { + infoLabel.setText(getMessage(MESSAGE_HASHDATALINK_TINY)); + } else { + infoLabel.setText(getMessage(MESSAGE_HASHDATALINK)); + } + infoLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + infoLabel.setForeground(HYPERLINK_COLOR); + infoLabel.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent me) { + ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, hashdataCommand); + hashdataListener.actionPerformed(e); + } + }); + helpListener.setHelpTopic(HELP_SIGNPIN); + } else { + String retryPattern; + if (numRetries < 2) { + retryPattern = getMessage(MESSAGE_LAST_RETRY); + } else { + retryPattern = getMessage(MESSAGE_RETRIES); + } + infoLabel.setText(MessageFormat.format(retryPattern, new Object[]{String.valueOf(numRetries)})); + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); + infoLabel.setForeground(ERROR_COLOR); + helpListener.setHelpTopic(HELP_RETRY); + } + + String pinSize = String.valueOf(pinSpec.getMinLength()); + if (pinSpec.getMinLength() != pinSpec.getMaxLength()) { + pinSize += "-" + pinSpec.getMaxLength(); + } + + String msgPattern = getMessage(MESSAGE_ENTERPIN_PINPAD); + String msg = MessageFormat.format(msgPattern, new Object[] { + pinSpec.getLocalizedName(), pinSize }); + + JLabel msgLabel = new JLabel(); + msgLabel.setFont(msgLabel.getFont().deriveFont(msgLabel.getFont().getStyle() & ~Font.BOLD)); + msgLabel.setText(msg); + + GroupLayout mainPanelLayout = new GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + + GroupLayout.SequentialGroup infoHorizontal = mainPanelLayout.createSequentialGroup() + .addComponent(infoLabel); + GroupLayout.ParallelGroup infoVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(infoLabel); + + if (!renderHeaderPanel) { + infoHorizontal + .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) + .addComponent(helpLabel); + infoVertical + .addComponent(helpLabel); + } + + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addGroup(infoHorizontal) + .addComponent(msgLabel)); + + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createSequentialGroup() + .addGroup(infoVertical) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(msgLabel)); + + //no cancel button (cancel via pinpad) +// if (renderCancelButton) { +// JButton cancelButton = new JButton(); +// cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); +// cancelButton.setText(getMessage(BUTTON_CANCEL)); +// cancelButton.setActionCommand(cancelCommand); +// cancelButton.addActionListener(cancelListener); +// +// GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); +// buttonPanel.setLayout(buttonPanelLayout); +// +// GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup() +// .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); +// GroupLayout.SequentialGroup buttonVertical = buttonPanelLayout.createSequentialGroup() +// .addComponent(cancelButton); +// +// buttonPanelLayout.setHorizontalGroup(buttonHorizontal); +// buttonPanelLayout.setVerticalGroup(buttonVertical); +// } + + contentPanel.validate(); + } + }); + } + @Override public void showSignaturePINDialog(final PINSpec pinSpec, final int numRetries, final ActionListener signListener, final String signCommand, @@ -717,7 +848,7 @@ public class BKUGUIImpl implements BKUGUIFacade { @Override public void run() { - log.debug("show signature-pin dialog"); + log.debug("show signature-pin dialog [" + Thread.currentThread().getName() + "]"); mainPanel.removeAll(); buttonPanel.removeAll(); @@ -730,6 +861,38 @@ public class BKUGUIImpl implements BKUGUIFacade { } } + JLabel infoLabel = new JLabel(); + if (numRetries < 0) { + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); + if (shortText) { + infoLabel.setText(getMessage(MESSAGE_HASHDATALINK_TINY)); + } else { + infoLabel.setText(getMessage(MESSAGE_HASHDATALINK)); + } + infoLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + infoLabel.setForeground(HYPERLINK_COLOR); + infoLabel.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent me) { + ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, hashdataCommand); + hashdataListener.actionPerformed(e); + } + }); + helpListener.setHelpTopic(HELP_SIGNPIN); + } else { + String retryPattern; + if (numRetries < 2) { + retryPattern = getMessage(MESSAGE_LAST_RETRY); + } else { + retryPattern = getMessage(MESSAGE_RETRIES); + } + infoLabel.setText(MessageFormat.format(retryPattern, new Object[]{String.valueOf(numRetries)})); + infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); + infoLabel.setForeground(ERROR_COLOR); + helpListener.setHelpTopic(HELP_RETRY); + } + JButton signButton = new JButton(); signButton.setFont(signButton.getFont().deriveFont(signButton.getFont().getStyle() & ~java.awt.Font.BOLD)); signButton.setText(getMessage(BUTTON_SIGN)); @@ -765,46 +928,14 @@ public class BKUGUIImpl implements BKUGUIFacade { } pinsizeLabel.setText(MessageFormat.format(pinsizePattern, new Object[]{pinSize})); - JLabel infoLabel = new JLabel(); - if (numRetries < 0) { - infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() & ~java.awt.Font.BOLD)); - if (shortText) { - infoLabel.setText(getMessage(MESSAGE_HASHDATALINK_TINY)); - } else { - infoLabel.setText(getMessage(MESSAGE_HASHDATALINK)); - } - infoLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - infoLabel.setForeground(HYPERLINK_COLOR); - infoLabel.addMouseListener(new MouseAdapter() { - - @Override - public void mouseClicked(MouseEvent me) { - ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, hashdataCommand); - hashdataListener.actionPerformed(e); - } - }); - helpListener.setHelpTopic(HELP_SIGNPIN); - } else { - String retryPattern; - if (numRetries < 2) { - retryPattern = getMessage(MESSAGE_LAST_RETRY); - } else { - retryPattern = getMessage(MESSAGE_RETRIES); - } - infoLabel.setText(MessageFormat.format(retryPattern, new Object[]{String.valueOf(numRetries)})); - infoLabel.setFont(infoLabel.getFont().deriveFont(infoLabel.getFont().getStyle() | java.awt.Font.BOLD)); - infoLabel.setForeground(ERROR_COLOR); - helpListener.setHelpTopic(HELP_RETRY); - } - GroupLayout mainPanelLayout = new GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); - + GroupLayout.SequentialGroup infoHorizontal = mainPanelLayout.createSequentialGroup() .addComponent(infoLabel); GroupLayout.ParallelGroup infoVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(infoLabel); - + if (!renderHeaderPanel) { infoHorizontal .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) @@ -814,8 +945,8 @@ public class BKUGUIImpl implements BKUGUIFacade { } // align pinfield and pinsize to the right - GroupLayout.ParallelGroup pinHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING); - GroupLayout.Group pinVertical; + GroupLayout.Group pinHorizontal = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING); + GroupLayout.SequentialGroup pinVertical = mainPanelLayout.createSequentialGroup(); if (pinLabelPos == PinLabelPosition.ABOVE) { pinHorizontal @@ -823,20 +954,25 @@ public class BKUGUIImpl implements BKUGUIFacade { .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(pinsizeLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); - pinVertical = mainPanelLayout.createSequentialGroup() + pinVertical .addComponent(signPinLabel) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); - } else { + .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinsizeLabel); + } else { // PinLabelPosition.LEFT pinHorizontal .addGroup(mainPanelLayout.createSequentialGroup() .addComponent(signPinLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(pinField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(pinsizeLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE); - pinVertical = mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(signPinLabel) - .addComponent(pinField); + pinVertical + .addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(signPinLabel) + .addComponent(pinField)) + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(pinsizeLabel); } mainPanelLayout.setHorizontalGroup( @@ -848,18 +984,14 @@ public class BKUGUIImpl implements BKUGUIFacade { mainPanelLayout.createSequentialGroup() .addGroup(infoVertical) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addGroup(pinVertical) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(pinsizeLabel)); + .addGroup(pinVertical)); GroupLayout buttonPanelLayout = new GroupLayout(buttonPanel); buttonPanel.setLayout(buttonPanelLayout); - GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(signButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); + GroupLayout.SequentialGroup buttonHorizontal = buttonPanelLayout.createSequentialGroup(); GroupLayout.Group buttonVertical; - + if (renderCancelButton) { JButton cancelButton = new JButton(); cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD)); @@ -868,17 +1000,19 @@ public class BKUGUIImpl implements BKUGUIFacade { cancelButton.addActionListener(cancelListener); buttonHorizontal + .addComponent(signButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); - buttonVertical = buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(signButton) - .addComponent(cancelButton); + .addComponent(cancelButton); } else { + buttonHorizontal + .addComponent(signButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE); buttonVertical = buttonPanelLayout.createSequentialGroup() .addComponent(signButton); } - + buttonPanelLayout.setHorizontalGroup(buttonHorizontal); buttonPanelLayout.setVerticalGroup(buttonVertical); @@ -951,7 +1085,7 @@ public class BKUGUIImpl implements BKUGUIFacade { @Override public void run() { - log.debug("show message dialog"); + log.debug("show message dialog [" + Thread.currentThread().getName() + "]"); mainPanel.removeAll(); buttonPanel.removeAll(); @@ -1011,7 +1145,6 @@ public class BKUGUIImpl implements BKUGUIFacade { buttonPanelLayout.setHorizontalGroup( buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(okButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); buttonPanelLayout.setVerticalGroup( buttonPanelLayout.createSequentialGroup() @@ -1084,68 +1217,69 @@ public class BKUGUIImpl implements BKUGUIFacade { } return null; } + + + //////////////////////////////////////////////////////////////////////////// + // SECURE VIEWER + //////////////////////////////////////////////////////////////////////////// + /** - * TODO handle multiple references in HashDataViewer * @param signedReferences - * @param okListener + * @param backListener gets notified if pin-dialog has to be redrawn + * (signedRefencesList returns via BACK button) * @param okCommand */ @Override - public void showSecureViewer(final List signedReferences, - final ActionListener okListener, - final String okCommand) { - - if (signedReferences == null) { - showErrorDialog(getMessage(ERR_NO_HASHDATA), new Object[] {"No SignedReferences provided"}, okListener, okCommand); - return; - } + public void showSecureViewer(final List dataToBeSigned, + final ActionListener backListener, final String backCommand) { - if (signedReferences.size() == 1) { + if (dataToBeSigned == null) { + showErrorDialog(getMessage(ERR_NO_HASHDATA), + new Object[] {"no signature data provided"}, + backListener, backCommand); + } else if (dataToBeSigned.size() == 1) { try { - log.debug("scheduling hashdata viewer"); + log.debug("scheduling secure viewer"); - SwingUtilities.invokeAndWait(new Runnable() { + SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - ActionListener saveHashDataListener = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - HashDataInput hdi = signedReferences.get(0); - showSaveHashDataInputDialog(Collections.singletonList(hdi), okListener, okCommand); - } - }; - showHashDataViewer(signedReferences.get(0), saveHashDataListener, "save"); + showSecureViewer(dataToBeSigned.get(0)); } }); - } catch (InterruptedException ex) { - log.error("Failed to display HashDataViewer: " + ex.getMessage()); - } catch (InvocationTargetException ex) { - log.error("Failed to display HashDataViewer: " + ex.getMessage()); + } catch (Exception ex) { //InterruptedException InvocationTargetException + log.error("Failed to display secure viewer: " + ex.getMessage()); + log.trace(ex); + showErrorDialog(ERR_UNKNOWN, null, backListener, backCommand); } } else { - showSignedReferencesListDialog(signedReferences, okListener, okCommand); + showSignedReferencesListDialog(dataToBeSigned, backListener, backCommand); } } /** * has to be called from event dispatcher thread + * This method blocks until the dialog's close button is pressed. * @param hashDataText * @param saveListener * @param saveCommand */ - private void showHashDataViewer(final HashDataInput hashDataInput, final ActionListener saveListener, final String saveCommand) { + private void showSecureViewer(HashDataInput dataToBeSigned) { - log.debug("show hashdata viewer"); - - ActionListener l = helpListener.getActionListener(); - HashDataViewer.showHashDataInput(contentPane, hashDataInput, messages, saveListener, saveCommand, l); + log.debug("show secure viewer [" + Thread.currentThread().getName() + "]"); + if (secureViewer == null) { + secureViewer = new SecureViewerDialog(null, messages, + helpListener.getActionListener()); + } + secureViewer.setContent(dataToBeSigned); + log.trace("show secure viewer returned"); } - private void showSignedReferencesListDialog(final List signedReferences, final ActionListener backListener, final String backCommand) { + private void showSignedReferencesListDialog(final List signedReferences, + final ActionListener backListener, final String backCommand) { log.debug("scheduling signed references list dialog"); @@ -1154,7 +1288,7 @@ public class BKUGUIImpl implements BKUGUIFacade { @Override public void run() { - log.debug("show signed references list dialog"); + log.debug("show signed references list dialog [" + Thread.currentThread().getName() + "]"); mainPanel.removeAll(); buttonPanel.removeAll(); @@ -1202,13 +1336,7 @@ public class BKUGUIImpl implements BKUGUIFacade { int selectionIdx = lsm.getMinSelectionIndex(); if (selectionIdx >= 0) { final HashDataInput selection = signedReferences.get(selectionIdx); - showHashDataViewer(selection, new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - showSaveHashDataInputDialog(Collections.singletonList(selection), null, null); - } - }, "save"); + showSecureViewer(selection); } } }); @@ -1255,9 +1383,8 @@ public class BKUGUIImpl implements BKUGUIFacade { buttonPanel.setLayout(buttonPanelLayout); buttonPanelLayout.setHorizontalGroup(buttonPanelLayout.createSequentialGroup() - .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(backButton, GroupLayout.PREFERRED_SIZE, buttonSize, GroupLayout.PREFERRED_SIZE)); - buttonPanelLayout.setVerticalGroup(buttonPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE) + buttonPanelLayout.setVerticalGroup(buttonPanelLayout.createSequentialGroup() .addComponent(backButton)); contentPanel.validate(); @@ -1266,96 +1393,101 @@ public class BKUGUIImpl implements BKUGUIFacade { } /** - * - * @param signedRefs * @param okListener may be null - * @param okCommand */ - private void showSaveHashDataInputDialog(final List signedRefs, final ActionListener okListener, final String okCommand) { - - log.debug("scheduling save hashdatainput dialog"); - - SwingUtilities.invokeLater(new Runnable() { +// private void showSaveDialog(final List signedRefs, +// final ActionListener okListener, final String okCommand) { +// +// log.debug("scheduling save dialog"); +// +// SwingUtilities.invokeLater(new Runnable() { +// +// @Override +// public void run() { +// +// log.debug("show save dialog"); +// +// String userHome = System.getProperty("user.home"); +// +// JFileChooser fileDialog = new JFileChooser(userHome); +// fileDialog.setMultiSelectionEnabled(false); +// fileDialog.setDialogType(JFileChooser.SAVE_DIALOG); +// fileDialog.setFileHidingEnabled(true); +// if (signedRefs.size() == 1) { +// fileDialog.setDialogTitle(getMessage(WINDOWTITLE_SAVE)); +// fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY); +// String mimeType = signedRefs.get(0).getMimeType(); +// MimeFilter mimeFilter = new MimeFilter(mimeType, messages); +// fileDialog.setFileFilter(mimeFilter); +// String filename = getMessage(SAVE_HASHDATAINPUT_PREFIX) + MimeFilter.getExtension(mimeType); +// fileDialog.setSelectedFile(new File(userHome, filename)); +// } else { +// fileDialog.setDialogTitle(getMessage(WINDOWTITLE_SAVEDIR)); +// fileDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); +// } +// +// //parent contentPane -> placed over applet +// switch (fileDialog.showSaveDialog(fileDialog)) { +// case JFileChooser.APPROVE_OPTION: +// File f = fileDialog.getSelectedFile(); +// for (HashDataInput hashDataInput : signedRefs) { +// String mimeType = hashDataInput.getMimeType(); +// String id = hashDataInput.getReferenceId(); +// File file; +// if (f.isDirectory()) { +// String filename = getMessage(SAVE_HASHDATAINPUT_PREFIX) + '_' + id + MimeFilter.getExtension(mimeType); +// file = new File(f, filename); +// } else { +// file = f; +// } +// if (file.exists()) { +// String ovrwrt = getMessage(MESSAGE_OVERWRITE); +// int overwrite = JOptionPane.showConfirmDialog(fileDialog, MessageFormat.format(ovrwrt, file), getMessage(WINDOWTITLE_OVERWRITE), JOptionPane.OK_CANCEL_OPTION); +// if (overwrite != JOptionPane.OK_OPTION) { +// continue; +// } +// } +// if (log.isDebugEnabled()) { +// log.debug("writing hashdata input " + id + " (" + mimeType + ") to file " + file); +// } +// FileOutputStream fos = null; +// try { +// fos = new FileOutputStream(file); +// BufferedOutputStream bos = new BufferedOutputStream(fos); +// InputStream hdi = hashDataInput.getHashDataInput(); +// int b; +// while ((b = hdi.read()) != -1) { +// bos.write(b); +// } +// bos.flush(); +// bos.close(); +// } catch (IOException ex) { +// log.error("Failed to write " + file + ": " + ex.getMessage()); +// showErrorDialog(ERR_WRITE_HASHDATA, new Object[] {ex.getMessage()}, null, null); +// ex.printStackTrace(); +// } finally { +// try { +// fos.close(); +// } catch (IOException ex) { +// } +// } +// } +// break; +// case JFileChooser.CANCEL_OPTION : +// log.debug("cancelled save dialog"); +// break; +// } +// if (okListener != null) { +// okListener.actionPerformed(new ActionEvent(fileDialog, ActionEvent.ACTION_PERFORMED, okCommand)); +// } +// } +// }); +// } + + //////////////////////////////////////////////////////////////////////////// + // UTILITY METHODS + //////////////////////////////////////////////////////////////////////////// - @Override - public void run() { - - log.debug("show save hashdatainput dialog"); - - String userHome = System.getProperty("user.home"); - - JFileChooser fileDialog = new JFileChooser(userHome); - fileDialog.setMultiSelectionEnabled(false); - fileDialog.setDialogType(JFileChooser.SAVE_DIALOG); - fileDialog.setFileHidingEnabled(true); - if (signedRefs.size() == 1) { - fileDialog.setDialogTitle(getMessage(WINDOWTITLE_SAVE)); - fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY); - String mimeType = signedRefs.get(0).getMimeType(); - MimeFilter mimeFilter = new MimeFilter(mimeType, messages); - fileDialog.setFileFilter(mimeFilter); - String filename = getMessage(SAVE_HASHDATAINPUT_PREFIX) + MimeFilter.getExtension(mimeType); - fileDialog.setSelectedFile(new File(userHome, filename)); - } else { - fileDialog.setDialogTitle(getMessage(WINDOWTITLE_SAVEDIR)); - fileDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - } - - //parent contentPane -> placed over applet - switch (fileDialog.showSaveDialog(fileDialog)) { - case JFileChooser.APPROVE_OPTION: - File f = fileDialog.getSelectedFile(); - for (HashDataInput hashDataInput : signedRefs) { - String mimeType = hashDataInput.getMimeType(); - String id = hashDataInput.getReferenceId(); - File file; - if (f.isDirectory()) { - String filename = getMessage(SAVE_HASHDATAINPUT_PREFIX) + '_' + id + MimeFilter.getExtension(mimeType); - file = new File(f, filename); - } else { - file = f; - } - if (file.exists()) { - String ovrwrt = getMessage(MESSAGE_OVERWRITE); - int overwrite = JOptionPane.showConfirmDialog(fileDialog, MessageFormat.format(ovrwrt, file), getMessage(WINDOWTITLE_OVERWRITE), JOptionPane.OK_CANCEL_OPTION); - if (overwrite != JOptionPane.OK_OPTION) { - continue; - } - } - if (log.isDebugEnabled()) { - log.debug("Writing HashDataInput " + id + " (" + mimeType + ") to file " + file); - } - FileOutputStream fos = null; - try { - fos = new FileOutputStream(file); - BufferedOutputStream bos = new BufferedOutputStream(fos); - InputStream hdi = hashDataInput.getHashDataInput(); - int b; - while ((b = hdi.read()) != -1) { - bos.write(b); - } - bos.flush(); - bos.close(); - } catch (IOException ex) { - log.error("Failed to write HashDataInput to file " + file + ": " + ex.getMessage()); - showErrorDialog(ERR_WRITE_HASHDATA, new Object[] {ex.getMessage()}, null, null); - ex.printStackTrace(); - } finally { - try { - fos.close(); - } catch (IOException ex) { - } - } - } - } - log.debug("done saving hashdatainput"); - if (okListener != null) { - okListener.actionPerformed(new ActionEvent(fileDialog, ActionEvent.ACTION_PERFORMED, okCommand)); - } - } - }); - } - private void registerHelpListener(ActionListener helpListener) { if (helpListener != null) { this.helpListener = new HelpMouseListener(helpListener); @@ -1371,6 +1503,11 @@ public class BKUGUIImpl implements BKUGUIFacade { } } + + //////////////////////////////////////////////////////////////////////////// + // INITIALIZERS (MAY BE OVERRIDDEN BY SUBCLASSES) + //////////////////////////////////////////////////////////////////////////// + /** * Called from constructor. * Subclasses may override this method to ensure the message bundle is loaded 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 6c097b2a..00000000 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/HashDataViewer.java +++ /dev/null @@ -1,293 +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.bku.gui.html.RestrictedHTMLEditorKit; -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.MouseAdapter; -import java.awt.event.MouseEvent; -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.io.Reader; -import java.nio.charset.Charset; -import java.text.MessageFormat; -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.StyledEditorKit; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * - * @author Clemens Orthacker - */ -public class HashDataViewer extends JDialog - implements ActionListener { - - public static final String PLAINTEXT_FONT = "Monospaced"; - protected static final Log log = LogFactory.getLog(HashDataViewer.class); - - private static HashDataViewer dialog; - - protected ResourceBundle messages; - - /** - * - * @param signedReferences currently, only one hashdata input (the first in the list) is displayed - */ - public static void showHashDataInput(HashDataInput hashDataInput, - ResourceBundle messages, - ActionListener saveListener, - String saveCommand, - ActionListener helpListener) { - showHashDataInput(null, hashDataInput, messages, saveListener, saveCommand, helpListener); - } - - /** - * - * @param frameComp owner - */ - public static void showHashDataInput(Component frameComp, - HashDataInput hashDataInput, - ResourceBundle messages, - ActionListener saveListener, - String saveCommand, - ActionListener helpListener) { - - Frame frame = null; - if (frameComp != null) { - JOptionPane.getFrameForComponent(frameComp); - } - dialog = new HashDataViewer(frame, - messages, - hashDataInput, - saveListener, - saveCommand, - helpListener); - dialog.setVisible(true); - } - - private HashDataViewer(Frame frame, - ResourceBundle messages, - HashDataInput hashDataInput, - ActionListener saveListener, - String saveCommand, - ActionListener helpListener) { - super(frame, messages.getString(BKUGUIFacade.WINDOWTITLE_VIEWER), true); - this.messages = messages; - - Charset cs; - if (hashDataInput.getEncoding() == null) { - cs = Charset.forName("UTF-8"); - } else { - try { - cs = Charset.forName(hashDataInput.getEncoding()); - } catch (Exception ex) { - log.debug("charset " + hashDataInput.getEncoding() + " not supported, assuming UTF-8: " + ex.getMessage()); - cs = Charset.forName("UTF-8"); - } - } - - - InputStreamReader isr = new InputStreamReader(hashDataInput.getHashDataInput(), cs); - Reader content = new BufferedReader(isr); - - JPanel hashDataPanel = createViewerPanel(content, - hashDataInput.getMimeType(), - helpListener); - JPanel buttonPanel = createButtonPanel(saveListener, saveCommand); - initContentPane(new Dimension(600, 400), hashDataPanel, 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(Reader content, - String mimeType, - final ActionListener helpListener) { - - if (mimeType == null) { - mimeType = "text/plain"; - } - log.debug("viewer dialog: " + mimeType); - - JEditorPane viewer = new JEditorPane(); - viewer.setEditable(false); - viewer.setContentType(mimeType); - - if ("text/plain".equals(mimeType)) { - viewer.setEditorKit(new StyledEditorKit()); - viewer.setFont(new Font(PLAINTEXT_FONT, viewer.getFont().getStyle(), viewer.getFont().getSize())); -// } else if ("text/html".equals(mimeType)) { -// viewer.setEditorKit(new RestrictedHTMLEditorKit()); - } else if ("application/xhtml+xml".equals(mimeType)) { - viewer.setContentType("text/html"); - } - - EditorKit editorKit = viewer.getEditorKit(); - Document document = editorKit.createDefaultDocument(); -// document.putProperty("IgnoreCharsetDirective", new Boolean(true)); - - try { - 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); - - JPanel viewerPanel = new JPanel(); - GroupLayout viewerPanelLayout = new GroupLayout(viewerPanel); - viewerPanel.setLayout(viewerPanelLayout); - - GroupLayout.SequentialGroup infoHorizontal = viewerPanelLayout.createSequentialGroup(); - GroupLayout.ParallelGroup infoVertical = viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); - - if ("application/xhtml+xml".equals(mimeType)) { - JLabel viewerLabel = new JLabel(); - viewerLabel.setText(messages.getString(BKUGUIFacade.WARNING_XHTML)); - viewerLabel.setFont(viewerLabel.getFont().deriveFont(viewerLabel.getFont().getStyle() | java.awt.Font.BOLD)); - viewerLabel.setLabelFor(viewer); - - infoHorizontal.addComponent(viewerLabel); - infoVertical.addComponent(viewerLabel); - } - - if (helpListener != null) { - JLabel helpLabel = new JLabel(); - helpLabel.setIcon(new ImageIcon(getClass().getResource(BKUGUIFacade.HELP_IMG))); - helpLabel.getAccessibleContext().setAccessibleName(messages.getString(BKUGUIFacade.ALT_HELP)); - helpLabel.addMouseListener(new MouseAdapter() { - - @Override - public void mouseClicked(MouseEvent arg0) { - ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, BKUGUIFacade.HELP_HASHDATAVIEWER); - helpListener.actionPerformed(e); - } - }); - helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - - infoHorizontal - .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE) - .addComponent(helpLabel); - infoVertical - .addComponent(helpLabel); - } - - viewerPanelLayout.setHorizontalGroup( - viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(infoHorizontal) - .addComponent(scrollPane)); - viewerPanelLayout.setVerticalGroup( - viewerPanelLayout.createSequentialGroup() - .addGroup(infoVertical) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(scrollPane)); - - - return viewerPanel; - } - - 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) { - HashDataViewer.dialog.setVisible(false); - } -} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java new file mode 100644 index 00000000..6a16306b --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java @@ -0,0 +1,371 @@ +/* + * 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.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.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.Charset; +import java.text.MessageFormat; +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.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.LayoutStyle; +import javax.swing.SwingUtilities; +import javax.swing.text.Document; +import javax.swing.text.EditorKit; +import javax.swing.text.StyledEditorKit; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author Clemens Orthacker + */ +public class SecureViewerDialog extends JDialog implements ActionListener { + + public static final String PLAINTEXT_FONT = "Monospaced"; + public static final Dimension VIEWER_DIMENSION = new Dimension(600, 400); + protected static final Log log = LogFactory.getLog(SecureViewerDialog.class); + +// private static SecureViewerDialog dialog; + protected ResourceBundle messages; + protected JEditorPane viewer; + protected JLabel viewerLabel; + protected JScrollPane scrollPane; + protected HashDataInput content; //remember for save dialog + + /** + * Create and display a modal SecureViewer dialog. + * This method blocks until the dialog's close button is pressed. + * + * @param owner, dialog is positioned relative to its owner + * (if null, at default location of native windowing system) + */ +// public static void showDataToBeSigned(HashDataInput dataToBeSigned, +// ResourceBundle messages, +// ActionListener saveListener, String saveCommand, +// ActionListener helpListener) { +// +//// Frame ownerFrame = (owner != null) ? +//// JOptionPane.getFrameForComponent(owner) : +//// null; +// dialog = new SecureViewerDialog(null, messages, +// saveListener, saveCommand, helpListener); +// dialog.setContent(dataToBeSigned); +// dialog.setVisible(true); +// } + public SecureViewerDialog(Frame owner, ResourceBundle messages, +// ActionListener saveListener, String saveCommand, + ActionListener helpListener) { + super(owner, messages.getString(BKUGUIFacade.WINDOWTITLE_VIEWER), true); + this.messages = messages; + + initContentPane(VIEWER_DIMENSION, + createViewerPanel(helpListener), + createButtonPanel()); //saveListener, saveCommand)); + + pack(); + if (owner != null) { + setLocationRelativeTo(owner); + } 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 helpListener may be null + */ + private JPanel createViewerPanel(final ActionListener helpListener) { + viewer = new JEditorPane(); + viewer.setEditable(false); + + scrollPane = new JScrollPane(); + + JPanel viewerPanel = new JPanel(); + GroupLayout viewerPanelLayout = new GroupLayout(viewerPanel); + viewerPanel.setLayout(viewerPanelLayout); + + GroupLayout.SequentialGroup infoHorizontal = viewerPanelLayout.createSequentialGroup(); + GroupLayout.ParallelGroup infoVertical = viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING); + + viewerLabel = new JLabel(); + viewerLabel.setFont(viewerLabel.getFont().deriveFont(viewerLabel.getFont().getStyle() | java.awt.Font.BOLD)); +// viewerLabel.setLabelFor(viewer); + + infoHorizontal.addComponent(viewerLabel); + infoVertical.addComponent(viewerLabel); + + if (helpListener != null) { + JLabel helpLabel = new JLabel(); + helpLabel.setIcon(new ImageIcon(getClass().getResource(BKUGUIFacade.HELP_IMG))); + helpLabel.getAccessibleContext().setAccessibleName(messages.getString(BKUGUIFacade.ALT_HELP)); + helpLabel.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent arg0) { + ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, BKUGUIFacade.HELP_HASHDATAVIEWER); + helpListener.actionPerformed(e); + } + }); + helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + + infoHorizontal.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 0, Short.MAX_VALUE).addComponent(helpLabel); + infoVertical.addComponent(helpLabel); + } + + viewerPanelLayout.setHorizontalGroup( + viewerPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(infoHorizontal).addComponent(scrollPane)); + viewerPanelLayout.setVerticalGroup( + viewerPanelLayout.createSequentialGroup().addGroup(infoVertical).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(scrollPane)); + + return viewerPanel; + } + + /** + * Sets the hashdataInput to be displayed and makes the dialog visible. + * This method blocks until the dialog's close button is pressed. + * + * @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 hashDataInput + */ + public void setContent(HashDataInput hashDataInput) { + + this.content = null; + + String mimeType = hashDataInput.getMimeType(); + if (mimeType == null) { + mimeType = "text/plain"; + } + log.debug("secure viewer mime type: " + mimeType); + // loads editorkit for text/plain if unrecognized + viewer.setContentType(mimeType); + + if ("text/plain".equals(mimeType)) { + viewer.setEditorKit(new StyledEditorKit()); + viewer.setFont(new Font(PLAINTEXT_FONT, viewer.getFont().getStyle(), viewer.getFont().getSize())); +// } else if ("text/html".equals(mimeType)) { +// viewer.setEditorKit(new RestrictedHTMLEditorKit()); + } else if ("application/xhtml+xml".equals(mimeType)) { + viewer.setContentType("text/html"); + } + + EditorKit editorKit = viewer.getEditorKit(); + Document document = editorKit.createDefaultDocument(); +// document.putProperty("IgnoreCharsetDirective", new Boolean(true)); + + try { + Charset cs = (hashDataInput.getEncoding() == null) ? Charset.forName("UTF-8") : Charset.forName(hashDataInput.getEncoding()); + log.debug("secure viewer encoding: " + cs.toString()); + + InputStreamReader isr = new InputStreamReader(hashDataInput.getHashDataInput(), cs); + Reader contentReader = new BufferedReader(isr); + viewer.read(contentReader, document); + contentReader.close(); + + this.content = hashDataInput; + +// } catch (IllegalCharsetNameException ex) { +// } catch (UnsupportedCharsetException ex) { + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + String p = messages.getString(BKUGUIFacade.ERR_VIEWER); + viewer.setText(MessageFormat.format(p, ex.getMessage())); + } + viewer.setCaretPosition(0); + + scrollPane.setViewportView(viewer); + scrollPane.setPreferredSize(viewer.getPreferredSize()); + scrollPane.setAlignmentX(LEFT_ALIGNMENT); + + if ("application/xhtml+xml".equals(mimeType)) { + viewerLabel.setText(messages.getString(BKUGUIFacade.WARNING_XHTML)); + } else { + viewerLabel.setText(""); + } + + setVisible(true); + } + + private JPanel createButtonPanel() { //ActionListener saveListener, String saveCommand) { + JButton closeButton = new JButton(); + closeButton.setText(messages.getString(BKUGUIFacade.BUTTON_CLOSE)); + closeButton.setActionCommand("close"); + closeButton.addActionListener(this); + + JButton saveButton = new JButton(); + saveButton.setText(messages.getString(BKUGUIFacade.BUTTON_SAVE)); + saveButton.setActionCommand("save"); + saveButton.addActionListener(this); + + 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())) { +// SecureViewerDialog.dialog.setVisible(false); + log.trace("closing secure viewer"); + setVisible(false); + log.trace("secure viewer closed"); + } else if ("save".equals(e.getActionCommand())) { + log.trace("display secure viewer save dialog"); + showSaveDialog(content, null, null); + log.trace("done secure viewer save"); + } else { + log.warn("unknown action command " + e.getActionCommand()); + } + } + + private void showSaveDialog(final HashDataInput hashDataInput, + final ActionListener okListener, final String okCommand) { + + log.debug("scheduling save dialog [" + Thread.currentThread().getName() + "]"); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + log.debug("show save dialog [" + Thread.currentThread().getName() + "]"); + + String userHome = System.getProperty("user.home"); + + JFileChooser fileDialog = new JFileChooser(userHome); + fileDialog.setMultiSelectionEnabled(false); + fileDialog.setDialogType(JFileChooser.SAVE_DIALOG); + fileDialog.setFileHidingEnabled(true); + fileDialog.setDialogTitle(messages.getString(BKUGUIFacade.WINDOWTITLE_SAVE)); + fileDialog.setFileSelectionMode(JFileChooser.FILES_ONLY); + String mimeType = hashDataInput.getMimeType(); + MimeFilter mimeFilter = new MimeFilter(mimeType, messages); + fileDialog.setFileFilter(mimeFilter); + String filename = messages.getString(BKUGUIFacade.SAVE_HASHDATAINPUT_PREFIX) + + MimeFilter.getExtension(mimeType); + fileDialog.setSelectedFile(new File(userHome, filename)); + + //parent contentPane -> placed over applet + switch (fileDialog.showSaveDialog(fileDialog)) { + case JFileChooser.APPROVE_OPTION: + File file = fileDialog.getSelectedFile(); + String id = hashDataInput.getReferenceId(); + if (file.exists()) { + String msgPattern = messages.getString(BKUGUIFacade.MESSAGE_OVERWRITE); + int overwrite = JOptionPane.showConfirmDialog(fileDialog, + MessageFormat.format(msgPattern, file), + messages.getString(BKUGUIFacade.WINDOWTITLE_OVERWRITE), + JOptionPane.OK_CANCEL_OPTION); + if (overwrite != JOptionPane.OK_OPTION) { + return; + } + } + if (log.isDebugEnabled()) { + log.debug("writing hashdata input " + id + " (" + mimeType + ") to file " + file); + } + FileOutputStream fos = null; + try { + fos = new FileOutputStream(file); + BufferedOutputStream bos = new BufferedOutputStream(fos); + InputStream hdi = hashDataInput.getHashDataInput(); + int b; + while ((b = hdi.read()) != -1) { + bos.write(b); + } + bos.flush(); + bos.close(); + } catch (IOException ex) { + log.error("Failed to write " + file + ": " + ex.getMessage()); + log.debug(ex); + String errPattern = messages.getString(BKUGUIFacade.ERR_WRITE_HASHDATA); + JOptionPane.showMessageDialog(fileDialog, + MessageFormat.format(errPattern, ex.getMessage()), + messages.getString(BKUGUIFacade.WINDOWTITLE_ERROR), + JOptionPane.ERROR_MESSAGE); + } finally { + try { + if (fos != null) { + fos.close(); + } + } catch (IOException ex) { + } + } + break; + case JFileChooser.CANCEL_OPTION: + log.debug("cancelled save dialog"); + break; + } + if (okListener != null) { + okListener.actionPerformed(new ActionEvent(fileDialog, ActionEvent.ACTION_PERFORMED, okCommand)); + } + } + }); + } +} 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 6d651b2d..9bfe8fb1 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 @@ -25,6 +25,7 @@ title.retry=Falsche PIN title.wait=Bitte warten title.hashdata=Signaturdaten windowtitle.save=Signaturdaten speichern +windowtitle.error=Fehler windowtitle.savedir=Signaturdaten in Verzeichnis speichern windowtitle.overwrite=Datei \u00FCberschreiben? windowtitle.viewer=Signaturdaten @@ -79,7 +80,7 @@ error.unknown.param=Ein Fehler trat auf: {0} error.unknown=Ein Fehler trat auf error.test=Fehler1 {0} - Fehler2 {1} error.card.locked=B\u00FCrgerkarte ist gesperrt -error.card.notactivated=B\u00FCrgerkartenfunktion ist nicht aktiviert +error.card.notactivated=Die B\u00FCrgerkarte ist nicht aktiviert error.pin.timeout=Zeit\u00FCberschreitung bei Eingabe der PIN error.viewer=Der Inhalt kann nicht dargestellt werden: {0} error.external.link=Externer Link {0} wird nicht ge\u00F6ffnet 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 2fb66969..a36f9b83 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 @@ -25,6 +25,7 @@ title.retry=Wrong PIN title.wait=Please wait title.hashdata=Signature data windowtitle.save=Save signature data +windowtitle.error=Error windowtitle.savedir=Save signature data to directory windowtitle.overwrite=Overwrite file? windowtitle.viewer=Signature data diff --git a/BKUCommonGUI/src/main/resources/images/ChipperlingLogo.png b/BKUCommonGUI/src/main/resources/images/ChipperlingLogo.png new file mode 100644 index 00000000..eee4be4f Binary files /dev/null and b/BKUCommonGUI/src/main/resources/images/ChipperlingLogo.png differ diff --git a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java index c8cff617..b3eaf8c7 100644 --- a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java +++ b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java @@ -39,8 +39,9 @@ public class BKUGUITest { public void testBKUGUI() { JFrame testFrame = new JFrame("BKUGUITest"); Container contentPane = testFrame.getContentPane(); - contentPane.setPreferredSize(new Dimension(170, 150)); - BKUGUIFacade gui = new BKUGUIImpl(contentPane, null, BKUGUIFacade.Style.tiny, null, null); +// contentPane.setPreferredSize(new Dimension(170, 150)); + contentPane.setPreferredSize(new Dimension(290, 190)); + BKUGUIFacade gui = new BKUGUIImpl(contentPane, null, BKUGUIFacade.Style.advanced, null, null); BKUGUIWorker worker = new BKUGUIWorker(); worker.init(gui); testFrame.pack(); 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 194e18b0..5475a45b 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 @@ -149,7 +149,9 @@ public class BKUGUIWorker implements Runnable { // // Thread.sleep(2000); // - gui.showSignaturePINDialog(signPinSpec, -1, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); +// gui.showSignaturePINDialog(signPinSpec, -1, signListener, "sign", cancelListener, "cancel", hashdataListener, "hashdata"); + + gui.showPinpadSignaturePINDialog(signPinSpec, -1, hashdataListener, "hashdata"); // // Thread.sleep(4000); // 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 5a0ba84a..3f560967 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 @@ -144,4 +144,12 @@ public class BKUGuiProxy implements BKUGUIFacade { showDialog(); delegate.showMessageDialog(titleKey, msgKey); } + + @Override + public void showPinpadSignaturePINDialog(PINSpec pinSpec, int numRetries, + ActionListener viewerListener, String viewerCommand) { + showDialog(); + delegate.showPinpadSignaturePINDialog(pinSpec, numRetries, + viewerListener, viewerCommand); + } } diff --git a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalBKUWorker.java b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalBKUWorker.java index 61cc7c4c..a782de1a 100644 --- a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalBKUWorker.java +++ b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalBKUWorker.java @@ -37,7 +37,8 @@ public class LocalBKUWorker extends AbstractBKUWorker { public LocalBKUWorker(BKUGUIFacade gui, JDialog container) { super(gui); this.container = container; - addRequestHandler(SignRequest.class, new LocalSignRequestHandler()); + addRequestHandler(SignRequest.class, + new LocalSignRequestHandler(new LocalSecureViewer(gui))); } @Override diff --git a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSecureViewer.java b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSecureViewer.java new file mode 100644 index 00000000..cbe5af7a --- /dev/null +++ b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSecureViewer.java @@ -0,0 +1,109 @@ + +package at.gv.egiz.bku.local.stal; + +import at.gv.egiz.bku.slcommands.impl.DataObjectHashDataInput; +import at.gv.egiz.bku.smccstal.SecureViewer; +import java.io.IOException; +import java.util.ArrayList; + +import at.gv.egiz.bku.gui.BKUGUIFacade; +import at.gv.egiz.stal.HashDataInput; +import at.gv.egiz.stal.impl.ByteArrayHashDataInput; +import at.gv.egiz.stal.signedinfo.ReferenceType; +import at.gv.egiz.stal.signedinfo.SignedInfoType; +import java.awt.event.ActionListener; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.util.Collections; +import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class LocalSecureViewer implements SecureViewer { + + private static final Log log = LogFactory.getLog(LocalSignRequestHandler.class); + private List hashDataInputs = Collections.EMPTY_LIST; + + protected BKUGUIFacade gui; + + public LocalSecureViewer(BKUGUIFacade gui) { + this.gui = gui; + } + + public void setDataToBeSigned(List dataToBeSigned) { + this.hashDataInputs = dataToBeSigned; + } + + /** + * + * @param dsigReferences + * @throws java.lang.Exception + */ + @Override + public void displayDataToBeSigned(SignedInfoType signedInfo, + ActionListener okListener, String okCommand) + throws Exception { + if (signedInfo.getReference().size() == 0) { + log.error("No hashdata input selected to be displayed: null"); + throw new Exception("No HashData Input selected to be displayed"); + } + + ArrayList selectedHashDataInputs = new ArrayList(); + for (ReferenceType dsigRef : signedInfo.getReference()) { + // don't get Manifest, QualifyingProperties, ... + if (dsigRef.getType() == null) { + String dsigRefId = dsigRef.getId(); + if (dsigRefId != null) { + boolean hdiAvailable = false; + for (HashDataInput hashDataInput : hashDataInputs) { + if (dsigRefId.equals(hashDataInput.getReferenceId())) { + log.debug("display hashdata input for dsig:SignedReference " + + dsigRefId); + selectedHashDataInputs.add( + ensureCachedHashDataInput(hashDataInput)); + hdiAvailable = true; + break; + } + } + if (!hdiAvailable) { + log.error("no hashdata input for dsig:SignedReference " + dsigRefId); + throw new Exception( + "No HashDataInput available for dsig:SignedReference " + dsigRefId); + } + } else { + throw new Exception( + "Cannot get HashDataInput for dsig:Reference without Id attribute"); + } + } + } + + if (selectedHashDataInputs.size() < 1) { + log.error("dsig:SignedInfo does not contain a data reference"); + throw new Exception("dsig:SignedInfo does not contain a data reference"); + } + gui.showSecureViewer(selectedHashDataInputs, okListener, okCommand); + } + + + private HashDataInput ensureCachedHashDataInput(HashDataInput hashDataInput) + throws IOException { + if (!(hashDataInput instanceof DataObjectHashDataInput)) { + + log.warn("expected DataObjectHashDataInput for LocalSignRequestHandler, got " + + hashDataInput.getClass().getName()); + + InputStream hdIs = hashDataInput.getHashDataInput(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(hdIs.available()); + int b; + while ((b = hdIs.read()) != -1) { + baos.write(b); + } + hashDataInput = new ByteArrayHashDataInput(baos.toByteArray(), + hashDataInput.getReferenceId(), + hashDataInput.getMimeType(), + hashDataInput.getEncoding()); + } + return hashDataInput; + } + +} diff --git a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSignRequestHandler.java b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSignRequestHandler.java index 531e6591..492b8a05 100644 --- a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSignRequestHandler.java +++ b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSignRequestHandler.java @@ -16,9 +16,7 @@ */ package at.gv.egiz.bku.local.stal; -import at.gv.egiz.bku.slcommands.impl.DataObjectHashDataInput; -import java.io.IOException; -import java.util.ArrayList; +import at.gv.egiz.bku.smccstal.SecureViewer; import java.util.Collections; import java.util.List; @@ -40,9 +38,16 @@ import java.io.InputStream; * @author clemens */ public class LocalSignRequestHandler extends SignRequestHandler { +// implements SecureViewer { private static final Log log = LogFactory.getLog(LocalSignRequestHandler.class); - private List hashDataInputs = Collections.EMPTY_LIST; + + protected LocalSecureViewer secureViewer; + + public LocalSignRequestHandler(LocalSecureViewer secureViewer) { + super(secureViewer); + } + /** * If the request is a SIGN request, it contains a list of DataObjectHashDataInput @@ -53,75 +58,13 @@ public class LocalSignRequestHandler extends SignRequestHandler { */ @SuppressWarnings("unchecked") @Override - public STALResponse handleRequest(STALRequest request) throws InterruptedException { + public STALResponse handleRequest(STALRequest request) + throws InterruptedException { + if (request instanceof SignRequest) { SignRequest signReq = (SignRequest) request; - hashDataInputs = signReq.getHashDataInput(); + secureViewer.setDataToBeSigned(signReq.getHashDataInput()); } return super.handleRequest(request); } - - /** - * - * @param dsigReferences - * @throws java.lang.Exception - */ - @Override - public void displayDataToBeSigned(List dsigReferences) throws Exception { - if (dsigReferences == null || dsigReferences.size() < 1) { - log.error("No hashdata input selected to be displayed: null"); - throw new Exception("No HashData Input selected to be displayed"); - } - - ArrayList selectedHashDataInputs = new ArrayList(); - for (ReferenceType dsigRef : dsigReferences) { - // don't get Manifest, QualifyingProperties, ... - if (dsigRef.getType() == null) { - String dsigRefId = dsigRef.getId(); - if (dsigRefId != null) { - boolean hdiAvailable = false; - for (HashDataInput hashDataInput : hashDataInputs) { - if (dsigRefId.equals(hashDataInput.getReferenceId())) { - log.debug("display hashdata input for dsig:SignedReference " + dsigRefId); - if (!(hashDataInput instanceof DataObjectHashDataInput)) { - log.warn( - "expected DataObjectHashDataInput for LocalSignRequestHandler, got " + hashDataInput.getClass().getName()); - hashDataInput = getByteArrayHashDataInput(hashDataInput); - } - selectedHashDataInputs.add(hashDataInput); - hdiAvailable = true; - break; - } - } - if (!hdiAvailable) { - log.error("no hashdata input for dsig:SignedReference " + dsigRefId); - throw new Exception( - "No HashDataInput available for dsig:SignedReference " + dsigRefId); - } - } else { - throw new Exception( - "Cannot get HashDataInput for dsig:Reference without Id attribute"); - } - } - } - - if (selectedHashDataInputs.size() < 1) { - log.error("dsig:SignedInfo does not contain a data reference"); - throw new Exception("dsig:SignedInfo does not contain a data reference"); - } - gui.showSecureViewer(selectedHashDataInputs, this, "hashDataDone"); - } - - private ByteArrayHashDataInput getByteArrayHashDataInput(HashDataInput hashDataInput) throws IOException { - - InputStream hdIs = hashDataInput.getHashDataInput(); - ByteArrayOutputStream baos = new ByteArrayOutputStream(hdIs.available()); - int b; - while ((b = hdIs.read()) != -1) { - baos.write(b); - } - ByteArrayHashDataInput hdi = new ByteArrayHashDataInput(baos.toByteArray(), hashDataInput.getReferenceId(), hashDataInput.getMimeType(), hashDataInput.getEncoding()); - - return hdi; - } } diff --git a/BKUOnline/src/main/resources/at/gv/egiz/bku/online/conf/defaultConf.properties b/BKUOnline/src/main/resources/at/gv/egiz/bku/online/conf/defaultConf.properties index e2f07481..04c9c7bf 100644 --- a/BKUOnline/src/main/resources/at/gv/egiz/bku/online/conf/defaultConf.properties +++ b/BKUOnline/src/main/resources/at/gv/egiz/bku/online/conf/defaultConf.properties @@ -40,9 +40,12 @@ SSL.sslProtocol=TLS # warning do not set the following property to true # its intended for debugging and testing only SSL.disableAllChecks=false +#SSL.disableHostnameVerification=true # ------------ END SSL Config -------------------- +#UserAgent=citizen-card-environment/1.2 MOCCA/1.0 + ValidateHashDataInputs=true AppletTimeout=300000 diff --git a/BKUOnline/src/main/resources/log4j.properties b/BKUOnline/src/main/resources/log4j.properties index f608c83d..25ea9faa 100644 --- a/BKUOnline/src/main/resources/log4j.properties +++ b/BKUOnline/src/main/resources/log4j.properties @@ -30,7 +30,7 @@ log4j.appender.STDOUT.layout.ConversionPattern=%-5p | %t | %c %x - %m%n log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.maxFileSize=500KB log4j.appender.file.maxBackupIndex=9 -log4j.appender.file.File=${catalina.home}/logs/bkuonline.log +log4j.appender.file.File=${catalina.base}/logs/bkuonline.log log4j.appender.file.threshold=trace log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p | %t | %c{1}:%L - %m%n \ No newline at end of file diff --git a/BKUOnline/src/main/webapp/SLRequestForm.html b/BKUOnline/src/main/webapp/SLRequestForm.html index 9ff7b68a..4714e82f 100644 --- a/BKUOnline/src/main/webapp/SLRequestForm.html +++ b/BKUOnline/src/main/webapp/SLRequestForm.html @@ -103,6 +103,33 @@ --> + true ${project.build.outputDirectory} META-INF\/ diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index 6346b7f4..7a15f7a5 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -16,6 +16,7 @@ */ package at.gv.egiz.bku.online.applet; +import at.gv.egiz.bku.online.applet.viewer.URLFontLoader; import at.gv.egiz.bku.gui.BKUGUIFacade.Style; import at.gv.egiz.bku.gui.DefaultHelpListener; import at.gv.egiz.bku.gui.AbstractHelpListener; @@ -25,6 +26,8 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Locale; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.net.ssl.HttpsURLConnection; import javax.swing.JApplet; import javax.swing.JPanel; @@ -34,6 +37,7 @@ import org.apache.commons.logging.LogFactory; import at.gv.egiz.bku.gui.BKUGUIFacade; import at.gv.egiz.bku.gui.BKUGUIImpl; +import at.gv.egiz.bku.gui.viewer.FontProvider; import at.gv.egiz.stal.service.STALPortType; import at.gv.egiz.stal.service.STALService; import java.applet.AppletContext; @@ -46,289 +50,287 @@ import javax.xml.namespace.QName; * Note: all swing code is executed by the event dispatch thread (see * BKUGUIFacade) */ -public class BKUApplet extends JApplet { - - private static final long serialVersionUID = 1L; - - private static Log log = LogFactory.getLog(BKUApplet.class); - /** - * Applet parameter keys - */ - public static final String GUI_STYLE = "GuiStyle"; - public final static String LOCALE = "Locale"; - public final static String WSDL_URL = "WSDL_URL"; - public static final String HASHDATA_DISPLAY = "HashDataDisplay"; - public final static String HASHDATA_URL = "HashDataURL"; - public final static String HELP_URL = "HelpURL"; - public final static String SESSION_ID = "SessionID"; - public static final String BACKGROUND_IMG = "Background"; - public static final String BACKGROUND_COLOR = "BackgroundColor"; - public static final String REDIRECT_URL = "RedirectURL"; - public static final String REDIRECT_TARGET = "RedirectTarget"; - public static final String HASHDATA_DISPLAY_FRAME = "frame"; - /** - * STAL WSDL namespace and service name - */ - public static final String STAL_WSDL_NS = "http://www.egiz.gv.at/wsdl/stal"; - public static final String STAL_SERVICE = "STALService"; - /** - * Dummy session id, used if no sessionId parameter is provided - */ - protected static final String TEST_SESSION_ID = "TestSession"; - - static { - if (log.isTraceEnabled()) { - log.trace("enabling webservice communication dump"); - System - .setProperty( - "com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", - "true"); - } - } - - /** - * STAL - */ - protected AppletBKUWorker worker; - protected Thread workerThread; - - /* - * (non-Javadoc) - * - * @see java.applet.Applet#getParameterInfo() - */ - @Override - public String[][] getParameterInfo() { - return new String[][] { - { WSDL_URL, "url", - "URL of the WSDL of the MOCCA server side STAL" }, - { REDIRECT_URL, "url", - "URL to redirect the browser to when finished" }, - { REDIRECT_TARGET, "frame target", - "name of the target frame for redirection when finished" }, - { LOCALE, "locale", - "locale for UI localization (optional, default: system default)" }, - { GUI_STYLE, "simple, advanced, tiny", - "GUI style (optional, default: simple)" }, - { BACKGROUND_COLOR, "#hhhhhh", - "background color, e.g. '#333333' (optional, default: look and feel dependend)" }, - { BACKGROUND_IMG, "url", - "URL of a background image for the GUI (optional, default: no image)" }, - { HELP_URL, "url", - "URL for locating help files, e.g. '../help/' (no help provided if missing)" } }; - } - - /** - * Factory method to create and wire HelpListener, GUI and BKUWorker. - * (Config via applet parameters, see BKUApplet.* constants) - */ - @Override - public void init() { - log.info("Welcome to MOCCA"); - log.trace("Called init()"); - - HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory - .getInstance()); - - String locale = getParameter(LOCALE); - if (locale != null) { - this.setLocale(new Locale(locale)); - } - log.trace("default locale: " + Locale.getDefault()); - log.debug("setting locale: " + getLocale()); - - BKUGUIFacade.Style guiStyle; - String guiStyleParam = getParameter(GUI_STYLE); - if ("advanced".equals(guiStyleParam)) { - guiStyle = BKUGUIFacade.Style.advanced; - } else if ("tiny".equals(guiStyleParam)) { - guiStyle = BKUGUIFacade.Style.tiny; - } else { - guiStyle = BKUGUIFacade.Style.simple; - } - log.debug("setting gui-style: " + guiStyle); - - URL backgroundImgURL = null; - try { - backgroundImgURL = getURLParameter(BACKGROUND_IMG, null); - log.debug("setting background: " + backgroundImgURL); - } catch (MalformedURLException ex) { - log.warn("cannot load applet background image: " + ex.getMessage()); - } - - AbstractHelpListener helpListener = null; - try { - helpListener = new DefaultHelpListener(getAppletContext(), - getURLParameter(HELP_URL, null), getLocale()); - if (log.isDebugEnabled()) { - log - .debug("setting helpURL: " - + getURLParameter(HELP_URL, null)); - } - } catch (MalformedURLException ex) { - log.warn("failed to load help URL: " + ex.getMessage() - + ", disabling help"); - } - - SwitchFocusListener switchFocusListener = new SwitchFocusListener( - getAppletContext(), "focusToBrowser()"); - - // Note: We need a panel in order to be able to set the background - // properly. - // Setting the background without a panel has side effects with the - // different java plugins. - JPanel contentPanel = new JPanel(); - getContentPane().add(contentPanel); - - String backgroundColor = getParameter(BACKGROUND_COLOR); - if (backgroundColor != null && backgroundColor.startsWith("#")) { - try { - Color color = new Color(Integer.parseInt(backgroundColor - .substring(1), 16)); - log.debug("setting background color to " + color); - contentPanel.setBackground(color); - } catch (NumberFormatException e) { - log.debug("failed to set background color '" + backgroundColor - + "'"); - } - } - - BKUGUIFacade gui = createGUI(contentPanel, getLocale(), guiStyle, - backgroundImgURL, helpListener, switchFocusListener); - - worker = createBKUWorker(this, gui); - } - - @Override - public void start() { - log.trace("Called start()"); - workerThread = new Thread(worker); - workerThread.start(); - } - - @Override - public void stop() { - log.trace("Called stop()"); - if ((workerThread != null) && (workerThread.isAlive())) { - workerThread.interrupt(); - } - } - - @Override - public void destroy() { - log.trace("Called destroy()"); - } - - // /////////////////////////////////////////////////////////////////////////// - // factory methods for subclasses to inject different components - // /////////////////////////////////////////////////////////////////////////// - - protected BKUGUIFacade createGUI(Container contentPane, Locale locale, - Style guiStyle, URL backgroundImgURL, - AbstractHelpListener helpListener, - SwitchFocusListener switchFocusListener) { - return new BKUGUIImpl(contentPane, locale, guiStyle, backgroundImgURL, - helpListener, switchFocusListener); - } - - protected AppletBKUWorker createBKUWorker(BKUApplet applet, BKUGUIFacade gui) { - return new AppletBKUWorker(applet, gui); - } - - // /////////////////////////////////////////////////////////////////////////// - // callback for BKUWorker to allow extension - // /////////////////////////////////////////////////////////////////////////// - - /** - * Callback for BKUWorker to allow extension - * - * @return - * @throws java.net.MalformedURLException - */ - public STALPortType getSTALPort() throws MalformedURLException { - URL wsdlURL = getURLParameter(WSDL_URL, null); - log.debug("setting STAL WSDL: " + wsdlURL); - QName endpointName = new QName(STAL_WSDL_NS, STAL_SERVICE); - STALService stal = new STALService(wsdlURL, endpointName); - return stal.getSTALPort(); - } - - /** - * Callback for BKUWorker to allow extension (TODO STALPort could know its - * STALTranslator) - * - * @return - * @throws java.net.MalformedURLException - */ - public STALTranslator getSTALTranslator() { - return new STALTranslator(); - } - - /** - * Callback for BKUWorker to keep applet context out of BKUWorker - * - * @return - * @throws java.net.MalformedURLException - */ - protected void sendRedirect(String sessionId) { - try { - AppletContext ctx = getAppletContext(); - if (ctx == null) { - log - .error("no applet context (applet might already have been destroyed)"); - return; - } - URL redirectURL = getURLParameter(REDIRECT_URL, sessionId); - String redirectTarget = getParameter(REDIRECT_TARGET); - if (redirectTarget == null) { - log.info("Done. Redirecting to " + redirectURL + " ..."); - ctx.showDocument(redirectURL); - } else { - log.info("Done. Redirecting to " + redirectURL + " (target=" - + redirectTarget + ") ..."); - ctx.showDocument(redirectURL, redirectTarget); - } - } catch (MalformedURLException ex) { - log.warn("Failed to redirect: " + ex.getMessage(), ex); - // gui.showErrorDialog(errorMsg, okListener, actionCommand) - } - } - - public void getFocusFromBrowser() { - - worker.getFocusFromBrowser(); - } - - // /////////////////////////////////////////////////////////////////////////// - // utility methods - // /////////////////////////////////////////////////////////////////////////// - - protected URL getURLParameter(String paramKey, String sessionId) - throws MalformedURLException { - String urlParam = getParameter(paramKey); - if (urlParam != null && !"".equals(urlParam)) { - URL codebase = getCodeBase(); - try { - URL url; - if (codebase.getProtocol().equalsIgnoreCase("file")) { - // for debugging in appletrunner - url = new URL(urlParam); - } else { - if (sessionId != null) { - urlParam = urlParam + ";jsessionid=" + sessionId; - } - url = new URL(codebase, urlParam); - } - return url; - } catch (MalformedURLException ex) { - log.error("applet paremeter " + urlParam - + " is not a valid URL: " + ex.getMessage()); - throw ex; - } - } else { - log.error("applet paremeter " + paramKey + " not set"); - throw new MalformedURLException(paramKey + " not set"); - } - } - +public class BKUApplet extends JApplet { + + private static final long serialVersionUID = 1L; + private static Log log = LogFactory.getLog(BKUApplet.class); + /** + * Applet parameter keys + */ + public static final String GUI_STYLE = "GuiStyle"; + public final static String LOCALE = "Locale"; + public final static String WSDL_URL = "WSDL_URL"; + public static final String HASHDATA_DISPLAY = "HashDataDisplay"; + public final static String HASHDATA_URL = "HashDataURL"; + public final static String HELP_URL = "HelpURL"; + public final static String SESSION_ID = "SessionID"; + public static final String BACKGROUND_IMG = "Background"; + public static final String BACKGROUND_COLOR = "BackgroundColor"; + public static final String REDIRECT_URL = "RedirectURL"; + public static final String REDIRECT_TARGET = "RedirectTarget"; + public static final String HASHDATA_DISPLAY_FRAME = "frame"; + /** + * STAL WSDL namespace and service name + */ + public static final String STAL_WSDL_NS = "http://www.egiz.gv.at/wsdl/stal"; + public static final String STAL_SERVICE = "STALService"; + /** + * Dummy session id, used if no sessionId parameter is provided + */ + protected static final String TEST_SESSION_ID = "TestSession"; + + static { + if (log.isTraceEnabled()) { + log.trace("enabling webservice communication dump"); + System.setProperty( + "com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", + "true"); + } + } + /** + * STAL + */ + protected AppletBKUWorker worker; + protected Thread workerThread; + + /* + * (non-Javadoc) + * + * @see java.applet.Applet#getParameterInfo() + */ + @Override + public String[][] getParameterInfo() { + return new String[][]{ + {WSDL_URL, "url", + "URL of the WSDL of the MOCCA server side STAL"}, + {REDIRECT_URL, "url", + "URL to redirect the browser to when finished"}, + {REDIRECT_TARGET, "frame target", + "name of the target frame for redirection when finished"}, + {LOCALE, "locale", + "locale for UI localization (optional, default: system default)"}, + {GUI_STYLE, "simple, advanced, tiny", + "GUI style (optional, default: simple)"}, + {BACKGROUND_COLOR, "#hhhhhh", + "background color, e.g. '#333333' (optional, default: look and feel dependend)"}, + {BACKGROUND_IMG, "url", + "URL of a background image for the GUI (optional, default: no image)"}, + {HELP_URL, "url", + "URL for locating help files, e.g. '../help/' (no help provided if missing)"}}; + } + + /** + * Factory method to create and wire HelpListener, GUI and BKUWorker. + * (Config via applet parameters, see BKUApplet.* constants) + */ + @Override + public void init() { + log.info("Welcome to MOCCA"); + log.trace("Called init()"); + showStatus("Initializing MOCCA applet"); + + HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getInstance()); + + String locale = getParameter(LOCALE); + if (locale != null) { + this.setLocale(new Locale(locale)); + } + log.trace("default locale: " + Locale.getDefault()); + log.debug("setting locale: " + getLocale()); + + BKUGUIFacade.Style guiStyle; + String guiStyleParam = getParameter(GUI_STYLE); + if ("advanced".equals(guiStyleParam)) { + guiStyle = BKUGUIFacade.Style.advanced; + } else if ("tiny".equals(guiStyleParam)) { + guiStyle = BKUGUIFacade.Style.tiny; + } else { + guiStyle = BKUGUIFacade.Style.simple; + } + log.debug("setting gui-style: " + guiStyle); + + URL backgroundImgURL = null; + try { + backgroundImgURL = getURLParameter(BACKGROUND_IMG, null); + log.debug("setting background: " + backgroundImgURL); + } catch (MalformedURLException ex) { + log.warn("cannot load applet background image: " + ex.getMessage()); + } + + AbstractHelpListener helpListener = null; + try { + helpListener = new DefaultHelpListener(getAppletContext(), + getURLParameter(HELP_URL, null), getLocale()); + if (log.isDebugEnabled()) { + log.debug("setting helpURL: " + getURLParameter(HELP_URL, null)); + } + } catch (MalformedURLException ex) { + log.warn("failed to load help URL: " + ex.getMessage() + ", disabling help"); + } + + SwitchFocusListener switchFocusListener = new SwitchFocusListener( + getAppletContext(), "focusToBrowser()"); + + // Note: We need a panel in order to be able to set the background + // properly. + // Setting the background without a panel has side effects with the + // different java plugins. + JPanel contentPanel = new JPanel(); + getContentPane().add(contentPanel); + + String backgroundColor = getParameter(BACKGROUND_COLOR); + if (backgroundColor != null && backgroundColor.startsWith("#")) { + try { + Color color = new Color(Integer.parseInt(backgroundColor.substring(1), 16)); + log.debug("setting background color to " + color); + contentPanel.setBackground(color); + } catch (NumberFormatException e) { + log.debug("failed to set background color '" + backgroundColor + "'"); + } + } + + try { + URLFontLoader fontProvider = new URLFontLoader(getCodeBase()); + fontProvider.loadInBackground(); + BKUGUIFacade gui = createGUI(contentPanel, getLocale(), guiStyle, + backgroundImgURL, fontProvider, helpListener, switchFocusListener); + + worker = createBKUWorker(this, gui); + } catch (MalformedURLException ex) { + log.fatal("failed to load font provider URL", ex); + System.err.println("invalid font provider URL " + ex.getMessage()); + } + } + + @Override + public void start() { + log.trace("Called start()"); + if (worker != null) { + showStatus("Starting MOCCA applet"); + workerThread = new Thread(worker); + workerThread.start(); + } else { + log.debug("cannot start uninitialzed MOCCA applet"); + } + } + + @Override + public void stop() { + log.trace("Called stop()"); + showStatus("Stopping MOCCA applet"); + if ((workerThread != null) && (workerThread.isAlive())) { + workerThread.interrupt(); + } + } + + @Override + public void destroy() { + log.trace("Called destroy()"); + } + + // /////////////////////////////////////////////////////////////////////////// + // factory methods for subclasses to inject different components + // /////////////////////////////////////////////////////////////////////////// + protected BKUGUIFacade createGUI(Container contentPane, Locale locale, + Style guiStyle, URL backgroundImgURL, + FontProvider fontProvider, AbstractHelpListener helpListener, + SwitchFocusListener switchFocusListener) { + return new BKUGUIImpl(contentPane, locale, guiStyle, backgroundImgURL, + fontProvider, helpListener, switchFocusListener); + } + + protected AppletBKUWorker createBKUWorker(BKUApplet applet, BKUGUIFacade gui) { + return new AppletBKUWorker(applet, gui); + } + + // /////////////////////////////////////////////////////////////////////////// + // callback for BKUWorker to allow extension + // /////////////////////////////////////////////////////////////////////////// + /** + * Callback for BKUWorker to allow extension + * + * @return + * @throws java.net.MalformedURLException + */ + public STALPortType getSTALPort() throws MalformedURLException { + URL wsdlURL = getURLParameter(WSDL_URL, null); + log.debug("setting STAL WSDL: " + wsdlURL); + QName endpointName = new QName(STAL_WSDL_NS, STAL_SERVICE); + STALService stal = new STALService(wsdlURL, endpointName); + return stal.getSTALPort(); + } + + /** + * Callback for BKUWorker to allow extension (TODO STALPort could know its + * STALTranslator) + * + * @return + * @throws java.net.MalformedURLException + */ + public STALTranslator getSTALTranslator() { + return new STALTranslator(); + } + + /** + * Callback for BKUWorker to keep applet context out of BKUWorker + * + * @return + * @throws java.net.MalformedURLException + */ + protected void sendRedirect(String sessionId) { + try { + AppletContext ctx = getAppletContext(); + if (ctx == null) { + log.error("no applet context (applet might already have been destroyed)"); + return; + } + URL redirectURL = getURLParameter(REDIRECT_URL, sessionId); + String redirectTarget = getParameter(REDIRECT_TARGET); + if (redirectTarget == null) { + log.info("Done. Redirecting to " + redirectURL + " ..."); + ctx.showDocument(redirectURL); + } else { + log.info("Done. Redirecting to " + redirectURL + " (target=" + redirectTarget + ") ..."); + ctx.showDocument(redirectURL, redirectTarget); + } + } catch (MalformedURLException ex) { + log.warn("Failed to redirect: " + ex.getMessage(), ex); + // gui.showErrorDialog(errorMsg, okListener, actionCommand) + } + } + + public void getFocusFromBrowser() { + + worker.getFocusFromBrowser(); + } + + // /////////////////////////////////////////////////////////////////////////// + // utility methods + // /////////////////////////////////////////////////////////////////////////// + protected URL getURLParameter(String paramKey, String sessionId) + throws MalformedURLException { + String urlParam = getParameter(paramKey); + if (urlParam != null && !"".equals(urlParam)) { + URL codebase = getCodeBase(); + try { + URL url; + if (codebase.getProtocol().equalsIgnoreCase("file")) { + // for debugging in appletrunner + url = new URL(urlParam); + } else { + if (sessionId != null) { + urlParam = urlParam + ";jsessionid=" + sessionId; + } + url = new URL(codebase, urlParam); + } + return url; + } catch (MalformedURLException ex) { + log.error("applet paremeter " + urlParam + " is not a valid URL: " + ex.getMessage()); + throw ex; + } + } else { + log.error("applet paremeter " + paramKey + " not set"); + throw new MalformedURLException(paramKey + " not set"); + } + } } diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/viewer/URLFontLoader.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/viewer/URLFontLoader.java new file mode 100644 index 00000000..f914aed7 --- /dev/null +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/viewer/URLFontLoader.java @@ -0,0 +1,82 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package at.gv.egiz.bku.online.applet.viewer; + +import at.gv.egiz.bku.gui.viewer.FontProviderException; +import at.gv.egiz.bku.gui.viewer.FontProvider; +import java.awt.Font; +import java.awt.FontFormatException; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.concurrent.ExecutionException; +import javax.swing.SwingWorker; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author Clemens Orthacker + */ +public class URLFontLoader extends SwingWorker implements FontProvider { + + protected static final Log log = LogFactory.getLog(URLFontLoader.class); + protected URL fontURL; + protected Font font; + + public URLFontLoader(URL codebase) throws MalformedURLException { + this.fontURL = new URL(codebase, SANSMONO_FONT_RESOURCE); + if (log.isDebugEnabled()) { + log.debug(Thread.currentThread() + " setting font load URL: " + fontURL); + } + } + + public void loadInBackground() { + if (log.isDebugEnabled()) { + log.debug(Thread.currentThread() + " scheduling font loading in background: " + fontURL); + } + this.execute(); + } + + @Override + protected Font doInBackground() throws MalformedURLException, FontFormatException, IOException { + if (log.isDebugEnabled()) { + log.debug(Thread.currentThread() + " loading font in background..."); + } + return Font.createFont(Font.TRUETYPE_FONT, fontURL.openStream()); + } + + /** + * waits for loadInBackground to finish + * @return the font loaded in loadInbackground + * @throws Exception + */ + @Override + public Font getFont() throws FontProviderException { + log.debug(Thread.currentThread() + " get font"); + try { + return get(); + } catch (InterruptedException ex) { + log.error("font loader interrupted"); +// Thread.currentThread().interrupt(); + throw new FontProviderException("font loader interrupted", ex); + } catch (ExecutionException ex) { + log.error("failed to load font", ex.getCause()); + throw new FontProviderException("failed to load font", ex.getCause()); + } + } +} diff --git a/BKUApplet/src/test/resources/appletTest.html b/BKUApplet/src/test/resources/appletTest.html index 4a768f91..d1a0f6e2 100644 --- a/BKUApplet/src/test/resources/appletTest.html +++ b/BKUApplet/src/test/resources/appletTest.html @@ -15,20 +15,25 @@ limitations under the License. --> + + + MOCCA Applet + + -
- - - - - - - - - - -
+ + + + + + + + + + + + - \ No newline at end of file + diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/ActivationApplet.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/ActivationApplet.java index 5bab2ef8..4f2f1331 100644 --- a/BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/ActivationApplet.java +++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/ActivationApplet.java @@ -21,6 +21,7 @@ import at.gv.egiz.bku.gui.ActivationGUI; import at.gv.egiz.bku.gui.BKUGUIFacade; import at.gv.egiz.bku.gui.SwitchFocusListener; import at.gv.egiz.bku.gui.BKUGUIFacade.Style; +import at.gv.egiz.bku.gui.viewer.FontProvider; import at.gv.egiz.bku.online.applet.BKUApplet; import at.gv.egiz.bku.smccstal.AbstractSMCCSTAL; import at.gv.egiz.bku.smccstal.CardMgmtRequestHandler; @@ -85,8 +86,9 @@ public class ActivationApplet extends BKUApplet { Locale locale, Style guiStyle, URL backgroundImgURL, + FontProvider fontProvider, AbstractHelpListener helpListener, SwitchFocusListener switchFocusListener) { - return new ActivationGUI(contentPane, locale, guiStyle, backgroundImgURL, helpListener, switchFocusListener); + return new ActivationGUI(contentPane, locale, guiStyle, backgroundImgURL, fontProvider, helpListener, switchFocusListener); } } diff --git a/BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/PINManagementApplet.java b/BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/PINManagementApplet.java index 055e9c31..bf323969 100644 --- a/BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/PINManagementApplet.java +++ b/BKUAppletExt/src/main/java/at/gv/egiz/bku/online/applet/PINManagementApplet.java @@ -21,6 +21,7 @@ import at.gv.egiz.bku.gui.BKUGUIFacade; import at.gv.egiz.bku.gui.PINManagementGUI; import at.gv.egiz.bku.gui.PINManagementGUIFacade; import at.gv.egiz.bku.gui.SwitchFocusListener; +import at.gv.egiz.bku.gui.viewer.FontProvider; import java.awt.Container; import java.net.URL; import java.util.Locale; @@ -41,9 +42,10 @@ public class PINManagementApplet extends BKUApplet { Locale locale, BKUGUIFacade.Style guiStyle, URL backgroundImgURL, + FontProvider fontProvider, AbstractHelpListener helpListener, SwitchFocusListener switchFocusListener) { - return new PINManagementGUI(contentPane, locale, guiStyle, backgroundImgURL, helpListener, switchFocusListener); + return new PINManagementGUI(contentPane, locale, guiStyle, backgroundImgURL, fontProvider, helpListener, switchFocusListener); } @Override diff --git a/BKUCommonGUI/pom.xml b/BKUCommonGUI/pom.xml index 9fecb661..feefa18b 100644 --- a/BKUCommonGUI/pom.xml +++ b/BKUCommonGUI/pom.xml @@ -21,6 +21,13 @@ 1.2.8-SNAPSHOT compile + @@ -33,15 +40,4 @@ - \ No newline at end of file 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 e83502a8..8df4bd72 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 @@ -17,6 +17,8 @@ package at.gv.egiz.bku.gui; +import at.gv.egiz.bku.gui.viewer.FontProviderException; +import at.gv.egiz.bku.gui.viewer.FontProvider; import at.gv.egiz.smcc.PINSpec; import at.gv.egiz.stal.HashDataInput; import java.awt.Color; @@ -73,6 +75,7 @@ public class BKUGUIImpl implements BKUGUIFacade { protected HelpKeyListener helpKeyListener; protected SwitchFocusFocusListener switchFocusKeyListener; protected SecureViewerDialog secureViewer; + protected FontProvider fontProvider; protected Container contentPane; protected ResourceBundle messages; @@ -115,8 +118,9 @@ public class BKUGUIImpl implements BKUGUIFacade { */ public BKUGUIImpl(Container contentPane, Locale locale, - Style guiStyle, + Style guiStyle, URL background, + FontProvider fontProvider, ActionListener helpListener, SwitchFocusListener switchFocusListener) { this.contentPane = contentPane; @@ -139,7 +143,8 @@ public class BKUGUIImpl implements BKUGUIFacade { registerHelpListener(helpListener); registerSwitchFocusListener(switchFocusListener); - + + this.fontProvider = fontProvider; createGUI(background); } @@ -1386,7 +1391,12 @@ public class BKUGUIImpl implements BKUGUIFacade { @Override public void run() { - showSecureViewer(dataToBeSigned.get(0)); + try { + showSecureViewer(dataToBeSigned.get(0)); + } catch (FontProviderException ex) { + log.error("failed to display secure viewer", ex); + showErrorDialog(ERR_VIEWER, new Object[] {ex.getMessage()}, backListener, backCommand); + } } }); @@ -1407,12 +1417,12 @@ public class BKUGUIImpl implements BKUGUIFacade { * @param saveListener * @param saveCommand */ - private void showSecureViewer(HashDataInput dataToBeSigned) { + private void showSecureViewer(HashDataInput dataToBeSigned) throws FontProviderException { log.debug("show secure viewer [" + Thread.currentThread().getName() + "]"); if (secureViewer == null) { secureViewer = new SecureViewerDialog(null, messages, - helpMouseListener.getActionListener()); + fontProvider, helpMouseListener.getActionListener()); // workaround for [#439] // avoid AlwaysOnTop at least in applet, otherwise make secureViewer AlwaysOnTop since MOCCA Dialog (JFrame created in LocalSTALFactory) is always on top. @@ -1485,7 +1495,12 @@ public class BKUGUIImpl implements BKUGUIFacade { int selectionIdx = lsm.getMinSelectionIndex(); if (selectionIdx >= 0) { final HashDataInput selection = signedReferences.get(selectionIdx); - showSecureViewer(selection); + try { + showSecureViewer(selection); + } catch (FontProviderException ex) { + log.error("failed to display secure viewer", ex); + showErrorDialog(ERR_VIEWER, new Object[] {ex.getMessage()}, backListener, backCommand); + } } } }); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUIcons.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUIcons.java new file mode 100644 index 00000000..92d6897b --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/BKUIcons.java @@ -0,0 +1,57 @@ +/* + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package at.gv.egiz.bku.gui; + +import java.awt.Image; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import javax.imageio.ImageIO; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * @author Clemens Orthacker + */ +public class BKUIcons { + + protected static final Log log = LogFactory.getLog(BKUIcons.class); + + /** 16x16, 24x24, 32x32, 48x48, 128x128 pixels */ + public static final ArrayList icons = new ArrayList(); + + static { + String[] iconResources = new String[] { + "/at/gv/egiz/bku/gui/chip16.png", + "/at/gv/egiz/bku/gui/chip24.png", + "/at/gv/egiz/bku/gui/chip32.png", + "/at/gv/egiz/bku/gui/chip48.png", + "/at/gv/egiz/bku/gui/chip128.png" }; + for (String ir : iconResources) { + URL resource = BKUIcons.class.getResource(ir); + if (ir != null) { + try { + icons.add(ImageIO.read(resource)); + } catch (IOException ex) { + log.warn("failed to load mocca icon " + ir, ex); + } + } + } + } +} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java index ef70f94b..1883fce5 100644 --- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/SecureViewerDialog.java @@ -16,6 +16,7 @@ */ package at.gv.egiz.bku.gui; +import at.gv.egiz.bku.gui.viewer.FontProvider; import at.gv.egiz.stal.HashDataInput; import java.awt.Container; import java.awt.Cursor; @@ -53,9 +54,12 @@ import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.LayoutStyle; import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import javax.swing.text.DefaultEditorKit; import javax.swing.text.Document; import javax.swing.text.EditorKit; import javax.swing.text.StyledEditorKit; +import javax.swing.text.html.HTMLEditorKit; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -65,16 +69,20 @@ import org.apache.commons.logging.LogFactory; */ public class SecureViewerDialog extends JDialog implements ActionListener { - public static final String PLAINTEXT_FONT = "Monospaced"; + /** don't import BKUFonts in order not to load BKUFonts.jar + * BKUApplet includes BKUFonts as runtime dependency only, the jar is copied to the applet dir in BKUOnline with dependency-plugin + * BKUViewer has compile dependency BKUFonts, transitive in BKUOnline and BKULocal + */ + public static final String PLAINTEXT_FONT_RESOURCE = "DejaVuSansMono.ttf"; public static final Dimension VIEWER_DIMENSION = new Dimension(600, 400); protected static final Log log = LogFactory.getLog(SecureViewerDialog.class); - // private static SecureViewerDialog dialog; protected ResourceBundle messages; protected JEditorPane viewer; protected JLabel viewerLabel; protected JScrollPane scrollPane; protected HashDataInput content; //remember for save dialog + protected FontProvider fontProvider; /** * Create and display a modal SecureViewer dialog. @@ -97,10 +105,12 @@ public class SecureViewerDialog extends JDialog implements ActionListener { // dialog.setVisible(true); // } public SecureViewerDialog(Frame owner, ResourceBundle messages, -// ActionListener saveListener, String saveCommand, - ActionListener helpListener) { + // ActionListener saveListener, String saveCommand, + FontProvider fontProvider, ActionListener helpListener) { super(owner, messages.getString(BKUGUIFacade.WINDOWTITLE_VIEWER), true); + this.setIconImages(BKUIcons.icons); this.messages = messages; + this.fontProvider = fontProvider; initContentPane(VIEWER_DIMENSION, createViewerPanel(helpListener), @@ -135,7 +145,8 @@ public class SecureViewerDialog extends JDialog implements ActionListener { private JPanel createViewerPanel(final ActionListener helpListener) { viewer = new JEditorPane(); viewer.setEditable(false); - + viewer.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE); + scrollPane = new JScrollPane(); JPanel viewerPanel = new JPanel(); @@ -167,31 +178,29 @@ public class SecureViewerDialog extends JDialog implements ActionListener { }); helpLabel.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent arg0) { - - if(arg0.getKeyCode() == KeyEvent.VK_ENTER) { - ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, BKUGUIFacade.HELP_HASHDATAVIEWER); - helpListener.actionPerformed(e); - } + @Override + public void keyPressed(KeyEvent arg0) { + + if (arg0.getKeyCode() == KeyEvent.VK_ENTER) { + ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, BKUGUIFacade.HELP_HASHDATAVIEWER); + helpListener.actionPerformed(e); } - }); - + } + }); + helpLabel.addFocusListener(new FocusAdapter() { - - @Override - public void focusGained(FocusEvent e) { - - helpLabel.setIcon(new ImageIcon(getClass().getResource(BKUGUIFacade.HELP_IMG_FOCUS))); - } - - @Override - public void focusLost(FocusEvent e) { - - helpLabel.setIcon(new ImageIcon(getClass().getResource(BKUGUIFacade.HELP_IMG))); - } - - + + @Override + public void focusGained(FocusEvent e) { + + helpLabel.setIcon(new ImageIcon(getClass().getResource(BKUGUIFacade.HELP_IMG_FOCUS))); + } + + @Override + public void focusLost(FocusEvent e) { + + helpLabel.setIcon(new ImageIcon(getClass().getResource(BKUGUIFacade.HELP_IMG))); + } }); helpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); @@ -216,9 +225,10 @@ public class SecureViewerDialog extends JDialog implements ActionListener { * @param hashDataInput */ - public void setContent(HashDataInput hashDataInput) { + public void setContent(HashDataInput hashDataInput) { //throws FontProviderException { this.content = null; + viewer.setText(null); String mimeType = hashDataInput.getMimeType(); if (mimeType == null) { @@ -228,20 +238,21 @@ public class SecureViewerDialog extends JDialog implements ActionListener { // loads editorkit for text/plain if unrecognized viewer.setContentType(mimeType); - if ("text/plain".equals(mimeType)) { - viewer.setEditorKit(new StyledEditorKit()); - viewer.setFont(new Font(PLAINTEXT_FONT, viewer.getFont().getStyle(), viewer.getFont().getSize())); -// } else if ("text/html".equals(mimeType)) { -// viewer.setEditorKit(new RestrictedHTMLEditorKit()); - } else if ("application/xhtml+xml".equals(mimeType)) { - viewer.setContentType("text/html"); - } + try { + + if ("text/plain".equals(mimeType)) { + viewer.setEditorKit(new StyledEditorKit()); + viewer.setFont(fontProvider.getFont().deriveFont(Font.PLAIN, viewer.getFont().getSize())); + } else if ("application/xhtml+xml".equals(mimeType)) { + viewer.setEditorKit(new HTMLEditorKit()); + //reset font if fontprovider font was set before (TODO also html font from fontprovider) + viewer.setFont(new Font("Dialog", Font.PLAIN, viewer.getFont().getSize())); //UIManager.getFont("Label.font")); + } - EditorKit editorKit = viewer.getEditorKit(); - Document document = editorKit.createDefaultDocument(); -// document.putProperty("IgnoreCharsetDirective", new Boolean(true)); + EditorKit editorKit = viewer.getEditorKit(); + Document document = editorKit.createDefaultDocument(); + // document.putProperty("IgnoreCharsetDirective", new Boolean(true)); - try { Charset cs = (hashDataInput.getEncoding() == null) ? Charset.forName("UTF-8") : Charset.forName(hashDataInput.getEncoding()); log.debug("secure viewer encoding: " + cs.toString()); @@ -252,11 +263,14 @@ public class SecureViewerDialog extends JDialog implements ActionListener { this.content = hashDataInput; +// } catch (Exception ex) // fontProvider // } catch (IllegalCharsetNameException ex) { // } catch (UnsupportedCharsetException ex) { +// } catch (FontProviderException ex) { } catch (Exception ex) { log.error(ex.getMessage(), ex); String p = messages.getString(BKUGUIFacade.ERR_VIEWER); + viewer.setContentType("text/plain"); viewer.setText(MessageFormat.format(p, ex.getMessage())); } viewer.setCaretPosition(0); @@ -280,7 +294,7 @@ public class SecureViewerDialog extends JDialog implements ActionListener { closeButton.setText(messages.getString(BKUGUIFacade.BUTTON_CLOSE)); closeButton.setActionCommand("close"); closeButton.addActionListener(this); - + JButton saveButton = new JButton(); saveButton.setText(messages.getString(BKUGUIFacade.BUTTON_SAVE)); saveButton.setActionCommand("save"); diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/FontProvider.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/FontProvider.java new file mode 100644 index 00000000..8fb815b0 --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/FontProvider.java @@ -0,0 +1,40 @@ +/* + * 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.viewer; + +import java.awt.Font; + +/** + * + * @author Clemens Orthacker + */ +public interface FontProvider { + + /** will be replaced by more sophisticated font selection mechanism + * (see java.awt.Font int/String constants) */ + String SANSMONO_FONT_RESOURCE = "DejaVuLGCSansMono.ttf"; + + /** + * + * @return + * @throws InterruptedException + * @throws FileNotFoundException if remote font file cannot be retrieved + */ + Font getFont() throws FontProviderException; + +} diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/FontProviderException.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/FontProviderException.java new file mode 100644 index 00000000..5a6a277e --- /dev/null +++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/viewer/FontProviderException.java @@ -0,0 +1,29 @@ +/* + * 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.viewer; + +/** + * Encapsulates the reason why a font could not be loaded. + * @author Clemens Orthacker + */ +public class FontProviderException extends Exception { + + public FontProviderException(String msg, Throwable cause) { + super(msg, cause); + } +} 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 a96b835f..b458a214 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 @@ -86,7 +86,7 @@ error.test=Fehler1 {0} - Fehler2 {1} error.card.locked=B\u00FCrgerkarte ist gesperrt error.card.notactivated=Die B\u00FCrgerkarte ist nicht aktiviert error.pin.timeout=Zeit\u00FCberschreitung bei Eingabe der PIN -error.viewer=Der Inhalt kann nicht dargestellt werden: {0} +error.viewer=Der Inhalt kann nicht dargestellt werden: {0} error.external.link=Externer Link {0} wird nicht ge\u00F6ffnet error.config=Fehlerhafte Konfiguration des Systems: {0} 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 c795b3fa..22b9095c 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 @@ -84,7 +84,7 @@ error.test=Error1 {0} - Error2 {1} error.card.locked=Citizen card is locked error.card.notactivated=Citizen card not activated error.pin.timeout=Timeout during PIN entry -error.viewer=Failed to display contents: {0} +error.viewer=Failed to display contents: {0} error.external.link=Cannot open external link {0} error.config=Incorrect system configuration: {0} diff --git a/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip128.png b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip128.png new file mode 100644 index 00000000..c36d8079 Binary files /dev/null and b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip128.png differ diff --git a/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip16.png b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip16.png new file mode 100644 index 00000000..96b580e9 Binary files /dev/null and b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip16.png differ diff --git a/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip24.png b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip24.png new file mode 100644 index 00000000..efd6dbeb Binary files /dev/null and b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip24.png differ diff --git a/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip48.png b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip48.png new file mode 100644 index 00000000..491fbcac Binary files /dev/null and b/BKUCommonGUI/src/main/resources/at/gv/egiz/bku/gui/chip48.png differ diff --git a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java index 9f1cb612..fdd58850 100644 --- a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java +++ b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/BKUGUITest.java @@ -41,7 +41,7 @@ public class BKUGUITest { Container contentPane = testFrame.getContentPane(); // contentPane.setPreferredSize(new Dimension(170, 150)); contentPane.setPreferredSize(new Dimension(290, 190)); - BKUGUIFacade gui = new BKUGUIImpl(contentPane, null, BKUGUIFacade.Style.advanced, null, null, null); + BKUGUIFacade gui = new BKUGUIImpl(contentPane, null, BKUGUIFacade.Style.advanced, null, new DummyFontLoader(), null, null); BKUGUIWorker worker = new BKUGUIWorker(); worker.init(gui); testFrame.pack(); diff --git a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/DummyFontLoader.java b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/DummyFontLoader.java new file mode 100644 index 00000000..87d67adc --- /dev/null +++ b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/DummyFontLoader.java @@ -0,0 +1,35 @@ +/* + * 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.bku.gui.viewer.FontProviderException; +import at.gv.egiz.bku.gui.viewer.FontProvider; +import java.awt.Font; + +/** + * + * @author Clemens Orthacker + */ +public class DummyFontLoader implements FontProvider { + + @Override + public Font getFont() throws FontProviderException { + return new Font("monospaced", Font.PLAIN, 10); + } + +} diff --git a/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/SecureViewerDialogTest.java b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/SecureViewerDialogTest.java new file mode 100644 index 00000000..fc8dcd96 --- /dev/null +++ b/BKUCommonGUI/src/test/java/at/gv/egiz/bku/gui/SecureViewerDialogTest.java @@ -0,0 +1,165 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package at.gv.egiz.bku.gui; + +import at.gv.egiz.stal.impl.ByteArrayHashDataInput; +import java.awt.Font; +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.ResourceBundle; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +/** + * + * @author clemens + */ +@Ignore +public class SecureViewerDialogTest { + + static SecureViewerDialog secureViewer; + static ResourceBundle messages; + + @BeforeClass + public static void setUpClass() throws Exception { + messages = ResourceBundle.getBundle("at/gv/egiz/bku/gui/Messages"); + secureViewer = new SecureViewerDialog(null, messages, new DummyFontLoader(), null); + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + + @Test + @Ignore + public void testLatin1Supplement() throws UnsupportedEncodingException, FileNotFoundException, IOException { +// StringBuilder data = new StringBuilder(); +// data.append("\nhttp://www.unicode.org/charts/PDF/U0080.pdf\n"); +// for (int i = 0x0080; i <= 0x00ff; i++) { +// data.append((char) i); +// } +// System.out.println(data.toString()); + BufferedInputStream bis = new BufferedInputStream(new FileInputStream("/home/clemens/IAIK/MOCCA/encoding/test_iso-8859-1.txt")); + byte[] bytes = new byte[bis.available()]; + bis.read(bytes); + String s = new String(bytes, "iso-8859-1"); + System.out.println("read iso-8859-1 bytes " + s); + + secureViewer.setContent(new ByteArrayHashDataInput(s.getBytes("UTF-8"), "id-1", "text/plain", "iso-8859-1")); + + } + + @Test + @Ignore + public void testGreek() throws UnsupportedEncodingException { +// Font fm = new Font(Font.MONOSPACED, Font.PLAIN, 10); + Font fm = new Font("Lucida Sans Typewriter", Font.PLAIN, 18); //GothicBBB-MediumH", Font.PLAIN, 10); + System.out.println(fm.getFontName() + ", " + fm.getPSName() + ", " + fm); + + StringBuilder data = new StringBuilder(); + data.append("\nhttp://www.unicode.org/charts/PDF/U0370.pdf\n"); + for (int i = 0x0370; i <= 0x03ff; i++) { + if (!fm.canDisplay((char) i)) { + System.out.println("cannot display " + Integer.toHexString(i) ); + } + data.append((char) i); + } + + System.out.println(data.toString()); + secureViewer.setContent(new ByteArrayHashDataInput(data.toString().getBytes("UTF-8"), "id-1", "text/plain", "UTF-8")); + + } + + /** + * Test of setContent method, of class SecureViewerDialog. + */ + @Test +// @Ignore + public void testCyrillic() throws UnsupportedEncodingException { + + StringBuilder data = new StringBuilder("\n"); + + int[] mocca = new int[] {0x041c, 0x04a8, 0x0480, 0x0480, 0x0466 }; + + for (int i = 0; i < mocca.length; i++) { + data.append((char) mocca[i]); + } + data.append(" goes cyrillic\n"); + + data.append("\nCyrillic - http://www.unicode.org/charts/PDF/U0400.pdf\n"); + for (int i = 0x0400; i <= 0x04ff; i++) { +// System.out.printf("%c%04x=%c\t", (i & 7) == 0 ? '\n' : '\0', i, (char)i); +// System.out.print((char) i); + data.append((char)i); + } + + data.append("\n\nCyrillic Supplement - http://www.unicode.org/charts/PDF/U0500.pdf\n"); + for (int i = 0x0500; i <= 0x0525; i++) { +// System.out.printf("%c%04x=%c\t", (i & 7) == 0 ? '\n' : '\0', i, (char)i); +// System.out.print((char) i); + data.append((char) i); + } + + for (int i = 0; i < data.length(); i++) { + char c = data.charAt(i); + if (c >= '\u0400' && c <= '\u0525') { + System.out.println(c + "\tcyrillic"); + } else if (c < '\u007f') { + System.out.println(c + "\tlatin"); + } else { + System.out.println(c + "\tunknown"); + } + } + + System.out.println(data.toString()); + +// char[] cyrillicChars = new char[] {(char) 0x0411, (char) 0x0444}; +// System.out.println(new String(cyrillicChars)); // + ": " + SMCCHelper.toString(cyrillicBytes)); +// byte[] cyrillicBytes = new byte[] {(byte) 0x11, (byte) 0x04, (byte) 0x0444}; +// System.out.println(new String(cyrillicBytes, "UTF-8") + ": " + SMCCHelper.toString(cyrillicBytes)); + +// String encoding = "cp1252"; +// String data = "öäü߀"; +// byte[] bytes = data.getBytes(encoding); +// System.out.println(data + "\t" + SMCCHelper.toString(bytes)); +// byte[] bytes2 = data.getBytes("cp1252"); +// System.out.println(data + "\t" + SMCCHelper.toString(bytes2)); + + secureViewer.setContent(new ByteArrayHashDataInput(data.toString().getBytes("UTF-8"), "id-1", "text/plain", "UTF-8")); + + System.out.println("\n\n=============================\n"); +// +//// int[] mocca = new int[] {0x0428, 0x0429, 0x04a8, 0x04e8, 0x047a, 0x042d, 0x042d, 0x0421, 0x0421, 0x04d0, 0x0466 }; +// int[] mocca = new int[] {0x0429, 0x04a8, 0x0480, 0x0480, 0x0466 }; + for (int i = 0; i < mocca.length; i++) { + System.out.print((char) mocca[i]); + } +// for (int i = 0; i < mocca.length; i++) { +// System.out.printf(" 0x%04x", mocca[i]); +// } +// + System.out.println("\n=============================\n"); + + } + + +} \ No newline at end of file diff --git a/BKUFonts/pom.xml b/BKUFonts/pom.xml new file mode 100644 index 00000000..a798f5d1 --- /dev/null +++ b/BKUFonts/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + + bku + at.gv.egiz + 1.2.8-SNAPSHOT + + at.gv.egiz + BKUFonts + 1.0 + BKUFonts + + This module is used in validator(s) and viewer and is a direct dependency of + - BKUViewer (attention, this is the validator!) + TextValidator depends on the fonts. (compile scope, make available for BKULocal/Online TextValidator) + (TextValidator should rather use a FontProvider) + - BKUOnline: + - direct/provided if jar inclusion in applet dir, but do not enforce inclusion as WEB-INF/lib + - transitive from BKUViewer if unpack-fonts to applet dir + - removed the BKUCommonGUI (runtime; propagate dependency to BKUApplet): + no real dependency: BKUCommonGUI contains SecureFontProvider interface only + (which does not state how fonts are loaded); implementations should depend no BKUFonts + (ResourceFontLoader in BKULocal depends on the fonts, however URLFontLoader in BKUApplet doesn't. + BKUOnline however depends on BKUFonts for providing the fonts as web-resource for the applet) + + + at.gv.egiz.bku.text.TextValidator and xxx.LocalFontProvider load fonts from classpath, + resource name must be known, TODO: encapsulate resource loading (FontProvider constants?) + + at.gv.egiz.bku.online.applet.URLFontLoader loads (unpacked) font files from applet codebase, + resource names _must_ be known since applet has no BKUFonts dependency + + + + + + src/main/fonts + + + + diff --git a/BKUFonts/src/main/fonts/DejaVuLGCSans.ttf b/BKUFonts/src/main/fonts/DejaVuLGCSans.ttf new file mode 100644 index 00000000..cae5a48b Binary files /dev/null and b/BKUFonts/src/main/fonts/DejaVuLGCSans.ttf differ diff --git a/BKUFonts/src/main/fonts/DejaVuLGCSansMono.ttf b/BKUFonts/src/main/fonts/DejaVuLGCSansMono.ttf new file mode 100644 index 00000000..21647753 Binary files /dev/null and b/BKUFonts/src/main/fonts/DejaVuLGCSansMono.ttf differ diff --git a/BKUFonts/src/main/fonts/DejaVuLGCSerif.ttf b/BKUFonts/src/main/fonts/DejaVuLGCSerif.ttf new file mode 100644 index 00000000..4b3bf2e6 Binary files /dev/null and b/BKUFonts/src/main/fonts/DejaVuLGCSerif.ttf differ diff --git a/BKUFonts/src/main/fonts/LICENSE b/BKUFonts/src/main/fonts/LICENSE new file mode 100644 index 00000000..254e2cc4 --- /dev/null +++ b/BKUFonts/src/main/fonts/LICENSE @@ -0,0 +1,99 @@ +Fonts are (c) Bitstream (see below). DejaVu changes are in public domain. +Glyphs imported from Arev fonts are (c) Tavmjong Bah (see below) + +Bitstream Vera Fonts Copyright +------------------------------ + +Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is +a trademark of Bitstream, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of the fonts accompanying this license ("Fonts") and associated +documentation files (the "Font Software"), to reproduce and distribute the +Font Software, including without limitation the rights to use, copy, merge, +publish, distribute, and/or sell copies of the Font Software, and to permit +persons to whom the Font Software is furnished to do so, subject to the +following conditions: + +The above copyright and trademark notices and this permission notice shall +be included in all copies of one or more of the Font Software typefaces. + +The Font Software may be modified, altered, or added to, and in particular +the designs of glyphs or characters in the Fonts may be modified and +additional glyphs or characters may be added to the Fonts, only if the fonts +are renamed to names not containing either the words "Bitstream" or the word +"Vera". + +This License becomes null and void to the extent applicable to Fonts or Font +Software that has been modified and is distributed under the "Bitstream +Vera" names. + +The Font Software may be sold as part of a larger software package but no +copy of one or more of the Font Software typefaces may be sold by itself. + +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, +TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME +FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING +ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE +FONT SOFTWARE. + +Except as contained in this notice, the names of Gnome, the Gnome +Foundation, and Bitstream Inc., shall not be used in advertising or +otherwise to promote the sale, use or other dealings in this Font Software +without prior written authorization from the Gnome Foundation or Bitstream +Inc., respectively. For further information, contact: fonts at gnome dot +org. + +Arev Fonts Copyright +------------------------------ + +Copyright (c) 2006 by Tavmjong Bah. All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of the fonts accompanying this license ("Fonts") and +associated documentation files (the "Font Software"), to reproduce +and distribute the modifications to the Bitstream Vera Font Software, +including without limitation the rights to use, copy, merge, publish, +distribute, and/or sell copies of the Font Software, and to permit +persons to whom the Font Software is furnished to do so, subject to +the following conditions: + +The above copyright and trademark notices and this permission notice +shall be included in all copies of one or more of the Font Software +typefaces. + +The Font Software may be modified, altered, or added to, and in +particular the designs of glyphs or characters in the Fonts may be +modified and additional glyphs or characters may be added to the +Fonts, only if the fonts are renamed to names not containing either +the words "Tavmjong Bah" or the word "Arev". + +This License becomes null and void to the extent applicable to Fonts +or Font Software that has been modified and is distributed under the +"Tavmjong Bah Arev" names. + +The Font Software may be sold as part of a larger software package but +no copy of one or more of the Font Software typefaces may be sold by +itself. + +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL +TAVMJONG BAH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. + +Except as contained in this notice, the name of Tavmjong Bah shall not +be used in advertising or otherwise to promote the sale, use or other +dealings in this Font Software without prior written authorization +from Tavmjong Bah. For further information, contact: tavmjong @ free +. fr. + +$Id: LICENSE 2133 2007-11-28 02:46:28Z lechimp $ diff --git a/BKUFonts/src/main/fonts/META-INF/services/at.gv.egiz.bku.gui.SecureFontProvider b/BKUFonts/src/main/fonts/META-INF/services/at.gv.egiz.bku.gui.SecureFontProvider new file mode 100644 index 00000000..c9bf2059 --- /dev/null +++ b/BKUFonts/src/main/fonts/META-INF/services/at.gv.egiz.bku.gui.SecureFontProvider @@ -0,0 +1,3 @@ +Serif DejaVuLGCSerif.ttf +Sans DejaVuLGCSans.ttf +SansMono DejaVuLGCSansMono.ttf diff --git a/BKUGuiExt/src/main/java/at/gv/egiz/bku/gui/ActivationGUI.java b/BKUGuiExt/src/main/java/at/gv/egiz/bku/gui/ActivationGUI.java index 1a1426a5..37f30340 100644 --- a/BKUGuiExt/src/main/java/at/gv/egiz/bku/gui/ActivationGUI.java +++ b/BKUGuiExt/src/main/java/at/gv/egiz/bku/gui/ActivationGUI.java @@ -16,14 +16,13 @@ */ package at.gv.egiz.bku.gui; -import at.gv.egiz.bku.gui.*; +import at.gv.egiz.bku.gui.viewer.FontProvider; import java.awt.Container; import java.awt.Cursor; import java.awt.event.ActionListener; import java.net.URL; import java.text.MessageFormat; import java.util.Locale; -import java.util.ResourceBundle; import javax.swing.GroupLayout; import javax.swing.JButton; import javax.swing.JLabel; @@ -50,9 +49,10 @@ public class ActivationGUI extends CardMgmtGUI implements ActivationGUIFacade { Locale locale, Style guiStyle, URL backgroundImgURL, + FontProvider fontProvider, AbstractHelpListener helpListener, SwitchFocusListener switchFocusListener) { - super(contentPane, locale, guiStyle, backgroundImgURL, helpListener, switchFocusListener); + super(contentPane, locale, guiStyle, backgroundImgURL, fontProvider, helpListener, switchFocusListener); progressBar = new JProgressBar(); } diff --git a/BKUGuiExt/src/main/java/at/gv/egiz/bku/gui/CardMgmtGUI.java b/BKUGuiExt/src/main/java/at/gv/egiz/bku/gui/CardMgmtGUI.java index 68b2a2ba..98f44d55 100644 --- a/BKUGuiExt/src/main/java/at/gv/egiz/bku/gui/CardMgmtGUI.java +++ b/BKUGuiExt/src/main/java/at/gv/egiz/bku/gui/CardMgmtGUI.java @@ -17,7 +17,7 @@ package at.gv.egiz.bku.gui; -import at.gv.egiz.bku.gui.*; +import at.gv.egiz.bku.gui.viewer.FontProvider; import java.awt.Container; import java.net.URL; import java.util.Locale; @@ -38,9 +38,10 @@ public class CardMgmtGUI extends BKUGUIImpl { Locale locale, Style guiStyle, URL backgroundImgURL, + FontProvider fontProvider, AbstractHelpListener helpListener, SwitchFocusListener switchFocusListener) { - super(contentPane, locale, guiStyle, backgroundImgURL, helpListener, switchFocusListener); + super(contentPane, locale, guiStyle, backgroundImgURL, fontProvider, helpListener, switchFocusListener); } diff --git a/BKUGuiExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUI.java b/BKUGuiExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUI.java index 12f032d8..6699554e 100644 --- a/BKUGuiExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUI.java +++ b/BKUGuiExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUI.java @@ -17,6 +17,7 @@ package at.gv.egiz.bku.gui; +import at.gv.egiz.bku.gui.viewer.FontProvider; import at.gv.egiz.smcc.PINSpec; import java.awt.Container; import java.awt.Cursor; @@ -58,9 +59,10 @@ public class PINManagementGUI extends CardMgmtGUI implements PINManagementGUIFac Locale locale, Style guiStyle, URL backgroundImgURL, + FontProvider fontProvider, AbstractHelpListener helpListener, SwitchFocusListener switchFocusListener) { - super(contentPane, locale, guiStyle, backgroundImgURL, helpListener, switchFocusListener); + super(contentPane, locale, guiStyle, backgroundImgURL, fontProvider, helpListener, switchFocusListener); } @Override diff --git a/BKUGuiExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUIFacade.java b/BKUGuiExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUIFacade.java index 297173d9..f99bcfd1 100644 --- a/BKUGuiExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUIFacade.java +++ b/BKUGuiExt/src/main/java/at/gv/egiz/bku/gui/PINManagementGUIFacade.java @@ -17,7 +17,6 @@ package at.gv.egiz.bku.gui; -import at.gv.egiz.bku.gui.*; import at.gv.egiz.smcc.PINSpec; import java.awt.event.ActionListener; import java.util.Map; diff --git a/BKUGuiExt/src/test/java/at/gv/egiz/bku/gui/ActivationGuiTest.java b/BKUGuiExt/src/test/java/at/gv/egiz/bku/gui/ActivationGuiTest.java index fd562a21..cb05e5f1 100644 --- a/BKUGuiExt/src/test/java/at/gv/egiz/bku/gui/ActivationGuiTest.java +++ b/BKUGuiExt/src/test/java/at/gv/egiz/bku/gui/ActivationGuiTest.java @@ -21,7 +21,6 @@ package at.gv.egiz.bku.gui; -import at.gv.egiz.bku.gui.*; import java.awt.Container; import java.awt.Dimension; import javax.swing.JFrame; @@ -42,7 +41,7 @@ public class ActivationGuiTest { Container contentPane = testFrame.getContentPane(); contentPane.setPreferredSize(new Dimension(152, 145)); // contentPane.setPreferredSize(new Dimension(300, 190)); - ActivationGUIFacade gui = new ActivationGUI(contentPane, null, BKUGUIFacade.Style.tiny, null, null, null); + ActivationGUIFacade gui = new ActivationGUI(contentPane, null, BKUGUIFacade.Style.tiny, null, new DummyFontLoader(), null, null); BKUGUIWorker worker = new BKUGUIWorker(); worker.init(gui); testFrame.pack(); diff --git a/BKUGuiExt/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java b/BKUGuiExt/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java index 74ea8952..b01abe72 100644 --- a/BKUGuiExt/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java +++ b/BKUGuiExt/src/test/java/at/gv/egiz/bku/gui/BKUGUIWorker.java @@ -20,7 +20,6 @@ */ package at.gv.egiz.bku.gui; -import at.gv.egiz.bku.gui.*; import at.gv.egiz.smcc.PINSpec; import at.gv.egiz.stal.HashDataInput; import at.gv.egiz.stal.impl.ByteArrayHashDataInput; diff --git a/BKUGuiExt/src/test/java/at/gv/egiz/bku/gui/DummyFontLoader.java b/BKUGuiExt/src/test/java/at/gv/egiz/bku/gui/DummyFontLoader.java new file mode 100644 index 00000000..87d67adc --- /dev/null +++ b/BKUGuiExt/src/test/java/at/gv/egiz/bku/gui/DummyFontLoader.java @@ -0,0 +1,35 @@ +/* + * 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.bku.gui.viewer.FontProviderException; +import at.gv.egiz.bku.gui.viewer.FontProvider; +import java.awt.Font; + +/** + * + * @author Clemens Orthacker + */ +public class DummyFontLoader implements FontProvider { + + @Override + public Font getFont() throws FontProviderException { + return new Font("monospaced", Font.PLAIN, 10); + } + +} diff --git a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSTALFactory.java b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSTALFactory.java index 65a0d5ae..44322a07 100644 --- a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSTALFactory.java +++ b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSTALFactory.java @@ -16,33 +16,23 @@ */ package at.gv.egiz.bku.local.stal; +import at.gv.egiz.bku.viewer.ResourceFontLoader; import java.awt.Dimension; import java.awt.Toolkit; -import java.awt.event.WindowEvent; -import java.io.IOException; import java.net.MalformedURLException; import java.util.Locale; import at.gv.egiz.bku.gui.BKUGUIFacade; -import at.gv.egiz.bku.gui.BKUGUIImpl; +import at.gv.egiz.bku.gui.BKUIcons; import at.gv.egiz.bku.gui.PINManagementGUI; import at.gv.egiz.bku.gui.PINManagementGUIFacade; import at.gv.egiz.bku.local.gui.GUIProxy; import at.gv.egiz.bku.local.gui.LocalHelpListener; import at.gv.egiz.stal.STAL; import at.gv.egiz.stal.STALFactory; -import java.awt.Image; -import java.awt.Window; -import java.awt.event.WindowAdapter; import java.net.URL; -import java.util.ArrayList; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.imageio.ImageIO; -import javax.swing.ImageIcon; import javax.swing.JFrame; -import javax.swing.JRootPane; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -56,25 +46,6 @@ public class LocalSTALFactory implements STALFactory { protected static final Log log = LogFactory.getLog(LocalSTALFactory.class); protected static final Dimension PREFERRED_SIZE = new Dimension(318, 200); - protected static ArrayList icons = new ArrayList(); - static { - String[] iconResources = new String[] { - "/at/gv/egiz/bku/gui/chip16.png", - "/at/gv/egiz/bku/gui/chip24.png", - "/at/gv/egiz/bku/gui/chip32.png", - "/at/gv/egiz/bku/gui/chip48.png", - "/at/gv/egiz/bku/gui/chip128.png" }; - for (String ir : iconResources) { - URL resource = LocalSTALFactory.class.getResource(ir); - if (ir != null) { - try { - icons.add(ImageIO.read(resource)); - } catch (IOException ex) { - log.warn("failed to set ui dialog icon", ex); - } - } - } - } protected String helpURL; protected Locale locale; @@ -91,7 +62,7 @@ public class LocalSTALFactory implements STALFactory { } // [#439] make mocca dialog alwaysOnTop dialog.setAlwaysOnTop(true); - dialog.setIconImages(icons); + dialog.setIconImages(BKUIcons.icons); dialog.setUndecorated(true); // dialog.getRootPane().setWindowDecorationStyle(JRootPane.NONE); // dialog.addWindowListener(new WindowAdapter() { @@ -120,6 +91,7 @@ public class LocalSTALFactory implements STALFactory { dialog.getLocale(), BKUGUIFacade.Style.advanced, null, + new ResourceFontLoader(), helpListener, null); BKUGUIFacade proxy = (BKUGUIFacade) GUIProxy.newInstance(gui, dialog, new Class[] { PINManagementGUIFacade.class} ); diff --git a/BKULocal/src/main/resources/at/gv/egiz/bku/gui/chip128.png b/BKULocal/src/main/resources/at/gv/egiz/bku/gui/chip128.png deleted file mode 100644 index c36d8079..00000000 Binary files a/BKULocal/src/main/resources/at/gv/egiz/bku/gui/chip128.png and /dev/null differ diff --git a/BKULocal/src/main/resources/at/gv/egiz/bku/gui/chip16.png b/BKULocal/src/main/resources/at/gv/egiz/bku/gui/chip16.png deleted file mode 100644 index 96b580e9..00000000 Binary files a/BKULocal/src/main/resources/at/gv/egiz/bku/gui/chip16.png and /dev/null differ diff --git a/BKULocal/src/main/resources/at/gv/egiz/bku/gui/chip24.png b/BKULocal/src/main/resources/at/gv/egiz/bku/gui/chip24.png deleted file mode 100644 index efd6dbeb..00000000 Binary files a/BKULocal/src/main/resources/at/gv/egiz/bku/gui/chip24.png and /dev/null differ diff --git a/BKULocal/src/main/resources/at/gv/egiz/bku/gui/chip32.png b/BKULocal/src/main/resources/at/gv/egiz/bku/gui/chip32.png deleted file mode 100644 index e7efb020..00000000 Binary files a/BKULocal/src/main/resources/at/gv/egiz/bku/gui/chip32.png and /dev/null differ diff --git a/BKULocal/src/main/resources/at/gv/egiz/bku/gui/chip48.png b/BKULocal/src/main/resources/at/gv/egiz/bku/gui/chip48.png deleted file mode 100644 index 491fbcac..00000000 Binary files a/BKULocal/src/main/resources/at/gv/egiz/bku/gui/chip48.png and /dev/null differ diff --git a/BKUOnline/pom.xml b/BKUOnline/pom.xml index 408ce195..3d504a8d 100644 --- a/BKUOnline/pom.xml +++ b/BKUOnline/pom.xml @@ -128,6 +128,15 @@ 1.2.8-SNAPSHOT provided + iaik iaik_jce_me4se @@ -159,6 +168,19 @@ true + + unpack-fonts + + unpack-dependencies + + + ${project.build.directory}/${project.build.finalName}/applet + at.gv.egiz + BKUFonts + META-INF/,LICENSE + false + + copy-certificates diff --git a/BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALRequestBrokerImpl.java b/BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALRequestBrokerImpl.java index 9a9bd444..a2447ab7 100644 --- a/BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALRequestBrokerImpl.java +++ b/BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALRequestBrokerImpl.java @@ -33,7 +33,6 @@ import at.gv.egiz.stalx.service.translator.STALXTranslationHandler; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Locale; import javax.xml.bind.JAXBElement; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/BKUOnline/src/main/webapp/SLRequestForm.html b/BKUOnline/src/main/webapp/SLRequestForm.html index f705a0cb..24a88a1e 100644 --- a/BKUOnline/src/main/webapp/SLRequestForm.html +++ b/BKUOnline/src/main/webapp/SLRequestForm.html @@ -20,7 +20,7 @@ Security-Layer v1.2 Request Formular - - - - -

Security-Layer v1.2 Request Formular

+ + +

Security-Layer v1.2 Request Formular

@@ -110,7 +110,7 @@ SecureSignatureKeypair - Ich bin ein einfacher Text. + Ich bin ein einfacher Text. llöäü߀ @@ -120,7 +120,27 @@ - TestXHTML + + +

Heading3 large bold llöäü߀

+

Ich bin ein einfacher Text. llöäü߀

+

Ich bin ein einfacher Text. llöäü߀

+

Ich bin ein einfacher Text. llöäü߀

+ + + +
@@ -145,7 +165,8 @@ --> - + +
Request Parameters

tiny @@ -185,8 +206,9 @@ name="StylesheetURL" value="" id="StylesheetURL">

--> +

-
+
diff --git a/BKUOnline/src/main/webapp/applet.jsp b/BKUOnline/src/main/webapp/applet.jsp index 31f3362b..df0b3ca5 100644 --- a/BKUOnline/src/main/webapp/applet.jsp +++ b/BKUOnline/src/main/webapp/applet.jsp @@ -72,14 +72,13 @@ %> - diff --git a/BKUOnline/src/main/webapp/index.html b/BKUOnline/src/main/webapp/index.html index 5bc01297..b39dafb7 100644 --- a/BKUOnline/src/main/webapp/index.html +++ b/BKUOnline/src/main/webapp/index.html @@ -22,6 +22,7 @@ +
@@ -46,7 +47,7 @@

MOCCA Web Start

-

diff --git a/BKUOnline/src/main/webapp/js/deployJava_orig.js b/BKUOnline/src/main/webapp/js/deployJava_orig.js new file mode 100644 index 00000000..316fa278 --- /dev/null +++ b/BKUOnline/src/main/webapp/js/deployJava_orig.js @@ -0,0 +1,725 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of Sun Microsystems nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Added by EGIZ: + * This file contains workarounds to + * [#423] Firefox 3.0.11 bug #498132 causes applet loading failure + * (lines 95-99) + * [#424] Web Start loading via java plugin (Sun deployment script) fails on WinXP/Vista + * (lines 501-506) + * + * features: + * [#425] Disable WebStart Launch Button for MacOS + * (lines 492-504) + * + */ + +/* + * deployJava.js + * + * This file is part of the Deployment Toolkit. It provides functions for web + * pages to detect the presence of a JRE, install the latest JRE, and easily run + * applets or Web Start programs. Usage guide may be found at http:///. + * + * The "live" copy of this file may be found at + * http://java.com/js/deployJava.js. + * You are encouraged to link directly to the live copy of the file. + * + * @version @(#)deployJava.js XXXXX + */ + +var deployJava={ + debug:null, + + myInterval:null, + preInstallJREList:null, + returnPage:null, + brand:null, + locale:null, + installType:null, + + EAInstallEnabled:false, + EarlyAccessURL:null, + + // GetJava page + getJavaURL:'http://java.sun.com/webapps/getjava/BrowserRedirect?host=java.com', + + // Apple redirect page + appleRedirectPage:'http://www.apple.com/support/downloads/', + oldMimeType:'application/npruntime-scriptable-plugin;DeploymentToolkit', + mimeType:'application/java-deployment-toolkit', + launchButtonPNG:'http://java.sun.com/products/jfc/tsc/articles/swing2d/webstart.png', + + getJREs:function(){ + var list=new Array(); + if(deployJava.isPluginInstalled()){ + var plugin=deployJava.getPlugin(); + var VMs=plugin.jvms; + for(var i=0;i'; + document.write(s); + } + if(!codebaseParam){ + document.write(''); + } + } + document.write('<'+'/'+'applet'+'>'); + }, + + versionCheck:function(versionPattern) + + { + var index=0; + var regex="^(\\d+)(?:\\.(\\d+)(?:\\.(\\d+)(?:_(\\d+))?)?)?(\\*|\\+)?$"; + + var matchData=versionPattern.match(regex); + + if(matchData!=null){ + var familyMatch=true; + + var patternArray=new Array(); + + for(var i=1;i<'+'img '+'src="'+deployJava.launchButtonPNG+'" '+'border="0" /><'+'/'+'a'+'>'); + }, + + launch:function(jnlp){ + if(deployJava.isPluginInstalled()){ + return deployJava.getPlugin().launch(jnlp); + }else{ + document.location=jnlp;return true; + } + }, + + isPluginInstalled:function(){ + var plugin=deployJava.getPlugin(); + if(plugin&&plugin.jvms){ + return true; + }else{ + return false; + } + }, + + isAutoUpdateEnabled:function(){ + if(deployJava.isPluginInstalled()){ + return deployJava.getPlugin().isAutoUpdateEnabled(); + } + return false; + }, + + setAutoUpdateEnabled:function(){ + if(deployJava.isPluginInstalled()){ + return deployJava.getPlugin().setAutoUpdateEnabled(); + } + return false; + }, + + setInstallerType:function(type){ + deployJava.installType=type; + if(deployJava.isPluginInstalled()){ + return deployJava.getPlugin().setInstallerType(type); + } + return false; + }, + + setAdditionalPackages:function(packageList){ + if(deployJava.isPluginInstalled()){ + return deployJava.getPlugin().setAdditionalPackages( + packageList); + } + return false; + }, + + setEarlyAccess:function(enabled){ + deployJava.EAInstallEnabled=enabled; + }, + + isPlugin2:function(){ + if(deployJava.isPluginInstalled()){ + if(deployJava.versionCheck('1.6.0_10+')){ + try{ + return deployJava.getPlugin().isPlugin2(); + }catch(err){ + + } + } + } + return false; + }, + + + getPlugin:function(){ + deployJava.refresh(); + var ret=document.getElementById('deployJavaPlugin'); + return ret; + }, + + compareVersionToPattern:function(version,patternArray,familyMatch){ + var regex="^(\\d+)(?:\\.(\\d+)(?:\\.(\\d+)(?:_(\\d+))?)?)?$"; + var matchData=version.match(regex); + + if(matchData!=null){ + var index=0; + var result=new Array(); + + for(var i=1;ipatternArray[i]){ + return true; + } + } + + return true; + } + }else{ + return false; + } + }, + + + getBrowser:function(){ + var browser=navigator.userAgent.toLowerCase(); + + if(deployJava.debug){ + alert('userAgent -> '+browser); + } + + if((navigator.vendor)&& + (navigator.vendor.toLowerCase().indexOf('apple')!=-1)&& + (browser.indexOf('safari')!=-1)){ + if(deployJava.debug){ + alert('We claim to have detected "Safari".'); + } + return'Safari'; + }else if(browser.indexOf('msie')!=-1){ + if(deployJava.debug){ + alert('We claim to have detected "IE".'); + } + return'MSIE'; + }else if((browser.indexOf('mozilla')!=-1)|| + (browser.indexOf('firefox')!=-1)){ + if(deployJava.debug){ + alert('We claim to have detected a Netscape family browser.'); + } + return'Netscape Family'; + }else{ + if(deployJava.debug){ + alert('We claim to have failed to detect a browser.'); + } + return'?'; + } + }, + + + testUsingActiveX:function(version){ + var objectName='JavaWebStart.isInstalled.'+version+'.0'; + + if(!ActiveXObject){ + if(deployJava.debug){ + alert('Browser claims to be IE, but no ActiveXObject object?'); + } + return false; + } + + try{ + return(new ActiveXObject(objectName)!=null); + }catch(exception){ + return false; + } + }, + + + testForMSVM:function(){ + var clsid='{08B0E5C0-4FCB-11CF-AAA5-00401C608500}'; + + if(typeof oClientCaps!='undefined'){ + var v=oClientCaps.getComponentVersion(clsid,"ComponentID"); + if((v=='')||(v=='5,0,5000,0')){ + return false; + }else{ + return true; + } + }else{ + return false; + } + }, + + + testUsingMimeTypes:function(version){ + if(!navigator.mimeTypes){ + if(deployJava.debug){ + alert('Browser claims to be Netscape family, but no mimeTypes[] array?'); + } + return false; + } + + for(var i=0;ib[0])return true; + if(a[0]b[1])return true; + if(a[1]b[2])return true; + if(a[2]'+ + '<'+'/'+'object'+'>'); + }else if(browser=='Netscape Family'){ + deployJava.writeEmbedTag(); + } + }, + + refresh:function(){ + navigator.plugins.refresh(false);var browser=deployJava.getBrowser();if(browser=='Netscape Family'){ + var plugin=document.getElementById('deployJavaPlugin');if(plugin==null){ + deployJava.writeEmbedTag(); + } + } + }, + + writeEmbedTag:function(){ + var written=false;if(navigator.mimeTypes!=null){ + for(var i=0;i