优化

This commit is contained in:
如梦技术 2018-12-24 12:32:40 +08:00
parent cc24f5b02f
commit 7efc0e9cbd

View File

@ -37,6 +37,7 @@ import java.util.Map;
* Secure工具类
*/
public class SecureUtil {
public static final String BLADE_USER_REQUEST_ATTR = "_BLADE_USER_REQUEST_ATTR_";
public final static String header = "Authorization";
public final static String bearer = "bearer";
@ -53,7 +54,17 @@ public class SecureUtil {
* @return
*/
public static BladeUser getUser() {
return getUser(WebUtil.getRequest());
HttpServletRequest request = WebUtil.getRequest();
// 优先从 request 中获取
BladeUser bladeUser = (BladeUser) request.getAttribute(BLADE_USER_REQUEST_ATTR);
if (bladeUser == null) {
bladeUser = getUser(request);
if (bladeUser != null) {
// 设置到 request
request.setAttribute(BLADE_USER_REQUEST_ATTR, bladeUser);
}
}
return bladeUser;
}
/**