FINERACT-2140: added hsts protocol support through system property

This commit is contained in:
mark.vituska
2025-04-23 12:22:45 +02:00
committed by Adam Saghy
parent a9fe523eae
commit 99f12d6091
5 changed files with 19 additions and 0 deletions
@@ -491,6 +491,7 @@ public class FineractProperties {
private FineractSecurityBasicAuth basicauth;
private FineractSecurityTwoFactorAuth twoFactor;
private FineractSecurityOAuth oauth;
private FineractSecurityHsts hsts;
public void set2fa(FineractSecurityTwoFactorAuth twoFactor) {
this.twoFactor = twoFactor;
@@ -518,6 +519,13 @@ public class FineractProperties {
private boolean enabled;
}
@Getter
@Setter
public static class FineractSecurityHsts {
private boolean enabled;
}
@Getter
@Setter
public static class FineractTransactionProcessorItemProperties {
@@ -128,6 +128,10 @@ public class OAuth2SecurityConfig {
http.requiresChannel(channel -> channel.requestMatchers(antMatcher("/api/**")).requiresSecure());
}
if (fineractProperties.getSecurity().getHsts().isEnabled()) {
http.requiresChannel(channel -> channel.anyRequest().requiresSecure()).headers(
headers -> headers.httpStrictTransportSecurity(hsts -> hsts.includeSubDomains(true).maxAgeInSeconds(31536000)));
}
return http.build();
}
@@ -158,6 +158,11 @@ public class SecurityConfig {
if (serverProperties.getSsl().isEnabled()) {
http.requiresChannel(channel -> channel.requestMatchers(antMatcher("/api/**")).requiresSecure());
}
if (fineractProperties.getSecurity().getHsts().isEnabled()) {
http.requiresChannel(channel -> channel.anyRequest().requiresSecure()).headers(
headers -> headers.httpStrictTransportSecurity(hsts -> hsts.includeSubDomains(true).maxAgeInSeconds(31536000)));
}
return http.build();
}
@@ -24,6 +24,7 @@ fineract.node-id=${FINERACT_NODE_ID:1}
fineract.security.basicauth.enabled=${FINERACT_SECURITY_BASICAUTH_ENABLED:true}
fineract.security.oauth.enabled=${FINERACT_SECURITY_OAUTH_ENABLED:false}
fineract.security.2fa.enabled=${FINERACT_SECURITY_2FA_ENABLED:false}
fineract.security.hsts.enabled=${FINERACT_SECURITY_HSTS_ENABLED:false}
fineract.tenant.host=${FINERACT_DEFAULT_TENANTDB_HOSTNAME:localhost}
fineract.tenant.port=${FINERACT_DEFAULT_TENANTDB_PORT:3306}
@@ -22,6 +22,7 @@ fineract.node-id=1
fineract.security.basicauth.enabled=true
fineract.security.oauth.enabled=false
fineract.security.2fa.enabled=false
fineract.security.hsts.enabled=false
fineract.tenant.host=localhost
fineract.tenant.port=3306