|
34 | 34 | import org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException; |
35 | 35 | import org.springframework.security.config.test.SpringTestContext; |
36 | 36 | import org.springframework.security.config.test.SpringTestContextExtension; |
37 | | -import org.springframework.security.core.Authentication; |
38 | | -import org.springframework.security.web.session.SessionLimitStrategy; |
39 | 37 | import org.springframework.test.web.servlet.MockMvc; |
40 | 38 | import org.springframework.test.web.servlet.ResultMatcher; |
41 | 39 | import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; |
@@ -842,69 +840,6 @@ public void requestWhenSessionManagementConcurrencyControlMaxSessionIsUnlimited( |
842 | 840 | assertThat(firstSession.getId()).isNotEqualTo(secondSession.getId()); |
843 | 841 | } |
844 | 842 |
|
845 | | - @Test |
846 | | - public void requestWhenSessionManagementConcurrencyControlMaxSessionRefIsOneForNonAdminUsers() throws Exception { |
847 | | - this.spring.configLocations(this.xml("DefaultsSessionManagementConcurrencyControlMaxSessionsRef")).autowire(); |
848 | | - // @formatter:off |
849 | | - MockHttpServletRequestBuilder requestBuilder = post("/login") |
850 | | - .with(csrf()) |
851 | | - .param("username", "user") |
852 | | - .param("password", "password"); |
853 | | - HttpSession firstSession = this.mvc.perform(requestBuilder) |
854 | | - .andExpect(status().is3xxRedirection()) |
855 | | - .andExpect(redirectedUrl("/")) |
856 | | - .andReturn() |
857 | | - .getRequest() |
858 | | - .getSession(false); |
859 | | - // @formatter:on |
860 | | - assertThat(firstSession).isNotNull(); |
861 | | - // @formatter:off |
862 | | - this.mvc.perform(requestBuilder) |
863 | | - .andExpect(status().isFound()) |
864 | | - .andExpect(redirectedUrl("/login?error")); |
865 | | - // @formatter:on |
866 | | - } |
867 | | - |
868 | | - @Test |
869 | | - public void requestWhenSessionManagementConcurrencyControlMaxSessionRefIsTwoForAdminUsers() throws Exception { |
870 | | - this.spring.configLocations(this.xml("DefaultsSessionManagementConcurrencyControlMaxSessionsRef")).autowire(); |
871 | | - // @formatter:off |
872 | | - MockHttpServletRequestBuilder requestBuilder = post("/login") |
873 | | - .with(csrf()) |
874 | | - .param("username", "admin") |
875 | | - .param("password", "password"); |
876 | | - HttpSession firstSession = this.mvc.perform(requestBuilder) |
877 | | - .andExpect(status().is3xxRedirection()) |
878 | | - .andExpect(redirectedUrl("/")) |
879 | | - .andReturn() |
880 | | - .getRequest() |
881 | | - .getSession(false); |
882 | | - assertThat(firstSession).isNotNull(); |
883 | | - HttpSession secondSession = this.mvc.perform(requestBuilder) |
884 | | - .andExpect(status().is3xxRedirection()) |
885 | | - .andExpect(redirectedUrl("/")) |
886 | | - .andReturn() |
887 | | - .getRequest() |
888 | | - .getSession(false); |
889 | | - assertThat(secondSession).isNotNull(); |
890 | | - // @formatter:on |
891 | | - assertThat(firstSession.getId()).isNotEqualTo(secondSession.getId()); |
892 | | - // @formatter:off |
893 | | - this.mvc.perform(requestBuilder) |
894 | | - .andExpect(status().isFound()) |
895 | | - .andExpect(redirectedUrl("/login?error")); |
896 | | - // @formatter:on |
897 | | - } |
898 | | - |
899 | | - @Test |
900 | | - public void requestWhenSessionManagementConcurrencyControlWithInvalidMaxSessionConfig() { |
901 | | - assertThatExceptionOfType(BeanDefinitionParsingException.class) |
902 | | - .isThrownBy(() -> this.spring |
903 | | - .configLocations(this.xml("DefaultsSessionManagementConcurrencyControlWithInvalidMaxSessionsConfig")) |
904 | | - .autowire()) |
905 | | - .withMessageContaining("Cannot use 'max-sessions' attribute and 'max-sessions-ref' attribute together."); |
906 | | - } |
907 | | - |
908 | 843 | private static ResultMatcher includesDefaults() { |
909 | 844 | return includes(defaultHeaders); |
910 | 845 | } |
@@ -955,16 +890,4 @@ public String ok() { |
955 | 890 |
|
956 | 891 | } |
957 | 892 |
|
958 | | - public static class CustomSessionLimit implements SessionLimitStrategy { |
959 | | - |
960 | | - @Override |
961 | | - public Integer apply(Authentication authentication) { |
962 | | - if ("admin".equals(authentication.getName())) { |
963 | | - return 2; |
964 | | - } |
965 | | - return 1; |
966 | | - } |
967 | | - |
968 | | - } |
969 | | - |
970 | 893 | } |
0 commit comments