|
|
|
@ -2,11 +2,13 @@ package com.xxl.job.admin.controller.interceptor;
|
|
|
|
|
|
|
|
|
|
import com.xxl.job.admin.controller.annotation.PermessionLimit;
|
|
|
|
|
import com.xxl.job.admin.core.util.CookieUtil;
|
|
|
|
|
import com.xxl.job.admin.core.util.PropertiesUtil;
|
|
|
|
|
import org.springframework.web.method.HandlerMethod;
|
|
|
|
|
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.math.BigInteger;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 权限拦截, 简易版
|
|
|
|
@ -15,10 +17,16 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
public class PermissionInterceptor extends HandlerInterceptorAdapter {
|
|
|
|
|
|
|
|
|
|
public static final String LOGIN_IDENTITY_KEY = "LOGIN_IDENTITY";
|
|
|
|
|
public static final String LOGIN_IDENTITY_VAL = "sdf!121sdf$78sd!8";
|
|
|
|
|
public static final String LOGIN_IDENTITY_TOKEN;
|
|
|
|
|
static {
|
|
|
|
|
String username = PropertiesUtil.getString("xxl.job.login.username");
|
|
|
|
|
String password = PropertiesUtil.getString("xxl.job.login.password");
|
|
|
|
|
String temp = username + "_" + password;
|
|
|
|
|
LOGIN_IDENTITY_TOKEN = new BigInteger(1, temp.getBytes()).toString(16);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean login(HttpServletResponse response, boolean ifRemember){
|
|
|
|
|
CookieUtil.set(response, LOGIN_IDENTITY_KEY, LOGIN_IDENTITY_VAL, ifRemember);
|
|
|
|
|
CookieUtil.set(response, LOGIN_IDENTITY_KEY, LOGIN_IDENTITY_TOKEN, ifRemember);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
public static void logout(HttpServletRequest request, HttpServletResponse response){
|
|
|
|
@ -26,7 +34,7 @@ public class PermissionInterceptor extends HandlerInterceptorAdapter {
|
|
|
|
|
}
|
|
|
|
|
public static boolean ifLogin(HttpServletRequest request){
|
|
|
|
|
String indentityInfo = CookieUtil.getValue(request, LOGIN_IDENTITY_KEY);
|
|
|
|
|
if (indentityInfo==null || !LOGIN_IDENTITY_VAL.equals(indentityInfo.trim())) {
|
|
|
|
|
if (indentityInfo==null || !LOGIN_IDENTITY_TOKEN.equals(indentityInfo.trim())) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
@ -43,7 +51,9 @@ public class PermissionInterceptor extends HandlerInterceptorAdapter {
|
|
|
|
|
HandlerMethod method = (HandlerMethod)handler;
|
|
|
|
|
PermessionLimit permission = method.getMethodAnnotation(PermessionLimit.class);
|
|
|
|
|
if (permission == null || permission.limit()) {
|
|
|
|
|
throw new Exception("登陆失效");
|
|
|
|
|
response.sendRedirect("/toLogin");
|
|
|
|
|
//request.getRequestDispatcher("/toLogin").forward(request, response);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|