From ef1113edf2cafaffc3668ea27b295d9a738f1a24 Mon Sep 17 00:00:00 2001 From: Jakob Heher Date: Fri, 8 Jul 2022 11:33:57 +0200 Subject: keystore configuration redesign for #68 and #69 (todo: trial-and-error + saving in memory) --- .../KeystoreConfigurationComposite.java | 141 +++++++++++++++------ 1 file changed, 103 insertions(+), 38 deletions(-) (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/KeystoreConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/KeystoreConfigurationComposite.java index 757c31d7..86a9f5e9 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/KeystoreConfigurationComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/KeystoreConfigurationComposite.java @@ -27,7 +27,10 @@ import java.security.cert.CertificateException; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; +import java.util.Vector; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; import org.eclipse.swt.SWT; import org.eclipse.swt.events.FocusAdapter; import org.eclipse.swt.events.FocusEvent; @@ -56,6 +59,7 @@ import at.asit.pdfover.gui.exceptions.KeystoreDoesntExistException; import at.asit.pdfover.gui.exceptions.KeystoreKeyPasswordException; import at.asit.pdfover.commons.Messages; import at.asit.pdfover.gui.workflow.config.ConfigurationManager; +import at.asit.pdfover.gui.workflow.config.ConfigurationDataInMemory.KeyStorePassStorageType; import at.asit.pdfover.gui.workflow.config.ConfigurationDataInMemory; import at.asit.pdfover.gui.workflow.states.State; import iaik.security.provider.IAIK; @@ -77,16 +81,16 @@ public class KeystoreConfigurationComposite extends ConfigurationCompositeBase { private Button btnBrowse; private Label lblKeystoreType; Combo cmbKeystoreType; - private Label lblKeystoreStorePass; - Text txtKeystoreStorePass; private Button btnLoad; private Label lblKeystoreAlias; Combo cmbKeystoreAlias; + private Label lblKeystorePassStoreType; + Combo cmbKeystorePassStoreType; + private Label lblKeystoreStorePass; + Text txtKeystoreStorePass; private Label lblKeystoreKeyPass; Text txtKeystoreKeyPass; - Map keystoreTypes; - private KeyStore ks; /** @@ -129,24 +133,17 @@ public class KeystoreConfigurationComposite extends ConfigurationCompositeBase { StateComposite.anchor(lblKeystoreType).top(txtKeystoreFile, 5).left(0,5).set(); StateComposite.setFontHeight(lblKeystoreType, Constants.TEXT_SIZE_NORMAL); + this.btnLoad = new Button(this.grpKeystore, SWT.NONE); + StateComposite.anchor(btnLoad).top(lblKeystoreType, 5).right(100,-5).set(); + StateComposite.setFontHeight(btnLoad, Constants.TEXT_SIZE_BUTTON); + this.cmbKeystoreType = new Combo(grpKeystore, SWT.READ_ONLY); - StateComposite.anchor(cmbKeystoreType).right(100, -5).top(lblKeystoreType, 5).left(0,15).set(); + StateComposite.anchor(cmbKeystoreType).top(lblKeystoreType, 5).left(0,15).right(btnLoad, -5).set(); StateComposite.setFontHeight(cmbKeystoreType, Constants.TEXT_SIZE_NORMAL); StateComposite.disableEventDefault(cmbKeystoreType, SWT.MouseVerticalWheel); - this.lblKeystoreStorePass = new Label(this.grpKeystore, SWT.NONE); - StateComposite.anchor(lblKeystoreStorePass).top(cmbKeystoreType, 5).left(0,5).set(); - StateComposite.setFontHeight(lblKeystoreStorePass, Constants.TEXT_SIZE_NORMAL); - - this.txtKeystoreStorePass = new Text(this.grpKeystore, SWT.BORDER | SWT.PASSWORD); - this.btnLoad = new Button(this.grpKeystore, SWT.NONE); - StateComposite.anchor(txtKeystoreStorePass).top(lblKeystoreStorePass, 5).left(0,15).right(btnLoad, -5).set(); - StateComposite.anchor(btnLoad).top(lblKeystoreStorePass, 5).right(100,-5).set(); - StateComposite.setFontHeight(txtKeystoreStorePass, Constants.TEXT_SIZE_NORMAL); - StateComposite.setFontHeight(btnLoad, Constants.TEXT_SIZE_BUTTON); - this.lblKeystoreAlias = new Label(grpKeystore, SWT.NONE); - StateComposite.anchor(lblKeystoreAlias).top(txtKeystoreStorePass, 5).left(0, 5).set(); + StateComposite.anchor(lblKeystoreAlias).top(cmbKeystoreType, 5).left(0, 5).set(); StateComposite.setFontHeight(lblKeystoreAlias, Constants.TEXT_SIZE_NORMAL); this.cmbKeystoreAlias = new Combo(grpKeystore, SWT.NONE); @@ -154,11 +151,28 @@ public class KeystoreConfigurationComposite extends ConfigurationCompositeBase { StateComposite.setFontHeight(cmbKeystoreAlias, Constants.TEXT_SIZE_NORMAL); StateComposite.disableEventDefault(cmbKeystoreAlias, SWT.MouseVerticalWheel); - this.lblKeystoreKeyPass = new Label(this.grpKeystore, SWT.NONE); - StateComposite.anchor(lblKeystoreKeyPass).top(cmbKeystoreAlias, 5).left(0,5).set(); + this.lblKeystorePassStoreType = new Label(this.grpKeystore, SWT.NONE); + StateComposite.anchor(lblKeystorePassStoreType).top(cmbKeystoreAlias, 5).left(0,5).set(); + StateComposite.setFontHeight(lblKeystorePassStoreType, Constants.TEXT_SIZE_NORMAL); + + this.cmbKeystorePassStoreType = new Combo(grpKeystore, SWT.READ_ONLY); + StateComposite.anchor(cmbKeystorePassStoreType).top(lblKeystorePassStoreType, 5).left(0,15).right(100,-5).set(); + StateComposite.setFontHeight(cmbKeystorePassStoreType, Constants.TEXT_SIZE_NORMAL); + StateComposite.disableEventDefault(cmbKeystorePassStoreType, SWT.MouseVerticalWheel); + + this.lblKeystoreStorePass = new Label(grpKeystore, SWT.NONE); + StateComposite.anchor(lblKeystoreStorePass).top(cmbKeystorePassStoreType, 5).left(0,5).set(); + StateComposite.setFontHeight(lblKeystoreStorePass, Constants.TEXT_SIZE_NORMAL); + + this.txtKeystoreStorePass = new Text(grpKeystore, SWT.BORDER | SWT.PASSWORD); + StateComposite.anchor(txtKeystoreStorePass).right(100, -5).top(lblKeystoreStorePass, 5).left(0,15).set(); + StateComposite.setFontHeight(txtKeystoreStorePass, Constants.TEXT_SIZE_NORMAL); + + this.lblKeystoreKeyPass = new Label(grpKeystore, SWT.NONE); + StateComposite.anchor(lblKeystoreKeyPass).top(txtKeystoreStorePass, 5).left(0,5).set(); StateComposite.setFontHeight(lblKeystoreKeyPass, Constants.TEXT_SIZE_NORMAL); - this.txtKeystoreKeyPass = new Text(this.grpKeystore, SWT.BORDER | SWT.PASSWORD); + this.txtKeystoreKeyPass = new Text(grpKeystore, SWT.BORDER | SWT.PASSWORD); StateComposite.anchor(txtKeystoreKeyPass).top(lblKeystoreKeyPass, 5).left(0,15).right(100,-5).set(); StateComposite.setFontHeight(txtKeystoreKeyPass, Constants.TEXT_SIZE_NORMAL); @@ -251,16 +265,25 @@ public class KeystoreConfigurationComposite extends ConfigurationCompositeBase { this.cmbKeystoreAlias.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { - performKeystoreAliasChanged(KeystoreConfigurationComposite. - this.cmbKeystoreAlias.getText()); + performKeystoreAliasChanged(KeystoreConfigurationComposite.this.cmbKeystoreAlias.getText()); + } + }); + + this.cmbKeystorePassStoreType.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + performKeystorePassStorageTypeChanged( + keystorePassStorageTypeOptions.get( + KeystoreConfigurationComposite.this.cmbKeystorePassStoreType.getSelectionIndex() + ).getLeft() + ); } }); this.txtKeystoreKeyPass.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { - performKeystoreKeyPassChanged(KeystoreConfigurationComposite. - this.txtKeystoreKeyPass.getText()); + performKeystoreKeyPassChanged(KeystoreConfigurationComposite.this.txtKeystoreKeyPass.getText()); } }); @@ -291,12 +314,6 @@ public class KeystoreConfigurationComposite extends ConfigurationCompositeBase { this.cmbKeystoreAlias.add(aliases.nextElement()); } - private void initKeystoreTypes() { - this.keystoreTypes = new HashMap(); - this.keystoreTypes.put(Messages.getString("keystore_config.KeystoreType_PKCS12"), "PKCS12"); - this.keystoreTypes.put(Messages.getString("keystore_config.KeystoreType_JKS"), "JCEKS"); - } - /** * @param fileName */ @@ -333,13 +350,34 @@ public class KeystoreConfigurationComposite extends ConfigurationCompositeBase { } } + protected void performKeystorePassStorageTypeChanged(KeyStorePassStorageType p) { + this.configurationContainer.keystorePassStorageType = p; + for (int i=0; i keystoreTypes; + private void reloadKeystoreTypeStrings() { + this.keystoreTypes = new HashMap(); + this.keystoreTypes.put(Messages.getString("keystore_config.KeystoreType_PKCS12"), "PKCS12"); + this.keystoreTypes.put(Messages.getString("keystore_config.KeystoreType_JKS"), "JCEKS"); + } + + Vector> keystorePassStorageTypeOptions; + private void reloadKeystorePassStorageTypeStrings() { + keystorePassStorageTypeOptions = new Vector>(); + java.util.function.BiConsumer add = (k,v) -> { + keystorePassStorageTypeOptions.add(new ImmutablePair(k,Messages.getString(v))); + }; + add.accept(null, "keystore_config.SaveToWhere.None"); + add.accept(KeyStorePassStorageType.MEMORY, "keystore_config.SaveToWhere.Memory"); + add.accept(KeyStorePassStorageType.DISK, "keystore_config.SaveToWhere.Disk"); + + int n = keystorePassStorageTypeOptions.size(); + cmbKeystorePassStoreType.setVisibleItemCount(n); + cmbKeystorePassStoreType.setItems(); + for (int i=0; i