1
0
mirror of synced 2026-08-31 14:35:18 +00:00

Remove Direct Runtime Dependency on Access API

Issue gh-17847
This commit is contained in:
Josh Cummings
2025-09-02 18:45:09 -06:00
parent 10935632ee
commit 3a1692f3c3
8 changed files with 196 additions and 66 deletions
@@ -23,7 +23,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.test.context.showcase.service.HelloMessageService;
import org.springframework.security.test.context.showcase.service.MessageService;
import org.springframework.test.context.ContextConfiguration;
@@ -48,7 +49,8 @@ public class WithMockUserParentTests extends WithMockUserParent {
}
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableMethodSecurity
@EnableWebSecurity
@ComponentScan(basePackageClasses = HelloMessageService.class)
static class Config {
@@ -31,7 +31,8 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.AliasFor;
import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.test.context.showcase.service.HelloMessageService;
import org.springframework.security.test.context.showcase.service.MessageService;
import org.springframework.security.test.context.support.WithMockUser;
@@ -53,8 +54,8 @@ public class WithMockUserTests {
@Test
public void getMessageUnauthenticated() {
assertThatExceptionOfType(AuthenticationCredentialsNotFoundException.class)
.isThrownBy(() -> this.messageService.getMessage());
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> this.messageService.getMessage())
.withRootCauseInstanceOf(AuthenticationCredentialsNotFoundException.class);
}
@Test
@@ -104,7 +105,8 @@ public class WithMockUserTests {
assertThat(message).contains("admin").contains("ADMIN").contains("ROLE_ADMIN");
}
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableMethodSecurity
@EnableWebSecurity
@ComponentScan(basePackageClasses = HelloMessageService.class)
static class Config {
@@ -25,7 +25,8 @@ import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
@@ -51,8 +52,8 @@ public class WithUserDetailsTests {
@Test
public void getMessageUnauthenticated() {
assertThatExceptionOfType(AuthenticationCredentialsNotFoundException.class)
.isThrownBy(() -> this.messageService.getMessage());
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> this.messageService.getMessage())
.withRootCauseInstanceOf(AuthenticationCredentialsNotFoundException.class);
}
@Test
@@ -84,7 +85,8 @@ public class WithUserDetailsTests {
}
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableMethodSecurity
@EnableWebSecurity
@ComponentScan(basePackageClasses = HelloMessageService.class)
static class Config {