Skip to content

Commit cdf3757

Browse files
committed
NFC-82 Refactor application properties
1 parent d7e085f commit cdf3757

File tree

10 files changed

+109
-122
lines changed

10 files changed

+109
-122
lines changed

example/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
<groupId>org.springframework.boot</groupId>
3939
<artifactId>spring-boot-starter-thymeleaf</artifactId>
4040
</dependency>
41+
<dependency>
42+
<groupId>org.springframework.boot</groupId>
43+
<artifactId>spring-boot-starter-validation</artifactId>
44+
</dependency>
4145

4246
<dependency>
4347
<groupId>org.digidoc4j</groupId>

example/src/main/java/eu/webeid/example/config/ApplicationConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import eu.webeid.example.security.WebEidMobileAuthInitFilter;
2929
import eu.webeid.example.security.ui.WebEidLoginPageGeneratingFilter;
3030
import eu.webeid.security.challenge.ChallengeNonceGenerator;
31+
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
3132
import org.springframework.context.annotation.Bean;
3233
import org.springframework.context.annotation.Configuration;
3334
import org.springframework.http.HttpMethod;
@@ -43,6 +44,7 @@
4344
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
4445

4546
@Configuration
47+
@ConfigurationPropertiesScan
4648
@EnableWebSecurity
4749
@EnableMethodSecurity(securedEnabled = true)
4850
public class ApplicationConfiguration implements WebMvcConfigurer {

example/src/main/java/eu/webeid/example/config/ValidationConfiguration.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,19 @@ public ChallengeNonceGenerator generator(ChallengeNonceStore challengeNonceStore
7979
}
8080

8181
@Bean
82-
public AuthTokenValidator validator(YAMLConfig yamlConfig) {
82+
public AuthTokenValidator validator(WebEidAuthTokenProperties authTokenProperties) {
8383
try {
8484
return new AuthTokenValidatorBuilder()
85-
.withSiteOrigin(URI.create(yamlConfig.getLocalOrigin()))
85+
.withSiteOrigin(URI.create(authTokenProperties.validation().localOrigin()))
8686
.withTrustedCertificateAuthorities(loadTrustedCACertificatesFromCerFiles())
87-
.withTrustedCertificateAuthorities(loadTrustedCACertificatesFromTrustStore(yamlConfig))
88-
.withOcspRequestTimeout(yamlConfig.getOcspRequestTimeout())
87+
.withTrustedCertificateAuthorities(loadTrustedCACertificatesFromTrustStore(authTokenProperties))
88+
.withOcspRequestTimeout(authTokenProperties.validation().ocspRequestTimeout())
8989
.build();
9090
} catch (JceException e) {
9191
throw new RuntimeException("Error building the Web eID auth token validator.", e);
9292
}
9393
}
9494

95-
@Bean
96-
public YAMLConfig yamlConfig() {
97-
return new YAMLConfig();
98-
}
99-
10095
private X509Certificate[] loadTrustedCACertificatesFromCerFiles() {
10196
List<X509Certificate> caCertificates = new ArrayList<>();
10297

@@ -118,7 +113,7 @@ private X509Certificate[] loadTrustedCACertificatesFromCerFiles() {
118113
return caCertificates.toArray(new X509Certificate[0]);
119114
}
120115

121-
private X509Certificate[] loadTrustedCACertificatesFromTrustStore(YAMLConfig yamlConfig) {
116+
private X509Certificate[] loadTrustedCACertificatesFromTrustStore(WebEidAuthTokenProperties authTokenProperties) {
122117
List<X509Certificate> caCertificates = new ArrayList<>();
123118

124119
try (InputStream is = ValidationConfiguration.class.getResourceAsStream(CERTS_RESOURCE_PATH + activeProfile + "/" + TRUSTED_CERTIFICATES_JKS)) {
@@ -127,7 +122,7 @@ private X509Certificate[] loadTrustedCACertificatesFromTrustStore(YAMLConfig yam
127122
return new X509Certificate[0];
128123
}
129124
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
130-
keystore.load(is, yamlConfig.getTrustStorePassword().toCharArray());
125+
keystore.load(is, authTokenProperties.validation().trustStorePassword().toCharArray());
131126
Enumeration<String> aliases = keystore.aliases();
132127
while (aliases.hasMoreElements()) {
133128
String alias = aliases.nextElement();
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2020-2025 Estonian Information System Authority
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
package eu.webeid.example.config;
24+
25+
import jakarta.validation.constraints.NotBlank;
26+
import jakarta.validation.constraints.NotNull;
27+
import org.springframework.boot.context.properties.ConfigurationProperties;
28+
import org.springframework.boot.context.properties.bind.DefaultValue;
29+
import org.springframework.validation.annotation.Validated;
30+
31+
import java.time.Duration;
32+
33+
@Validated
34+
@ConfigurationProperties(prefix = "web-eid-auth-token")
35+
public record WebEidAuthTokenProperties(WebEidAuthTokenValidation validation) {
36+
37+
public record WebEidAuthTokenValidation(
38+
@NotBlank String localOrigin,
39+
String siteCertHash,
40+
@NotBlank String trustStorePassword,
41+
@DefaultValue("5s") Duration ocspRequestTimeout,
42+
@NotNull Boolean useDigiDoc4jProdConfiguration) {
43+
}
44+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2020-2025 Estonian Information System Authority
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
package eu.webeid.example.config;
24+
25+
import jakarta.validation.constraints.NotBlank;
26+
import org.springframework.boot.context.properties.ConfigurationProperties;
27+
import org.springframework.validation.annotation.Validated;
28+
29+
@Validated
30+
@ConfigurationProperties(prefix = "web-eid-mobile")
31+
public record WebEidMobileProperties(
32+
@NotBlank String baseRequestUri,
33+
boolean requestSigningCert) {
34+
}

example/src/main/java/eu/webeid/example/config/YAMLConfig.java

Lines changed: 0 additions & 100 deletions
This file was deleted.

example/src/main/java/eu/webeid/example/service/SigningService.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
package eu.webeid.example.service;
2424

2525
import com.fasterxml.jackson.databind.ObjectMapper;
26-
import eu.webeid.example.config.YAMLConfig;
26+
import eu.webeid.example.config.WebEidAuthTokenProperties;
27+
import eu.webeid.example.config.WebEidMobileProperties;
2728
import eu.webeid.example.security.WebEidAuthentication;
2829
import eu.webeid.example.service.dto.CertificateDTO;
2930
import eu.webeid.example.service.dto.DigestDTO;
@@ -78,13 +79,13 @@ public class SigningService {
7879
private final Configuration signingConfiguration;
7980

8081
private final ObjectFactory<HttpSession> httpSessionFactory;
81-
private final YAMLConfig yamlConfig;
82+
private final WebEidMobileProperties webEidMobileProperties;
8283

83-
public SigningService(ObjectFactory<HttpSession> httpSessionFactory, YAMLConfig yamlConfig) {
84+
public SigningService(ObjectFactory<HttpSession> httpSessionFactory, WebEidAuthTokenProperties authTokenProperties, WebEidMobileProperties webEidMobileProperties) {
8485
this.httpSessionFactory = httpSessionFactory;
85-
this.yamlConfig = yamlConfig;
86-
signingConfiguration = Configuration.of(yamlConfig.getUseDigiDoc4jProdConfiguration() ?
87-
Configuration.Mode.PROD : Configuration.Mode.TEST);
86+
this.webEidMobileProperties = webEidMobileProperties;
87+
signingConfiguration = Configuration.of(authTokenProperties.validation().useDigiDoc4jProdConfiguration() ?
88+
Configuration.Mode.PROD : Configuration.Mode.TEST);
8889
// Use automatic AIA OCSP URL selection from certificate for signatures.
8990
signingConfiguration.setPreferAiaOcsp(true);
9091
}
@@ -198,7 +199,7 @@ public Map<String, Object> buildMobileInitResponse(WebEidAuthentication authenti
198199
&& supportedSignatureAlgorithms != null
199200
&& !supportedSignatureAlgorithms.isEmpty();
200201

201-
boolean requestSigningCert = yamlConfig.getRequestSigningCert();
202+
boolean requestSigningCert = webEidMobileProperties.requestSigningCert();
202203
String nextPath = requestSigningCert
203204
? CERTIFICATE_URI
204205
: SIGNATURE_URI;
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
web-eid-auth-token:
22
validation:
3-
use-digidoc4j-prod-configuration: false
3+
use-digi-doc4j-prod-configuration: false
44
local-origin: "https://test.web-eid.eu"
5+
web-eid-mobile:
6+
base-request-uri: "web-eid-mobile://"
57
request-signing-cert: false
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
web-eid-auth-token:
22
validation:
3-
use-digidoc4j-prod-configuration: true
3+
use-digi-doc4j-prod-configuration: true
44
local-origin: "https://web-eid.eu"
55
truststore-password: "changeit"
6-
request-signing-cert: false
6+
web-eid-mobile:
7+
base-request-uri: "web-eid-mobile://"
8+
request-signing-cert: false
79
spring:
810
thymeleaf:
911
cache: true
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
web-eid-auth-token:
22
validation:
3-
use-digidoc4j-prod-configuration: false
3+
use-digi-doc4j-prod-configuration: false
44
local-origin: "https://ria.ee"
5+
web-eid-mobile:
6+
base-request-uri: "web-eid-mobile://"
7+
request-signing-cert: false

0 commit comments

Comments
 (0)