|
@@ -1,7 +1,6 @@
|
|
|
package cn.qinys.platform.base.security.utils;
|
|
package cn.qinys.platform.base.security.utils;
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
import cn.qinys.platform.base.redis.RedisKeyEnum;
|
|
import cn.qinys.platform.base.redis.RedisKeyEnum;
|
|
|
import cn.qinys.platform.base.security.constants.Constants;
|
|
import cn.qinys.platform.base.security.constants.Constants;
|
|
|
import cn.qinys.platform.base.utils.RedisUtils;
|
|
import cn.qinys.platform.base.utils.RedisUtils;
|
|
@@ -35,6 +34,9 @@ public class CurrentUtils {
|
|
|
*/
|
|
*/
|
|
|
public static String getCurrentUserId() {
|
|
public static String getCurrentUserId() {
|
|
|
String token = getToken();
|
|
String token = getToken();
|
|
|
|
|
+ if (token == null) {
|
|
|
|
|
+ return "0";
|
|
|
|
|
+ }
|
|
|
RedisUtils redisUtils = SpringUtil.getBean(RedisUtils.class);
|
|
RedisUtils redisUtils = SpringUtil.getBean(RedisUtils.class);
|
|
|
LoginUserInfo userInfo = (LoginUserInfo) redisUtils.get(RedisKeyEnum.CURRENT_USER.getCode() + token);
|
|
LoginUserInfo userInfo = (LoginUserInfo) redisUtils.get(RedisKeyEnum.CURRENT_USER.getCode() + token);
|
|
|
return userInfo == null ? "0" : userInfo.getId();
|
|
return userInfo == null ? "0" : userInfo.getId();
|
|
@@ -48,6 +50,9 @@ public class CurrentUtils {
|
|
|
*/
|
|
*/
|
|
|
public static String getCurrentWxId() {
|
|
public static String getCurrentWxId() {
|
|
|
String token = getToken();
|
|
String token = getToken();
|
|
|
|
|
+ if (token == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
RedisUtils redisUtils = SpringUtil.getBean(RedisUtils.class);
|
|
RedisUtils redisUtils = SpringUtil.getBean(RedisUtils.class);
|
|
|
LoginUserInfo userInfo = (LoginUserInfo) redisUtils.get(RedisKeyEnum.CURRENT_USER.getCode() + token);
|
|
LoginUserInfo userInfo = (LoginUserInfo) redisUtils.get(RedisKeyEnum.CURRENT_USER.getCode() + token);
|
|
|
return userInfo == null ? null : userInfo.getWxId();
|
|
return userInfo == null ? null : userInfo.getWxId();
|
|
@@ -60,6 +65,9 @@ public class CurrentUtils {
|
|
|
*/
|
|
*/
|
|
|
public static String getCurrentUsername() {
|
|
public static String getCurrentUsername() {
|
|
|
String token = getToken();
|
|
String token = getToken();
|
|
|
|
|
+ if (token == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
RedisUtils redisUtils = SpringUtil.getBean(RedisUtils.class);
|
|
RedisUtils redisUtils = SpringUtil.getBean(RedisUtils.class);
|
|
|
LoginUserInfo userInfo = (LoginUserInfo) redisUtils.get(RedisKeyEnum.CURRENT_USER.getCode() + token);
|
|
LoginUserInfo userInfo = (LoginUserInfo) redisUtils.get(RedisKeyEnum.CURRENT_USER.getCode() + token);
|
|
|
return userInfo == null ? "" : userInfo.getUsername();
|
|
return userInfo == null ? "" : userInfo.getUsername();
|
|
@@ -94,6 +102,9 @@ public class CurrentUtils {
|
|
|
*/
|
|
*/
|
|
|
public static LoginUserInfo getCurrentUserInfo() {
|
|
public static LoginUserInfo getCurrentUserInfo() {
|
|
|
String token = getToken();
|
|
String token = getToken();
|
|
|
|
|
+ if (token == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
RedisUtils redisUtils = SpringUtil.getBean(RedisUtils.class);
|
|
RedisUtils redisUtils = SpringUtil.getBean(RedisUtils.class);
|
|
|
return (LoginUserInfo) redisUtils.get(RedisKeyEnum.CURRENT_USER.getCode() + token);
|
|
return (LoginUserInfo) redisUtils.get(RedisKeyEnum.CURRENT_USER.getCode() + token);
|
|
|
}
|
|
}
|
|
@@ -106,6 +117,9 @@ public class CurrentUtils {
|
|
|
*/
|
|
*/
|
|
|
public static List<String> getPermissionCodes() {
|
|
public static List<String> getPermissionCodes() {
|
|
|
String token = getToken();
|
|
String token = getToken();
|
|
|
|
|
+ if (token == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
RedisUtils redisUtils = SpringUtil.getBean(RedisUtils.class);
|
|
RedisUtils redisUtils = SpringUtil.getBean(RedisUtils.class);
|
|
|
LoginUserInfo userInfo = (LoginUserInfo) redisUtils.get(RedisKeyEnum.CURRENT_USER.getCode() + token);
|
|
LoginUserInfo userInfo = (LoginUserInfo) redisUtils.get(RedisKeyEnum.CURRENT_USER.getCode() + token);
|
|
|
return userInfo == null || userInfo.getPermissionCodes() == null ? new ArrayList<>() : userInfo.getPermissionCodes();
|
|
return userInfo == null || userInfo.getPermissionCodes() == null ? new ArrayList<>() : userInfo.getPermissionCodes();
|
|
@@ -114,6 +128,9 @@ public class CurrentUtils {
|
|
|
|
|
|
|
|
public static String getToken() {
|
|
public static String getToken() {
|
|
|
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
|
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
|
|
|
|
+ if (attributes == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
HttpServletRequest request = attributes.getRequest();
|
|
HttpServletRequest request = attributes.getRequest();
|
|
|
String token = request.getHeader(Constants.JwtEnum.AUTHORIZATION.getCode());
|
|
String token = request.getHeader(Constants.JwtEnum.AUTHORIZATION.getCode());
|
|
|
return token == null ? null : token.replaceFirst(Constants.JwtEnum.BEARER.getCode(), "").trim();
|
|
return token == null ? null : token.replaceFirst(Constants.JwtEnum.BEARER.getCode(), "").trim();
|