Skip to content

Custom SAML Authority Extractor #7642

Closed
@mftruso

Description

@mftruso

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

Sample

https://github.com/mftruso/spring-security-saml-example/blob/master/src/main/java/com/miketruso/springsecurity/saml/demo/config/SecurityConfig.java

Metadata

Metadata

Assignees

Labels

in: saml2An issue in SAML2 modulesstatus: duplicateA duplicate of another issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions