🔄Update: 搭建 AOP 骨架
This commit is contained in:
@@ -59,5 +59,10 @@
|
||||
<version>4.4.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.hezhaohui.pc.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 自定义注解,实现鉴权
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface PreAuthorize {
|
||||
/**
|
||||
* 权限标识符
|
||||
*/
|
||||
public String value() default "";
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package cn.hezhaohui.pc.aspect;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Aspect
|
||||
public class AuthorizeAspect {
|
||||
|
||||
@Pointcut("@annotation(cn.hezhaohui.pc.annotation.PreAuthorize)")
|
||||
public void authorizePointCut() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 对后端接口鉴权
|
||||
* 1. 获取当前用户角色
|
||||
* 2. 获取角色对应权限
|
||||
* 3. 判断当前权限标识符是否被包含
|
||||
* @return
|
||||
*/
|
||||
@Around("authorizePointCut()")
|
||||
public Object handle(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
// TODO
|
||||
return joinPoint.proceed();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user