Spring Security - Custom matcher to get RegistrationId

Viewed 32

So we're updating to the newest spring security (5.7.3 as this time) and I have it working for grabbing my registrationId from the path (we use IDP initiated SSO), e.g. https://company.com/saml/someregid

What I'd like to do now is grab the registrationId from the subdomain e.g. https://someregid.company.com/saml/SSO

I've been learning as I go, so I'm hoping there's a way to specify a custom matcher to use to grab the registrationId. I see the code I'd like to affect in Saml2WebSsoAuthenticationFilter in it's call to Authentication authentication = this.authenticationConverter.convert(request); which seems to use DefaultRelyingPartyRegistrationResolver which uses an AntPathRequestMatcher.

That matcher just uses String url = getRequestPath(request) which tries to match just on /saml/SSO in this case, so I was thinking if I could use my own matcher, I could use request.getRequestURL() in my matcher to find the registrationId.

My current working configuration is:

http
            .authorizeRequests()
            .antMatchers("/authorized").hasRole("USER")
            .anyRequest()
            .authenticated()
            .and()
            .saml2Login()
            .successHandler(new MySamlLoginSuccessHandler())
            .loginProcessingUrl("/saml/{registrationId}"); // setting this must include {registrationId}

      SecurityFilterChain chain = http.build();

      return chain;

Thanks!

0 Answers
Related