AuthCheckAspect.java
1.9 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package cn.csbr.app.auth;
import cn.csbr.app.config.FxConfigure;
import cn.csbr.app.gui.GUIContext;
import cn.csbr.app.gui.page.WelcomePage;
import cn.csbr.app.gui.util.DialogUtils;
import javafx.application.Platform;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* 检查是否登录权限切面
*/
@Aspect
@Component
public class AuthCheckAspect {
@Autowired
private WelcomePage welcomePage;
@Autowired
private GUIContext guiContext;
@Autowired
private LoginService loginService;
@Autowired
private FxConfigure fxConfigure;
/**
* 配置检查登录的切面范围
*/
@Pointcut("execution(public * cn.csbr.app.service.*.*(..))")
public void authCheck() {
}
/**
* 实际进行登录检查的控制点
*
* @param joinPoint
* @throws Throwable
*/
@Before("authCheck()")
public void deBefore(JoinPoint joinPoint) throws Throwable {
if (fxConfigure.isNodatabase()) {
System.out.println("=================no database:" + joinPoint.getSignature());
return;
}
try {
loginService.checkLogin();
} catch (Exception e) {
loginService.logout();
Platform.runLater(() -> {
DialogUtils.showAlert(e.getMessage(), v -> {
guiContext.updateMainContent(welcomePage.getContent());
});
});
e.printStackTrace();
}
}
/**
* 处理操作后刷新超时时间
*
* @param jp
*/
@After("authCheck()")
public void after(JoinPoint jp) {
loginService.updateAction();
}
}