Summary
Refactor WebSecurityConfig.setupWebAuthn() to remove the inline, fully-qualified anonymous ObjectPostProcessor used only to set the WebAuthnAuthenticationSuccessHandler.
Current implementation works, but it is noisy and harder to maintain than necessary.
Context
During PR review, we identified a low-priority cleanup item in:
src/main/java/com/digitalsanctuary/spring/user/security/WebSecurityConfig.java
The current code block (around setupWebAuthn) has this pattern:
withObjectPostProcessor(new org.springframework.security.config.ObjectPostProcessor<org.springframework.security.web.webauthn.authentication.WebAuthnAuthenticationFilter>() { ... })
- The anonymous class only does one thing:
filter.setAuthenticationSuccessHandler(new WebAuthnAuthenticationSuccessHandler(userDetailsService));
Why this matters
The current approach is functionally correct, but has avoidable maintenance cost:
- Readability: fully-qualified types + anonymous class add visual noise in core security config.
- Change safety: success-handler wiring is buried inside inline boilerplate.
- Consistency: the rest of
WebSecurityConfig is mostly concise and method-extracted.
Goals
- Preserve current runtime behavior exactly.
- Reduce verbosity and improve local readability.
- Make the success-handler wiring explicit and easy to test/adjust.
Proposed Refactor
- Add imports for:
org.springframework.security.config.ObjectPostProcessor
org.springframework.security.web.webauthn.authentication.WebAuthnAuthenticationFilter
- Extract post-processing logic from inline anonymous class into a small helper method (or bean), for example:
private ObjectPostProcessor<WebAuthnAuthenticationFilter> webAuthnSuccessHandlerPostProcessor()
- In
setupWebAuthn(), replace inline anonymous class with:
.withObjectPostProcessor(webAuthnSuccessHandlerPostProcessor())
- Optionally extract success-handler construction so
new WebAuthnAuthenticationSuccessHandler(userDetailsService) is not inline.
Acceptance Criteria
- No fully-qualified
ObjectPostProcessor<WebAuthnAuthenticationFilter> anonymous class remains in setupWebAuthn().
- Behavior remains unchanged:
- WebAuthn authentication still installs
WebAuthnAuthenticationSuccessHandler.
- Existing WebAuthn tests continue to pass.
- Code compiles and tests pass:
./gradlew compileJava compileTestJava
./gradlew test --tests '*WebAuthn*'
Non-Goals
- No change to WebAuthn feature flags/conditionals.
- No change to WebAuthn endpoint behavior or API error handling.
- No broader security-chain redesign.
Suggested Validation
- Run existing WebAuthn tests:
WebAuthnAuthenticationSuccessHandlerTest
WebAuthnManagementAPITest
WebAuthnFeatureEnabledIntegrationTest
WebAuthnFeatureDisabledIntegrationTest
- Optionally run full suite if touching neighboring config code.
Priority
Low (code quality/refactor only, no functional defect).
Summary
Refactor
WebSecurityConfig.setupWebAuthn()to remove the inline, fully-qualified anonymousObjectPostProcessorused only to set theWebAuthnAuthenticationSuccessHandler.Current implementation works, but it is noisy and harder to maintain than necessary.
Context
During PR review, we identified a low-priority cleanup item in:
src/main/java/com/digitalsanctuary/spring/user/security/WebSecurityConfig.javaThe current code block (around
setupWebAuthn) has this pattern:withObjectPostProcessor(new org.springframework.security.config.ObjectPostProcessor<org.springframework.security.web.webauthn.authentication.WebAuthnAuthenticationFilter>() { ... })filter.setAuthenticationSuccessHandler(new WebAuthnAuthenticationSuccessHandler(userDetailsService));Why this matters
The current approach is functionally correct, but has avoidable maintenance cost:
WebSecurityConfigis mostly concise and method-extracted.Goals
Proposed Refactor
org.springframework.security.config.ObjectPostProcessororg.springframework.security.web.webauthn.authentication.WebAuthnAuthenticationFilterprivate ObjectPostProcessor<WebAuthnAuthenticationFilter> webAuthnSuccessHandlerPostProcessor()setupWebAuthn(), replace inline anonymous class with:.withObjectPostProcessor(webAuthnSuccessHandlerPostProcessor())new WebAuthnAuthenticationSuccessHandler(userDetailsService)is not inline.Acceptance Criteria
ObjectPostProcessor<WebAuthnAuthenticationFilter>anonymous class remains insetupWebAuthn().WebAuthnAuthenticationSuccessHandler../gradlew compileJava compileTestJava./gradlew test --tests '*WebAuthn*'Non-Goals
Suggested Validation
WebAuthnAuthenticationSuccessHandlerTestWebAuthnManagementAPITestWebAuthnFeatureEnabledIntegrationTestWebAuthnFeatureDisabledIntegrationTestPriority
Low (code quality/refactor only, no functional defect).