潘志宝
5 天以前 7fce3006ecd0b670e33c2d3ba123778e79e2e943
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.iailab.framework.security.core.aop;
 
import com.iailab.framework.security.core.annotations.PreAuthenticated;
import com.iailab.framework.security.core.util.SecurityFrameworkUtils;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
 
import static com.iailab.framework.common.exception.enums.GlobalErrorCodeConstants.UNAUTHORIZED;
import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception;
 
@Aspect
@Slf4j
public class PreAuthenticatedAspect {
 
    @Around("@annotation(preAuthenticated)")
    public Object around(ProceedingJoinPoint joinPoint, PreAuthenticated preAuthenticated) throws Throwable {
        if (SecurityFrameworkUtils.getLoginUser() == null) {
            throw exception(UNAUTHORIZED);
        }
        return joinPoint.proceed();
    }
 
}