|
42 | 42 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
43 | 43 | import org.springframework.security.config.test.SpringTestRule;
|
44 | 44 | import org.springframework.security.core.Authentication;
|
| 45 | +import org.springframework.security.core.AuthenticationException; |
45 | 46 | import org.springframework.security.core.userdetails.PasswordEncodedUser;
|
46 | 47 | import org.springframework.security.core.userdetails.UserDetailsService;
|
47 | 48 | import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
@@ -398,4 +399,30 @@ public AuthenticationEventPublisher authenticationEventPublisher() {
|
398 | 399 | return mock(AuthenticationEventPublisher.class);
|
399 | 400 | }
|
400 | 401 | }
|
| 402 | + |
| 403 | + // gh-4400 |
| 404 | + @Test |
| 405 | + public void performWhenUsingAuthenticationEventPublisherInDslThenUses() throws Exception { |
| 406 | + this.spring.register(CustomAuthenticationEventPublisherDsl.class).autowire(); |
| 407 | + |
| 408 | + AuthenticationEventPublisher authenticationEventPublisher = |
| 409 | + CustomAuthenticationEventPublisherDsl.EVENT_PUBLISHER; |
| 410 | + |
| 411 | + this.mockMvc.perform(get("/") |
| 412 | + .with(httpBasic("user", "password"))); // fails since no providers configured |
| 413 | + |
| 414 | + verify(authenticationEventPublisher).publishAuthenticationFailure( |
| 415 | + any(AuthenticationException.class), |
| 416 | + any(Authentication.class)); |
| 417 | + } |
| 418 | + |
| 419 | + @EnableWebSecurity |
| 420 | + static class CustomAuthenticationEventPublisherDsl extends WebSecurityConfigurerAdapter { |
| 421 | + static AuthenticationEventPublisher EVENT_PUBLISHER = mock(AuthenticationEventPublisher.class); |
| 422 | + |
| 423 | + @Override |
| 424 | + protected void configure(AuthenticationManagerBuilder auth) throws Exception { |
| 425 | + auth.authenticationEventPublisher(EVENT_PUBLISHER); |
| 426 | + } |
| 427 | + } |
401 | 428 | }
|
0 commit comments