SaCheckPermission permission verification annotation
In the front-end and back-end separate version 4 of RuoYi, the SaCheckPermission annotation is used for permission verification.
This annotation can be applied to the method to ensure that only users with the corresponding permissions can access the method.
Example of using SaCheckPermission annotation in a controller
import ; import ; import ; import ; @RestController @RequestMapping("/api") public class MyController { @GetMapping("/test") @SaCheckPermission("user:view") public String test() { return "Hello, world!"; } }
In this example,
The @SaCheckPermission("user:view") annotation means that only users with user:view permission can access the /api/test interface.
If the permission verification based on the framework is implemented based on Spring Security, it is necessary to introduce Spring Security-related dependencies into the project and configure corresponding security policies.
In the file
Example of adding Spring Security dependencies:
<dependency> <groupId></groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
in or file
Configure Spring Security related settings:
spring: security: user: name: admin password: 123456
Create a configuration class in the project
Inherit WebSecurityConfigurerAdapter, override the configure method, and configure permission verification policy:
import ; import ; import ; import ; @Configuration @EnableWebFluxSecurity public class SecurityConfig extends SaReactiveConfigurer { @Override protected void configure(ServerHttpSecurity http) throws Exception { (http); // Configure permission verification policy here } }
In this way, when the user tries to access a method with the SaCheckPermission annotation, permission verification will be performed automatically if it is based on the framework.
If the user has the corresponding permissions, access is allowed; otherwise, a 403 Forbidden error is returned.
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.