From 959f6889d4bfc11c24bef404705227fe42c5e8b0 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Wed, 24 Apr 2024 08:56:31 +0200 Subject: [PATCH] refactor: extract custom SSL gPAS rest template creation --- .../etl/processor/config/AppConfiguration.kt | 62 +++++++++++++------ 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/src/main/kotlin/dev/dnpm/etl/processor/config/AppConfiguration.kt b/src/main/kotlin/dev/dnpm/etl/processor/config/AppConfiguration.kt index b7b150d..09839a9 100644 --- a/src/main/kotlin/dev/dnpm/etl/processor/config/AppConfiguration.kt +++ b/src/main/kotlin/dev/dnpm/etl/processor/config/AppConfiguration.kt @@ -88,6 +88,47 @@ class AppConfiguration { @ConditionalOnProperty(value = ["app.pseudonymize.generator"], havingValue = "GPAS") @Bean fun gpasPseudonymGenerator(configProperties: GPasConfigProperties, retryTemplate: RetryTemplate, restTemplate: RestTemplate): Generator { + try { + if (!configProperties.sslCaLocation.isNullOrBlank()) { + return GpasPseudonymGenerator( + configProperties, + retryTemplate, + createCustomGpasRestTemplate(configProperties) + ) + } + } catch (e: Exception) { + throw RuntimeException(e) + } + + return GpasPseudonymGenerator(configProperties, retryTemplate, restTemplate) + } + + @ConditionalOnProperty(value = ["app.pseudonymize.generator"], havingValue = "BUILDIN", matchIfMissing = true) + @Bean + fun buildinPseudonymGenerator(): Generator { + return AnonymizingGenerator() + } + + @ConditionalOnProperty(value = ["app.pseudonymizer"], havingValue = "GPAS") + @ConditionalOnMissingBean + @Bean + fun gpasPseudonymGeneratorOnDeprecatedProperty(configProperties: GPasConfigProperties, retryTemplate: RetryTemplate, restTemplate: RestTemplate): Generator { + try { + if (!configProperties.sslCaLocation.isNullOrBlank()) { + return GpasPseudonymGenerator( + configProperties, + retryTemplate, + createCustomGpasRestTemplate(configProperties) + ) + } + } catch (e: Exception) { + throw RuntimeException(e) + } + + return GpasPseudonymGenerator(configProperties, retryTemplate, restTemplate) + } + + private fun createCustomGpasRestTemplate(configProperties: GPasConfigProperties): RestTemplate { fun getSslContext(certificateLocation: String): SSLContext? { val ks = KeyStore.getInstance(KeyStore.getDefaultType()) @@ -137,31 +178,14 @@ class AppConfiguration { ) if (customSslContext != null) { - return GpasPseudonymGenerator( - configProperties, - retryTemplate, - getCustomRestTemplate(customSslContext) - ) + return getCustomRestTemplate(customSslContext) } } } catch (e: Exception) { throw RuntimeException(e) } - return GpasPseudonymGenerator(configProperties, retryTemplate, restTemplate) - } - - @ConditionalOnProperty(value = ["app.pseudonymize.generator"], havingValue = "BUILDIN", matchIfMissing = true) - @Bean - fun buildinPseudonymGenerator(): Generator { - return AnonymizingGenerator() - } - - @ConditionalOnProperty(value = ["app.pseudonymizer"], havingValue = "GPAS") - @ConditionalOnMissingBean - @Bean - fun gpasPseudonymGeneratorOnDeprecatedProperty(configProperties: GPasConfigProperties, retryTemplate: RetryTemplate, restTemplate: RestTemplate): Generator { - return gpasPseudonymGenerator(configProperties, retryTemplate, restTemplate) + throw RuntimeException("Custom SSL configuration for gPAS not usable") } @ConditionalOnProperty(value = ["app.pseudonymizer"], havingValue = "BUILDIN")