mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-01 09:42:13 +00:00
AuthenticationEventPublisher DSL Lookup
Fixes gh-4400
This commit is contained in:
parent
5579846263
commit
f1f158b37e
@ -201,7 +201,6 @@ public abstract class WebSecurityConfigurerAdapter implements
|
|||||||
|
|
||||||
AuthenticationManager authenticationManager = authenticationManager();
|
AuthenticationManager authenticationManager = authenticationManager();
|
||||||
authenticationBuilder.parentAuthenticationManager(authenticationManager);
|
authenticationBuilder.parentAuthenticationManager(authenticationManager);
|
||||||
authenticationBuilder.authenticationEventPublisher(eventPublisher);
|
|
||||||
Map<Class<?>, Object> sharedObjects = createSharedObjects();
|
Map<Class<?>, Object> sharedObjects = createSharedObjects();
|
||||||
|
|
||||||
http = new HttpSecurity(objectPostProcessor, authenticationBuilder,
|
http = new HttpSecurity(objectPostProcessor, authenticationBuilder,
|
||||||
@ -383,6 +382,11 @@ public abstract class WebSecurityConfigurerAdapter implements
|
|||||||
return super.eraseCredentials(eraseCredentials);
|
return super.eraseCredentials(eraseCredentials);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AuthenticationManagerBuilder authenticationEventPublisher(AuthenticationEventPublisher eventPublisher) {
|
||||||
|
authenticationBuilder.authenticationEventPublisher(eventPublisher);
|
||||||
|
return super.authenticationEventPublisher(eventPublisher);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ import org.springframework.security.config.annotation.web.configuration.EnableWe
|
|||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||||
import org.springframework.security.config.test.SpringTestRule;
|
import org.springframework.security.config.test.SpringTestRule;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.security.core.AuthenticationException;
|
||||||
import org.springframework.security.core.userdetails.PasswordEncodedUser;
|
import org.springframework.security.core.userdetails.PasswordEncodedUser;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
@ -398,4 +399,30 @@ public class WebSecurityConfigurerAdapterTests {
|
|||||||
return mock(AuthenticationEventPublisher.class);
|
return mock(AuthenticationEventPublisher.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// gh-4400
|
||||||
|
@Test
|
||||||
|
public void performWhenUsingAuthenticationEventPublisherInDslThenUses() throws Exception {
|
||||||
|
this.spring.register(CustomAuthenticationEventPublisherDsl.class).autowire();
|
||||||
|
|
||||||
|
AuthenticationEventPublisher authenticationEventPublisher =
|
||||||
|
CustomAuthenticationEventPublisherDsl.EVENT_PUBLISHER;
|
||||||
|
|
||||||
|
this.mockMvc.perform(get("/")
|
||||||
|
.with(httpBasic("user", "password"))); // fails since no providers configured
|
||||||
|
|
||||||
|
verify(authenticationEventPublisher).publishAuthenticationFailure(
|
||||||
|
any(AuthenticationException.class),
|
||||||
|
any(Authentication.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@EnableWebSecurity
|
||||||
|
static class CustomAuthenticationEventPublisherDsl extends WebSecurityConfigurerAdapter {
|
||||||
|
static AuthenticationEventPublisher EVENT_PUBLISHER = mock(AuthenticationEventPublisher.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||||
|
auth.authenticationEventPublisher(EVENT_PUBLISHER);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user