@ -29,6 +29,7 @@ import org.springframework.security.saml2.provider.service.registration.RelyingP
@@ -29,6 +29,7 @@ import org.springframework.security.saml2.provider.service.registration.RelyingP
import org.springframework.security.saml2.provider.service.registration.Saml2MessageBinding ;
import org.springframework.security.saml2.provider.service.registration.TestRelyingPartyRegistrations ;
import org.springframework.security.saml2.provider.service.web.RelyingPartyRegistrationResolver ;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.mockito.ArgumentMatchers.any ;
@ -44,8 +45,7 @@ public class OpenSaml4AuthenticationRequestResolverTests {
@@ -44,8 +45,7 @@ public class OpenSaml4AuthenticationRequestResolverTests {
@BeforeEach
void setup ( ) {
this . request = new MockHttpServletRequest ( ) ;
this . request . setServletPath ( "/saml2/authenticate/registration-id" ) ;
this . request = givenRequest ( "/saml2/authenticate/registration-id" ) ;
this . registration = TestRelyingPartyRegistrations . full ( ) . build ( ) ;
}
@ -86,4 +86,25 @@ public class OpenSaml4AuthenticationRequestResolverTests {
@@ -86,4 +86,25 @@ public class OpenSaml4AuthenticationRequestResolverTests {
verify ( relayState ) . convert ( any ( ) ) ;
}
@Test
void resolveWhenCustomAuthenticationUrlTHenUses ( ) {
RelyingPartyRegistrationResolver relyingParties = mock ( RelyingPartyRegistrationResolver . class ) ;
given ( relyingParties . resolve ( any ( ) , any ( ) ) ) . willReturn ( this . registration ) ;
OpenSaml4AuthenticationRequestResolver resolver = new OpenSaml4AuthenticationRequestResolver ( relyingParties ) ;
resolver . setRequestMatcher ( new AntPathRequestMatcher ( "/custom/authentication/{registrationId}" ) ) ;
Saml2RedirectAuthenticationRequest authnRequest = resolver
. resolve ( givenRequest ( "/custom/authentication/registration-id" ) ) ;
assertThat ( authnRequest . getBinding ( ) ) . isEqualTo ( Saml2MessageBinding . REDIRECT ) ;
assertThat ( authnRequest . getAuthenticationRequestUri ( ) )
. isEqualTo ( this . registration . getAssertingPartyDetails ( ) . getSingleSignOnServiceLocation ( ) ) ;
}
private MockHttpServletRequest givenRequest ( String path ) {
MockHttpServletRequest request = new MockHttpServletRequest ( ) ;
request . setServletPath ( path ) ;
return request ;
}
}