feat: 完善注销功能逻辑,通过黑名单的方式实现注销场景JWT失效控制
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
package com.youlai.system.common.constant;
|
||||
|
||||
/**
|
||||
* Redis 缓存常量
|
||||
*
|
||||
* @author: haoxr
|
||||
* @date: 2023/03/24
|
||||
*/
|
||||
public interface CacheConstants {
|
||||
|
||||
/**
|
||||
* 验证码缓存前缀
|
||||
*/
|
||||
String VERIFY_CODE_CACHE_PREFIX = "AUTH:VERIFY_CODE:";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.youlai.system.common.constant;
|
||||
|
||||
/**
|
||||
* Security 常量
|
||||
*
|
||||
* @author: haoxr
|
||||
* @date: 2023/03/24
|
||||
*/
|
||||
public interface SecurityConstants {
|
||||
|
||||
/**
|
||||
* 登录接口路径
|
||||
*/
|
||||
String LOGIN_PATH = "/api/v1/auth/login";
|
||||
|
||||
|
||||
/**
|
||||
* Token 前缀
|
||||
*/
|
||||
String TOKEN_PREFIX = "Bearer ";
|
||||
|
||||
/**
|
||||
* 请求头Token的Key
|
||||
*/
|
||||
String TOKEN_KEY = "Authorization";
|
||||
|
||||
|
||||
/**
|
||||
* 验证码缓存前缀
|
||||
*/
|
||||
String VERIFY_CODE_CACHE_PREFIX = "AUTH:VERIFY_CODE:";
|
||||
|
||||
/**
|
||||
* 用户权限集合缓存前缀
|
||||
*/
|
||||
String USER_PERMS_CACHE_PREFIX = "AUTH:USER_PERMS:";
|
||||
|
||||
/**
|
||||
* 黑名单Token缓存前缀
|
||||
*/
|
||||
String BLACK_TOKEN_CACHE_PREFIX = "AUTH:BLACK_TOKEN:";
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.youlai.system.common.util;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.youlai.system.common.constant.SecurityConstants;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 请求工具类
|
||||
*
|
||||
* @author haoxr
|
||||
*/
|
||||
public class RequestUtils {
|
||||
|
||||
/**
|
||||
* 请求头解析获取 Token
|
||||
*/
|
||||
public static String resolveToken(HttpServletRequest request) {
|
||||
String bearerToken = request.getHeader(SecurityConstants.TOKEN_KEY);
|
||||
if (StrUtil.isNotBlank(bearerToken) && bearerToken.startsWith(SecurityConstants.TOKEN_PREFIX)) {
|
||||
return bearerToken.substring(SecurityConstants.TOKEN_PREFIX.length());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* response 响应工具类
|
||||
* 响应工具类
|
||||
*
|
||||
* @author haoxr
|
||||
* @date 2022/10/18
|
||||
|
||||
Reference in New Issue
Block a user