Closed
Description
Summary
It doesn't appear possible to use AuthenticationManagerBuilder
config with Saml2LoginConfigurer
to provide a custom Authority extractor.
Actual Behavior
OpenSamlAuthenticationProvider
always uses the default implementation for authoritiesExtractor
. See https://github.com/spring-projects/spring-security/blob/master/config/src/main/java/org/springframework/security/config/annotation/web/configurers/saml2/Saml2LoginConfigurer.java#L216-L219
Expected Behavior
Use AuthenticationManagerBuilder
to provide OpenSamlAuthenticationProvider
with a custom Authority mapper & extractor.
Configuration
Converter<Assertion, Collection<? extends GrantedAuthority>> authoritiesExtractor = (a ->
singletonList(new SimpleGrantedAuthority("ROLE_SUPERUSER"))
);
GrantedAuthoritiesMapper authoritiesMapper = (a -> a);
protected void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
OpenSamlAuthenticationProvider samlAuthProvider = new OpenSamlAuthenticationProvider();
samlAuthProvider.setAuthoritiesExtractor(authoritiesExtractor);
samlAuthProvider.setAuthoritiesMapper(authoritiesMapper);
authenticationManagerBuilder.authenticationProvider(samlAuthProvider);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.saml2Login()
.relyingPartyRegistrationRepository(
new InMemoryRelyingPartyRegistrationRepository(
getSaml2AuthenticationConfiguration()
)
)
.successHandler(getCustomLoginSuccessHandler());
// @formatter:on
}
Version
- Spring 5.1.6.RELEASE
- Spring Security 5.2.1.RELEASE