summaryrefslogtreecommitdiff
path: root/pdf-over-gui
diff options
context:
space:
mode:
authorTobias Kellner <imcybot@gmail.com>2015-10-12 08:36:18 +0200
committerTobias Kellner <tobias.kellner@iaik.tugraz.at>2015-10-12 11:53:41 +0200
commitfb04f57eb521381a2a888670ca3783cbe21e7d37 (patch)
tree44ae1f77c981d23b97eaa8f0aea8c4e435c231f4 /pdf-over-gui
parentd23140ea4818d74dab73c5265e68e2d3127ef40d (diff)
downloadmocca-fb04f57eb521381a2a888670ca3783cbe21e7d37.tar.gz
mocca-fb04f57eb521381a2a888670ca3783cbe21e7d37.tar.bz2
mocca-fb04f57eb521381a2a888670ca3783cbe21e7d37.zip
Allow to manually enter keystore alias
Diffstat (limited to 'pdf-over-gui')
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/KeystoreConfigurationComposite.java50
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/KeystoreAliasDoesntExistException.java36
2 files changed, 67 insertions, 19 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/KeystoreConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/KeystoreConfigurationComposite.java
index 24170e24..0596f708 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/KeystoreConfigurationComposite.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/KeystoreConfigurationComposite.java
@@ -52,9 +52,8 @@ import at.asit.pdfover.gui.Constants;
import at.asit.pdfover.gui.controls.Dialog.BUTTONS;
import at.asit.pdfover.gui.controls.ErrorDialog;
import at.asit.pdfover.gui.exceptions.CantLoadKeystoreException;
+import at.asit.pdfover.gui.exceptions.KeystoreAliasDoesntExistException;
import at.asit.pdfover.gui.exceptions.KeystoreDoesntExistException;
-import at.asit.pdfover.gui.exceptions.OutputfolderDoesntExistException;
-import at.asit.pdfover.gui.exceptions.OutputfolderNotADirectoryException;
import at.asit.pdfover.gui.utils.Messages;
import at.asit.pdfover.gui.workflow.config.ConfigManipulator;
import at.asit.pdfover.gui.workflow.config.ConfigurationContainer;
@@ -89,6 +88,8 @@ public class KeystoreConfigurationComposite extends BaseConfigurationComposite {
private Map<String, String> keystoreTypes;
private Map<String, String> keystoreTypes_i;
+ private KeyStore ks;
+
/**
* @param parent
* @param style
@@ -304,7 +305,7 @@ public class KeystoreConfigurationComposite extends BaseConfigurationComposite {
this.lblKeystoreAlias.setFont(new Font(Display.getCurrent(),
fD_lblKeystoreAlias[0]));
- this.cmbKeystoreAlias = new Combo(this.grpKeystore, SWT.READ_ONLY);
+ this.cmbKeystoreAlias = new Combo(this.grpKeystore, SWT.NONE);
FormData fd_cmbKeystoreAlias = new FormData();
fd_cmbKeystoreAlias.right = new FormAttachment(100, -5);
fd_cmbKeystoreAlias.top = new FormAttachment(this.lblKeystoreAlias, 5);
@@ -325,6 +326,13 @@ public class KeystoreConfigurationComposite extends BaseConfigurationComposite {
KeystoreConfigurationComposite.this.cmbKeystoreAlias.getSelectionIndex()));
}
});
+ this.cmbKeystoreAlias.addFocusListener(new FocusAdapter() {
+ @Override
+ public void focusLost(FocusEvent e) {
+ performKeystoreAliasChanged(KeystoreConfigurationComposite.
+ this.cmbKeystoreAlias.getText());
+ }
+ });
this.lblKeystoreKeyPass = new Label(this.grpKeystore, SWT.NONE);
FormData fd_lblKeystoreKeyPass = new FormData();
@@ -372,11 +380,11 @@ public class KeystoreConfigurationComposite extends BaseConfigurationComposite {
ConfigurationContainer config =
KeystoreConfigurationComposite.this.configurationContainer;
File f = new File(config.getKeyStoreFile());
- KeyStore ks = KeyStore.getInstance(config.getKeyStoreType());
+ this.ks = KeyStore.getInstance(config.getKeyStoreType());
FileInputStream fis = new FileInputStream(f);
- ks.load(fis, config.getKeyStoreStorePass().toCharArray());
- this.cmbKeystoreAlias.removeAll();
- Enumeration<String> aliases = ks.aliases();
+ this.ks.load(fis, config.getKeyStoreStorePass().toCharArray());
+ this.cmbKeystoreAlias.remove(0, this.cmbKeystoreAlias.getItemCount()-1);
+ Enumeration<String> aliases = this.ks.aliases();
while (aliases.hasMoreElements())
this.cmbKeystoreAlias.add(aliases.nextElement());
}
@@ -442,12 +450,7 @@ public class KeystoreConfigurationComposite extends BaseConfigurationComposite {
protected void performKeystoreAliasChanged(String alias) {
log.debug("Selected keystore alias: " + alias); //$NON-NLS-1$
this.configurationContainer.setKeyStoreAlias(alias);
- for (int i = 0; i < this.cmbKeystoreAlias.getItemCount(); ++i) {
- if (this.cmbKeystoreAlias.getItem(i).equals(alias)) {
- this.cmbKeystoreAlias.select(i);
- break;
- }
- }
+ this.cmbKeystoreAlias.setText(alias);
}
/**
@@ -506,14 +509,16 @@ public class KeystoreConfigurationComposite extends BaseConfigurationComposite {
@Override
public void loadConfiguration() {
// Initialize form fields from configuration Container
- performKeystoreFileChanged(
- this.configurationContainer.getKeyStoreFile());
+ String ks = this.configurationContainer.getKeyStoreFile();
+ performKeystoreFileChanged(ks);
performKeystoreTypeChanged(
this.configurationContainer.getKeyStoreType());
performKeystoreStorePassChanged(
this.configurationContainer.getKeyStoreStorePass());
try {
- loadKeystore();
+ File ksf = new File(ks);
+ if (ksf.exists())
+ loadKeystore();
} catch (Exception e) {
log.error("Error loading keystore", e); //$NON-NLS-1$
}
@@ -547,17 +552,24 @@ public class KeystoreConfigurationComposite extends BaseConfigurationComposite {
public void validateSettings(int resumeFrom) throws Exception {
switch (resumeFrom) {
case 0:
- File f = new File(this.configurationContainer.getKeyStoreFile());
+ String fname = this.configurationContainer.getKeyStoreFile();
+ if (fname.isEmpty())
+ break; //no checks required
+ File f = new File(fname);
if (!f.exists() || !f.isFile())
- throw new KeystoreDoesntExistException(f, 2); //skip next check
+ throw new KeystoreDoesntExistException(f, 3); //skip next checks
// Fall through
case 1:
try {
loadKeystore();
} catch (Exception e) {
- throw new CantLoadKeystoreException(e, 2);
+ throw new CantLoadKeystoreException(e, 3); //skip next check
}
// Fall through
+ case 2:
+ String alias = this.configurationContainer.getKeyStoreAlias();
+ if (!this.ks.containsAlias(alias))
+ throw new KeystoreAliasDoesntExistException(alias, 3);
}
}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/KeystoreAliasDoesntExistException.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/KeystoreAliasDoesntExistException.java
new file mode 100644
index 00000000..591af5f5
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/exceptions/KeystoreAliasDoesntExistException.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;
+
+import at.asit.pdfover.gui.utils.Messages;
+
+/**
+ *
+ */
+public class KeystoreAliasDoesntExistException extends ResumableException {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 2264150118185552023L;
+
+ /**
+ * @param alias The keystore key alias
+ * @param resumeIndex The resume Index
+ */
+ public KeystoreAliasDoesntExistException(final String alias, int resumeIndex) {
+ super(String.format(Messages.getString("error.KeyStoreAlias"), alias), resumeIndex); //$NON-NLS-1$
+ }
+}