|
@@ -72,6 +72,14 @@ public class AuthorizeHttpRequestsConfigurerTests {
|
|
"At least one mapping is required (for example, authorizeHttpRequests().anyRequest().authenticated())");
|
|
"At least one mapping is required (for example, authorizeHttpRequests().anyRequest().authenticated())");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
+ public void configureWhenAuthorizedHttpRequestsAndNoRequestsThenExceptionWithDefaultConfig() {
|
|
|
|
+ assertThatExceptionOfType(BeanCreationException.class)
|
|
|
|
+ .isThrownBy(() -> this.spring.register(NoRequestsConfigWithDefaultConfig.class).autowire())
|
|
|
|
+ .withMessageContaining(
|
|
|
|
+ "At least one mapping is required (for example, authorizeHttpRequests().anyRequest().authenticated())");
|
|
|
|
+ }
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
public void configureWhenAnyRequestIncompleteMappingThenException() {
|
|
public void configureWhenAnyRequestIncompleteMappingThenException() {
|
|
assertThatExceptionOfType(BeanCreationException.class)
|
|
assertThatExceptionOfType(BeanCreationException.class)
|
|
@@ -79,6 +87,14 @@ public class AuthorizeHttpRequestsConfigurerTests {
|
|
.withMessageContaining("An incomplete mapping was found for ");
|
|
.withMessageContaining("An incomplete mapping was found for ");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
+ public void configureWhenAnyRequestIncompleteMappingDefaultConfigThenException() {
|
|
|
|
+ assertThatExceptionOfType(BeanCreationException.class)
|
|
|
|
+ this.spring.register(IncompleteMappingConfigWithDefaultConfig.class, BasicController.class).autowire();
|
|
|
|
+ this.mvc.perform(get("/")).andExpect(status().isOk());
|
|
|
|
+ verify(CustomAuthorizationManagerConfig.authorizationManager).check(any(), any());
|
|
|
|
+ }
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
public void configureWhenMvcMatcherAfterAnyRequestThenException() {
|
|
public void configureWhenMvcMatcherAfterAnyRequestThenException() {
|
|
assertThatExceptionOfType(BeanCreationException.class)
|
|
assertThatExceptionOfType(BeanCreationException.class)
|
|
@@ -94,6 +110,14 @@ public class AuthorizeHttpRequestsConfigurerTests {
|
|
verify(CustomAuthorizationManagerConfig.authorizationManager).check(any(), any());
|
|
verify(CustomAuthorizationManagerConfig.authorizationManager).check(any(), any());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
+ public void configureMvcMatcherAccessAuthorizationManagerOnDefault() throws Exception {
|
|
|
|
+ CustomAuthorizationManagerConfig.authorizationManager = mock(AuthorizationManager.class);
|
|
|
|
+ this.spring.register(IncompleteMappingConfigWithDefaultConfig.class).autowire();
|
|
|
|
+ this.mvc.perform(get("/")).andExpect(status().isUnauthorized());
|
|
|
|
+ verify(CustomAuthorizationManagerConfig.authorizationManager).check(any(), any());
|
|
|
|
+ }
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
public void configureMvcMatcherAccessAuthorizationManagerWhenNullThenException() {
|
|
public void configureMvcMatcherAccessAuthorizationManagerWhenNullThenException() {
|
|
CustomAuthorizationManagerConfig.authorizationManager = null;
|
|
CustomAuthorizationManagerConfig.authorizationManager = null;
|
|
@@ -370,6 +394,34 @@ public class AuthorizeHttpRequestsConfigurerTests {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @EnableWebSecurity
|
|
|
|
+ static class NoRequestsConfigWithDefaultConfig {
|
|
|
|
+
|
|
|
|
+ @Bean
|
|
|
|
+ SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
|
|
+ // @formatter:off
|
|
|
|
+ return http
|
|
|
|
+ .authorizeHttpRequests()
|
|
|
|
+ .build();
|
|
|
|
+ // @formatter:on
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @EnableWebSecurity
|
|
|
|
+ static class IncompleteMappingConfigWithDefaultConfig {
|
|
|
|
+
|
|
|
|
+ @Bean
|
|
|
|
+ FormLoginConfigurer<HttpSecurity> filterChain(HttpSecurity http) throws Exception {
|
|
|
|
+ // @formatter:off
|
|
|
|
+ return http
|
|
|
|
+ .authorizeHttpRequests()
|
|
|
|
+ .formLogin();
|
|
|
|
+ // @formatter:on
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
@EnableWebSecurity
|
|
@EnableWebSecurity
|
|
static class IncompleteMappingConfig {
|
|
static class IncompleteMappingConfig {
|
|
|
|
|