|
27 | 27 | import com.webauthn4j.metadata.*; |
28 | 28 | import com.webauthn4j.metadata.converter.jackson.WebAuthnMetadataJSONModule; |
29 | 29 | import com.webauthn4j.springframework.security.WebAuthnRegistrationRequestValidator; |
| 30 | +import com.webauthn4j.springframework.security.authenticator.InMemoryWebAuthnAuthenticatorManager; |
| 31 | +import com.webauthn4j.springframework.security.authenticator.WebAuthnAuthenticatorManager; |
30 | 32 | import com.webauthn4j.springframework.security.authenticator.WebAuthnAuthenticatorService; |
31 | 33 | import com.webauthn4j.springframework.security.challenge.ChallengeRepository; |
32 | 34 | import com.webauthn4j.springframework.security.challenge.HttpSessionChallengeRepository; |
|
53 | 55 | import org.springframework.core.io.Resource; |
54 | 56 | import org.springframework.core.io.ResourceLoader; |
55 | 57 | import org.springframework.core.io.support.ResourcePatternUtils; |
56 | | -import org.springframework.security.access.AccessDeniedException; |
57 | 58 | import org.springframework.security.authentication.AuthenticationTrustResolver; |
58 | 59 | import org.springframework.security.authentication.AuthenticationTrustResolverImpl; |
59 | 60 | import org.springframework.security.authentication.dao.DaoAuthenticationProvider; |
60 | | -import org.springframework.security.core.AuthenticationException; |
61 | 61 | import org.springframework.security.core.userdetails.UserDetailsService; |
62 | 62 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
63 | 63 | import org.springframework.security.crypto.password.PasswordEncoder; |
64 | | -import org.springframework.security.web.AuthenticationEntryPoint; |
65 | | -import org.springframework.security.web.access.AccessDeniedHandler; |
66 | | -import org.springframework.security.web.access.AccessDeniedHandlerImpl; |
67 | | -import org.springframework.security.web.access.DelegatingAccessDeniedHandler; |
68 | | -import org.springframework.security.web.authentication.*; |
69 | | -import org.springframework.security.web.authentication.logout.ForwardLogoutSuccessHandler; |
70 | | -import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; |
71 | | -import org.springframework.security.web.csrf.InvalidCsrfTokenException; |
72 | | -import org.springframework.security.web.csrf.MissingCsrfTokenException; |
| 64 | +import org.springframework.security.provisioning.InMemoryUserDetailsManager; |
| 65 | +import org.springframework.security.provisioning.UserDetailsManager; |
73 | 66 | import org.springframework.web.client.RestTemplate; |
74 | 67 |
|
75 | 68 | import java.io.IOException; |
76 | 69 | import java.security.cert.X509Certificate; |
77 | 70 | import java.util.ArrayList; |
78 | 71 | import java.util.Arrays; |
79 | | -import java.util.LinkedHashMap; |
80 | 72 | import java.util.List; |
81 | 73 |
|
82 | 74 | @Configuration |
83 | 75 | public class WebSecurityBeanConfig { |
84 | 76 |
|
| 77 | + @Bean |
| 78 | + public WebAuthnAuthenticatorManager webAuthnAuthenticatorManager(){ |
| 79 | + return new InMemoryWebAuthnAuthenticatorManager(); |
| 80 | + } |
| 81 | + |
| 82 | + @Bean |
| 83 | + public UserDetailsManager userDetailsManager(){ |
| 84 | + return new InMemoryUserDetailsManager(); |
| 85 | + } |
| 86 | + |
85 | 87 | @Bean |
86 | 88 | public WebAuthnRegistrationRequestValidator webAuthnRegistrationRequestValidator(WebAuthnManager webAuthnManager, ServerPropertyProvider serverPropertyProvider) { |
87 | 89 | return new WebAuthnRegistrationRequestValidator(webAuthnManager, serverPropertyProvider); |
@@ -242,57 +244,4 @@ public ObjectConverter objectConverter() { |
242 | 244 | return new ObjectConverter(jsonMapper, cborMapper); |
243 | 245 | } |
244 | 246 |
|
245 | | - |
246 | | - @Bean |
247 | | - public AuthenticationSuccessHandler authenticationSuccessHandler() { |
248 | | - return new ForwardAuthenticationSuccessHandler("/api/status/200"); |
249 | | - } |
250 | | - |
251 | | - @Bean |
252 | | - public AuthenticationFailureHandler authenticationFailureHandler() { |
253 | | - LinkedHashMap<Class<? extends AuthenticationException>, AuthenticationFailureHandler> authenticationFailureHandlers = new LinkedHashMap<>(); |
254 | | - |
255 | | - // authenticator error handler |
256 | | - ForwardAuthenticationFailureHandler authenticationFailureHandler = new ForwardAuthenticationFailureHandler("/api/status/401"); |
257 | | - authenticationFailureHandlers.put(AuthenticationException.class, authenticationFailureHandler); |
258 | | - |
259 | | - // default error handler |
260 | | - AuthenticationFailureHandler defaultAuthenticationFailureHandler = new ForwardAuthenticationFailureHandler("/api/status/401"); |
261 | | - |
262 | | - return new DelegatingAuthenticationFailureHandler(authenticationFailureHandlers, defaultAuthenticationFailureHandler); |
263 | | - } |
264 | | - |
265 | | - @Bean |
266 | | - public LogoutSuccessHandler logoutSuccessHandler() { |
267 | | - return new ForwardLogoutSuccessHandler("/api/status/200"); |
268 | | - } |
269 | | - |
270 | | - @Bean |
271 | | - public AccessDeniedHandler accessDeniedHandler() { |
272 | | - LinkedHashMap<Class<? extends AccessDeniedException>, AccessDeniedHandler> errorHandlers = new LinkedHashMap<>(); |
273 | | - |
274 | | - // invalid csrf authenticator error handler |
275 | | - AccessDeniedHandlerImpl invalidCsrfTokenErrorHandler = new AccessDeniedHandlerImpl(); |
276 | | - invalidCsrfTokenErrorHandler.setErrorPage("/api/status/403"); |
277 | | - errorHandlers.put(InvalidCsrfTokenException.class, invalidCsrfTokenErrorHandler); |
278 | | - |
279 | | - // missing csrf authenticator error handler |
280 | | - AccessDeniedHandlerImpl missingCsrfTokenErrorHandler = new AccessDeniedHandlerImpl(); |
281 | | - missingCsrfTokenErrorHandler.setErrorPage("/api/status/403"); |
282 | | - errorHandlers.put(MissingCsrfTokenException.class, missingCsrfTokenErrorHandler); |
283 | | - |
284 | | - // default error handler |
285 | | - AccessDeniedHandlerImpl defaultErrorHandler = new AccessDeniedHandlerImpl(); |
286 | | - defaultErrorHandler.setErrorPage("/api/status/403"); |
287 | | - |
288 | | - return new DelegatingAccessDeniedHandler(errorHandlers, defaultErrorHandler); |
289 | | - } |
290 | | - |
291 | | - @Bean |
292 | | - public AuthenticationEntryPoint authenticationEntryPoint() { |
293 | | - LoginUrlAuthenticationEntryPoint authenticationEntryPoint = new LoginUrlAuthenticationEntryPoint("/api/status/401"); |
294 | | - authenticationEntryPoint.setUseForward(true); |
295 | | - return authenticationEntryPoint; |
296 | | - } |
297 | | - |
298 | 247 | } |
0 commit comments