获取请求token方法移至权限工具类

This commit is contained in:
RuoYi
2020-11-30 15:09:59 +08:00
committed by 疯狂的狮子li
parent 7f1f9f368a
commit a29bb0bc51
4 changed files with 34 additions and 14 deletions

View File

@@ -31,4 +31,9 @@ public class CacheConstants
* 用户名字段
*/
public static final String DETAILS_USERNAME = "username";
/**
* 授权信息字段
*/
public static final String AUTHORIZATION_HEADER = "authorization";
}

View File

@@ -1,5 +1,6 @@
package com.ruoyi.common.core.utils;
import javax.servlet.http.HttpServletRequest;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import com.ruoyi.common.core.constant.CacheConstants;
import com.ruoyi.common.core.text.Convert;
@@ -27,6 +28,27 @@ public class SecurityUtils
return Convert.toLong(ServletUtils.getRequest().getHeader(CacheConstants.DETAILS_USER_ID));
}
/**
* 获取请求token
*/
public static String getToken()
{
return getToken(ServletUtils.getRequest());
}
/**
* 根据request获取请求token
*/
public static String getToken(HttpServletRequest request)
{
String token = ServletUtils.getRequest().getHeader(CacheConstants.HEADER);
if (StringUtils.isNotEmpty(token) && token.startsWith(CacheConstants.TOKEN_PREFIX))
{
token = token.replace(CacheConstants.TOKEN_PREFIX, "");
}
return token;
}
/**
* 是否为管理员
*