|
@@ -1,5 +1,5 @@
|
|
/*
|
|
/*
|
|
- * Copyright 2002-2022 the original author or authors.
|
|
|
|
|
|
+ * Copyright 2002-2023 the original author or authors.
|
|
*
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* you may not use this file except in compliance with the License.
|
|
@@ -92,6 +92,21 @@ public class PrePostMethodSecurityConfigurationTests {
|
|
@Autowired(required = false)
|
|
@Autowired(required = false)
|
|
BusinessService businessService;
|
|
BusinessService businessService;
|
|
|
|
|
|
|
|
+ @WithMockUser
|
|
|
|
+ @Test
|
|
|
|
+ public void customMethodSecurityPreAuthorizeAdminWhenRoleUserThenAccessDeniedException() {
|
|
|
|
+ this.spring.register(CustomMethodSecurityServiceConfig.class).autowire();
|
|
|
|
+ assertThatExceptionOfType(AccessDeniedException.class).isThrownBy(this.methodSecurityService::preAuthorizeAdmin)
|
|
|
|
+ .withMessage("Access Denied");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @WithMockUser(roles = "ADMIN")
|
|
|
|
+ @Test
|
|
|
|
+ public void customMethodSecurityPreAuthorizeAdminWhenRoleAdminThenPasses() {
|
|
|
|
+ this.spring.register(CustomMethodSecurityServiceConfig.class).autowire();
|
|
|
|
+ this.methodSecurityService.preAuthorizeAdmin();
|
|
|
|
+ }
|
|
|
|
+
|
|
@WithMockUser(roles = "ADMIN")
|
|
@WithMockUser(roles = "ADMIN")
|
|
@Test
|
|
@Test
|
|
public void preAuthorizeWhenRoleAdminThenAccessDeniedException() {
|
|
public void preAuthorizeWhenRoleAdminThenAccessDeniedException() {
|
|
@@ -418,6 +433,17 @@ public class PrePostMethodSecurityConfigurationTests {
|
|
assertThat(this.spring.getContext().containsBean("annotationSecurityAspect$0")).isFalse();
|
|
assertThat(this.spring.getContext().containsBean("annotationSecurityAspect$0")).isFalse();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Configuration
|
|
|
|
+ @EnableCustomMethodSecurity
|
|
|
|
+ static class CustomMethodSecurityServiceConfig {
|
|
|
|
+
|
|
|
|
+ @Bean
|
|
|
|
+ MethodSecurityService methodSecurityService() {
|
|
|
|
+ return new MethodSecurityServiceImpl();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
@Configuration
|
|
@Configuration
|
|
@EnableMethodSecurity
|
|
@EnableMethodSecurity
|
|
static class MethodSecurityServiceConfig {
|
|
static class MethodSecurityServiceConfig {
|