summaryrefslogtreecommitdiff
path: root/pdf-over-gui/src/main/java/at/asit
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit')
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/DeveloperMain.java10
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindow.java26
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ArgumentHandler.java115
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/BKUArgument.java67
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/CLIArgument.java102
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ConfigFileArgument.java72
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/HelpArgument.java71
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/PhoneNumberArgument.java77
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/AdvancedConfigurationComposite.java60
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BaseConfigurationComposite.java42
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationComposite.java218
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationContainer.java114
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationContainerImpl.java227
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java96
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SimpleConfigurationComposite.java349
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/InitializationException.java35
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/InvalidEmblemFile.java53
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/InvalidNumberException.java36
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/InvalidPasswordException.java35
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/InvalidPortException.java35
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/PasswordTooLongException.java36
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/PasswordTooShortException.java36
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigManipulator.java126
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java36
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java206
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachine.java13
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachineImpl.java86
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StatusImpl.java4
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java93
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ErrorState.java6
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java2
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java12
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java237
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ASITTrustManager.java179
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHelper.java112
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/TrustedSocketFactory.java4
36 files changed, 2882 insertions, 146 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/DeveloperMain.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/DeveloperMain.java
index a27113f9..1fdb550d 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/DeveloperMain.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/DeveloperMain.java
@@ -18,6 +18,8 @@ package at.asit.pdfover.gui;
//Imports
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
+import at.asit.pdfover.gui.cliarguments.ArgumentHandler;
import at.asit.pdfover.gui.workflow.StateMachineImpl;
/**
@@ -41,12 +43,12 @@ public class DeveloperMain {
// Set PDF-AS log4j configuration:
//System.setProperty("log4j.configuration", "log4j.properties");
- StateMachineImpl flow = new StateMachineImpl(args);
- log.debug("Starting workflow ...");
+ StateMachineImpl stateMachine = new StateMachineImpl(args);
+ log.debug("Starting stateMachine ...");
- flow.start();
+ stateMachine.start();
- log.debug("Ended workflow ...");
+ log.debug("Ended stateMachine ...");
}
}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindow.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindow.java
index 1e465467..b8cd9ea7 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindow.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindow.java
@@ -24,6 +24,7 @@ import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
@@ -37,6 +38,7 @@ import org.slf4j.LoggerFactory;
import at.asit.pdfover.gui.composites.StateComposite;
import at.asit.pdfover.gui.workflow.StateMachine;
+import at.asit.pdfover.gui.workflow.states.ConfigurationUIState;
import at.asit.pdfover.gui.workflow.states.OpenState;
import at.asit.pdfover.gui.workflow.states.PositioningState;
@@ -46,6 +48,29 @@ import at.asit.pdfover.gui.workflow.states.PositioningState;
public class MainWindow {
/**
+ *
+ */
+ private final class ConfigSelectionListener implements SelectionListener {
+ /**
+ *
+ */
+ public ConfigSelectionListener() {
+ // Nothing to do here
+ }
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ MainWindow.this.stateMachine.jumpToState(new ConfigurationUIState(
+ MainWindow.this.stateMachine));
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // Nothing to do here
+ }
+ }
+
+ /**
* Selection Listener for Position Button
*/
private final class PositionSelectionListener extends SelectionAdapter {
@@ -220,6 +245,7 @@ public class MainWindow {
fd_config.bottom = new FormAttachment(100, 0);
this.btn_config.setLayoutData(fd_config);
this.btn_config.setText("Config ...");
+ this.btn_config.addSelectionListener(new ConfigSelectionListener());
this.buttonMap.put(Buttons.CONFIG, this.btn_config);
this.btn_open = new Button(composite, SWT.NONE);
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ArgumentHandler.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ArgumentHandler.java
new file mode 100644
index 00000000..f43b636c
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ArgumentHandler.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.gui.cliarguments;
+
+// Imports
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.asit.pdfover.gui.exceptions.InitializationException;
+import at.asit.pdfover.gui.workflow.StateMachine;
+
+/**
+ *
+ */
+public class ArgumentHandler {
+ /**
+ * SLF4J Logger instance
+ **/
+ @SuppressWarnings("unused")
+ private static final Logger log = LoggerFactory
+ .getLogger(ArgumentHandler.class);
+
+ private Map<String, CLIArgument> cliArguments = new HashMap<String, CLIArgument>();
+
+ private StateMachine stateMachine = null;
+
+ private boolean requiredExit = false;
+
+ /**
+ * Constructor
+ * @param stateMachine
+ */
+ public ArgumentHandler(StateMachine stateMachine) {
+ this.stateMachine = stateMachine;
+ }
+
+ /**
+ * Gets available Arguments
+ * @return the list of available arguments
+ */
+ public Set<CLIArgument> getArguments() {
+ return new HashSet<CLIArgument>(this.cliArguments.values());
+ }
+
+ /**
+ * Adds a CLIArgument to the handler
+ *
+ * @param arg
+ */
+ public void addCLIArgument(CLIArgument arg) {
+ if(arg == null) {
+ return;
+ }
+
+ String[] commandOptions = arg.getCommandOptions();
+
+ if(commandOptions == null) {
+ return;
+ }
+
+ for(int i = 0; i < commandOptions.length; i++)
+ {
+ this.cliArguments.put(commandOptions[i], arg);
+ }
+ }
+
+ /**
+ * Handle CLI Arguments
+ *
+ * @param args
+ * @throws InitializationException
+ */
+ public void handleArguments(String[] args) throws InitializationException {
+ for(int i = 0; i < args.length; i++) {
+ if(this.cliArguments.containsKey(args[i])) {
+ this.cliArguments.get(args[i]).handleArgument(args, i, this.stateMachine, this);
+ }
+ }
+ }
+
+ /**
+ * Set by an cli argument if it wants the program to exit
+ * @param requireExit
+ */
+ public void setRequireExit(boolean requireExit) {
+ this.requiredExit = requireExit;
+ }
+
+ /**
+ * Checks if one argument required the program to exit again
+ *
+ * @return true or false
+ */
+ public boolean IsRequireExit() {
+ return this.requiredExit;
+ }
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/BKUArgument.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/BKUArgument.java
new file mode 100644
index 00000000..e8d721ca
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/BKUArgument.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.gui.cliarguments;
+
+import at.asit.pdfover.gui.exceptions.InitializationException;
+import at.asit.pdfover.gui.workflow.ConfigManipulator;
+import at.asit.pdfover.gui.workflow.StateMachine;
+import at.asit.pdfover.signator.BKUs;
+
+/**
+ *
+ */
+public class BKUArgument extends CLIArgument {
+ /**
+ * Constructor
+ */
+ public BKUArgument() {
+ super(
+ new String[] { "-b" }, "Select the BKU to use values are: LOCAL, MOBILE (example: -b <option>"); //$NON-NLS-1$
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * at.asit.pdfover.gui.cliarguments.CLIArgument#handleArgument(java.lang
+ * .String[], int, at.asit.pdfover.gui.workflow.StateMachine,
+ * at.asit.pdfover.gui.cliarguments.ArgumentHandler)
+ */
+ @Override
+ public int handleArgument(String[] args, int argOffset,
+ StateMachine stateMachine, ArgumentHandler handler)
+ throws InitializationException {
+ try {
+ if (args.length > argOffset + 1) {
+
+ BKUs argumentValue = BKUs.valueOf(args[argOffset + 1]);
+
+ ConfigManipulator configManipulator = stateMachine.getConfigManipulator();
+
+ configManipulator.setDefaultBKU(argumentValue);
+
+ return argOffset + 1;
+ }
+ } catch (Exception ex) {
+ throw new InitializationException(
+ "BKU Argument invalid! Use: " + this.getHelpText(), ex); //$NON-NLS-1$
+ }
+
+ throw new InitializationException(
+ "BKU Argument invalid! Use: " + this.getHelpText(), null); //$NON-NLS-1$
+ }
+
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/CLIArgument.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/CLIArgument.java
new file mode 100644
index 00000000..7f8d4366
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/CLIArgument.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.gui.cliarguments;
+
+import at.asit.pdfover.gui.exceptions.InitializationException;
+import at.asit.pdfover.gui.workflow.StateMachine;
+
+/**
+ *
+ */
+public abstract class CLIArgument {
+
+ private String helpText = null;
+
+ private String[] commandOptions = null;
+
+ /**
+ * @param commandOptions
+ * @param helpText
+ */
+ protected CLIArgument(String[] commandOptions, String helpText) {
+ this.helpText = helpText;
+ this.commandOptions = commandOptions;
+ }
+
+ /**
+ * Set help text
+ *
+ * @param value
+ */
+ protected void setHelpText(String value) {
+ this.helpText = value;
+ }
+
+ /**
+ * Gets help text
+ *
+ * @return help text
+ */
+ public String getHelpText() {
+ return this.helpText;
+ }
+
+ /**
+ * Set the command option in format: -...
+ *
+ * Examples: -h
+ *
+ * @param value
+ */
+ protected void setCommandOptions(String[] value) {
+ this.commandOptions = value;
+ }
+
+ /**
+ * Get the command option
+ *
+ * Examples: -h
+ * @return the command option
+ */
+ public String[] getCommandOptions() {
+ return this.commandOptions;
+ }
+
+ /**
+ * Invokes the argument to set stuff within the stateMachine
+ *
+ * It should return the offset within the args array where the last used argument of this CLIArgument was used.
+ *
+ * Example:
+ * args[] = { "-h", "-b", "LOCAL" }
+ *
+ * Help Argument call:
+ * offset = 0
+ * returns 0
+ *
+ * BKU Argument call:
+ * offset = 1
+ * returns 2
+ *
+ * @param stateMachine
+ * @param args
+ * @param argOffset
+ * @param handler
+ * @return returns the argumentOffset ending the section of this Argument
+ * @throws InitializationException
+ */
+ public abstract int handleArgument(String[] args, int argOffset, StateMachine stateMachine, ArgumentHandler handler) throws InitializationException;
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ConfigFileArgument.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ConfigFileArgument.java
new file mode 100644
index 00000000..9ddeaf6c
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ConfigFileArgument.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.gui.cliarguments;
+
+// Imports
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.asit.pdfover.gui.exceptions.InitializationException;
+import at.asit.pdfover.gui.workflow.ConfigManipulator;
+import at.asit.pdfover.gui.workflow.StateMachine;
+import at.asit.pdfover.gui.workflow.states.mobilebku.ATrustHelper;
+
+/**
+ *
+ */
+public class ConfigFileArgument extends CLIArgument {
+ /**
+ * SLF4J Logger instance
+ **/
+ private static final Logger log = LoggerFactory
+ .getLogger(ConfigFileArgument.class);
+
+ /**
+ * Constructor
+ */
+ public ConfigFileArgument() {
+ super(new String[] {"-c"}, "Defines which configuration file to use. Example: -c <config file>"); //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.cliarguments.CLIArgument#handleArgument(java.lang.String[], int, at.asit.pdfover.gui.workflow.StateMachine, at.asit.pdfover.gui.cliarguments.ArgumentHandler)
+ */
+ @Override
+ public int handleArgument(String[] args, int argOffset,
+ StateMachine stateMachine, ArgumentHandler handler)
+ throws InitializationException {
+ try {
+ if (args.length > argOffset + 1) {
+
+ String configFile = args[argOffset + 1];
+
+ ConfigManipulator configManipulator = stateMachine.getConfigManipulator();
+
+ configManipulator.setConfigurationFile(configFile);
+
+ return argOffset + 1;
+ }
+ } catch (Exception ex) {
+ log.error("Configuration File Argument invalid!", ex); //$NON-NLS-1$
+ throw new InitializationException(
+ "Configuration File Argument invalid! Use: " + this.getHelpText(), ex); //$NON-NLS-1$
+ }
+
+ throw new InitializationException(
+ "Configuration File invalid! Use: " + this.getHelpText(), null); //$NON-NLS-1$
+ }
+
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/HelpArgument.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/HelpArgument.java
new file mode 100644
index 00000000..8087807c
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/HelpArgument.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.gui.cliarguments;
+
+// Imports
+import java.util.Iterator;
+import java.util.Set;
+
+import at.asit.pdfover.gui.exceptions.InitializationException;
+import at.asit.pdfover.gui.workflow.StateMachine;
+
+/**
+ *
+ */
+public class HelpArgument extends CLIArgument {
+
+ /**
+ * Constructor
+ */
+ public HelpArgument() {
+ super(new String[] {"-h", "-?" }, "shows this help message"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.cliarguments.CLIArgument#handleArgument(java.lang.String[], int, at.asit.pdfover.gui.workflow.StateMachine, at.asit.pdfover.gui.cliarguments.ArgumentHandler)
+ */
+ @Override
+ public int handleArgument(String[] args, int argOffset,
+ StateMachine stateMachine, ArgumentHandler handler)
+ throws InitializationException {
+ Set<CLIArgument> arguments = handler.getArguments();
+
+ Iterator<CLIArgument> argumentIterator = arguments.iterator();
+
+ System.out.println("The following options are available"); //$NON-NLS-1$
+
+ while(argumentIterator.hasNext()) {
+ CLIArgument agrument = argumentIterator.next();
+ StringBuilder sb = new StringBuilder();
+
+ for(int i = 0; i < agrument.getCommandOptions().length; i++) {
+ sb.append(agrument.getCommandOptions()[i]);
+
+ if(i < agrument.getCommandOptions().length -1) {
+ sb.append(", "); //$NON-NLS-1$
+ }
+ }
+
+ System.out.println(sb.toString() + ":"); //$NON-NLS-1$
+ System.out.println("\t" + agrument.getHelpText()); //$NON-NLS-1$
+ }
+
+ handler.setRequireExit(true);
+
+ return argOffset;
+ }
+
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/PhoneNumberArgument.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/PhoneNumberArgument.java
new file mode 100644
index 00000000..255b4f91
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/PhoneNumberArgument.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.gui.cliarguments;
+
+// Imports
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.asit.pdfover.gui.exceptions.InitializationException;
+import at.asit.pdfover.gui.workflow.ConfigManipulator;
+import at.asit.pdfover.gui.workflow.StateMachine;
+import at.asit.pdfover.gui.workflow.states.mobilebku.ATrustHelper;
+
+/**
+ *
+ */
+public class PhoneNumberArgument extends CLIArgument {
+ /**
+ * Constructor
+ */
+ public PhoneNumberArgument() {
+ super(new String[] {"-n" }, "Sets the telephone number to use for mobile bku. Example: -n <number>"); //$NON-NLS-1$
+ }
+
+
+ /**
+ * SLF4J Logger instance
+ **/
+ private static final Logger log = LoggerFactory
+ .getLogger(PhoneNumberArgument.class);
+
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.cliarguments.CLIArgument#handleArgument(java.lang.String[], int, at.asit.pdfover.gui.workflow.StateMachine, at.asit.pdfover.gui.cliarguments.ArgumentHandler)
+ */
+ @Override
+ public int handleArgument(String[] args, int argOffset,
+ StateMachine stateMachine, ArgumentHandler handler)
+ throws InitializationException {
+
+ try {
+ if (args.length > argOffset + 1) {
+
+ String number = args[argOffset + 1];
+
+ number = ATrustHelper.normalizeMobileNumber(number);
+
+ ConfigManipulator configManipulator = stateMachine.getConfigManipulator();
+
+ configManipulator.setDefaultMobileNumber(number);
+
+ return argOffset + 1;
+ }
+ } catch (Exception ex) {
+ log.error("Phone Number Argument invalid!", ex); //$NON-NLS-1$
+ throw new InitializationException(
+ "Phone Number Argument invalid! Use: " + this.getHelpText(), ex); //$NON-NLS-1$
+ }
+
+ throw new InitializationException(
+ "Phone Number invalid! Use: " + this.getHelpText(), null); //$NON-NLS-1$
+ }
+
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/AdvancedConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/AdvancedConfigurationComposite.java
new file mode 100644
index 00000000..5b826097
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/AdvancedConfigurationComposite.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.gui.composites;
+
+// Imports
+import org.eclipse.swt.widgets.Composite;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.asit.pdfover.gui.workflow.states.State;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.SWT;
+
+/**
+ *
+ */
+public class AdvancedConfigurationComposite extends BaseConfigurationComposite {
+ /**
+ * @param parent
+ * @param style
+ * @param state
+ */
+ public AdvancedConfigurationComposite(Composite parent, int style,
+ State state, ConfigurationContainer container) {
+ super(parent, style, state, container);
+
+ Label lblAdvancedConfigLayout = new Label(this, SWT.NONE);
+ lblAdvancedConfigLayout.setBounds(113, 126, 243, 15);
+ lblAdvancedConfigLayout.setText("Advanced Config Layout!");
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * SLF4J Logger instance
+ **/
+ private static final Logger log = LoggerFactory
+ .getLogger(AdvancedConfigurationComposite.class);
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.composites.StateComposite#doLayout()
+ */
+ @Override
+ public void doLayout() {
+ // TODO Auto-generated method stub
+
+ }
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BaseConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BaseConfigurationComposite.java
new file mode 100644
index 00000000..831a4aa6
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BaseConfigurationComposite.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.gui.composites;
+
+
+import org.eclipse.swt.widgets.Composite;
+import at.asit.pdfover.gui.workflow.states.State;
+
+/**
+ *
+ */
+public abstract class BaseConfigurationComposite extends StateComposite {
+
+ /**
+ * the configuration container
+ */
+ protected ConfigurationContainer configurationContainer;
+
+ /**
+ * @param parent
+ * @param style
+ * @param state
+ * @param configuration
+ */
+ public BaseConfigurationComposite(Composite parent, int style, State state, ConfigurationContainer configuration) {
+ super(parent, style, state);
+ this.configurationContainer = configuration;
+ }
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationComposite.java
new file mode 100644
index 00000000..db58ae4a
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationComposite.java
@@ -0,0 +1,218 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.gui.composites;
+
+// Imports
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.asit.pdfover.gui.workflow.ConfigManipulator;
+import at.asit.pdfover.gui.workflow.states.State;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.custom.StackLayout;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormAttachment;
+
+/**
+ *
+ */
+public class ConfigurationComposite extends StateComposite {
+
+ /**
+ *
+ */
+ private final class ConfigurationModeSelectionListener implements
+ SelectionListener {
+ /**
+ *
+ */
+ public ConfigurationModeSelectionListener() {
+ // Nothing to do
+ }
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (ConfigurationComposite.this.configComposite instanceof SimpleConfigurationComposite) {
+ // switch to advanced
+ ConfigurationComposite.this.configComposite.dispose();
+ ConfigurationComposite.this.configComposite = new AdvancedConfigurationComposite(
+ ConfigurationComposite.this.containerComposite,
+ ConfigurationComposite.this.style,
+ ConfigurationComposite.this.state,
+ ConfigurationComposite.this.configurationContainer);
+ ConfigurationComposite.this.btnAdvanced.setText("Simple");
+ } else {
+ // switch to simple
+ ConfigurationComposite.this.configComposite.dispose();
+ ConfigurationComposite.this.configComposite = new SimpleConfigurationComposite(
+ ConfigurationComposite.this.containerComposite,
+ ConfigurationComposite.this.style,
+ ConfigurationComposite.this.state,
+ ConfigurationComposite.this.configurationContainer);
+ ConfigurationComposite.this.btnAdvanced.setText("Advanced");
+ }
+
+ ConfigurationComposite.this.compositeStack.topControl = ConfigurationComposite.this.configComposite;
+ ConfigurationComposite.this.doLayout();
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // Nothing to do
+ }
+ }
+
+ /**
+ * SLF4J Logger instance
+ **/
+ private static final Logger log = LoggerFactory
+ .getLogger(ConfigurationComposite.class);
+
+ ConfigManipulator configManipulator = null;
+
+ BaseConfigurationComposite configComposite;
+
+ ConfigurationContainer configurationContainer = new ConfigurationContainerImpl();
+
+ StackLayout compositeStack = new StackLayout();
+
+ int style;
+
+ Composite containerComposite;
+
+ boolean userDone = false;
+
+ Button btnAdvanced;
+
+ /**
+ * Sets the configuration manipulator
+ *
+ * @param manipulator
+ */
+ public void setConfigManipulator(ConfigManipulator manipulator) {
+ this.configManipulator = manipulator;
+ }
+
+ /**
+ * Create the composite.
+ *
+ * @param parent
+ * @param style
+ * @param state
+ */
+ public ConfigurationComposite(Composite parent, int style, State state) {
+ super(parent, SWT.FILL | style, state);
+ this.style = SWT.FILL | style;
+
+ this.setLayout(new FormLayout());
+
+ this.containerComposite = new Composite(this, SWT.FILL | SWT.RESIZE);
+
+ this.configComposite = new SimpleConfigurationComposite(
+ this.containerComposite, SWT.FILL | style, state, this.configurationContainer);
+
+ FormData fd_composite = new FormData();
+ fd_composite.top = new FormAttachment(0, 5);
+ fd_composite.bottom = new FormAttachment(90, -5);
+ fd_composite.left = new FormAttachment(0, 5);
+ fd_composite.right = new FormAttachment(100, -5);
+ this.containerComposite.setLayoutData(fd_composite);
+ this.containerComposite.setLayout(this.compositeStack);
+ this.compositeStack.topControl = this.configComposite;
+
+ this.doLayout();
+
+ Button btnSpeichern = new Button(this, SWT.NONE);
+ FormData fd_btnSpeichern = new FormData();
+ fd_btnSpeichern.left = new FormAttachment(0, 5);
+ fd_btnSpeichern.bottom = new FormAttachment(100, -5);
+ btnSpeichern.setLayoutData(fd_btnSpeichern);
+ btnSpeichern.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ }
+ });
+ btnSpeichern.setText("Speichern");
+
+ Button btnAbbrechen = new Button(this, SWT.NONE);
+ FormData fd_btnAbrechen = new FormData();
+ fd_btnAbrechen.left = new FormAttachment(btnSpeichern, 10);
+ fd_btnAbrechen.bottom = new FormAttachment(100, -5);
+ btnAbbrechen.setLayoutData(fd_btnAbrechen);
+ btnAbbrechen.setText("Abbrechen");
+ btnAbbrechen.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ ConfigurationComposite.this.userDone = true;
+ ConfigurationComposite.this.state.updateStateMachine();
+ }
+ });
+
+ this.btnAdvanced = new Button(this, SWT.NONE);
+ FormData fd_btnAdvanced = new FormData();
+ fd_btnAdvanced.right = new FormAttachment(100, -5);
+ fd_btnAdvanced.bottom = new FormAttachment(100, -5);
+ this.btnAdvanced.setLayoutData(fd_btnAdvanced);
+ this.btnAdvanced.setText("Advanced");
+ this.btnAdvanced
+ .addSelectionListener(new ConfigurationModeSelectionListener());
+
+ }
+
+ private void storeConfiguration() {
+ // TODO: Collect info from UI and set in ConfigManipulator
+
+ // TODO: call save configuration in ConfigManipulator
+ }
+
+ /**
+ * Checks if the user has finished working with the configuration composite
+ *
+ * @return
+ */
+ public boolean isUserDone() {
+ return this.userDone;
+ }
+
+ @Override
+ protected void checkSubclass() {
+ // Disable the check that prevents subclassing of SWT components
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see at.asit.pdfover.gui.composites.StateComposite#doLayout()
+ */
+ @Override
+ public void doLayout() {
+ Control ctrl = this.compositeStack.topControl;
+ this.containerComposite.layout(true, true);
+ this.getShell().layout(true, true);
+ // Note: SWT only layouts children! No grandchildren!
+ if (ctrl instanceof StateComposite) {
+ ((StateComposite) ctrl).doLayout();
+ }
+ }
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationContainer.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationContainer.java
new file mode 100644
index 00000000..dbc32206
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationContainer.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.gui.composites;
+
+import at.asit.pdfover.gui.exceptions.InvalidEmblemFile;
+import at.asit.pdfover.gui.exceptions.InvalidNumberException;
+import at.asit.pdfover.gui.exceptions.InvalidPortException;
+import at.asit.pdfover.signator.BKUs;
+
+/**
+ *
+ */
+public interface ConfigurationContainer {
+
+ /**
+ * Gets the configured emblem
+ * @return the configured emblem
+ */
+ public String getEmblem();
+
+ /**
+ * Sets the emblem
+ * @param emblem the emblem
+ * @throws InvalidEmblemFile
+ */
+ public void setEmblem(String emblem) throws InvalidEmblemFile;
+
+ /**
+ * Gets the mobile phone number
+ * @return the mobile phone number
+ */
+ public String getNumber();
+
+ /**
+ * Sets the mobile phone number
+ * @param number the mobile phone number
+ * @throws InvalidNumberException
+ */
+ public void setNumber(String number) throws InvalidNumberException;
+
+ /**
+ * Gets the proxy host
+ * @return the proxy host
+ */
+ public String getProxyHost();
+
+ /**
+ * Sets the proxy host
+ * @param host the proxy host
+ */
+ public void setProxyHost(String host);
+
+ /**
+ * Gets the proxy port
+ * @return the proxy port
+ */
+ public int getProxyPort();
+
+ /**
+ * Sets the proxy port
+ * @param port the proxy port
+ * @throws InvalidPortException
+ */
+ public void setProxyPort(int port) throws InvalidPortException;
+
+ /**
+ * Gets the automatic position
+ * @return the automatic position
+ */
+ public boolean getAutomaticPosition();
+
+ /**
+ * Sets the automatic position
+ * @param automatic the automatic position
+ */
+ public void setAutomaticPosition(boolean automatic);
+
+ /**
+ * Gets the default BKU
+ * @return the default BKU
+ */
+ public BKUs getBKUSelection();
+
+ /**
+ * Sets the default BKU
+ * @param bkuSelection the default BKU
+ */
+ public void setBKUSelection(BKUs bkuSelection);
+
+ /**
+ * Gets the default output folder
+ * @return the default output folder
+ */
+ public String getOutputFolder();
+
+ /**
+ * Sets the default output folder
+ * @param folder the default output folder
+ */
+ public void setOutputFolder(String folder);
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationContainerImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationContainerImpl.java
new file mode 100644
index 00000000..f8489d71
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationContainerImpl.java
@@ -0,0 +1,227 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.gui.composites;
+
+// Imports
+import java.io.File;
+import java.io.FileNotFoundException;
+
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.widgets.Display;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.asit.pdfover.gui.exceptions.InvalidEmblemFile;
+import at.asit.pdfover.gui.exceptions.InvalidNumberException;
+import at.asit.pdfover.gui.exceptions.InvalidPortException;
+import at.asit.pdfover.gui.workflow.states.mobilebku.ATrustHelper;
+import at.asit.pdfover.signator.BKUs;
+
+/**
+ *
+ */
+public class ConfigurationContainerImpl implements ConfigurationContainer {
+ /**
+ * SLF4J Logger instance
+ **/
+ private static final Logger log = LoggerFactory
+ .getLogger(ConfigurationContainerImpl.class);
+
+
+ /**
+ * the emblem File
+ */
+ protected String emblemFile = null;
+
+ /**
+ * The mobile phone number
+ */
+ protected String mobileNumber = null;
+
+ /**
+ * Holds the proxy Host
+ */
+ protected String proxyHost = null;
+
+ /**
+ * Holds the proxy port number
+ */
+ protected int proxyPort = -1;
+
+ /**
+ * Holds the output folder
+ */
+ protected String folder = null;
+
+ /**
+ * Holds the default BKU to use
+ */
+ protected BKUs defaulBKU = BKUs.NONE;
+
+ /**
+ * Holds the automatic positioning value
+ */
+ protected boolean automaticPositioning = false;
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.composites.ConfigurationContainer#getEmblem()
+ */
+ @Override
+ public String getEmblem() {
+ return this.emblemFile;
+ }
+
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.composites.ConfigurationContainer#setEmblem(java.lang.String)
+ */
+ @Override
+ public void setEmblem(String emblemFile) throws InvalidEmblemFile {
+ if (this.emblemFile == null || this.emblemFile.trim().equals("")) { //$NON-NLS-1$
+ // Ok to set no file ...
+ } else {
+ File imageFile = new File(emblemFile);
+ if (!imageFile.exists()) {
+ throw new InvalidEmblemFile(imageFile,
+ new FileNotFoundException(emblemFile));
+ }
+
+ try {
+ Image img = new Image(Display.getDefault(), new ImageData(
+ emblemFile));
+
+ img.dispose();
+ } catch (Exception ex) {
+ throw new InvalidEmblemFile(imageFile, ex);
+ }
+ }
+
+ this.emblemFile = emblemFile;
+ }
+
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.composites.ConfigurationContainer#getNumber()
+ */
+ @Override
+ public String getNumber() {
+ return this.mobileNumber;
+ }
+
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.composites.ConfigurationContainer#setNumber(java.lang.String)
+ */
+ @Override
+ public void setNumber(String number) throws InvalidNumberException {
+ this.mobileNumber = ATrustHelper.normalizeMobileNumber(number);
+ }
+
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.composites.ConfigurationContainer#getProxyHost()
+ */
+ @Override
+ public String getProxyHost() {
+ return this.proxyHost;
+ }
+
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.composites.ConfigurationContainer#setProxyHost(java.lang.String)
+ */
+ @Override
+ public void setProxyHost(String host) {
+ this.proxyHost = host;
+ }
+
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.composites.ConfigurationContainer#getProxyPort()
+ */
+ @Override
+ public int getProxyPort() {
+ return this.proxyPort;
+ }
+
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.composites.ConfigurationContainer#setProxyPort(int)
+ */
+ @Override
+ public void setProxyPort(int port) throws InvalidPortException {
+ if(port > 0 && port < 0xFFFF) {
+ this.proxyPort = port;
+ }
+ throw new InvalidPortException(port);
+ }
+
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.composites.ConfigurationContainer#getAutomaticPosition()
+ */
+ @Override
+ public boolean getAutomaticPosition() {
+ return this.automaticPositioning;
+ }
+
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.composites.ConfigurationContainer#setAutomaticPosition(boolean)
+ */
+ @Override
+ public void setAutomaticPosition(boolean automatic) {
+ this.automaticPositioning = automatic;
+ }
+
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.composites.ConfigurationContainer#getBKUSelection()
+ */
+ @Override
+ public BKUs getBKUSelection() {
+ return this.defaulBKU;
+ }
+
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.composites.ConfigurationContainer#setBKUSelection(at.asit.pdfover.signator.BKUs)
+ */
+ @Override
+ public void setBKUSelection(BKUs bkuSelection) {
+ this.defaulBKU = bkuSelection;
+ }
+
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.composites.ConfigurationContainer#getOutputFolder()
+ */
+ @Override
+ public String getOutputFolder() {
+ return this.folder;
+ }
+
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.composites.ConfigurationContainer#setOutputFolder(java.lang.String)
+ */
+ @Override
+ public void setOutputFolder(String folder) {
+ this.folder = folder;
+ }
+
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java
index c1a72fb2..bd630f8e 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java
@@ -32,7 +32,17 @@ import org.eclipse.swt.widgets.Text;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import at.asit.pdfover.gui.exceptions.InvalidNumberException;
+import at.asit.pdfover.gui.exceptions.InvalidPasswordException;
import at.asit.pdfover.gui.workflow.states.State;
+import at.asit.pdfover.gui.workflow.states.mobilebku.ATrustHelper;
+
+import org.eclipse.swt.custom.StackLayout;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
/**
*
@@ -47,18 +57,8 @@ public class MobileBKUEnterNumberComposite extends StateComposite {
/**
*
*/
- private final class OkSelectionListener extends SelectionAdapter {
- /**
- * Regular expression for mobile phone numbers:
- * this allows the entrance of mobile numbers in the following formats:
- *
- * +(countryCode)99999999999
- * 00(countryCode)99999999999
- * 099999999999
- * 1030199999999999 (A-Trust Test bku)
- */
- private static final String NUMBER_REGEX = "^((\\+[\\d]{2})|(00[\\d]{2})|(0)|(10301))([1-9][\\d]+)$"; //$NON-NLS-1$
-
+ private final class OkSelectionListener implements SelectionListener {
+
/**
* Empty constructor
*/
@@ -71,40 +71,9 @@ public class MobileBKUEnterNumberComposite extends StateComposite {
String number = MobileBKUEnterNumberComposite.this.txt_number
.getText();
- // Verify number and normalize
-
- // Compile and use regular expression
- Pattern pattern = Pattern.compile(NUMBER_REGEX);
- Matcher matcher = pattern.matcher(number);
-
- if (!matcher.find()) {
- MobileBKUEnterNumberComposite.this
- .setErrorMessage("Given phone number is invalid! Example: +43664123456789");
- return;
- }
-
- if (matcher.groupCount() != 6) {
- MobileBKUEnterNumberComposite.this
- .setErrorMessage("Given phone number is invalid! Example: +43664123456789");
- return;
- }
-
- String countryCode = matcher.group(1);
-
- String normalNumber = matcher.group(6);
-
- if (countryCode.equals("10301")) { //$NON-NLS-1$
- // A-Trust Testnumber!
- } else {
-
- countryCode = countryCode.replace("00", "+"); //$NON-NLS-1$ //$NON-NLS-2$
-
- if (countryCode.equals("0")) { //$NON-NLS-1$
- countryCode = "+43"; //$NON-NLS-1$
- }
-
- number = countryCode + normalNumber;
- }
+
+ number = ATrustHelper.normalizeMobileNumber(number);
+
MobileBKUEnterNumberComposite.this.setMobileNumber(number);
MobileBKUEnterNumberComposite.this.mobileNumber = number;
@@ -112,30 +81,37 @@ public class MobileBKUEnterNumberComposite extends StateComposite {
String password = MobileBKUEnterNumberComposite.this.txt_password
.getText();
- // TODO: Logic to verify password
-
- if (password.length() < 6 || password.length() > 20) {
- if (password.length() < 6) {
- MobileBKUEnterNumberComposite.this
- .setErrorMessage("Given password is too short!");
- } else {
- MobileBKUEnterNumberComposite.this
- .setErrorMessage("Given password is too long!");
- }
- return;
- }
+ ATrustHelper.validatePassword(password);
MobileBKUEnterNumberComposite.this.mobilePassword = password;
MobileBKUEnterNumberComposite.this.setUserAck(true);
- } catch (Exception ex) {
+ } catch(InvalidNumberException ex) {
+ log.error("Validating input for Mobile BKU failed!", ex); //$NON-NLS-1$
+ MobileBKUEnterNumberComposite.this
+ .setErrorMessage("Given phone number is invalid! Example: +43664123456789");
+ } catch(InvalidPasswordException ex) {
+ log.error("Validating input for Mobile BKU failed!", ex); //$NON-NLS-1$
+ MobileBKUEnterNumberComposite.this
+ .setErrorMessage(ex.getMessage());
+ }
+ catch (Exception ex) {
log.error("Validating input for Mobile BKU failed!", ex); //$NON-NLS-1$
- // TODO: NOT VALID
MobileBKUEnterNumberComposite.this
.setErrorMessage("Given phone number is invalid! Example: +43664123456789");
return;
}
+
MobileBKUEnterNumberComposite.this.state.updateStateMachine();
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
+ */
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // TODO Auto-generated method stub
+
+ }
}
String mobileNumber;
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SimpleConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SimpleConfigurationComposite.java
new file mode 100644
index 00000000..b8f31dec
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SimpleConfigurationComposite.java
@@ -0,0 +1,349 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.gui.composites;
+
+// Imports
+import java.io.File;
+import java.io.FileNotFoundException;
+
+import org.apache.fontbox.afm.Composite;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.TraverseEvent;
+import org.eclipse.swt.events.TraverseListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.asit.pdfover.gui.workflow.states.State;
+
+/**
+ *
+ */
+public class SimpleConfigurationComposite extends BaseConfigurationComposite {
+
+ private Label lblEmblem;
+ private Text text;
+ private Text text_1;
+ private Text txtMobileNumber;
+ Text txtEmblemFile;
+ private Image origEmblem = null;
+
+
+
+ void recalculateEmblemSize() {
+ if (this.origEmblem != null) {
+
+ int width = this.origEmblem.getBounds().width;
+ int height = this.origEmblem.getBounds().height;
+
+ int scaledWidth = this.lblEmblem.getSize().x;
+ int scaledHeight = this.lblEmblem.getSize().y;
+
+ float scaleFactorWidth = (float) scaledWidth / (float) width;
+ float scaleFactorHeight = (float) scaledHeight / (float) height;
+
+ float betterFactor = 1;
+
+ int testHeight = (int) (height * scaleFactorWidth);
+ int testWidth = (int) (width * scaleFactorHeight);
+
+ // check for better scale factor ...
+
+ if (testHeight > scaledHeight) {
+ // width scaling fails!! use Height scaling
+ betterFactor = scaleFactorHeight;
+ } else if (testWidth > scaledWidth) {
+ // height scaling fails!! use Width scaling
+ betterFactor = scaleFactorWidth;
+ } else {
+ // Both are ok test* < scaled*
+
+ int heightDiff = scaledHeight - testHeight;
+
+ int widthDiff = scaledWidth - testWidth;
+
+ if (widthDiff < heightDiff) {
+ // width diff better use scaleFactorHeight
+ betterFactor = scaleFactorHeight;
+ } else {
+ // height diff better or equal so use scaleFactorWidth
+ betterFactor = scaleFactorWidth;
+ }
+ }
+
+ log.debug("Scaling factor: " + betterFactor); //$NON-NLS-1$
+
+ Image emblem = new Image(this.getDisplay(), this.origEmblem
+ .getImageData().scaledTo((int) (width * betterFactor),
+ (int) (height * betterFactor)));
+
+ Image old = this.lblEmblem.getImage();
+
+ if(old != null) {
+ old.dispose();
+ }
+
+ this.lblEmblem.setText(""); //$NON-NLS-1$
+ this.lblEmblem.setImage(emblem);
+ }
+ }
+
+ private void setEmblemFileInternal(final String filename) throws Exception {
+ if (this.configurationContainer.getEmblem() != null) {
+ if (this.configurationContainer.getEmblem().equals(filename)) {
+ return; // Ignore ...
+ }
+ }
+
+ try {
+ this.configurationContainer.setEmblem(filename);
+
+ this.txtEmblemFile.setText(this.configurationContainer.getEmblem());
+
+ if(this.origEmblem != null) {
+ this.origEmblem.dispose();
+ }
+
+ this.origEmblem = new Image(this.getDisplay(), new ImageData(
+ filename));
+
+ this.lblEmblem.setText(""); //$NON-NLS-1$
+
+ this.recalculateEmblemSize();
+ } catch (Exception e) {
+ this.lblEmblem.setText("No Image");
+ this.lblEmblem.setImage(null);
+ if(this.origEmblem != null) {
+ this.origEmblem.dispose();
+ }
+ this.origEmblem = null;
+ throw e;
+ }
+
+ this.lblEmblem.pack();
+ this.lblEmblem.getParent().pack();
+ this.doLayout();
+ }
+
+ void processEmblemChanged() {
+ try {
+ String filename = this.txtEmblemFile.getText();
+ this.setEmblemFileInternal(filename);
+ } catch (Exception ex) {
+ // TODO: Show error message!
+ log.error("processEmblemChanged: ", ex); //$NON-NLS-1$
+ }
+ }
+
+ ConfigurationComposite configurationComposite;
+
+ /**
+ * @return the configurationComposite
+ */
+ public ConfigurationComposite getConfigurationComposite() {
+ return this.configurationComposite;
+ }
+
+ /**
+ * @param configurationComposite the configurationComposite to set
+ */
+ public void setConfigurationComposite(
+ ConfigurationComposite configurationComposite) {
+ this.configurationComposite = configurationComposite;
+ }
+
+ /**
+ * @param parent
+ * @param style
+ * @param state
+ * @param container
+ */
+ public SimpleConfigurationComposite(
+ org.eclipse.swt.widgets.Composite parent, int style, State state, ConfigurationContainer container) {
+ super(parent, style, state, container);
+ setLayout(new FormLayout());
+
+ Group grpHandySignatur = new Group(this, SWT.NONE | SWT.RESIZE);
+ FormData fd_grpHandySignatur = new FormData();
+ fd_grpHandySignatur.right = new FormAttachment(100, -5);
+ fd_grpHandySignatur.left = new FormAttachment(0, 5);
+ fd_grpHandySignatur.top = new FormAttachment(0, 5);
+ fd_grpHandySignatur.bottom = new FormAttachment(20, -5);
+ grpHandySignatur.setLayoutData(fd_grpHandySignatur);
+ grpHandySignatur.setText("Handy Signatur");
+ grpHandySignatur.setLayout(new GridLayout(2, false));
+
+ Label lblMobileNumber = new Label(grpHandySignatur, SWT.NONE
+ | SWT.RESIZE);
+ lblMobileNumber.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
+ false, 1, 1));
+ lblMobileNumber.setText("Handy Nummer:");
+
+ this.txtMobileNumber = new Text(grpHandySignatur, SWT.BORDER
+ | SWT.RESIZE);
+ this.txtMobileNumber.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
+ true, false, 1, 1));
+
+ Group grpBildmarke = new Group(this, SWT.NONE);
+ FormData fd_grpBildmarke = new FormData();
+ fd_grpBildmarke.left = new FormAttachment(0, 5);
+ fd_grpBildmarke.right = new FormAttachment(100, -5);
+ fd_grpBildmarke.bottom = new FormAttachment(65, -5);
+ fd_grpBildmarke.top = new FormAttachment(20, 5);
+ grpBildmarke.setLayoutData(fd_grpBildmarke);
+ grpBildmarke.setLayout(new GridLayout(3, false));
+ grpBildmarke.setText("Bildmarke");
+
+ this.lblEmblem = new Label(grpBildmarke, SWT.BORDER | SWT.RESIZE);
+ this.lblEmblem.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
+ true, 1, 4));
+ this.lblEmblem.setAlignment(SWT.CENTER);
+ this.lblEmblem.setText("No Image");
+ this.lblEmblem.addListener(SWT.Resize, new Listener() {
+
+ @Override
+ public void handleEvent(Event event) {
+ SimpleConfigurationComposite.this.recalculateEmblemSize();
+ }
+ });
+
+ Label lblDateiname = new Label(grpBildmarke, SWT.NONE);
+ lblDateiname.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false,
+ false, 1, 1));
+ lblDateiname.setText("Dateiname:");
+ new Label(grpBildmarke, SWT.NONE);
+
+ this.txtEmblemFile = new Text(grpBildmarke, SWT.BORDER);
+ GridData gd_txtEmblemFile = new GridData(SWT.FILL, SWT.FILL, false,
+ false, 2, 1);
+ gd_txtEmblemFile.widthHint = 123;
+ this.txtEmblemFile.setLayoutData(gd_txtEmblemFile);
+ this.txtEmblemFile.addFocusListener(new FocusListener() {
+
+ @Override
+ public void focusLost(FocusEvent e) {
+ processEmblemChanged();
+ }
+
+ @Override
+ public void focusGained(FocusEvent e) {
+ // Nothing to do here!
+ }
+ });
+ this.txtEmblemFile.addTraverseListener(new TraverseListener() {
+
+ @Override
+ public void keyTraversed(TraverseEvent e) {
+ if (e.detail == SWT.TRAVERSE_RETURN) {
+ processEmblemChanged();
+ }
+ }
+ });
+ new Label(grpBildmarke, SWT.NONE);
+
+ Button btnBrowseEmblem = new Button(grpBildmarke, SWT.NONE);
+ btnBrowseEmblem.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ FileDialog dialog = new FileDialog(SimpleConfigurationComposite.this
+ .getShell(), SWT.OPEN);
+ dialog.setFilterExtensions(new String[] { "*.jpg", "*.gif" }); //$NON-NLS-1$ //$NON-NLS-2$
+ dialog.setFilterNames(new String[] { "JPG Dateien",
+ "Gif Dateien" });
+ String fileName = dialog.open();
+ File file = null;
+ if (fileName != null) {
+ file = new File(fileName);
+ if (file.exists()) {
+ SimpleConfigurationComposite.this.txtEmblemFile
+ .setText(fileName);
+ processEmblemChanged();
+ }
+ }
+ }
+ });
+ btnBrowseEmblem.setText("Browse");
+
+ Label label = new Label(grpBildmarke, SWT.NONE);
+ GridData gd_label = new GridData(SWT.FILL, SWT.FILL, false, true, 2, 1);
+ gd_label.widthHint = 189;
+ label.setLayoutData(gd_label);
+
+ Group grpProxy = new Group(this, SWT.NONE);
+ FormData fd_grpProxy = new FormData();
+ fd_grpProxy.right = new FormAttachment(100, -5);
+ fd_grpProxy.top = new FormAttachment(65, 5);
+ fd_grpProxy.left = new FormAttachment(0, 5);
+ fd_grpProxy.bottom = new FormAttachment(90, -5);
+ grpProxy.setLayoutData(fd_grpProxy);
+ grpProxy.setText("Proxy");
+ grpProxy.setLayout(new GridLayout(2, false));
+
+ Label lblNewLabel = new Label(grpProxy, SWT.NONE);
+ GridData gd_lblNewLabel = new GridData(SWT.LEFT, SWT.CENTER, false,
+ false, 1, 1);
+ gd_lblNewLabel.widthHint = 66;
+ lblNewLabel.setLayoutData(gd_lblNewLabel);
+ lblNewLabel.setBounds(0, 0, 57, 15);
+ lblNewLabel.setText("Host:");
+
+ this.text = new Text(grpProxy, SWT.BORDER);
+ this.text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false,
+ 1, 1));
+
+ Label lblNewLabel_1 = new Label(grpProxy, SWT.NONE);
+ lblNewLabel_1.setBounds(0, 0, 57, 15);
+ lblNewLabel_1.setText("Port:");
+
+ this.text_1 = new Text(grpProxy, SWT.BORDER);
+ this.text_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false,
+ 1, 1));
+
+ }
+
+ /**
+ * SLF4J Logger instance
+ **/
+ private static final Logger log = LoggerFactory
+ .getLogger(SimpleConfigurationComposite.class);
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.composites.StateComposite#doLayout()
+ */
+ @Override
+ public void doLayout() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/InitializationException.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/InitializationException.java
new file mode 100644
index 00000000..d54b5d0b
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/InitializationException.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.gui.exceptions;
+
+/**
+ *
+ */
+public class InitializationException extends Exception {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 433744698649684034L;
+
+ /**
+ * @param msg
+ * @param cause
+ */
+ public InitializationException(String msg, Throwable cause) {
+ super(msg, cause);
+ }
+
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/InvalidEmblemFile.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/InvalidEmblemFile.java
new file mode 100644
index 00000000..9ba8f66a
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/InvalidEmblemFile.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.gui.exceptions;
+
+// Imports
+import java.io.File;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ */
+public class InvalidEmblemFile extends Exception {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -5826910929131650685L;
+ /**
+ * SLF4J Logger instance
+ **/
+ private static final Logger log = LoggerFactory
+ .getLogger(InvalidEmblemFile.class);
+
+ /**
+ * Constructor
+ * @param file
+ */
+ public InvalidEmblemFile(final File file) {
+ super("File: " + file.getAbsolutePath() + " is an invalid emblem file!");
+ }
+
+ /**
+ * Constructor
+ * @param file
+ */
+ public InvalidEmblemFile(final File file, Throwable reason) {
+ super("File: " + file.getAbsolutePath() + " is an invalid emblem file!", reason);
+ }
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/InvalidNumberException.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/InvalidNumberException.java
new file mode 100644
index 00000000..467ff327
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/InvalidNumberException.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.gui.exceptions;
+
+// Imports
+
+/**
+ *
+ */
+public class InvalidNumberException extends Exception {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -4201886410518715443L;
+
+ /**
+ *
+ */
+ public InvalidNumberException() {
+
+ }
+
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/InvalidPasswordException.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/InvalidPasswordException.java
new file mode 100644
index 00000000..06bf279f
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/InvalidPasswordException.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.gui.exceptions;
+
+/**
+ * Base Class for Invalid password exceptions
+ */
+public abstract class InvalidPasswordException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 6735754648793405145L;
+
+ /**
+ * Invalid Password
+ * @param msg
+ */
+ public InvalidPasswordException(String msg) {
+ super(msg);
+ }
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/InvalidPortException.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/InvalidPortException.java
new file mode 100644
index 00000000..923a04a5
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/InvalidPortException.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.gui.exceptions;
+
+/**
+ *
+ */
+public class InvalidPortException extends Exception {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -4809078091773253962L;
+
+
+ /**
+ * Constructor
+ * @param port
+ */
+ public InvalidPortException(int port) {
+ super("Port " + port + " is invalid has to be between 1 and " + 0xffff);
+ }
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/PasswordTooLongException.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/PasswordTooLongException.java
new file mode 100644
index 00000000..ac578664
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/PasswordTooLongException.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.gui.exceptions;
+
+// Imports
+
+/**
+ *
+ */
+public class PasswordTooLongException extends InvalidPasswordException {
+
+ /**
+ * Constructor
+ */
+ public PasswordTooLongException() {
+ super("Given password is too long!");
+ }
+ /**
+ *
+ */
+ private static final long serialVersionUID = -3268343884240608304L;
+
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/PasswordTooShortException.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/PasswordTooShortException.java
new file mode 100644
index 00000000..0e6a98f7
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/PasswordTooShortException.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.gui.exceptions;
+
+// Imports
+
+/**
+ *
+ */
+public class PasswordTooShortException extends InvalidPasswordException {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 3015765967751806169L;
+
+ /**
+ * Constructor
+ */
+ public PasswordTooShortException() {
+ super("Given password is too short!");
+ }
+
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigManipulator.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigManipulator.java
new file mode 100644
index 00000000..702fa6bb
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigManipulator.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.gui.workflow;
+
+import java.io.IOException;
+
+import at.asit.pdfover.signator.BKUs;
+import at.asit.pdfover.signator.SignaturePosition;
+
+/**
+ *
+ */
+public interface ConfigManipulator {
+
+ /**
+ * The default config file location
+ */
+ public static final String DEFAULT_CONFIG_FILE = "PDFOver.config"; //$NON-NLS-1$
+
+ /**
+ * The bku config parameter
+ */
+ public static final String BKU_CONFIG = "BKU"; //$NON-NLS-1$
+
+ /**
+ * The value for the Singature position in the configuration file
+ * values for this entry are:
+ *
+ * x=vx;y=vy;p=vp or auto
+ *
+ * vx:= float value
+ * vy:= float value
+ * vp:= integer value
+ */
+ public static final String SIGNATURE_POSITION_CONFIG = "SIGNATURE_POSITION"; //$NON-NLS-1$
+
+ /**
+ * The mobile number config parameter
+ */
+ public static final String MOBILE_NUMBER_CONFIG = "MOBILE_NUMBER"; //$NON-NLS-1$
+
+ /**
+ * The emblem config parameter
+ */
+ public static final String EMBLEM_CONFIG = "EMBLEM"; //$NON-NLS-1$
+
+ /**
+ * The proxy host config parameter
+ */
+ public static final String PROXY_HOST_CONFIG = "PROXY_HOST"; //$NON-NLS-1$
+
+ /**
+ * The proxy port config parameter
+ */
+ public static final String PROXY_PORT_CONFIG = "PROXY_PORT"; //$NON-NLS-1$
+
+ /**
+ * Sets the default bku type
+ * @param bku the bku type
+ */
+ public void setDefaultBKU(BKUs bku);
+
+ /**
+ * Sets the default signature position
+ *
+ * @param signaturePosition the default signature position
+ */
+ public void setDefaultSignaturePosition(SignaturePosition signaturePosition);
+
+ /**
+ * Sets the default mobile number
+ * @param number the default mobile number
+ */
+ public void setDefaultMobileNumber(String number);
+
+ /**
+ * Sets the default password
+ * @param password the default password
+ */
+ public void setDefaultPassword(String password);
+
+ /**
+ * Sets the default emblem
+ *
+ * @param emblem the default emblem
+ */
+ public void setDefaultEmblem(String emblem);
+
+ /**
+ * Sets the proxy host
+ * @param host the proxy host
+ */
+ public void setProxyHost(String host);
+
+ /**
+ * Sets the proxy port
+ *
+ * @param port the proxy port
+ */
+ public void setProxyPort(int port);
+
+ /**
+ * Sets the configuration file
+ * @param configurationFile
+ */
+ public void setConfigurationFile(String configurationFile);
+
+ /**
+ * Saves the current configuration to the current configuration file
+ * @throws IOException
+ */
+ public void saveCurrentConfiguration() throws IOException;
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java
index b2f1336b..8ada4d2d 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java
@@ -25,6 +25,42 @@ public interface ConfigProvider {
//TODO: define interface for config provider ....
/**
+ * Gets the configuration file
+ * @return the configuration file
+ */
+ public String getConfigurationFile();
+
+ /**
+ * Gets the default Mobile number
+ * @return the default mobile number
+ */
+ public String getDefaultMobileNumber();
+
+ /**
+ * Gets the password to use for Mobile BKU
+ * @return the password
+ */
+ public String getDefaultPassword();
+
+ /**
+ * Gets the filename of the default emblem
+ * @return the emblem
+ */
+ public String getDefaultEmblem();
+
+ /**
+ * Gets the proxy host
+ * @return the proxy hostname or ip address
+ */
+ public String getProxyHost();
+
+ /**
+ * Gets the proxy port
+ * @return the proxy port
+ */
+ public int getProxyPort();
+
+ /**
* Get the default configured BKU
* @return the default configured BKU
*/
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java
index adedd1b0..6a128e73 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java
@@ -16,6 +16,11 @@
package at.asit.pdfover.gui.workflow;
// Imports
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -25,30 +30,219 @@ import at.asit.pdfover.signator.SignaturePosition;
/**
*
*/
-public class ConfigProviderImpl implements ConfigProvider {
+public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator {
/**
* SLF4J Logger instance
**/
@SuppressWarnings("unused")
private static final Logger log = LoggerFactory
.getLogger(ConfigProviderImpl.class);
-
+
+ private BKUs defaultBKU = BKUs.NONE;
+
+ private SignaturePosition defaultSignaturePosition = null;
+
+ private String defaultMobileNumber = null;
+
+ private String defaultPassword = null;
+
+ private String emblem = null;
+
+ private String proxyHost = null;
+
+ private String configurationFile = ConfigManipulator.DEFAULT_CONFIG_FILE;
+
+ private int proxyPort = -1;
+
+ /**
+ * Sets the default bku type
+ * @param bku the bku type
+ */
+ @Override
+ public void setDefaultBKU(BKUs bku) {
+ this.defaultBKU = bku;
+ }
+
/* (non-Javadoc)
* @see at.asit.pdfover.gui.workflow.ConfigProvider#getDefaultBKU()
*/
@Override
public BKUs getDefaultBKU() {
- // TODO Read Config
- return BKUs.NONE;
+ return this.defaultBKU;
}
+ /**
+ * Sets the default signature position
+ *
+ * @param signaturePosition the default signature position
+ */
+ @Override
+ public void setDefaultSignaturePosition(SignaturePosition signaturePosition) {
+ this.defaultSignaturePosition = signaturePosition;
+ }
+
/* (non-Javadoc)
* @see at.asit.pdfover.gui.workflow.ConfigProvider#getDefaultSignaturePosition()
*/
@Override
public SignaturePosition getDefaultSignaturePosition() {
- // TODO Read Config
- return null;
+ return this.defaultSignaturePosition;
}
+ /**
+ * Sets the default mobile number
+ * @param number the default mobile number
+ */
+ @Override
+ public void setDefaultMobileNumber(String number) {
+ if(number == null || number.trim().equals("")) { //$NON-NLS-1$
+ this.defaultMobileNumber = null;
+ } else {
+ this.defaultMobileNumber = number;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.workflow.ConfigProvider#getDefaultMobileNumber()
+ */
+ @Override
+ public String getDefaultMobileNumber() {
+ return this.defaultMobileNumber;
+ }
+
+ /**
+ * Sets the default password
+ * @param password the default password
+ */
+ @Override
+ public void setDefaultPassword(String password) {
+ if(password == null || password.trim().equals("")) { //$NON-NLS-1$
+ this.defaultPassword = null;
+ } else {
+ this.defaultPassword = password;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.workflow.ConfigProvider#getDefaultPassword()
+ */
+ @Override
+ public String getDefaultPassword() {
+ return this.defaultPassword;
+ }
+
+ /**
+ * Sets the default emblem
+ *
+ * @param emblem the default emblem
+ */
+ @Override
+ public void setDefaultEmblem(String emblem) {
+ if(emblem == null || emblem.trim().equals("")) { //$NON-NLS-1$
+ this.emblem = null;
+ } else {
+ this.emblem = emblem;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.workflow.ConfigProvider#getDefaultEmblem()
+ */
+ @Override
+ public String getDefaultEmblem() {
+ return this.emblem;
+ }
+
+ /**
+ * Sets the proxy host
+ * @param host the proxy host
+ */
+ @Override
+ public void setProxyHost(String host) {
+ if(host == null || host.trim().equals("")) { //$NON-NLS-1$
+ this.emblem = null;
+ } else {
+ this.emblem = host;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.workflow.ConfigProvider#getProxyHost()
+ */
+ @Override
+ public String getProxyHost() {
+ return this.proxyHost;
+ }
+
+ /**
+ * Sets the proxy port
+ *
+ * @param port the proxy port
+ */
+ @Override
+ public void setProxyPort(int port) {
+ this.proxyPort = port;
+ }
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.workflow.ConfigProvider#getProxyPort()
+ */
+ @Override
+ public int getProxyPort() {
+ return this.proxyPort;
+ }
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.workflow.ConfigManipulator#setConfigurationFile(java.lang.String)
+ */
+ @Override
+ public void setConfigurationFile(String configurationFile) {
+ this.configurationFile = configurationFile;
+ }
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.workflow.ConfigProvider#getConfigurationFile()
+ */
+ @Override
+ public String getConfigurationFile() {
+ return this.configurationFile;
+ }
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.workflow.ConfigManipulator#saveCurrentConfiguration()
+ */
+ @Override
+ public void saveCurrentConfiguration() throws IOException{
+ String filename = this.getConfigurationFile();
+
+ File configFile = new File(filename);
+
+ Properties props = new Properties();
+
+ props.setProperty(BKU_CONFIG, this.getDefaultBKU().toString());
+ props.setProperty(PROXY_HOST_CONFIG, this.getProxyHost());
+ props.setProperty(PROXY_PORT_CONFIG, Integer.toString(this.getProxyPort()));
+ props.setProperty(EMBLEM_CONFIG, this.getDefaultEmblem());
+ props.setProperty(MOBILE_NUMBER_CONFIG, this.getDefaultMobileNumber());
+
+ SignaturePosition pos = this.getDefaultSignaturePosition();
+
+ if(pos == null) {
+ props.setProperty(SIGNATURE_POSITION_CONFIG, ""); //$NON-NLS-1$
+ } else if(pos.useAutoPositioning()) {
+ props.setProperty(SIGNATURE_POSITION_CONFIG, "auto"); //$NON-NLS-1$
+ } else {
+ props.setProperty(SIGNATURE_POSITION_CONFIG,
+ String.format("x=%f;y=%f;p=%d", //$NON-NLS-1$
+ pos.getX(),
+ pos.getY(),
+ pos.getPage()));
+ }
+
+ FileOutputStream outputstream = new FileOutputStream(configFile, false);
+
+ props.store(outputstream, "Configuration file was generated!"); //$NON-NLS-1$
+
+ }
+
}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachine.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachine.java
index c98d9895..9bcc757e 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachine.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachine.java
@@ -28,6 +28,12 @@ public interface StateMachine {
public ConfigProvider getConfigProvider();
/**
+ * Gets the Config Manipulator
+ * @return the config manipulator
+ */
+ public ConfigManipulator getConfigManipulator();
+
+ /**
* Get the PDF Signer
* @return the PDF Signer
*/
@@ -75,4 +81,11 @@ public interface StateMachine {
* Exit state machine execution
*/
public void exit();
+
+ /**
+ * Gets the command line arguments
+ *
+ * @return the command line arguments
+ */
+ public String[] getCmdArgs();
}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachineImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachineImpl.java
index cf764a73..90b2fba9 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachineImpl.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachineImpl.java
@@ -80,32 +80,45 @@ public class StateMachineImpl implements StateMachine, GUIProvider {
State next = null;
while (this.status.getCurrentState() != null) {
State current = this.status.getCurrentState();
- try
- {
+ try {
current.run();
- }
- catch(Exception e) {
+ } catch (Exception e) {
log.error("StateMachine update: ", e); //$NON-NLS-1$
// TODO: GOTO generic error state!
}
- if (this.mainWindow != null
- && !this.mainWindow.getShell().isDisposed()) {
- log.debug("Allowing MainWindow to update its state for " //$NON-NLS-1$
- + current);
- current.updateMainWindowBehavior();
- this.mainWindow.applyBehavior();
- this.mainWindow.doLayout();
- }
- next = current.nextState();
- if (next == current) {
- break;
+
+ if (this.exit) {
+ // exit request ignore
+ next = null;
+ this.status.setCurrentState(next);
+ } else {
+
+ if (this.mainWindow != null
+ && !this.mainWindow.getShell().isDisposed()) {
+ log.debug("Allowing MainWindow to update its state for " //$NON-NLS-1$
+ + current);
+ current.updateMainWindowBehavior();
+ this.mainWindow.applyBehavior();
+ this.mainWindow.doLayout();
+ }
+ next = current.nextState();
+ if (next == current) {
+ break;
+ }
+
+ if (next == null) {
+ log.info("Next state is null -> exit"); //$NON-NLS-1$
+ this.status.setCurrentState(next);
+ break;
+ }
+
+ log.debug("Changing state from: " //$NON-NLS-1$
+ + current + " to " //$NON-NLS-1$
+ + next.toString());
+ this.status.setCurrentState(next);
}
- log.debug("Changing state from: " //$NON-NLS-1$
- + current + " to " //$NON-NLS-1$
- + next.toString());
- this.status.setCurrentState(next);
}
-
+
// TODO: Remove following line when releasing ...
if (this.status.getCurrentState() != null) {
this.setCurrentStateMessage(this.status.getCurrentState()
@@ -205,9 +218,8 @@ public class StateMachineImpl implements StateMachine, GUIProvider {
Composite.class, int.class, State.class);
composite = constructor.newInstance(getComposite(), style, state);
} catch (Exception e) {
- log.error(
- "Could not create Composite for Class " //$NON-NLS-1$
- + compositeClass.getName(), e);
+ log.error("Could not create Composite for Class " //$NON-NLS-1$
+ + compositeClass.getName(), e);
}
return composite;
}
@@ -221,12 +233,17 @@ public class StateMachineImpl implements StateMachine, GUIProvider {
return this.shell;
}
+ private boolean exit = false;
+
/**
* Exists the Workflow
*/
@Override
public void exit() {
- this.shell.dispose();
+ this.exit = true;
+ if (this.shell != null) {
+ this.shell.dispose();
+ }
}
/**
@@ -249,6 +266,12 @@ public class StateMachineImpl implements StateMachine, GUIProvider {
Shell shell = this.nonCreatingGetShell();
Display display = this.nonCreatingGetDisplay();
+ if (this.status.getCurrentState() == null) {
+ if (shell != null) {
+ this.shell.dispose();
+ }
+ }
+
if (shell != null && display != null) {
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
@@ -288,8 +311,10 @@ public class StateMachineImpl implements StateMachine, GUIProvider {
public PDFSigner getPDFSigner() {
return this.pdfSigner;
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see at.asit.pdfover.gui.workflow.StateMachine#getGUIProvider()
*/
@Override
@@ -318,7 +343,16 @@ public class StateMachineImpl implements StateMachine, GUIProvider {
*
* @return the command line arguments
*/
+ @Override
public String[] getCmdArgs() {
return this.cmdLineArgs;
}
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.workflow.StateMachine#getConfigManipulator()
+ */
+ @Override
+ public ConfigManipulator getConfigManipulator() {
+ return this.configProvider;
+ }
}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StatusImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StatusImpl.java
index 355ab6bd..b60608b6 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StatusImpl.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StatusImpl.java
@@ -71,8 +71,8 @@ public class StatusImpl implements Status {
* @param currentState the current State
*/
public void setCurrentState(State currentState) {
- if (this.previousState == this.currentState)
- log.error("Changing to same state? " + this.currentState); //$NON-NLS-1$
+ //if (this.previousState == this.currentState)
+ // log.error("Changing to same state? " + this.currentState); //$NON-NLS-1$
if (this.previousState != null && this.previousState != currentState)
{
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java
new file mode 100644
index 00000000..4b468ad8
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.gui.workflow.states;
+
+// Imports
+import org.eclipse.swt.SWT;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import at.asit.pdfover.gui.composites.ConfigurationComposite;
+import at.asit.pdfover.gui.workflow.StateMachine;
+import at.asit.pdfover.gui.workflow.Status;
+
+/**
+ *
+ */
+public class ConfigurationUIState extends State {
+ /**
+ * SLF4J Logger instance
+ **/
+ private static final Logger log = LoggerFactory
+ .getLogger(ConfigurationUIState.class);
+
+
+ private ConfigurationComposite configurationComposite = null;
+
+ private ConfigurationComposite getConfigurationComposite() {
+ if (this.configurationComposite == null) {
+ this.configurationComposite =
+ this.stateMachine.getGUIProvider().createComposite(ConfigurationComposite.class, SWT.RESIZE, this);
+ this.configurationComposite.setConfigManipulator(this.stateMachine.getConfigManipulator());
+ }
+
+ return this.configurationComposite;
+ }
+
+ /**
+ * @param stateMachine
+ */
+ public ConfigurationUIState(StateMachine stateMachine) {
+ super(stateMachine);
+ }
+
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.workflow.states.State#run()
+ */
+ @Override
+ public void run() {
+ Status status = this.stateMachine.getStatus();
+
+ ConfigurationComposite config = this.getConfigurationComposite();
+
+ this.stateMachine.getGUIProvider().display(config);
+
+ if(config.isUserDone())
+ {
+ this.setNextState(status.getPreviousState());
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.workflow.states.State#cleanUp()
+ */
+ @Override
+ public void cleanUp() {
+ if(this.configurationComposite != null)
+ this.configurationComposite.dispose();
+ }
+
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.gui.workflow.states.State#updateMainWindowBehavior()
+ */
+ @Override
+ public void updateMainWindowBehavior() {
+ // Leave the state as it is
+ }
+
+}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ErrorState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ErrorState.java
index 47485a0c..af648dfd 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ErrorState.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ErrorState.java
@@ -22,7 +22,6 @@ import org.slf4j.LoggerFactory;
import at.asit.pdfover.gui.composites.ErrorComposite;
import at.asit.pdfover.gui.workflow.StateMachine;
-import at.asit.pdfover.gui.workflow.Status;
/**
*
@@ -67,8 +66,6 @@ public class ErrorState extends State {
*/
@Override
public void run() {
- Status status = this.stateMachine.getStatus();
-
ErrorComposite errorComposite = this.getComposite();
if(this.exception != null && !errorComposite.isUserOk()) {
@@ -94,7 +91,8 @@ public class ErrorState extends State {
*/
@Override
public void cleanUp() {
- // TODO
+ if (this.errorComposite != null)
+ this.errorComposite.dispose();
}
/* (non-Javadoc)
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java
index deec44dd..ca0e164c 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java
@@ -121,6 +121,8 @@ public class LocalBKUState extends State {
} catch (Exception e) {
log.error("SignLocalBKUThread: ", e); //$NON-NLS-1$
+ // TODO: Is local BKU running?
+ this.state.threadException = e;
} finally {
this.state.stateMachine.invokeUpdate();
}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java
index 25df5b7e..234cd215 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java
@@ -199,7 +199,7 @@ public class MobileBKUState extends State {
postCredentialsThread.start();
} else {
- // We need at least number of password => show UI!
+ // We need number and password => show UI!
// set possible error message
ui.setErrorMessage(mobileStatus.getErrorMessage());
@@ -257,7 +257,12 @@ public class MobileBKUState extends State {
*/
@Override
public void cleanUp() {
- // No composite - no cleanup necessary
+ if(this.mobileBKUEnterNumberComposite != null)
+ this.mobileBKUEnterNumberComposite.dispose();
+ if(this.mobileBKUEnterTANComposite != null)
+ this.mobileBKUEnterTANComposite.dispose();
+ if(this.waitingComposite != null)
+ this.waitingComposite.dispose();
}
/*
@@ -280,6 +285,9 @@ public class MobileBKUState extends State {
return this.getClass().getName();
}
+ /**
+ * invoke state machine update in main thread
+ */
public void invokeUpdate() {
this.stateMachine.invokeUpdate();
}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java
index 2a71890d..b4b05318 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java
@@ -16,12 +16,28 @@
package at.asit.pdfover.gui.workflow.states;
//Imports
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import at.asit.pdfover.gui.cliarguments.ArgumentHandler;
+import at.asit.pdfover.gui.cliarguments.BKUArgument;
+import at.asit.pdfover.gui.cliarguments.ConfigFileArgument;
+import at.asit.pdfover.gui.cliarguments.HelpArgument;
+import at.asit.pdfover.gui.cliarguments.PhoneNumberArgument;
+import at.asit.pdfover.gui.exceptions.InitializationException;
+import at.asit.pdfover.gui.workflow.ConfigManipulator;
import at.asit.pdfover.gui.workflow.StateMachine;
+import at.asit.pdfover.signator.BKUs;
import at.asit.pdfover.signator.Signator;
-
+import at.asit.pdfover.signator.SignaturePosition;
/**
* Starting state of workflow proccess
@@ -31,34 +47,221 @@ import at.asit.pdfover.signator.Signator;
public class PrepareConfigurationState extends State {
/**
+ * Regex for parsing signature position
+ */
+ public static final String SIGN_POS_REGEX = "(x=(\\d\\.?\\d?);y=(\\d\\.?\\d?);p=(\\d))|(auto)|(x=(\\d\\.?\\d?);y=(\\d\\.?\\d?))"; //$NON-NLS-1$
+
+ /**
* @param stateMachine
*/
public PrepareConfigurationState(StateMachine stateMachine) {
super(stateMachine);
+ this.handler = new ArgumentHandler(this.stateMachine);
+ this.handler.addCLIArgument(new HelpArgument());
+ this.handler.addCLIArgument(new BKUArgument());
+ this.handler.addCLIArgument(new PhoneNumberArgument());
+
+ // adding config file argument to this handler so it appears in help
+ this.handler.addCLIArgument(new ConfigFileArgument());
+
+ this.configFilehandler = new ArgumentHandler(this.stateMachine);
+ this.configFilehandler.addCLIArgument(new ConfigFileArgument());
}
+ private ArgumentHandler handler;
+
+ private ArgumentHandler configFilehandler;
+
/**
* SFL4J Logger instance
**/
- @SuppressWarnings("unused")
private static final Logger log = LoggerFactory
.getLogger(PrepareConfigurationState.class);
+ private void initializeFromConfigurationFile(String filename)
+ throws InitializationException {
+ try {
+ Properties config = new Properties();
+
+ try {
+ config.load(new FileInputStream(filename));
+ } catch (FileNotFoundException ex) {
+ if (filename.equals(ConfigManipulator.DEFAULT_CONFIG_FILE)) {
+ // we only check for resource config file if it is the
+ // default value!
+ try {
+ InputStream is = this.getClass().getResourceAsStream(
+ "/" + filename); //$NON-NLS-1$
+ config.load(is);
+ } catch (Exception eex) {
+ throw ex;
+ }
+ } else {
+ throw ex;
+ }
+ }
+
+ // Load ok ...
+ ConfigManipulator configManipulator = this.stateMachine
+ .getConfigManipulator();
+
+ // Set Emblem
+ configManipulator.setDefaultEmblem(config
+ .getProperty(ConfigManipulator.EMBLEM_CONFIG));
+
+ // Set Mobile Phone Number
+ configManipulator.setDefaultMobileNumber(config
+ .getProperty(ConfigManipulator.MOBILE_NUMBER_CONFIG));
+
+ // Set Proxy Host
+ configManipulator.setProxyHost(config
+ .getProperty(ConfigManipulator.PROXY_HOST_CONFIG));
+
+ // Set Proxy Port
+ String proxyPortString = config
+ .getProperty(ConfigManipulator.PROXY_PORT_CONFIG);
+
+ if (proxyPortString != null && !proxyPortString.trim().equals("")) { //$NON-NLS-1$
+ int port = Integer.parseInt(proxyPortString);
+
+ if (port > 0 && port <= 0xFFFF) {
+ configManipulator.setProxyPort(port);
+ } else {
+ log.warn("Proxy port is out of range!: " + port); //$NON-NLS-1$
+ }
+ }
+
+ // Set Default BKU
+ String bkuString = config.getProperty(ConfigManipulator.BKU_CONFIG);
+
+ BKUs defaultBKU = BKUs.NONE;
+
+ try {
+ defaultBKU = BKUs.valueOf(bkuString);
+ } catch (IllegalArgumentException ex) {
+ log.error("Invalid BKU config value " + bkuString + " using none!"); //$NON-NLS-1$ //$NON-NLS-2$
+ defaultBKU = BKUs.NONE;
+ } catch (NullPointerException ex) {
+ log.error("Invalid BKU config value " + bkuString + " using none!"); //$NON-NLS-1$ //$NON-NLS-2$
+ defaultBKU = BKUs.NONE;
+ }
+
+ configManipulator.setDefaultBKU(defaultBKU);
+
+ // Set Signature Position
+ String signaturePosition = config
+ .getProperty(ConfigManipulator.SIGNATURE_POSITION_CONFIG);
+
+ SignaturePosition position = null;
+
+ if (signaturePosition != null
+ && !signaturePosition.trim().equals("")) { //$NON-NLS-1$
+
+ signaturePosition = signaturePosition.trim().toLowerCase();
+
+ Pattern pattern = Pattern.compile(SIGN_POS_REGEX);
+
+ Matcher matcher = pattern.matcher(signaturePosition);
+
+ if (matcher.matches()) {
+ if (matcher.groupCount() == 8) {
+ if (matcher.group(1) != null) {
+ // we have format: x=..;y=..;p=...
+ try {
+ // group 2 = x value
+ float x = Float.parseFloat(matcher.group(2));
+
+ // group 3 = y value
+ float y = Float.parseFloat(matcher.group(3));
+
+ // group 4 = p value
+ int p = Integer.parseInt(matcher.group(3));
+
+ position = new SignaturePosition(x, y, p);
+ } catch (NumberFormatException ex) {
+ log.error(
+ "Signature Position read from config failed: Not a valid number", ex); //$NON-NLS-1$
+ }
+ } else if (matcher.group(5) != null) {
+ // we have format auto
+ position = new SignaturePosition();
+ } else if (matcher.group(6) != null) {
+ // we have format x=...;y=...;
+ // group 7 = x value
+ float x = Float.parseFloat(matcher.group(7));
+
+ // group 8 = y value
+ float y = Float.parseFloat(matcher.group(8));
+
+ position = new SignaturePosition(x, y);
+ }
+ } else {
+ log.error("Signature Position read from config failed: wrong group Count!"); //$NON-NLS-1$
+ }
+ } else {
+ log.error("Signature Position read from config failed: not matching string"); //$NON-NLS-1$
+ }
+
+ }
+
+ configManipulator.setDefaultSignaturePosition(position);
+
+ } catch (IOException ex) {
+ throw new InitializationException(
+ "Failed to read configuration from config file", ex); //$NON-NLS-1$
+ }
+ }
+
+ private void initializeFromArguments(String[] args, ArgumentHandler handler)
+ throws InitializationException {
+ handler.handleArguments(args);
+
+ if (handler.IsRequireExit()) {
+ this.stateMachine.exit();
+ }
+ }
+
@Override
public void run() {
- // TODO: Read config file and command line arguments
- // Set usedSignerLib ...
- this.stateMachine.getPDFSigner().setUsedPDFSignerLibrary(Signator.Signers.PDFAS);
-
- // Create PDF Signer
- this.stateMachine.getStatus().setBKU(this.stateMachine.getConfigProvider().getDefaultBKU());
-
- this.stateMachine.getStatus().setSignaturePosition(this.stateMachine.getConfigProvider().getDefaultSignaturePosition());
-
- this.setNextState(new OpenState(this.stateMachine));
+ // Read config file
+ try {
+ // Read cli arguments with for config file!
+ this.initializeFromArguments(this.stateMachine.getCmdArgs(),
+ this.configFilehandler);
+
+ // initialize from config file
+ this.initializeFromConfigurationFile(this.stateMachine
+ .getConfigProvider().getConfigurationFile());
+
+ // Read cli arguments
+ this.initializeFromArguments(this.stateMachine.getCmdArgs(),
+ this.handler);
+
+ // Set usedSignerLib ...
+ this.stateMachine.getPDFSigner().setUsedPDFSignerLibrary(
+ Signator.Signers.PDFAS);
+
+ // Create PDF Signer
+ this.stateMachine.getStatus().setBKU(
+ this.stateMachine.getConfigProvider().getDefaultBKU());
+
+ this.stateMachine.getStatus().setSignaturePosition(
+ this.stateMachine.getConfigProvider()
+ .getDefaultSignaturePosition());
+
+ this.setNextState(new OpenState(this.stateMachine));
+
+ } catch (InitializationException e) {
+ log.error("Failed to initialize: ", e); //$NON-NLS-1$
+ ErrorState error = new ErrorState(this.stateMachine);
+ error.setException(e);
+ this.setNextState(error);
+ }
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see at.asit.pdfover.gui.workflow.states.State#cleanUp()
*/
@Override
@@ -66,16 +269,18 @@ public class PrepareConfigurationState extends State {
// No composite - no cleanup necessary
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see at.asit.pdfover.gui.workflow.states.State#setMainWindowBehavior()
*/
@Override
public void updateMainWindowBehavior() {
- //no behavior necessary yet
+ // no behavior necessary yet
}
@Override
- public String toString() {
+ public String toString() {
return this.getClass().getName();
}
}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ASITTrustManager.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ASITTrustManager.java
index 2428ef65..6f557bc6 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ASITTrustManager.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ASITTrustManager.java
@@ -16,13 +16,22 @@
package at.asit.pdfover.gui.workflow.states.mobilebku;
// Imports
+import java.security.KeyStore;
import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
-
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.commons.lang.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
/**
*
@@ -34,31 +43,181 @@ public class ASITTrustManager implements X509TrustManager {
private static final Logger log = LoggerFactory
.getLogger(ASITTrustManager.class);
- /* (non-Javadoc)
- * @see javax.net.ssl.X509TrustManager#checkClientTrusted(java.security.cert.X509Certificate[], java.lang.String)
+ /*
+ * The default X509TrustManager returned by SunX509. We'll delegate
+ * decisions to it, and fall back to the logic in this class if the default
+ * X509TrustManager doesn't trust it.
+ */
+ X509TrustManager sunJSSEX509TrustManager;
+
+ /**
+ * Trust Manager for A-Trust Certificates
+ */
+ X509TrustManager atrustTrustManager;
+
+ /**
+ * Constructs the TrustManager
+ *
+ * @throws Exception
+ */
+ public ASITTrustManager() throws Exception {
+ // create a "default" JSSE X509TrustManager.
+
+ TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); //$NON-NLS-1$
+ tmf.init((KeyStore) null);
+
+ TrustManager tms[] = tmf.getTrustManagers();
+
+ /*
+ * Iterate over the returned trustmanagers, look for an instance of
+ * X509TrustManager. If found, use that as our "default" trust manager.
+ */
+ for (int i = 0; i < tms.length; i++) {
+ if (tms[i] instanceof X509TrustManager) {
+ this.sunJSSEX509TrustManager = (X509TrustManager) tms[i];
+ break;
+ }
+ }
+
+ /*
+ * A-Trust Certificates
+ */
+
+ KeyStore atrustKeyStore = KeyStore.getInstance(KeyStore
+ .getDefaultType());
+
+ atrustKeyStore.load(null);
+
+ String usedCertificates = "/certificates/used_certificates.xml"; //$NON-NLS-1$
+
+ Document doc = DocumentBuilderFactory.newInstance()
+ .newDocumentBuilder()
+ .parse(this.getClass().getResourceAsStream(usedCertificates));
+
+ Node certificates = doc.getFirstChild();
+
+ if (!certificates.getNodeName().equals("certificates")) { //$NON-NLS-1$
+ throw new Exception(
+ "Used certificates xml is invalid! no certificates node"); //$NON-NLS-1$
+ }
+
+ NodeList certificateList = certificates.getChildNodes();
+
+ for (int i = 0; i < certificateList.getLength(); i++) {
+ try {
+
+ Node certificateNode = certificateList.item(i);
+
+ if (certificateNode.getNodeName().equals("#text")) { //$NON-NLS-1$
+ continue; // Ignore dummy text node ..
+ }
+
+ if (!certificateNode.getNodeName().equals("certificate")) { //$NON-NLS-1$
+ log.warn("Ignoring XML node: " + certificateNode.getNodeName()); //$NON-NLS-1$
+ continue;
+ }
+
+ String certResource = "/certificates/" + certificateNode.getTextContent() + ".crt"; //$NON-NLS-1$ //$NON-NLS-2$
+
+ X509Certificate cert = (X509Certificate) CertificateFactory
+ .getInstance("X509"). //$NON-NLS-1$
+ generateCertificate(
+ this.getClass().getResourceAsStream(
+ certResource));
+
+ atrustKeyStore.setCertificateEntry(certificateNode.getTextContent(), cert);
+
+ log.debug("Loaded certificate : " + certResource); //$NON-NLS-1$
+
+ } catch (Exception ex) {
+ log.error("Failed to load certificate [" + "]", ex); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ tmf.init(atrustKeyStore);
+
+ tms = tmf.getTrustManagers();
+
+ /*
+ * Iterate over the returned trustmanagers, look for an instance of
+ * X509TrustManager. If found, use that as our "default" trust manager.
+ */
+ for (int i = 0; i < tms.length; i++) {
+ if (tms[i] instanceof X509TrustManager) {
+ this.atrustTrustManager = (X509TrustManager) tms[i];
+ break;
+ }
+ }
+
+ if (this.sunJSSEX509TrustManager != null
+ && this.atrustTrustManager != null) {
+ return;
+ }
+
+ /*
+ * Find some other way to initialize, or else we have to fail the
+ * constructor.
+ */
+ throw new Exception("Couldn't initialize ASITTrustManager"); //$NON-NLS-1$
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * javax.net.ssl.X509TrustManager#checkClientTrusted(java.security.cert.
+ * X509Certificate[], java.lang.String)
*/
@Override
public void checkClientTrusted(X509Certificate[] arg0, String arg1)
throws CertificateException {
- // Ignore client certificates ...
+ try {
+ this.atrustTrustManager.checkServerTrusted(arg0, arg1);
+ } catch (CertificateException ex) {
+ try {
+ this.sunJSSEX509TrustManager.checkClientTrusted(arg0, arg1);
+ } catch (CertificateException ex2) {
+ log.info("checkClientTrusted: ", ex2); //$NON-NLS-1$
+ throw ex2;
+ }
+ }
}
- /* (non-Javadoc)
- * @see javax.net.ssl.X509TrustManager#checkServerTrusted(java.security.cert.X509Certificate[], java.lang.String)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * javax.net.ssl.X509TrustManager#checkServerTrusted(java.security.cert.
+ * X509Certificate[], java.lang.String)
*/
@Override
public void checkServerTrusted(X509Certificate[] arg0, String arg1)
throws CertificateException {
- // TODO: Check trusted server certificate!
+ try {
+ this.atrustTrustManager.checkServerTrusted(arg0, arg1);
+ } catch (CertificateException ex) {
+ try {
+ this.sunJSSEX509TrustManager.checkServerTrusted(arg0, arg1);
+ } catch (CertificateException ex2) {
+ log.info("checkServerTrusted: ", ex2); //$NON-NLS-1$
+ throw ex2;
+ }
+ }
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see javax.net.ssl.X509TrustManager#getAcceptedIssuers()
*/
@Override
public X509Certificate[] getAcceptedIssuers() {
- // TODO: Build accepted issuers
- return null;
+
+ X509Certificate[] default_certs = this.sunJSSEX509TrustManager.getAcceptedIssuers();
+
+ X509Certificate[] atrust_cerst = this.atrustTrustManager.getAcceptedIssuers();
+
+ return (X509Certificate[]) ArrayUtils.addAll(default_certs, atrust_cerst);
}
}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHelper.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHelper.java
index c9254317..1ea265ad 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHelper.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHelper.java
@@ -16,9 +16,18 @@
package at.asit.pdfover.gui.workflow.states.mobilebku;
// Imports
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import at.asit.pdfover.gui.composites.MobileBKUEnterNumberComposite;
+import at.asit.pdfover.gui.exceptions.InvalidNumberException;
+import at.asit.pdfover.gui.exceptions.InvalidPasswordException;
+import at.asit.pdfover.gui.exceptions.PasswordTooLongException;
+import at.asit.pdfover.gui.exceptions.PasswordTooShortException;
+
/**
*
*/
@@ -30,36 +39,111 @@ public class ATrustHelper {
.getLogger(ATrustHelper.class);
/**
+ * Regular expression for mobile phone numbers: this allows the entrance of
+ * mobile numbers in the following formats:
+ *
+ * +(countryCode)99999999999 00(countryCode)99999999999 099999999999
+ * 1030199999999999 (A-Trust Test bku)
+ */
+ private static final String NUMBER_REGEX = "^((\\+[\\d]{2})|(00[\\d]{2})|(0)|(10301))([1-9][\\d]+)$"; //$NON-NLS-1$
+
+ /**
+ * Extracts a substring from data starting after start and ending with end
+ *
* @param data
+ * the whole data string
* @param start
+ * the start marker
* @param end
- * @return
+ * the end marker
+ * @return the substring
* @throws Exception
*/
- public static String extractTag(String data, String start, String end) throws Exception {
+ public static String extractTag(String data, String start, String end)
+ throws Exception {
int startidx = data.indexOf(start);
- if(startidx > 0) {
- startidx = startidx+start.length();
+ if (startidx > 0) {
+ startidx = startidx + start.length();
int endidx = data.indexOf(end, startidx);
- if(endidx > startidx) {
+ if (endidx > startidx) {
return data.substring(startidx, endidx);
- } else {
- // TODO: throw exception
- throw new Exception("end tag not available!");
}
- } else {
- // TODO: throw exception
- throw new Exception("start tag not available!");
+ // TODO: throw proper exception
+ log.error("extracting Tag: end tag not valid!: " + start + " ... " + end); //$NON-NLS-1$//$NON-NLS-2$
+ throw new Exception("end tag not available!"); //$NON-NLS-1$
}
+ // TODO: throw proper exception
+ log.error("extracting Tag: start tag not valid!: " + start + " ... " + end); //$NON-NLS-1$//$NON-NLS-2$
+ throw new Exception("start tag not available!"); //$NON-NLS-1$
}
-
+
+ /**
+ * Validates the Mobile phone number
+ *
+ * @param number
+ * @return the normalized Phone number
+ * @throws InvalidNumberException
+ */
+ public static String normalizeMobileNumber(String number)
+ throws InvalidNumberException {
+ // Verify number and normalize
+
+ // Compile and use regular expression
+ Pattern pattern = Pattern.compile(NUMBER_REGEX);
+ Matcher matcher = pattern.matcher(number);
+
+ if (!matcher.find()) {
+ throw new InvalidNumberException();
+ }
+
+ if (matcher.groupCount() != 6) {
+ throw new InvalidNumberException();
+ }
+
+ String countryCode = matcher.group(1);
+
+ String normalNumber = matcher.group(6);
+
+ if (countryCode.equals("10301")) { //$NON-NLS-1$
+ // A-Trust Testnumber! Don't change
+ return number;
+ }
+
+ countryCode = countryCode.replace("00", "+"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ if (countryCode.equals("0")) { //$NON-NLS-1$
+ countryCode = "+43"; //$NON-NLS-1$
+ }
+
+ return countryCode + normalNumber;
+ }
+
+ /**
+ * Validate given Password for Mobile BKU
+ *
+ * @param password
+ * @throws InvalidPasswordException
+ */
+ public static void validatePassword(String password)
+ throws InvalidPasswordException {
+ if (password.length() < 6 || password.length() > 20) {
+ if (password.length() < 6) {
+ throw new PasswordTooShortException();
+ }
+ throw new PasswordTooLongException();
+ }
+ }
+
/**
+ * Removes file extension from URL
+ *
* @param query
- * @return
+ * the url string
+ * @return the stripped url
*/
public static String stripQueryString(String query) {
int pathidx = query.lastIndexOf('/');
- if(pathidx > 0) {
+ if (pathidx > 0) {
return query.substring(0, pathidx);
}
return query;
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/TrustedSocketFactory.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/TrustedSocketFactory.java
index bfe84605..5e9d8159 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/TrustedSocketFactory.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/TrustedSocketFactory.java
@@ -46,8 +46,8 @@ public class TrustedSocketFactory implements ProtocolSocketFactory {
private static final Logger log = LoggerFactory
.getLogger(TrustedSocketFactory.class);
- private static SSLSocketFactory getFactory() throws NoSuchAlgorithmException,
- KeyManagementException {
+ private SSLSocketFactory getFactory() throws NoSuchAlgorithmException,
+ KeyManagementException, Exception {
SSLContext sslContext = SSLContext.getInstance("TLS"); //$NON-NLS-1$
sslContext.init(null, new TrustManager[] { new ASITTrustManager() },
new java.security.SecureRandom());