Skip to content

Commit 8c90bbd

Browse files
authored
refactor: migrate @ConfigurationProperties from @component to @EnableConfigurationProperties (#264)
* refactor(config): migrate @ConfigurationProperties from @component to @EnableConfigurationProperties Remove @component and @propertysource from DevLoginConfigProperties and WebAuthnConfigProperties so they are passive data holders per Spring Boot convention. Registration is now handled by dedicated @configuration classes with @EnableConfigurationProperties: - DevLoginAutoConfiguration: guards with @Profile("local") and @ConditionalOnProperty, owns @propertysource - WebAuthnAutoConfiguration: always active (WebSecurityConfig requires the properties), owns @propertysource Closes #263 * fix(review): address PR #264 review feedback - Rename DevLoginAutoConfiguration → DevLoginConfiguration and WebAuthnAutoConfiguration → WebAuthnConfiguration to avoid implying Spring Boot SPI semantics (these are component-scanned, not SPI-registered via AutoConfiguration.imports) - Remove @propertysource from DevLoginConfiguration: the annotation cannot influence its own @ConditionalOnProperty evaluation (condition is checked before @propertysource is processed), and defaults are already available via WebAuthnConfiguration which unconditionally loads dsspringuserconfig.properties
1 parent 99f00b1 commit 8c90bbd

4 files changed

Lines changed: 47 additions & 8 deletions

File tree

src/main/java/com/digitalsanctuary/spring/user/dev/DevLoginConfigProperties.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.digitalsanctuary.spring.user.dev;
22

33
import org.springframework.boot.context.properties.ConfigurationProperties;
4-
import org.springframework.context.annotation.PropertySource;
5-
import org.springframework.stereotype.Component;
64
import lombok.Data;
75

86
/**
@@ -17,8 +15,6 @@
1715
* </p>
1816
*/
1917
@Data
20-
@Component
21-
@PropertySource("classpath:config/dsspringuserconfig.properties")
2218
@ConfigurationProperties(prefix = "user.dev")
2319
public class DevLoginConfigProperties {
2420

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.digitalsanctuary.spring.user.dev;
2+
3+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
4+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.context.annotation.Profile;
7+
8+
/**
9+
* Configuration that registers {@link DevLoginConfigProperties}.
10+
* <p>
11+
* Activates only when the {@code local} profile is active and
12+
* {@code user.dev.auto-login-enabled=true}. Individual dev-login components
13+
* ({@link DevLoginController}, {@link DevLoginStartupWarning}) carry their own
14+
* guards for defense-in-depth.
15+
* </p>
16+
* <p>
17+
* Note: this class is registered via component scan (not Spring Boot SPI), so
18+
* default property values are provided by {@code WebAuthnConfiguration}, which
19+
* unconditionally loads {@code classpath:config/dsspringuserconfig.properties}.
20+
* </p>
21+
*/
22+
@Configuration
23+
@Profile("local")
24+
@ConditionalOnProperty(name = "user.dev.auto-login-enabled", havingValue = "true", matchIfMissing = false)
25+
@EnableConfigurationProperties(DevLoginConfigProperties.class)
26+
public class DevLoginConfiguration {
27+
}

src/main/java/com/digitalsanctuary/spring/user/security/WebAuthnConfigProperties.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22

33
import java.util.Set;
44
import org.springframework.boot.context.properties.ConfigurationProperties;
5-
import org.springframework.context.annotation.PropertySource;
6-
import org.springframework.stereotype.Component;
75
import lombok.Data;
86

97
/**
108
* Configuration properties for WebAuthn (Passkey) authentication.
119
*/
1210
@Data
13-
@Component
14-
@PropertySource("classpath:config/dsspringuserconfig.properties")
1511
@ConfigurationProperties(prefix = "user.webauthn")
1612
public class WebAuthnConfigProperties {
1713

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.digitalsanctuary.spring.user.security;
2+
3+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.context.annotation.PropertySource;
6+
7+
/**
8+
* Configuration that registers {@link WebAuthnConfigProperties}.
9+
* <p>
10+
* This configuration is always active because {@code WebSecurityConfig} requires
11+
* {@link WebAuthnConfigProperties} regardless of whether WebAuthn is enabled.
12+
* Individual WebAuthn components carry their own
13+
* {@code @ConditionalOnProperty(name = "user.webauthn.enabled")} guards.
14+
* </p>
15+
*/
16+
@Configuration
17+
@PropertySource("classpath:config/dsspringuserconfig.properties")
18+
@EnableConfigurationProperties(WebAuthnConfigProperties.class)
19+
public class WebAuthnConfiguration {
20+
}

0 commit comments

Comments
 (0)