|
1 | 1 | package com.lmxdawn.admin.aspect;
|
2 | 2 |
|
| 3 | +import com.lmxdawn.admin.annotation.AdminAuthRuleAnnotation; |
3 | 4 | import com.lmxdawn.admin.enums.ResultEnum;
|
4 | 5 | import com.lmxdawn.admin.exception.JsonException;
|
5 | 6 | import com.lmxdawn.admin.utils.JwtUtil;
|
6 | 7 | import io.jsonwebtoken.Claims;
|
7 | 8 | import lombok.extern.slf4j.Slf4j;
|
| 9 | +import org.aspectj.lang.JoinPoint; |
8 | 10 | import org.aspectj.lang.annotation.Aspect;
|
9 | 11 | import org.aspectj.lang.annotation.Before;
|
10 | 12 | import org.aspectj.lang.annotation.Pointcut;
|
| 13 | +import org.aspectj.lang.reflect.MethodSignature; |
11 | 14 | import org.springframework.stereotype.Component;
|
12 |
| -import org.springframework.util.StringUtils; |
13 | 15 | import org.springframework.web.context.request.RequestContextHolder;
|
14 | 16 | import org.springframework.web.context.request.ServletRequestAttributes;
|
15 | 17 |
|
16 |
| -import javax.servlet.http.Cookie; |
17 | 18 | import javax.servlet.http.HttpServletRequest;
|
| 19 | +import java.lang.reflect.Method; |
18 | 20 |
|
19 | 21 | /**
|
20 | 22 | * 登录验证 AOP
|
|
23 | 25 | @Component
|
24 | 26 | @Slf4j
|
25 | 27 | public class AdminAuthorizeAspect {
|
26 |
| - @Pointcut("execution(public * com.lmxdawn.admin.controller.*.Auth*.*(..))" + |
27 |
| - "&& !execution(public * com.lmxdawn.admin.controller.admin.AuthLoginController.index(..))") |
28 |
| - public void verify() {} |
| 28 | + @Pointcut("@annotation(com.lmxdawn.admin.annotation.AdminAuthRuleAnnotation)") |
| 29 | + public void adminAuthVerify() {} |
| 30 | + |
| 31 | + @Before("adminAuthVerify()") |
| 32 | + public void doAdminAuthVerify(JoinPoint joinPoint) { |
| 33 | + |
| 34 | + MethodSignature signature = (MethodSignature) joinPoint.getSignature(); |
| 35 | + //从切面中获取当前方法 |
| 36 | + Method method = signature.getMethod(); |
| 37 | + //得到了方,提取出他的注解 |
| 38 | + AdminAuthRuleAnnotation action = method.getAnnotation(AdminAuthRuleAnnotation.class); |
| 39 | + System.out.println(action.value()); |
29 | 40 |
|
30 |
| - @Before("verify()") |
31 |
| - public void doVerify() { |
32 | 41 | ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
33 | 42 | if (attributes == null) {
|
34 | 43 | throw new JsonException(ResultEnum.NOT_NETWORK);
|
|
0 commit comments