|
@@ -22,26 +22,14 @@ import org.junit.Assert;
|
|
|
import org.junit.Before;
|
|
|
import org.junit.Test;
|
|
|
|
|
|
-import org.springframework.mock.web.MockFilterChain;
|
|
|
import org.springframework.mock.web.MockHttpServletRequest;
|
|
|
import org.springframework.mock.web.MockHttpServletResponse;
|
|
|
-import org.springframework.security.authentication.AuthenticationManager;
|
|
|
-import org.springframework.security.authentication.TestingAuthenticationToken;
|
|
|
-import org.springframework.security.core.Authentication;
|
|
|
import org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationException;
|
|
|
-import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration;
|
|
|
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository;
|
|
|
-import org.springframework.security.saml2.provider.service.registration.TestRelyingPartyRegistrations;
|
|
|
-import org.springframework.security.saml2.provider.service.web.DefaultRelyingPartyRegistrationResolver;
|
|
|
-import org.springframework.security.saml2.provider.service.web.RelyingPartyRegistrationResolver;
|
|
|
-import org.springframework.security.saml2.provider.service.web.Saml2AuthenticationTokenConverter;
|
|
|
-import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
|
|
-import org.springframework.security.web.util.matcher.RequestMatcher;
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
|
import static org.mockito.BDDMockito.given;
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
-import static org.mockito.Mockito.verify;
|
|
|
|
|
|
public class Saml2WebSsoAuthenticationFilterTests {
|
|
|
|
|
@@ -53,8 +41,6 @@ public class Saml2WebSsoAuthenticationFilterTests {
|
|
|
|
|
|
private HttpServletResponse response = new MockHttpServletResponse();
|
|
|
|
|
|
- private AuthenticationManager authenticationManager = mock(AuthenticationManager.class);
|
|
|
-
|
|
|
@Before
|
|
|
public void setup() {
|
|
|
this.filter = new Saml2WebSsoAuthenticationFilter(this.repository);
|
|
@@ -98,26 +84,4 @@ public class Saml2WebSsoAuthenticationFilterTests {
|
|
|
.withMessage("No relying party registration found");
|
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
- public void doFilterWhenPathStartsWithRegistrationIdThenAuthenticates() throws Exception {
|
|
|
- RelyingPartyRegistration registration = TestRelyingPartyRegistrations.full().build();
|
|
|
- Authentication authentication = new TestingAuthenticationToken("user", "password");
|
|
|
- given(this.repository.findByRegistrationId("registration-id")).willReturn(registration);
|
|
|
- given(this.authenticationManager.authenticate(authentication)).willReturn(authentication);
|
|
|
- String loginProcessingUrl = "/{registrationId}/login/saml2/sso";
|
|
|
- RequestMatcher matcher = new AntPathRequestMatcher(loginProcessingUrl);
|
|
|
- DefaultRelyingPartyRegistrationResolver delegate = new DefaultRelyingPartyRegistrationResolver(this.repository);
|
|
|
- RelyingPartyRegistrationResolver resolver = (request, id) -> {
|
|
|
- String registrationId = matcher.matcher(request).getVariables().get("registrationId");
|
|
|
- return delegate.resolve(request, registrationId);
|
|
|
- };
|
|
|
- Saml2AuthenticationTokenConverter authenticationConverter = new Saml2AuthenticationTokenConverter(resolver);
|
|
|
- this.filter = new Saml2WebSsoAuthenticationFilter(authenticationConverter, loginProcessingUrl);
|
|
|
- this.filter.setAuthenticationManager(this.authenticationManager);
|
|
|
- this.request.setPathInfo("/registration-id/login/saml2/sso");
|
|
|
- this.request.setParameter("SAMLResponse", "response");
|
|
|
- this.filter.doFilter(this.request, this.response, new MockFilterChain());
|
|
|
- verify(this.repository).findByRegistrationId("registration-id");
|
|
|
- }
|
|
|
-
|
|
|
}
|