summaryrefslogtreecommitdiff
path: root/eaaf_core_utils/src/main
diff options
context:
space:
mode:
authorThomas Lenz <thomas.lenz@egiz.gv.at>2020-05-05 15:38:33 +0200
committerThomas Lenz <thomas.lenz@egiz.gv.at>2020-05-05 15:38:33 +0200
commitf5d3668fbc9f2e261185bbf110ddf867d7004b2a (patch)
tree22a75bfac0600379e2e3d2d026e3deea2f324d37 /eaaf_core_utils/src/main
parent538dc3f696e12a7a16d3f705419424cbd0ea6898 (diff)
downloadEAAF-Components-f5d3668fbc9f2e261185bbf110ddf867d7004b2a.tar.gz
EAAF-Components-f5d3668fbc9f2e261185bbf110ddf867d7004b2a.tar.bz2
EAAF-Components-f5d3668fbc9f2e261185bbf110ddf867d7004b2a.zip
some more code polishing
Diffstat (limited to 'eaaf_core_utils/src/main')
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/credential/EaafKeyStoreFactory.java40
1 files changed, 28 insertions, 12 deletions
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/credential/EaafKeyStoreFactory.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/credential/EaafKeyStoreFactory.java
index 0cdb4a65..9db38670 100644
--- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/credential/EaafKeyStoreFactory.java
+++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/credential/EaafKeyStoreFactory.java
@@ -57,6 +57,10 @@ public class EaafKeyStoreFactory {
private static final String HSM_FACADE_PROVIDER_CLASS = "at.asitplus.hsmfacade.provider.HsmFacadeProvider";
private static final String HSM_FACADE_KEYSTORELOADPARAMETERS_CLASS
= "at.asitplus.hsmfacade.provider.RemoteKeyStoreLoadParameter";
+ private static final String HSM_FACADE_PROVIDER_METHOD_CONSTRUCT = "getInstance";
+ private static final String HSM_FACADE_PROVIDER_METHOD_INIT = "init";
+ private static final String HSM_FACADE_PROVIDER_INIT_ERROR_MSG
+ = "Has HSM-Facade class supported '{}' method: {}";
private static final String HSM_FACADE_PROVIDER = "HsmFacade";
private static final String HSM_FACADE_KEYSTORE_TYPE = "RemoteKeyStore";
@@ -134,22 +138,34 @@ public class EaafKeyStoreFactory {
//initialize HSM-Facade by using JAVA Reflection, because in that case HSM-Facade
//has not be in ClassPath on every project
- Method initMethod = hsmProviderClazz.getMethod("init",
- X509Certificate.class, String.class, String.class, String.class, int.class);
- Object rawProvider =
- hsmProviderClazz.getMethod("getInstance", new Class[]{}).invoke(hsmProviderClazz);
- if (rawProvider instanceof Provider && initMethod != null) {
+
+ Method constructor = hsmProviderClazz.getMethod(HSM_FACADE_PROVIDER_METHOD_CONSTRUCT, new Class[]{});
+ Method initMethod = hsmProviderClazz.getMethod(HSM_FACADE_PROVIDER_METHOD_INIT,
+ X509Certificate.class, String.class, String.class, String.class, int.class);
+ if (initMethod != null && constructor != null) {
+ Object rawProvider = constructor.invoke(hsmProviderClazz);
initMethod.invoke(
rawProvider, getHsmFacadeTrustSslCertificate(),
clientUsername, clientPassword, hsmFacadeHost, port);
- Security.insertProviderAt((Provider) rawProvider, 0);
- isHsmFacadeInitialized = true;
- log.info("HSM Facade is initialized. {} can provide KeyStores based on remote HSM",
- EaafKeyStoreFactory.class.getSimpleName());
+
+ if (rawProvider instanceof Provider) {
+ Security.insertProviderAt((Provider) rawProvider, 0);
+ isHsmFacadeInitialized = true;
+ log.info("HSM Facade is initialized. {} can provide KeyStores based on remote HSM",
+ EaafKeyStoreFactory.class.getSimpleName());
+
+ } else {
+ log.warn("Is HSM-Facade class type of 'java.security.Provider': {}",
+ rawProvider instanceof Provider);
+ throw new EaafException(ERRORCODE_10, new Object[] {HSM_FACADE_PROVIDER_CLASS});
+
+ }
- } else {
- log.warn("Is HSM-Facade class type of 'java.security.Provider': {}", rawProvider instanceof Provider);
- log.warn("Has HSM-Facade class supported 'init' method: {}", initMethod != null);
+ } else {
+ log.warn(HSM_FACADE_PROVIDER_INIT_ERROR_MSG,
+ HSM_FACADE_PROVIDER_METHOD_CONSTRUCT, constructor != null);
+ log.warn(HSM_FACADE_PROVIDER_INIT_ERROR_MSG,
+ HSM_FACADE_PROVIDER_METHOD_INIT, initMethod != null);
throw new EaafException(ERRORCODE_10, new Object[] {HSM_FACADE_PROVIDER_CLASS});
}