@@ -27,6 +27,7 @@ import org.springframework.context.annotation.Configuration
2727import org.springframework.http.HttpMethod
2828import org.springframework.security.access.hierarchicalroles.RoleHierarchy
2929import org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl
30+ import org.springframework.security.authentication.TestAuthentication
3031import org.springframework.security.authorization.AuthorizationDecision
3132import org.springframework.security.authorization.AuthorizationManager
3233import org.springframework.security.config.annotation.web.builders.HttpSecurity
@@ -38,6 +39,7 @@ import org.springframework.security.core.Authentication
3839import org.springframework.security.core.userdetails.User
3940import org.springframework.security.core.userdetails.UserDetailsService
4041import org.springframework.security.provisioning.InMemoryUserDetailsManager
42+ import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors
4143import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf
4244import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic
4345import org.springframework.security.web.SecurityFilterChain
@@ -961,4 +963,45 @@ class AuthorizeHttpRequestsDslTests {
961963 }
962964
963965 }
966+
967+ @Test
968+ fun `request when fully authenticated configured then responds ok` () {
969+ this .spring.register(FullyAuthenticatedConfig ::class .java).autowire()
970+
971+ this .mockMvc.post(" /path" ) {
972+ with (SecurityMockMvcRequestPostProcessors .user(" user" ).roles(" USER" ))
973+ with (csrf())
974+ }
975+ .andExpect {
976+ status { isOk() }
977+ }
978+ }
979+
980+ @Configuration
981+ @EnableWebSecurity
982+ @EnableWebMvc
983+ open class FullyAuthenticatedConfig {
984+ @Bean
985+ open fun securityFilterChain (http : HttpSecurity ): SecurityFilterChain {
986+ http {
987+ authorizeHttpRequests {
988+ authorize(" /path" , fullyAuthenticated)
989+ }
990+ httpBasic { }
991+ rememberMe { }
992+ }
993+ return http.build()
994+ }
995+
996+ @Bean
997+ open fun userDetailsService (): UserDetailsService = InMemoryUserDetailsManager (TestAuthentication .user())
998+
999+ @RestController
1000+ internal class PathController {
1001+ @RequestMapping(" /path" )
1002+ fun path (): String {
1003+ return " ok"
1004+ }
1005+ }
1006+ }
9641007}
0 commit comments