|
|
@@ -2,11 +2,13 @@ package com.xxl.job.admin.controller.interceptor;
|
|
2
|
2
|
|
|
3
|
3
|
import com.xxl.job.admin.controller.annotation.PermessionLimit;
|
|
4
|
4
|
import com.xxl.job.admin.core.util.CookieUtil;
|
|
|
5
|
+import com.xxl.job.admin.core.util.PropertiesUtil;
|
|
5
|
6
|
import org.springframework.web.method.HandlerMethod;
|
|
6
|
7
|
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
|
7
|
8
|
|
|
8
|
9
|
import javax.servlet.http.HttpServletRequest;
|
|
9
|
10
|
import javax.servlet.http.HttpServletResponse;
|
|
|
11
|
+import java.math.BigInteger;
|
|
10
|
12
|
|
|
11
|
13
|
/**
|
|
12
|
14
|
* 权限拦截, 简易版
|
|
|
@@ -15,10 +17,16 @@ import javax.servlet.http.HttpServletResponse;
|
|
15
|
17
|
public class PermissionInterceptor extends HandlerInterceptorAdapter {
|
|
16
|
18
|
|
|
17
|
19
|
public static final String LOGIN_IDENTITY_KEY = "LOGIN_IDENTITY";
|
|
18
|
|
- public static final String LOGIN_IDENTITY_VAL = "sdf!121sdf$78sd!8";
|
|
|
20
|
+ public static final String LOGIN_IDENTITY_TOKEN;
|
|
|
21
|
+ static {
|
|
|
22
|
+ String username = PropertiesUtil.getString("xxl.job.login.username");
|
|
|
23
|
+ String password = PropertiesUtil.getString("xxl.job.login.password");
|
|
|
24
|
+ String temp = username + "_" + password;
|
|
|
25
|
+ LOGIN_IDENTITY_TOKEN = new BigInteger(1, temp.getBytes()).toString(16);
|
|
|
26
|
+ }
|
|
19
|
27
|
|
|
20
|
28
|
public static boolean login(HttpServletResponse response, boolean ifRemember){
|
|
21
|
|
- CookieUtil.set(response, LOGIN_IDENTITY_KEY, LOGIN_IDENTITY_VAL, ifRemember);
|
|
|
29
|
+ CookieUtil.set(response, LOGIN_IDENTITY_KEY, LOGIN_IDENTITY_TOKEN, ifRemember);
|
|
22
|
30
|
return true;
|
|
23
|
31
|
}
|
|
24
|
32
|
public static void logout(HttpServletRequest request, HttpServletResponse response){
|
|
|
@@ -26,7 +34,7 @@ public class PermissionInterceptor extends HandlerInterceptorAdapter {
|
|
26
|
34
|
}
|
|
27
|
35
|
public static boolean ifLogin(HttpServletRequest request){
|
|
28
|
36
|
String indentityInfo = CookieUtil.getValue(request, LOGIN_IDENTITY_KEY);
|
|
29
|
|
- if (indentityInfo==null || !LOGIN_IDENTITY_VAL.equals(indentityInfo.trim())) {
|
|
|
37
|
+ if (indentityInfo==null || !LOGIN_IDENTITY_TOKEN.equals(indentityInfo.trim())) {
|
|
30
|
38
|
return false;
|
|
31
|
39
|
}
|
|
32
|
40
|
return true;
|
|
|
@@ -43,7 +51,9 @@ public class PermissionInterceptor extends HandlerInterceptorAdapter {
|
|
43
|
51
|
HandlerMethod method = (HandlerMethod)handler;
|
|
44
|
52
|
PermessionLimit permission = method.getMethodAnnotation(PermessionLimit.class);
|
|
45
|
53
|
if (permission == null || permission.limit()) {
|
|
46
|
|
- throw new Exception("登陆失效");
|
|
|
54
|
+ response.sendRedirect("/toLogin");
|
|
|
55
|
+ //request.getRequestDispatcher("/toLogin").forward(request, response);
|
|
|
56
|
+ return false;
|
|
47
|
57
|
}
|
|
48
|
58
|
}
|
|
49
|
59
|
|