|
35 | 35 | import org.springframework.security.config.test.SpringTestContext;
|
36 | 36 | import org.springframework.security.config.test.SpringTestContextExtension;
|
37 | 37 | import org.springframework.security.core.authority.AuthorityUtils;
|
| 38 | +import org.springframework.security.core.context.SecurityContextHolderStrategy; |
38 | 39 | import org.springframework.security.saml2.core.Saml2Utils;
|
39 | 40 | import org.springframework.security.saml2.provider.service.authentication.DefaultSaml2AuthenticatedPrincipal;
|
40 | 41 | import org.springframework.security.saml2.provider.service.authentication.Saml2Authentication;
|
|
63 | 64 | import static org.hamcrest.Matchers.containsString;
|
64 | 65 | import static org.mockito.ArgumentMatchers.any;
|
65 | 66 | import static org.mockito.BDDMockito.given;
|
| 67 | +import static org.mockito.Mockito.atLeastOnce; |
66 | 68 | import static org.mockito.Mockito.verify;
|
67 | 69 | import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication;
|
68 | 70 | import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
|
@@ -233,6 +235,23 @@ public void saml2LogoutRequestWhenDefaultsThenLogsOutAndSendsLogoutResponse() th
|
233 | 235 | assertThat(location).startsWith("https://ap.example.org/logout/saml2/response");
|
234 | 236 | }
|
235 | 237 |
|
| 238 | + @Test |
| 239 | + public void saml2LogoutRequestWhenCustomSecurityContextHolderStrategyThenUses() throws Exception { |
| 240 | + this.spring.configLocations(this.xml("WithSecurityContextHolderStrategy")).autowire(); |
| 241 | + DefaultSaml2AuthenticatedPrincipal principal = new DefaultSaml2AuthenticatedPrincipal("user", |
| 242 | + Collections.emptyMap()); |
| 243 | + principal.setRelyingPartyRegistrationId("get"); |
| 244 | + Saml2Authentication user = new Saml2Authentication(principal, "response", |
| 245 | + AuthorityUtils.createAuthorityList("ROLE_USER")); |
| 246 | + MvcResult result = this.mvc.perform(get("/logout/saml2/slo").param("SAMLRequest", this.apLogoutRequest) |
| 247 | + .param("RelayState", this.apLogoutRequestRelayState).param("SigAlg", this.apLogoutRequestSigAlg) |
| 248 | + .param("Signature", this.apLogoutRequestSignature).with(samlQueryString()).with(authentication(user))) |
| 249 | + .andExpect(status().isFound()).andReturn(); |
| 250 | + String location = result.getResponse().getHeader("Location"); |
| 251 | + assertThat(location).startsWith("https://ap.example.org/logout/saml2/response"); |
| 252 | + verify(getBean(SecurityContextHolderStrategy.class), atLeastOnce()).getContext(); |
| 253 | + } |
| 254 | + |
236 | 255 | @Test
|
237 | 256 | public void saml2LogoutRequestWhenNoRegistrationThen400() throws Exception {
|
238 | 257 | this.spring.configLocations(this.xml("Default")).autowire();
|
|
0 commit comments