I'm using spring-security-saml2-service-provider
to authenticate my SpringBoot webapp against a SAML IdP - this works. I can also access the SAML assertions within a REST Controller using @AuthenticationPrincipal Saml2AuthenticatedPrincipal principal
, but what I would like to do is restrict access by url using the values within the assertions within the Saml2AuthenticatedPrincipal principal - its a common approach within SAML federations to release values of eduPersonEntitlement, and decide access based on this. Has anyone done this? All my research/trials on this have come up with nothing.
Here's what I have so far:
@EnableWebSecurity
public class SAMLSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
RelyingPartyRegistrationRepository relyingPartyRegistrationRepository;
protected void configure(HttpSecurity http) throws Exception {
RelyingPartyRegistrationResolver relyingPartyRegistrationResolver =
new DefaultRelyingPartyRegistrationResolver(this.relyingPartyRegistrationRepository);
Saml2MetadataFilter filter = new Saml2MetadataFilter(relyingPartyRegistrationResolver, new OpenSamlMetadataResolver());
http
.saml2Login(withDefaults())
.addFilterBefore(filter, Saml2WebSsoAuthenticationFilter.class).antMatcher("/**")
.authorizeRequests()
.anyRequest().authenticated();
}
}
I think I need to swap out authenticated()
with something maybe to do with roles, and somehow set roles for users as they log in, but have got nowhere with this. Any ideas?