Skip to content

Commit 0928a60

Browse files
committed
Post Process WebAuthnAuthenticationFilter
This commit ensures that WebAuthnAuthenticationFilter is post processed by BeanPostProcessors and ObjectPostProcessor. Closes gh-18128
1 parent 322634c commit 0928a60

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

config/src/main/java/org/springframework/security/config/annotation/web/configurers/WebAuthnConfigurer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ public void configure(H http) {
177177
WebAuthnAuthenticationFilter webAuthnAuthnFilter = new WebAuthnAuthenticationFilter();
178178
webAuthnAuthnFilter.setAuthenticationManager(
179179
new ProviderManager(new WebAuthnAuthenticationProvider(rpOperations, userDetailsService)));
180+
webAuthnAuthnFilter = postProcess(webAuthnAuthnFilter);
180181
WebAuthnRegistrationFilter webAuthnRegistrationFilter = new WebAuthnRegistrationFilter(userCredentials,
181182
rpOperations);
182183
PublicKeyCredentialCreationOptionsFilter creationOptionsFilter = new PublicKeyCredentialCreationOptionsFilter(

config/src/test/java/org/springframework/security/config/annotation/web/configurers/WebAuthnConfigurerTests.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.junit.jupiter.api.extension.ExtendWith;
2424

2525
import org.springframework.beans.factory.annotation.Autowired;
26+
import org.springframework.beans.factory.config.BeanPostProcessor;
2627
import org.springframework.context.annotation.Bean;
2728
import org.springframework.context.annotation.Configuration;
2829
import org.springframework.http.HttpOutputMessage;
@@ -42,6 +43,7 @@
4243
import org.springframework.security.web.authentication.ui.DefaultResourcesFilter;
4344
import org.springframework.security.web.webauthn.api.PublicKeyCredentialCreationOptions;
4445
import org.springframework.security.web.webauthn.api.TestPublicKeyCredentialCreationOptions;
46+
import org.springframework.security.web.webauthn.authentication.WebAuthnAuthenticationFilter;
4547
import org.springframework.security.web.webauthn.management.WebAuthnRelyingPartyOperations;
4648
import org.springframework.security.web.webauthn.registration.HttpSessionPublicKeyCredentialCreationOptionsRepository;
4749
import org.springframework.test.web.servlet.MockMvc;
@@ -88,6 +90,14 @@ public void webauthnWhenConfiguredConfiguredThenServesCss() throws Exception {
8890
.andExpect(content().string(containsString("body {")));
8991
}
9092

93+
// gh-18128
94+
@Test
95+
public void webAuthnAuthenticationFilterIsPostProcessed() throws Exception {
96+
this.spring.register(DefaultWebauthnConfiguration.class, PostProcessorConfiguration.class).autowire();
97+
PostProcessorConfiguration postProcess = this.spring.getContext().getBean(PostProcessorConfiguration.class);
98+
assertThat(postProcess.webauthnFilter).isNotNull();
99+
}
100+
91101
@Test
92102
public void webauthnWhenNoFormLoginAndDefaultRegistrationPageConfiguredThenServesJavascript() throws Exception {
93103
this.spring.register(NoFormLoginAndDefaultRegistrationPageConfiguration.class).autowire();
@@ -289,6 +299,26 @@ SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
289299

290300
}
291301

302+
@Configuration(proxyBeanMethods = false)
303+
static class PostProcessorConfiguration {
304+
305+
WebAuthnAuthenticationFilter webauthnFilter;
306+
307+
@Bean
308+
BeanPostProcessor beanPostProcessor() {
309+
return new BeanPostProcessor() {
310+
@Override
311+
public Object postProcessAfterInitialization(Object bean, String beanName) {
312+
if (bean instanceof WebAuthnAuthenticationFilter filter) {
313+
PostProcessorConfiguration.this.webauthnFilter = filter;
314+
}
315+
return bean;
316+
}
317+
};
318+
}
319+
320+
}
321+
292322
@Configuration
293323
@EnableWebSecurity
294324
static class DefaultWebauthnConfiguration {

0 commit comments

Comments
 (0)