feat(core security): 适配 spring security 6.3 新增 @HasPermisson 注解
使用 @HasPermisson 替换 @PreAuthority(xxxx),简化接口上的注解 (cherry picked from commit 448e77607fec651d18bde97e3d5cc6734342e51a)
This commit is contained in:
1 parent
1359415965
commit
4747aa1098
2 files changed
+38
No files matched your search
+28
@@ -0,0 +1,28 @@
|
||||
package com.pig4cloud.pigx.common.security.annotation;
|
||||
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 判断是否有权限
|
||||
*
|
||||
* @author lengleng
|
||||
* @date 2024/07/15
|
||||
*/
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@PreAuthorize("@pms.hasPermission('{value}'.split(','))")
|
||||
public @interface HasPermission {
|
||||
|
||||
/**
|
||||
* 权限字符串
|
||||
*
|
||||
* @return {@link String[] }
|
||||
*/
|
||||
String[] value();
|
||||
|
||||
}
|
||||
+10
@@ -21,6 +21,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.security.authorization.method.PrePostTemplateDefaults;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
@@ -70,4 +71,13 @@ public class PigxResourceServerConfiguration {
|
||||
return http.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 支持自定义权限表达式
|
||||
*
|
||||
* @return {@link PrePostTemplateDefaults }
|
||||
*/
|
||||
@Bean
|
||||
PrePostTemplateDefaults prePostTemplateDefaults() {
|
||||
return new PrePostTemplateDefaults();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user