完善登录、请求鉴权
This commit is contained in:
parent
c4404bd46a
commit
fa704f6171
|
|
@ -0,0 +1,44 @@
|
|||
package com.qihang.oms.api.constant;
|
||||
|
||||
/**
|
||||
* 缓存的key 常量
|
||||
*
|
||||
* @author qihang
|
||||
*/
|
||||
public class CacheConstants
|
||||
{
|
||||
/**
|
||||
* 登录用户 redis key
|
||||
*/
|
||||
public static final String LOGIN_TOKEN_KEY = "login_tokens:";
|
||||
|
||||
/**
|
||||
* 验证码 redis key
|
||||
*/
|
||||
public static final String CAPTCHA_CODE_KEY = "captcha_codes:";
|
||||
|
||||
/**
|
||||
* 参数管理 cache key
|
||||
*/
|
||||
public static final String SYS_CONFIG_KEY = "sys_config:";
|
||||
|
||||
/**
|
||||
* 字典管理 cache key
|
||||
*/
|
||||
public static final String SYS_DICT_KEY = "sys_dict:";
|
||||
|
||||
/**
|
||||
* 防重提交 redis key
|
||||
*/
|
||||
public static final String REPEAT_SUBMIT_KEY = "repeat_submit:";
|
||||
|
||||
/**
|
||||
* 限流 redis key
|
||||
*/
|
||||
public static final String RATE_LIMIT_KEY = "rate_limit:";
|
||||
|
||||
/**
|
||||
* 登录账户密码错误次数 redis key
|
||||
*/
|
||||
public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:";
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.qihang.oms.api.common;
|
||||
package com.qihang.oms.api.constant;
|
||||
|
||||
import io.jsonwebtoken.Claims;
|
||||
|
||||
|
|
@ -2,6 +2,8 @@ package com.qihang.oms.api.service;
|
|||
|
||||
import com.alibaba.cloud.commons.lang.StringUtils;
|
||||
import com.qihang.oms.api.config.RedisCache;
|
||||
import com.qihang.oms.api.constant.CacheConstants;
|
||||
import com.qihang.oms.api.constant.Constants;
|
||||
import com.qihang.oms.api.domain.LoginUser;
|
||||
import com.qihang.oms.api.utils.IdUtils;
|
||||
import com.qihang.oms.api.utils.ServletUtils;
|
||||
|
|
@ -64,7 +66,7 @@ public class TokenService
|
|||
{
|
||||
Claims claims = parseToken(token);
|
||||
// 解析对应的权限以及用户信息
|
||||
String uuid = (String) claims.get("login_user_key");
|
||||
String uuid = (String) claims.get(Constants.LOGIN_USER_KEY);
|
||||
String userKey = getTokenKey(uuid);
|
||||
LoginUser user = redisCache.getCacheObject(userKey);
|
||||
return user;
|
||||
|
|
@ -113,7 +115,7 @@ public class TokenService
|
|||
refreshToken(loginUser);
|
||||
|
||||
Map<String, Object> claims = new HashMap<>();
|
||||
claims.put("login_user_key", token);
|
||||
claims.put(Constants.LOGIN_USER_KEY, token);
|
||||
return createToken(claims);
|
||||
}
|
||||
|
||||
|
|
@ -211,16 +213,15 @@ public class TokenService
|
|||
private String getToken(HttpServletRequest request)
|
||||
{
|
||||
String token = request.getHeader("Authorization");
|
||||
// if (StringUtils.isNotEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX))
|
||||
// {
|
||||
// token = token.replace(Constants.TOKEN_PREFIX, "");
|
||||
// }
|
||||
if (StringUtils.isNotEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX))
|
||||
{
|
||||
token = token.replace(Constants.TOKEN_PREFIX, "");
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
private String getTokenKey(String uuid)
|
||||
{
|
||||
// return CacheConstants.LOGIN_TOKEN_KEY + uuid;
|
||||
return uuid;
|
||||
return CacheConstants.LOGIN_TOKEN_KEY + uuid;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.qihang.oms.api.utils;
|
||||
|
||||
|
||||
import com.qihang.oms.api.common.Constants;
|
||||
import com.qihang.oms.api.constant.Constants;
|
||||
import com.qihang.oms.api.common.Convert;
|
||||
import jakarta.servlet.ServletRequest;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.qihang.oms.api.utils;
|
||||
|
||||
|
||||
import com.qihang.oms.api.common.Constants;
|
||||
import com.qihang.oms.api.constant.Constants;
|
||||
import com.qihang.oms.api.common.StrFormatter;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.qihang.oms.api.utils.http;
|
||||
|
||||
import com.qihang.oms.api.common.Constants;
|
||||
import com.qihang.oms.api.constant.Constants;
|
||||
import com.qihang.oms.api.utils.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package com.qihang.oms.api.utils.ip;
|
|||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.qihang.oms.api.common.Constants;
|
||||
import com.qihang.oms.api.constant.Constants;
|
||||
import com.qihang.oms.api.utils.http.HttpUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
|
|||
Loading…
Reference in New Issue