summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Heher <jakob.heher@iaik.tugraz.at>2022-10-06 10:11:35 +0200
committerJakob Heher <jakob.heher@iaik.tugraz.at>2022-10-06 10:11:35 +0200
commit434ad00d88ce24785b9d9edbcd03ffa562fd8a4e (patch)
treed68c5a06bf49ca8bff6fba48ab6ef068c4ad4804
parente9a7e90fda934dd5d053127470d0b849b1b8fc4b (diff)
downloadpdf-over-434ad00d88ce24785b9d9edbcd03ffa562fd8a4e.tar.gz
pdf-over-434ad00d88ce24785b9d9edbcd03ffa562fd8a4e.tar.bz2
pdf-over-434ad00d88ce24785b9d9edbcd03ffa562fd8a4e.zip
sanitizing NULLable config values
-rw-r--r--pdf-over-commons/src/main/java/at/asit/pdfover/commons/Messages.java6
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindow.java2
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java2
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AdvancedConfigurationComposite.java21
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUEnterTANComposite.java6
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/LocaleSerializer.java8
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationDataInMemory.java54
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationManager.java328
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java2
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/Emblem.java2
10 files changed, 182 insertions, 249 deletions
diff --git a/pdf-over-commons/src/main/java/at/asit/pdfover/commons/Messages.java b/pdf-over-commons/src/main/java/at/asit/pdfover/commons/Messages.java
index 6ed52d5b..04c8583a 100644
--- a/pdf-over-commons/src/main/java/at/asit/pdfover/commons/Messages.java
+++ b/pdf-over-commons/src/main/java/at/asit/pdfover/commons/Messages.java
@@ -22,6 +22,8 @@ import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
+import javax.annotation.Nonnull;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -49,13 +51,13 @@ public class Messages {
* Get the closest match to the system default Locale out of the supported locales
* @return the default locale
*/
- public static Locale getDefaultLocale() {
+ public static @Nonnull Locale getDefaultLocale() {
Locale ld = Locale.getDefault();
for (Locale l : Constants.SUPPORTED_LOCALES) {
if (l.equals(ld) || l.getLanguage().equals(ld.getLanguage()))
return l;
}
- return Constants.SUPPORTED_LOCALES[0];
+ return Constants.ISNOTNULL(Constants.SUPPORTED_LOCALES[0]);
}
/**
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 79600265..2ce60634 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
@@ -229,7 +229,7 @@ public class MainWindow {
@Override
public void shellClosed(ShellEvent e) {
log.debug("Closing main window");
- MainWindow.this.stateMachine.configProvider.setMainWindowSizePersistent(getShell().getSize());
+ MainWindow.this.stateMachine.configProvider.setMainWindowSizePersistent(Constants.ISNOTNULL(getShell().getSize()));
try {
MainWindow.this.stateMachine.configProvider.saveToDisk();
} catch (IOException e1) {
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java
index 78943eee..995cc537 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/MobileBKUConnector.java
@@ -103,7 +103,7 @@ public class MobileBKUConnector implements BkuSlConnector {
}
lastHTTPRequestTime = now;
- log.debug("Sending request to '{}'...", request.getUri().toString());
+ log.debug("Sending {} request to '{}'...", request.getMethod(), request.getUri().toString());
try (final CloseableHttpResponse response = httpClient.execute(request)) {
int httpStatus = response.getCode();
if ((httpStatus == HttpStatus.SC_MOVED_PERMANENTLY) || (httpStatus == HttpStatus.SC_MOVED_TEMPORARILY)) {
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AdvancedConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AdvancedConfigurationComposite.java
index 20c8fdfd..d9ea02ed 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AdvancedConfigurationComposite.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AdvancedConfigurationComposite.java
@@ -22,6 +22,8 @@ import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
+import javax.annotation.Nonnull;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
@@ -246,7 +248,9 @@ public class AdvancedConfigurationComposite extends ConfigurationCompositeBase {
this.txtSaveFilePostFix.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
- performPostFixChanged(txtSaveFilePostFix.getText());
+ if (txtSaveFilePostFix.getText().trim().isEmpty())
+ txtSaveFilePostFix.setText(Constants.DEFAULT_POSTFIX);
+ performPostFixChanged(Constants.ISNOTNULL(txtSaveFilePostFix.getText()));
}
});
@@ -330,7 +334,7 @@ public class AdvancedConfigurationComposite extends ConfigurationCompositeBase {
reloadResources();
}
- private void performPostFixChanged(String postfix) {
+ private void performPostFixChanged(@Nonnull String postfix) {
log.debug("Save file postfix changed to : {}", postfix);
this.configurationContainer.saveFilePostFix = postfix;
@@ -355,7 +359,7 @@ public class AdvancedConfigurationComposite extends ConfigurationCompositeBase {
return i;
}
- void performBKUSelectionChanged(BKUs selected) {
+ void performBKUSelectionChanged(@Nonnull BKUs selected) {
log.debug("Selected BKU: {}", selected);
this.configurationContainer.defaultBKU = selected;
this.cmbBKUAuswahl.select(this.getBKUElementIndex(selected));
@@ -372,13 +376,13 @@ public class AdvancedConfigurationComposite extends ConfigurationCompositeBase {
}
}
- BKUs resolveBKU(String localizedBKU) {
+ @Nonnull BKUs resolveBKU(String localizedBKU) {
int blen = BKUs.values().length;
for (int i = 0; i < blen; i++) {
String lookup = "BKU." + BKUs.values()[i].toString();
if (Messages.getString(lookup).equals(localizedBKU)) {
- return BKUs.values()[i];
+ return Constants.ISNOTNULL(BKUs.values()[i]);
}
}
@@ -550,12 +554,7 @@ public class AdvancedConfigurationComposite extends ConfigurationCompositeBase {
if (outputFolder != null) {
performOutputFolderChanged(outputFolder);
}
- String postFix = this.configurationContainer.saveFilePostFix;
- if (postFix != null) {
- performPostFixChanged(postFix);
- } else {
- performPostFixChanged(Constants.DEFAULT_POSTFIX);
- }
+ performPostFixChanged(this.configurationContainer.saveFilePostFix);
performPositionSelection(this.configurationContainer.autoPositionSignature);
performUseMarkerSelection(this.configurationContainer.getUseMarker());
performUseSignatureFieldsSelection(this.configurationContainer.getUseSignatureFields());
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUEnterTANComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUEnterTANComposite.java
index 28aaf4c7..dfd9dc40 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUEnterTANComposite.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/mobilebku/MobileBKUEnterTANComposite.java
@@ -19,14 +19,8 @@ package at.asit.pdfover.gui.composites.mobilebku;
import java.net.URI;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
-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.graphics.Rectangle;
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/LocaleSerializer.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/LocaleSerializer.java
index 18d6e8c1..5d90ae6f 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/LocaleSerializer.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/LocaleSerializer.java
@@ -18,6 +18,10 @@ package at.asit.pdfover.gui.utils;
// Imports
import java.util.Locale;
+import javax.annotation.Nonnull;
+
+import at.asit.pdfover.commons.Constants;
+
/**
*
*/
@@ -49,7 +53,7 @@ public class LocaleSerializer {
* @param locale the locale
* @return the parsable string
*/
- public static String getParsableString(Locale locale) {
- return locale.toString();
+ public static @Nonnull String getParsableString(Locale locale) {
+ return Constants.ISNOTNULL(locale.toString());
}
}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationDataInMemory.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationDataInMemory.java
index 75fe5f89..e89f0924 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationDataInMemory.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationDataInMemory.java
@@ -19,6 +19,10 @@ package at.asit.pdfover.gui.workflow.config;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Locale;
+import java.util.Objects;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
import at.asit.pdfover.commons.Profile;
import org.eclipse.swt.graphics.Image;
@@ -34,6 +38,8 @@ import at.asit.pdfover.gui.bku.OLDmobile.MobileBKUHelper;
import at.asit.pdfover.gui.exceptions.InvalidEmblemFile;
import at.asit.pdfover.gui.exceptions.InvalidPortException;
+import static at.asit.pdfover.commons.Constants.ISNOTNULL;
+
/**
* Implementation of the configuration container
*/
@@ -74,8 +80,8 @@ public class ConfigurationDataInMemory {
}
/** The mobile phone number */
- protected String mobileNumber = null;
- public String getMobileNumber() { return this.mobileNumber; }
+ protected @CheckForNull String mobileNumber = null;
+ public @CheckForNull String getMobileNumber() { return this.mobileNumber; }
public void setMobileNumber(String number) {
if(number == null || number.trim().isEmpty()) {
this.mobileNumber = null;
@@ -85,12 +91,12 @@ public class ConfigurationDataInMemory {
}
/** The mobile phone password */
- public String mobilePassword = null;
+ public @CheckForNull String mobilePassword = null;
public boolean rememberPassword = false;
/** Holds the proxy host */
- public String proxyHost = null;
+ public @CheckForNull String proxyHost = null;
/** Holds the proxy port number */
protected int proxyPort = -1;
@@ -108,25 +114,25 @@ public class ConfigurationDataInMemory {
}
/** Holds the proxy username */
- public String proxyUser = null;
+ public @CheckForNull String proxyUser = null;
/** Holds the proxy password */
- public String proxyPass = null;
+ public @CheckForNull String proxyPass = null;
/** Holds the default BKU to use */
- public BKUs defaultBKU = BKUs.NONE;
+ public @Nonnull BKUs defaultBKU = BKUs.NONE;
/** Holds the output folder */
- public String outputFolder = null;
+ public @CheckForNull String outputFolder = null;
/** Holds the signatureNote */
- public String signatureNote = null;
+ public @CheckForNull String signatureNote = null;
/** Holds the locale */
- public Locale interfaceLocale = null;
+ public @CheckForNull Locale interfaceLocale = null;
/** Holds the signature locale */
- public Locale signatureLocale = null;
+ public @CheckForNull Locale signatureLocale = null;
/** Holds the PDF/A compatibility setting */
public boolean signaturePDFACompat = false;
@@ -136,13 +142,13 @@ public class ConfigurationDataInMemory {
/** Keystore signing options */
public enum KeyStorePassStorageType { MEMORY, DISK };
- public Boolean keystoreEnabled = null;
- public String keystoreFile = null;
- public String keystoreType = null;
- public String keystoreAlias = null;
- public KeyStorePassStorageType keystorePassStorageType = null;
- public String keystoreStorePass = null;
- public String keystoreKeyPass = null;
+ public @CheckForNull Boolean keystoreEnabled = null;
+ public @CheckForNull String keystoreFile = null;
+ public @CheckForNull String keystoreType = null;
+ public @CheckForNull String keystoreAlias = null;
+ public @CheckForNull KeyStorePassStorageType keystorePassStorageType = null;
+ public @CheckForNull String keystoreStorePass = null;
+ public @CheckForNull String keystoreKeyPass = null;
/** Whether to automatically check for updates */
public boolean updateCheck = true;
@@ -151,7 +157,7 @@ public class ConfigurationDataInMemory {
*
* @IMPORTANT this must always be valid and non-null, even if configuration failed to load for whatever reason (it is used by error handlers!)
*/
- public Point mainWindowSize = new Point(Constants.DEFAULT_MAINWINDOW_WIDTH, Constants.DEFAULT_MAINWINDOW_HEIGHT);
+ public @Nonnull Point mainWindowSize = new Point(Constants.DEFAULT_MAINWINDOW_WIDTH, Constants.DEFAULT_MAINWINDOW_HEIGHT);
/** Whether to skip the output state */
public boolean skipFinish = false;
@@ -176,14 +182,12 @@ public class ConfigurationDataInMemory {
public boolean enabledPlaceholderUsage = false;
/** The Signature Profile */
- protected Profile signatureProfile = null;
- public Profile getSignatureProfile() {
- if (this.signatureProfile == null)
- return Profile.SIGNATURBLOCK_SMALL;
- return this.signatureProfile;
+ protected @CheckForNull Profile signatureProfile = null;
+ public @Nonnull Profile getSignatureProfile() {
+ return ISNOTNULL(Objects.requireNonNullElse(this.signatureProfile, Profile.SIGNATURBLOCK_SMALL));
}
public void setSignatureProfile(Profile profile) { this.signatureProfile = profile; }
- public String saveFilePostFix = "_signed";
+ public @Nonnull String saveFilePostFix = Constants.DEFAULT_POSTFIX;
}
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationManager.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationManager.java
index 37a44e71..95d3876b 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationManager.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationManager.java
@@ -23,6 +23,9 @@ import java.io.IOException;
import java.util.Locale;
import java.util.Properties;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+
import at.asit.pdfover.commons.Profile;
import org.apache.commons.io.FileUtils;
@@ -39,6 +42,8 @@ import at.asit.pdfover.gui.utils.LocaleSerializer;
import at.asit.pdfover.gui.workflow.config.ConfigurationDataInMemory.KeyStorePassStorageType;
import at.asit.pdfover.commons.Messages;
+import static at.asit.pdfover.commons.Constants.ISNOTNULL;
+
/**
* Implementation of the configuration provider and manipulator
*/
@@ -54,11 +59,6 @@ public class ConfigurationManager {
**/
private static final Logger log = LoggerFactory.getLogger(ConfigurationManager.class);
- /**
- * An empty property entry
- */
- private static final String STRING_EMPTY = "";
-
private String configurationFile = Constants.DEFAULT_CONFIG_FILENAME;
private boolean loaded = false;
@@ -283,6 +283,8 @@ public class ConfigurationManager {
loaded = true;
}
+ private void setProperty(Properties props, @Nonnull String key, @Nonnull String value) { props.setProperty(key, value); }
+ private void setPropertyIfNotNull(Properties props, @Nonnull String key, @CheckForNull String value) { if (value != null) setProperty(props, key, value); }
/* save to file */
public void saveToDisk() throws IOException {
String filename = this.getConfigurationFileName();
@@ -291,101 +293,90 @@ public class ConfigurationManager {
Properties props = new Properties();
props.clear();
- props.setProperty(Constants.CFG_BKU, getDefaultBKUPersistent().toString());
+ setProperty(props, Constants.CFG_BKU, ISNOTNULL(getDefaultBKUPersistent().name()));
- String proxyHost = getProxyHostPersistent();
- if (proxyHost != STRING_EMPTY)
- props.setProperty(Constants.CFG_PROXY_HOST, proxyHost);
+ setPropertyIfNotNull(props, Constants.CFG_PROXY_HOST, getProxyHostPersistent());
int proxyPort = getProxyPortPersistent();
if (proxyPort != -1)
- props.setProperty(Constants.CFG_PROXY_PORT,Integer.toString(proxyPort));
- String proxyUser = getProxyUserPersistent();
- if (proxyUser != STRING_EMPTY)
- props.setProperty(Constants.CFG_PROXY_USER, proxyUser);
- String proxyPass = getProxyPassPersistent();
- if (proxyPass != STRING_EMPTY)
- props.setProperty(Constants.CFG_PROXY_PASS, proxyPass);
-
- props.setProperty(Constants.CFG_EMBLEM, getDefaultEmblemPersistent());
- props.setProperty(Constants.CFG_LOGO_ONLY_SIZE, Double.toString(getLogoOnlyTargetSize()));
- props.setProperty(Constants.CFG_SIGNATURE_NOTE, getSignatureNote());
- props.setProperty(Constants.CFG_MOBILE_NUMBER, getDefaultMobileNumberPersistent());
+ setProperty(props, Constants.CFG_PROXY_PORT, ISNOTNULL(Integer.toString(proxyPort)));
+ setPropertyIfNotNull(props, Constants.CFG_PROXY_USER, getProxyUserPersistent());
+ setPropertyIfNotNull(props, Constants.CFG_PROXY_PASS, getProxyPassPersistent());
+
+ setPropertyIfNotNull(props, Constants.CFG_EMBLEM, getDefaultEmblemPersistent());
+ setProperty(props, Constants.CFG_LOGO_ONLY_SIZE, ISNOTNULL(Double.toString(getLogoOnlyTargetSize())));
+
+ setPropertyIfNotNull(props, Constants.CFG_SIGNATURE_NOTE, getSignatureNote());
+ setPropertyIfNotNull(props, Constants.CFG_MOBILE_NUMBER, getDefaultMobileNumberPersistent());
if (getRememberMobilePassword())
- props.setProperty(Constants.CFG_MOBILE_PASSWORD_REMEMBER, Constants.TRUE);
- props.setProperty(Constants.CFG_OUTPUT_FOLDER, getDefaultOutputFolderPersistent());
- props.setProperty(Constants.CFG_POSTFIX, getSaveFilePostFix());
+ setProperty(props, Constants.CFG_MOBILE_PASSWORD_REMEMBER, Constants.TRUE);
+ setPropertyIfNotNull(props, Constants.CFG_OUTPUT_FOLDER, getDefaultOutputFolderPersistent());
+ setProperty(props, Constants.CFG_POSTFIX, getSaveFilePostFix());
Point size = this.configuration.mainWindowSize;
- props.setProperty(Constants.CFG_MAINWINDOW_SIZE, size.x + "," + size.y);
+ setProperty(props, Constants.CFG_MAINWINDOW_SIZE, size.x + "," + size.y);
Locale configLocale = getInterfaceLocale();
if(configLocale != null) {
- props.setProperty(Constants.CFG_LOCALE, LocaleSerializer.getParsableString(configLocale));
+ setProperty(props, Constants.CFG_LOCALE, LocaleSerializer.getParsableString(configLocale));
}
Locale signatureLocale = this.getSignatureLocale();
if(signatureLocale != null) {
- props.setProperty(Constants.CFG_SIGNATURE_LOCALE, LocaleSerializer.getParsableString(signatureLocale));
+ setProperty(props, Constants.CFG_SIGNATURE_LOCALE, LocaleSerializer.getParsableString(signatureLocale));
}
if (getUseMarker())
- props.setProperty(Constants.CFG_USE_MARKER, Constants.TRUE);
+ setProperty(props, Constants.CFG_USE_MARKER, Constants.TRUE);
if (getUseSignatureFields()) {
- props.setProperty(Constants.CFG_USE_SIGNATURE_FIELDS, Constants.TRUE);
+ setProperty(props, Constants.CFG_USE_SIGNATURE_FIELDS, Constants.TRUE);
}
if (getEnablePlaceholderUsage()) {
- props.setProperty(Constants.CFG_ENABLE_PLACEHOLDER, Constants.TRUE);
+ setProperty(props, Constants.CFG_ENABLE_PLACEHOLDER, Constants.TRUE);
}
if (getSignaturePdfACompat())
- props.setProperty(Constants.CFG_SIGNATURE_PDFA_COMPAT, Constants.TRUE);
+ setProperty(props, Constants.CFG_SIGNATURE_PDFA_COMPAT, Constants.TRUE);
if (!getAutoPositionSignaturePersistent())
- props.setProperty(Constants.CFG_SIGNATURE_POSITION, "");
+ setProperty(props, Constants.CFG_SIGNATURE_POSITION, "");
else
- props.setProperty(Constants.CFG_SIGNATURE_POSITION, "auto");
+ setProperty(props, Constants.CFG_SIGNATURE_POSITION, "auto");
if (Constants.THEME != Constants.Themes.DEFAULT)
- props.setProperty(Constants.CFG_THEME, Constants.THEME.name());
+ setProperty(props, Constants.CFG_THEME, ISNOTNULL(Constants.THEME.name()));
if (getKeyStoreEnabledPersistent())
- props.setProperty(Constants.CFG_KEYSTORE_ENABLED, Constants.TRUE);
- String keystoreFile = getKeyStoreFilePersistent();
- if (keystoreFile != STRING_EMPTY)
- props.setProperty(Constants.CFG_KEYSTORE_FILE, keystoreFile);
- String keystoreType = getKeyStoreTypePersistent();
- if (keystoreType != STRING_EMPTY)
- props.setProperty(Constants.CFG_KEYSTORE_TYPE, keystoreType);
- String keystoreAlias = getKeyStoreAliasPersistent();
- if (keystoreAlias != STRING_EMPTY)
- props.setProperty(Constants.CFG_KEYSTORE_ALIAS, keystoreAlias);
+ setProperty(props, Constants.CFG_KEYSTORE_ENABLED, Constants.TRUE);
+ setPropertyIfNotNull(props, Constants.CFG_KEYSTORE_FILE, getKeyStoreFilePersistent());
+ setPropertyIfNotNull(props, Constants.CFG_KEYSTORE_TYPE, getKeyStoreTypePersistent());
+ setPropertyIfNotNull(props, Constants.CFG_KEYSTORE_ALIAS, getKeyStoreAliasPersistent());
KeyStorePassStorageType keystorePassStorageType = getKeyStorePassStorageType();
if (keystorePassStorageType == null)
- props.setProperty(Constants.CFG_KEYSTORE_PASSSTORETYPE, "none");
+ setProperty(props, Constants.CFG_KEYSTORE_PASSSTORETYPE, "none");
else if (keystorePassStorageType == KeyStorePassStorageType.MEMORY)
- props.setProperty(Constants.CFG_KEYSTORE_PASSSTORETYPE, "memory");
+ setProperty(props, Constants.CFG_KEYSTORE_PASSSTORETYPE, "memory");
else if (keystorePassStorageType == KeyStorePassStorageType.DISK)
- props.setProperty(Constants.CFG_KEYSTORE_PASSSTORETYPE, "disk");
+ setProperty(props, Constants.CFG_KEYSTORE_PASSSTORETYPE, "disk");
if (keystorePassStorageType == KeyStorePassStorageType.DISK)
{
String keystoreStorePass = getKeyStoreStorePassPersistent();
if (keystoreStorePass == null)
- keystoreStorePass = STRING_EMPTY;
- props.setProperty(Constants.CFG_KEYSTORE_STOREPASS, keystoreStorePass);
+ keystoreStorePass = "";
+ setProperty(props, Constants.CFG_KEYSTORE_STOREPASS, keystoreStorePass);
String keystoreKeyPass = getKeyStoreKeyPassPersistent();
if (keystoreKeyPass == null)
- keystoreKeyPass = STRING_EMPTY;
- props.setProperty(Constants.CFG_KEYSTORE_KEYPASS, keystoreKeyPass);
+ keystoreKeyPass = "";
+ setProperty(props, Constants.CFG_KEYSTORE_KEYPASS, keystoreKeyPass);
}
if (!getUpdateCheck())
- props.setProperty(Constants.CFG_UPDATE_CHECK, Constants.FALSE);
+ setProperty(props, Constants.CFG_UPDATE_CHECK, Constants.FALSE);
- props.setProperty(Constants.SIGNATURE_PROFILE, getSignatureProfile().name());
+ setProperty(props, Constants.SIGNATURE_PROFILE, ISNOTNULL(getSignatureProfile().name()));
FileOutputStream outputstream = new FileOutputStream(configFile, false);
@@ -395,6 +386,8 @@ public class ConfigurationManager {
log.info("Configuration file saved to " + configFile.getAbsolutePath());
}
+ static private <T> T fallThroughOnNull(T one, T two) { return (one != null) ? one : two; }
+
public void setConfigurationFileName(String configurationFile)
{
if (this.configurationFile.equals(configurationFile))
@@ -405,22 +398,22 @@ public class ConfigurationManager {
}
public String getConfigurationFileName() { return this.configurationFile; }
- public void setDefaultBKUPersistent(BKUs bku) {
+ public void setDefaultBKUPersistent(@Nonnull BKUs bku) {
this.configuration.defaultBKU = bku;
}
- public void setDefaultBKUOverlay(BKUs bku) {
+ public void setDefaultBKUOverlay(@Nonnull BKUs bku) {
this.configurationOverlay.defaultBKU = bku;
}
- public BKUs getDefaultBKU() {
+ public @Nonnull BKUs getDefaultBKU() {
BKUs bku = this.configurationOverlay.defaultBKU;
if (bku == BKUs.NONE)
bku = getDefaultBKUPersistent();
return bku;
}
- public BKUs getDefaultBKUPersistent() {
+ public @Nonnull BKUs getDefaultBKUPersistent() {
return this.configuration.defaultBKU;
}
@@ -442,7 +435,7 @@ public class ConfigurationManager {
public void setDefaultMobileNumberPersistent(String number) {
if (number == null || number.trim().isEmpty()) {
- this.configuration.setMobileNumber(STRING_EMPTY);
+ this.configuration.setMobileNumber(null);
} else {
this.configuration.setMobileNumber(number);
}
@@ -450,35 +443,29 @@ public class ConfigurationManager {
public void setDefaultMobileNumberOverlay(String number) {
if (number == null || number.trim().isEmpty()) {
- this.configurationOverlay.setMobileNumber(STRING_EMPTY);
+ this.configurationOverlay.setMobileNumber(null);
} else {
this.configurationOverlay.setMobileNumber(number);
}
}
- public String getDefaultMobileNumber() {
- String number = this.configurationOverlay.getMobileNumber();
- if (number == null)
- number = getDefaultMobileNumberPersistent();
- return number;
+ public @CheckForNull String getDefaultMobileNumber() {
+ return fallThroughOnNull(this.configurationOverlay.getMobileNumber(), getDefaultMobileNumberPersistent());
}
- public String getDefaultMobileNumberPersistent() {
- String number = this.configuration.getMobileNumber();
- if (number == null)
- number = STRING_EMPTY;
- return number;
+ public @CheckForNull String getDefaultMobileNumberPersistent() {
+ return this.configuration.getMobileNumber();
}
public void setDefaultMobilePasswordOverlay(String password) {
if (password == null || password.trim().isEmpty()) {
- this.configurationOverlay.mobilePassword = STRING_EMPTY;
+ this.configurationOverlay.mobilePassword = null;
} else {
this.configurationOverlay.mobilePassword = password;
}
}
- public String getDefaultMobilePassword() {
+ public @CheckForNull String getDefaultMobilePassword() {
/* this does not exist as a permanent config variable */
return this.configurationOverlay.mobilePassword;
}
@@ -494,14 +481,14 @@ public class ConfigurationManager {
public void setDefaultEmblemPersistent(String emblem) {
try {
if (emblem == null || emblem.trim().isEmpty()) {
- this.configuration.setEmblem(STRING_EMPTY);
+ this.configuration.setEmblem(null);
} else {
this.configuration.setEmblem(emblem);
}
} catch (InvalidEmblemFile e) {
log.error("Error setting emblem file", e);
try {
- this.configuration.setEmblem(STRING_EMPTY);
+ this.configuration.setEmblem(null);
} catch (InvalidEmblemFile e1) {
// Ignore
}
@@ -511,32 +498,26 @@ public class ConfigurationManager {
public void setDefaultEmblemOverlay(String emblem) {
try {
if (emblem == null || emblem.trim().isEmpty()) {
- this.configurationOverlay.setEmblem(STRING_EMPTY);
+ this.configurationOverlay.setEmblem(null);
} else {
this.configurationOverlay.setEmblem(emblem);
}
} catch (InvalidEmblemFile e) {
log.error("Error setting emblem file", e);
try {
- this.configurationOverlay.setEmblem(STRING_EMPTY);
+ this.configurationOverlay.setEmblem(null);
} catch (InvalidEmblemFile e1) {
// Ignore
}
}
}
- public String getDefaultEmblemPath() {
- String emblem = this.configurationOverlay.getEmblemPath();
- if (emblem == null)
- emblem = getDefaultEmblemPersistent();
- return emblem;
+ public @CheckForNull String getDefaultEmblemPath() {
+ return fallThroughOnNull(this.configurationOverlay.getEmblemPath(), getDefaultEmblemPersistent());
}
- public String getDefaultEmblemPersistent() {
- String emblem = this.configuration.getEmblemPath();
- if (emblem == null)
- emblem = STRING_EMPTY;
- return emblem;
+ public @CheckForNull String getDefaultEmblemPersistent() {
+ return this.configuration.getEmblemPath();
}
public void setLogoOnlyTargetSizePersistent(double v) {
@@ -549,7 +530,7 @@ public class ConfigurationManager {
public void setProxyHostPersistent(String host) {
if (host == null || host.trim().isEmpty()) {
- this.configuration.proxyHost = STRING_EMPTY;
+ this.configuration.proxyHost = null;
} else {
this.configuration.proxyHost = host;
}
@@ -557,24 +538,18 @@ public class ConfigurationManager {
public void setProxyHostOverlay(String host) {
if (host == null || host.trim().isEmpty()) {
- this.configurationOverlay.proxyHost = STRING_EMPTY;
+ this.configurationOverlay.proxyHost = null;
} else {
this.configurationOverlay.proxyHost = host;
}
}
- public String getProxyHost() {
- String host = this.configurationOverlay.proxyHost;
- if (host == null)
- host = getProxyHostPersistent();
- return host;
+ public @CheckForNull String getProxyHost() {
+ return fallThroughOnNull(this.configurationOverlay.proxyHost, getProxyHostPersistent());
}
- public String getProxyHostPersistent() {
- String host = this.configuration.proxyHost;
- if (host == null)
- host = STRING_EMPTY;
- return host;
+ public @CheckForNull String getProxyHostPersistent() {
+ return this.configuration.proxyHost;
}
public void setProxyPortPersistent(int port) {
@@ -597,7 +572,7 @@ public class ConfigurationManager {
public int getProxyPort() {
int port = this.configurationOverlay.getProxyPort();
- if (port == -1)
+ if (port == -1) // TODO -1 is a terrible, no good, very bad hack
port = getProxyPortPersistent();
return port;
}
@@ -608,7 +583,7 @@ public class ConfigurationManager {
public void setProxyUserPersistent(String user) {
if (user == null || user.trim().isEmpty()) {
- this.configuration.proxyUser = STRING_EMPTY;
+ this.configuration.proxyUser = null;
} else {
this.configuration.proxyUser = user;
}
@@ -616,29 +591,23 @@ public class ConfigurationManager {
public void setProxyUserOverlay(String user) {
if (user == null || user.trim().isEmpty()) {
- this.configurationOverlay.proxyUser = STRING_EMPTY;
+ this.configurationOverlay.proxyUser = null;
} else {
this.configurationOverlay.proxyUser = user;
}
}
- public String getProxyUser() {
- String user = this.configurationOverlay.proxyUser;
- if (user == null)
- user = getProxyUserPersistent();
- return user;
+ public @CheckForNull String getProxyUser() {
+ return fallThroughOnNull(this.configurationOverlay.proxyUser, getProxyUserPersistent());
}
- public String getProxyUserPersistent() {
- String user = this.configuration.proxyUser;
- if (user == null)
- user = STRING_EMPTY;
- return user;
+ public @CheckForNull String getProxyUserPersistent() {
+ return this.configuration.proxyUser;
}
public void setProxyPassPersistent(String pass) {
if (pass == null || pass.trim().isEmpty()) {
- this.configuration.proxyPass = STRING_EMPTY;
+ this.configuration.proxyPass = null;
} else {
this.configuration.proxyPass = pass;
}
@@ -646,29 +615,23 @@ public class ConfigurationManager {
public void setProxyPassOverlay(String pass) {
if (pass == null || pass.trim().isEmpty()) {
- this.configurationOverlay.proxyPass = STRING_EMPTY;
+ this.configurationOverlay.proxyPass = null;
} else {
this.configurationOverlay.proxyPass = pass;
}
}
- public String getProxyPass() {
- String pass = this.configurationOverlay.proxyPass;
- if (pass == null)
- pass = getProxyPassPersistent();
- return pass;
+ public @CheckForNull String getProxyPass() {
+ return fallThroughOnNull(this.configurationOverlay.proxyPass, getProxyPassPersistent());
}
- public String getProxyPassPersistent() {
- String pass = this.configuration.proxyPass;
- if (pass == null)
- pass = STRING_EMPTY;
- return pass;
+ public @CheckForNull String getProxyPassPersistent() {
+ return this.configuration.proxyPass;
}
public void setDefaultOutputFolderPersistent(String outputFolder) {
if (outputFolder == null || outputFolder.trim().isEmpty()) {
- this.configuration.outputFolder = STRING_EMPTY;
+ this.configuration.outputFolder = null;
} else {
this.configuration.outputFolder = outputFolder;
}
@@ -676,39 +639,30 @@ public class ConfigurationManager {
public void setDefaultOutputFolderOverlay(String outputFolder) {
if (outputFolder == null || outputFolder.trim().isEmpty()) {
- this.configurationOverlay.outputFolder = STRING_EMPTY;
+ this.configurationOverlay.outputFolder = null;
} else {
this.configurationOverlay.outputFolder = outputFolder;
}
}
- public String getDefaultOutputFolder() {
- String outputFolder = this.configurationOverlay.outputFolder;
- if (outputFolder == null)
- outputFolder = getDefaultOutputFolderPersistent();
- return outputFolder;
+ public @CheckForNull String getDefaultOutputFolder() {
+ return fallThroughOnNull(this.configurationOverlay.outputFolder, getDefaultOutputFolderPersistent());
}
- public String getDefaultOutputFolderPersistent() {
- String outputFolder = this.configuration.outputFolder;
- if (outputFolder == null)
- outputFolder = STRING_EMPTY;
- return outputFolder;
+ public @CheckForNull String getDefaultOutputFolderPersistent() {
+ return this.configuration.outputFolder;
}
public void setSignatureNotePersistent(String note) {
if (note == null || note.trim().isEmpty()) {
- this.configuration.signatureNote = STRING_EMPTY;
+ this.configuration.signatureNote = null;
} else {
this.configuration.signatureNote = note;
}
}
- public String getSignatureNote() {
- String note = this.configuration.signatureNote;
- if (note == null)
- note = STRING_EMPTY;
- return note;
+ public @CheckForNull String getSignatureNote() {
+ return this.configuration.signatureNote;
}
public void setInterfaceLocalePersistent(Locale locale) {
@@ -721,7 +675,7 @@ public class ConfigurationManager {
}
}
- public Locale getInterfaceLocale() {
+ public @Nonnull Locale getInterfaceLocale() {
Locale locale = this.configuration.interfaceLocale;
if (locale == null)
locale = Messages.getDefaultLocale();
@@ -736,7 +690,7 @@ public class ConfigurationManager {
}
}
- public Locale getSignatureLocale() {
+ public @Nonnull Locale getSignatureLocale() {
Locale locale = this.configuration.signatureLocale;
if (locale == null)
locale = Messages.getDefaultLocale();
@@ -759,23 +713,17 @@ public class ConfigurationManager {
this.configurationOverlay.keystoreEnabled = enabled;
}
- public Boolean getKeyStoreEnabled() {
- Boolean enabled = this.configurationOverlay.keystoreEnabled;
- if (enabled == null)
- enabled = getKeyStoreEnabledPersistent();
- return enabled;
+ public boolean getKeyStoreEnabled() {
+ return ISNOTNULL(fallThroughOnNull(this.configurationOverlay.keystoreEnabled, getKeyStoreEnabledPersistent()));
}
- public Boolean getKeyStoreEnabledPersistent() {
- Boolean enabled = this.configuration.keystoreEnabled;
- if (enabled == null)
- enabled = false;
- return enabled;
+ public boolean getKeyStoreEnabledPersistent() {
+ return ISNOTNULL(fallThroughOnNull(this.configuration.keystoreEnabled, Boolean.FALSE));
}
public void setKeyStoreFilePersistent(String file) {
if (file == null || file.trim().isEmpty()) {
- this.configuration.keystoreFile = STRING_EMPTY;
+ this.configuration.keystoreFile = null;
} else {
this.configuration.keystoreFile = file;
}
@@ -783,29 +731,23 @@ public class ConfigurationManager {
public void setKeyStoreFileOverlay(String file) {
if (file == null || file.trim().isEmpty()) {
- this.configurationOverlay.keystoreFile = STRING_EMPTY;
+ this.configurationOverlay.keystoreFile = null;
} else {
this.configurationOverlay.keystoreFile = file;
}
}
- public String getKeyStoreFile() {
- String file = this.configurationOverlay.keystoreFile;
- if (file == null)
- file = getKeyStoreFilePersistent();
- return file;
+ public @CheckForNull String getKeyStoreFile() {
+ return fallThroughOnNull(this.configurationOverlay.keystoreFile, getKeyStoreFilePersistent());
}
- public String getKeyStoreFilePersistent() {
- String file = this.configuration.keystoreFile;
- if (file == null)
- file = STRING_EMPTY;
- return file;
+ public @CheckForNull String getKeyStoreFilePersistent() {
+ return this.configuration.keystoreFile;
}
public void setKeyStoreTypePersistent(String type) {
if (type == null || type.trim().isEmpty()) {
- this.configuration.keystoreType = STRING_EMPTY;
+ this.configuration.keystoreType = null;
} else {
this.configuration.keystoreType = type;
}
@@ -813,29 +755,23 @@ public class ConfigurationManager {
public void setKeyStoreTypeOverlay(String type) {
if (type == null || type.trim().isEmpty()) {
- this.configurationOverlay.keystoreType = STRING_EMPTY;
+ this.configurationOverlay.keystoreType = null;
} else {
this.configurationOverlay.keystoreType = type;
}
}
- public String getKeyStoreType() {
- String type = this.configurationOverlay.keystoreType;
- if (type == null)
- type = getKeyStoreTypePersistent();
- return type;
+ public @CheckForNull String getKeyStoreType() {
+ return fallThroughOnNull(this.configurationOverlay.keystoreType, getKeyStoreTypePersistent());
}
- public String getKeyStoreTypePersistent() {
- String type = this.configuration.keystoreType;
- if (type == null)
- type = STRING_EMPTY;
- return type;
+ public @CheckForNull String getKeyStoreTypePersistent() {
+ return this.configuration.keystoreType;
}
public void setKeyStoreAliasPersistent(String alias) {
if (alias == null || alias.trim().isEmpty()) {
- this.configuration.keystoreAlias = STRING_EMPTY;
+ this.configuration.keystoreAlias = null;
} else {
this.configuration.keystoreAlias = alias;
}
@@ -843,24 +779,18 @@ public class ConfigurationManager {
public void setKeyStoreAliasOverlay(String alias) {
if (alias == null || alias.trim().isEmpty()) {
- this.configurationOverlay.keystoreAlias = STRING_EMPTY;
+ this.configurationOverlay.keystoreAlias = null;
} else {
this.configurationOverlay.keystoreAlias = alias;
}
}
- public String getKeyStoreAlias() {
- String alias = this.configurationOverlay.keystoreAlias;
- if (alias == null)
- alias = getKeyStoreAliasPersistent();
- return alias;
+ public @CheckForNull String getKeyStoreAlias() {
+ return fallThroughOnNull(this.configurationOverlay.keystoreAlias, getKeyStoreAliasPersistent());
}
- public String getKeyStoreAliasPersistent() {
- String alias = this.configuration.keystoreAlias;
- if (alias == null)
- alias = STRING_EMPTY;
- return alias;
+ public @CheckForNull String getKeyStoreAliasPersistent() {
+ return this.configuration.keystoreAlias;
}
public void setKeyStorePassStorageTypePersistent(KeyStorePassStorageType type) {
@@ -879,7 +809,7 @@ public class ConfigurationManager {
this.configurationOverlay.keystoreStorePass = storePass;
}
- public String getKeyStoreStorePass() {
+ public @CheckForNull String getKeyStoreStorePass() {
String storePass = this.configurationOverlay.keystoreStorePass;
if (storePass != null)
return storePass;
@@ -888,7 +818,7 @@ public class ConfigurationManager {
return getKeyStoreStorePassPersistent();
}
- public String getKeyStoreStorePassPersistent() {
+ public @CheckForNull String getKeyStoreStorePassPersistent() {
return this.configuration.keystoreStorePass;
}
@@ -900,7 +830,7 @@ public class ConfigurationManager {
this.configurationOverlay.keystoreKeyPass = keyPass;
}
- public String getKeyStoreKeyPass() {
+ public @CheckForNull String getKeyStoreKeyPass() {
String keyPass = this.configurationOverlay.keystoreKeyPass;
if (keyPass != null)
return keyPass;
@@ -909,7 +839,7 @@ public class ConfigurationManager {
return getKeyStoreKeyPassPersistent();
}
- public String getKeyStoreKeyPassPersistent() {
+ public @CheckForNull String getKeyStoreKeyPassPersistent() {
return this.configuration.keystoreKeyPass;
}
@@ -921,11 +851,11 @@ public class ConfigurationManager {
return this.configuration.updateCheck;
}
- public void setMainWindowSizePersistent(Point size) {
+ public void setMainWindowSizePersistent(@Nonnull Point size) {
this.configuration.mainWindowSize = size;
}
- public Point getMainWindowSize() {
+ public @Nonnull Point getMainWindowSize() {
return this.configuration.mainWindowSize;
}
@@ -955,20 +885,20 @@ public class ConfigurationManager {
if (useMarker) setUseSignatureFieldsPersistent(false);
}
- public void setSaveFilePostFixPersistent(String postFix) {
+ public void setSaveFilePostFixPersistent(@Nonnull String postFix) {
this.configuration.saveFilePostFix = postFix;
}
- public String getSaveFilePostFix(){
+ public @Nonnull String getSaveFilePostFix(){
return this.configuration.saveFilePostFix;
}
- public Profile getSignatureProfile() {
- return this.configuration.getSignatureProfile();
+ public @Nonnull Profile getSignatureProfile() {
+ return ISNOTNULL(fallThroughOnNull(this.configuration.signatureProfile, Profile.SIGNATURBLOCK_SMALL));
}
public void setSignatureProfilePersistent(Profile profile) {
- this.configuration.setSignatureProfile(profile);
+ this.configuration.signatureProfile = profile;
}
public void setEnablePlaceholderUsagePersistent(boolean bool) {
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java
index 132a134b..1669f2f8 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java
@@ -228,7 +228,7 @@ public class PrepareSigningState extends State {
this.setNextState(new KSState(getStateMachine()));
break;
default:
- log.error("Invalid selected BKU Value \"NONE\" in PrepareSigningState!");
+ log.error("Invalid selected BKU Value \"{}\" in PrepareSigningState!", status.bku.name());
this.setNextState(new BKUSelectionState(getStateMachine()));
}
}
diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/Emblem.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/Emblem.java
index c045169a..6c368b16 100644
--- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/Emblem.java
+++ b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/Emblem.java
@@ -85,7 +85,7 @@ public class Emblem {
this.originalFileName = filename;
}
- private String getFileHash(String filename) throws IOException {
+ private static String getFileHash(String filename) throws IOException {
InputStream is = Files.newInputStream(Path.of(filename));
return DigestUtils.md5Hex(is);
}