|
17 | 17 | import org.springframework.security.authentication.AuthenticationEventPublisher; |
18 | 18 | import org.springframework.security.authentication.DefaultAuthenticationEventPublisher; |
19 | 19 | import org.springframework.security.authentication.dao.DaoAuthenticationProvider; |
| 20 | +import org.springframework.security.config.ObjectPostProcessor; |
20 | 21 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
21 | 22 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; |
22 | 23 | import org.springframework.security.core.session.SessionRegistry; |
|
26 | 27 | import org.springframework.security.crypto.password.PasswordEncoder; |
27 | 28 | import org.springframework.security.web.SecurityFilterChain; |
28 | 29 | import org.springframework.security.web.session.HttpSessionEventPublisher; |
| 30 | +import org.springframework.security.web.webauthn.authentication.WebAuthnAuthenticationFilter; |
29 | 31 | import com.digitalsanctuary.spring.user.roles.RolesAndPrivilegesConfig; |
30 | 32 | import com.digitalsanctuary.spring.user.service.DSOAuth2UserService; |
31 | 33 | import com.digitalsanctuary.spring.user.service.DSOidcUserService; |
@@ -224,15 +226,22 @@ private void setupWebAuthn(HttpSecurity http) throws Exception { |
224 | 226 |
|
225 | 227 | http.webAuthn(webAuthn -> webAuthn.rpName(webAuthnConfigProperties.getRpName()).rpId(webAuthnConfigProperties.getRpId()) |
226 | 228 | .allowedOrigins(normalizedAllowedOrigins) |
227 | | - .withObjectPostProcessor( |
228 | | - new org.springframework.security.config.ObjectPostProcessor<org.springframework.security.web.webauthn.authentication.WebAuthnAuthenticationFilter>() { |
229 | | - @Override |
230 | | - public <O extends org.springframework.security.web.webauthn.authentication.WebAuthnAuthenticationFilter> O postProcess( |
231 | | - O filter) { |
232 | | - filter.setAuthenticationSuccessHandler(new WebAuthnAuthenticationSuccessHandler(userDetailsService)); |
233 | | - return filter; |
234 | | - } |
235 | | - })); |
| 229 | + .withObjectPostProcessor(webAuthnSuccessHandlerPostProcessor())); |
| 230 | + } |
| 231 | + |
| 232 | + /** |
| 233 | + * Creates an ObjectPostProcessor that sets our custom WebAuthn success handler on the WebAuthnAuthenticationFilter. |
| 234 | + * |
| 235 | + * @return an ObjectPostProcessor that injects a custom authentication success handler |
| 236 | + */ |
| 237 | + private ObjectPostProcessor<WebAuthnAuthenticationFilter> webAuthnSuccessHandlerPostProcessor() { |
| 238 | + return new ObjectPostProcessor<WebAuthnAuthenticationFilter>() { |
| 239 | + @Override |
| 240 | + public <O extends WebAuthnAuthenticationFilter> O postProcess(O filter) { |
| 241 | + filter.setAuthenticationSuccessHandler(new WebAuthnAuthenticationSuccessHandler(userDetailsService)); |
| 242 | + return filter; |
| 243 | + } |
| 244 | + }; |
236 | 245 | } |
237 | 246 |
|
238 | 247 | // Commenting this out to try adding /error to the unprotected URIs list instead |
|
0 commit comments