puzhibing
2026-03-25 8be188e6c3a46dac1e6b49c555ca13691507cd05
还原jwt签名
7个文件已修改
74 ■■■■■ 已修改文件
xp-robotaxi-account-boot/src/main/java/com/xiaopeng/account/controller/TokenController.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-common/xp-common-core/src/main/java/com/xiaopeng/common/core/constant/TokenConstants.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-common/xp-common-core/src/main/java/com/xiaopeng/common/core/utils/JwtUtils.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-common/xp-common-security/src/main/java/com/xiaopeng/common/security/auth/AuthLogic.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-common/xp-common-security/src/main/java/com/xiaopeng/common/security/interceptor/HeaderInterceptor.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-common/xp-common-security/src/main/java/com/xiaopeng/common/security/service/TokenService.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-gateway-boot/src/main/java/com/xiaopeng/gateway/filter/AuthFilter.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-account-boot/src/main/java/com/xiaopeng/account/controller/TokenController.java
@@ -61,9 +61,6 @@
    @Value("${sms.appid}")
    private String sms_appid;
    @Value("${token.secret}")
    private String secret;
    // @Autowired
    // private EncryptionDecryptionUtil encryptionDecryptionUtil;
@@ -202,7 +199,7 @@
    public R<?> logout(HttpServletRequest request) {
        String token = SecurityUtils.getToken(request);
        if (StringUtils.isNotEmpty(token)) {
            String username = JwtUtils.getUserName(token, secret);
            String username = JwtUtils.getUserName(token);
            // 删除用户缓存记录
            AuthUtil.logoutByToken(token);
            // 记录用户退出日志
xp-robotaxi-common/xp-common-core/src/main/java/com/xiaopeng/common/core/constant/TokenConstants.java
@@ -16,6 +16,11 @@
     * 令牌前缀
     */
    public static final String PREFIX = "Bearer ";
    /**
     * 令牌秘钥
     */
    public final static String SECRET = "iymGhx1XkAAHrex2Zf4ASbiD9P2ksTam";
    
    /**
     * 参数签名
xp-robotaxi-common/xp-common-core/src/main/java/com/xiaopeng/common/core/utils/JwtUtils.java
@@ -15,6 +15,7 @@
 */
public class JwtUtils
{
    public static String secret = TokenConstants.SECRET;
    /**
     * 从数据声明生成令牌
@@ -22,7 +23,7 @@
     * @param claims 数据声明
     * @return 令牌
     */
    public static String createToken(Map<String, Object> claims, String secret)
    public static String createToken(Map<String, Object> claims)
    {
        String token = Jwts.builder().setClaims(claims).signWith(SignatureAlgorithm.HS512, secret).compact();
        return token;
@@ -34,7 +35,7 @@
     * @param token 令牌
     * @return 数据声明
     */
    public static Claims parseToken(String token, String secret)
    public static Claims parseToken(String token)
    {
        return Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody();
    }
@@ -45,9 +46,9 @@
     * @param token 令牌
     * @return 用户ID
     */
    public static String getUserKey(String token, String secret)
    public static String getUserKey(String token)
    {
        Claims claims = parseToken(token, secret);
        Claims claims = parseToken(token);
        return getValue(claims, SecurityConstants.USER_KEY);
    }
    /**
@@ -56,9 +57,9 @@
     * @param token 令牌
     * @return 用户ID
     */
    public static String getOperationUserKey(String token, String secret)
    public static String getOperationUserKey(String token)
    {
        Claims claims = parseToken(token, secret);
        Claims claims = parseToken(token);
        return getValue(claims, SecurityConstants.OPERATION_USER_KEY);
    }
@@ -90,9 +91,9 @@
     * @param token 令牌
     * @return 用户类型
     */
    public static String getUserType(String token, String secret)
    public static String getUserType(String token)
    {
        Claims claims = parseToken(token,  secret);
        Claims claims = parseToken(token);
        return getValue(claims, SecurityConstants.USER_TYPE);
    }
    
@@ -115,9 +116,9 @@
     * @param token 令牌
     * @return 用户ID
     */
    public static String getUserKeyApplet(String token, String secret)
    public static String getUserKeyApplet(String token)
    {
        Claims claims = parseToken(token,  secret);
        Claims claims = parseToken(token);
        return getValue(claims, SecurityConstants.USER_APPLET_KEY);
    }
    /**
@@ -126,9 +127,9 @@
     * @param token 令牌
     * @return 用户ID
     */
    public static String getUserId(String token, String secret)
    public static String getUserId(String token)
    {
        Claims claims = parseToken(token,  secret);
        Claims claims = parseToken(token);
        return getValue(claims, SecurityConstants.DETAILS_USER_ID);
    }
@@ -150,9 +151,9 @@
     * @param token 令牌
     * @return 用户名
     */
    public static String getUserName(String token, String secret)
    public static String getUserName(String token)
    {
        Claims claims = parseToken(token,  secret);
        Claims claims = parseToken(token);
        return getValue(claims, SecurityConstants.DETAILS_USERNAME);
    }
xp-robotaxi-common/xp-common-security/src/main/java/com/xiaopeng/common/security/auth/AuthLogic.java
@@ -81,7 +81,7 @@
        {
            throw new NotLoginException("未提供token");
        }
        Claims claims = JwtUtils.parseToken(token, tokenService.getSecret());
        Claims claims = JwtUtils.parseToken(token);
        String userType = JwtUtils.getUserType(claims);
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (loginUser == null && "system".equals(userType))
xp-robotaxi-common/xp-common-security/src/main/java/com/xiaopeng/common/security/interceptor/HeaderInterceptor.java
@@ -6,8 +6,6 @@
import com.xiaopeng.api.vo.account.LoginOperationUser;
import com.xiaopeng.api.vo.account.LoginUser;
import com.xiaopeng.common.core.utils.JwtUtils;
import com.xiaopeng.common.core.utils.SpringUtils;
import com.xiaopeng.common.security.service.TokenService;
import io.jsonwebtoken.Claims;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.AsyncHandlerInterceptor;
@@ -26,9 +24,6 @@
 */
public class HeaderInterceptor implements AsyncHandlerInterceptor
{
    private final TokenService tokenService = SpringUtils.getBean(TokenService.class);
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
    {
@@ -45,7 +40,7 @@
        String token = SecurityUtils.getToken();
        if (StringUtils.isNotEmpty(token))
        {
            String userType = JwtUtils.getUserType(token, tokenService.getSecret());
            String userType = JwtUtils.getUserType(token);
            if ("system".equals(userType)) {
                LoginUser loginUser = AuthUtil.getLoginUser(token);
                if (StringUtils.isNotNull(loginUser))
xp-robotaxi-common/xp-common-security/src/main/java/com/xiaopeng/common/security/service/TokenService.java
@@ -9,7 +9,6 @@
import com.xiaopeng.common.core.exception.auth.NotLoginException;
import com.xiaopeng.api.vo.account.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.xiaopeng.common.core.constant.CacheConstants;
import com.xiaopeng.common.core.constant.SecurityConstants;
@@ -30,9 +29,6 @@
public class TokenService {
    @Autowired
    private RedisService redisService;
    @Value("${token.secret}")
    private String secret;
    
    protected static final long MILLIS_SECOND = 1000;
    
@@ -66,7 +62,7 @@
        claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName);
        // 接口返回信息
        Map<String, Object> rspMap = new HashMap<String, Object>();
        rspMap.put("access_token", JwtUtils.createToken(claimsMap, secret));
        rspMap.put("access_token", JwtUtils.createToken(claimsMap));
        rspMap.put("expires_in", expireTime);
        return rspMap;
    }
@@ -94,7 +90,7 @@
        claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName);
        // 接口返回信息
        Map<String, Object> rspMap = new HashMap<String, Object>();
        rspMap.put("access_token", JwtUtils.createToken(claimsMap, secret));
        rspMap.put("access_token", JwtUtils.createToken(claimsMap));
        rspMap.put("expires_in", expireTime);
        return rspMap;
    }
@@ -154,7 +150,7 @@
        LoginUser user = null;
        try {
            if (StringUtils.isNotEmpty(token)) {
                String userkey = JwtUtils.getUserKey(token, secret);
                String userkey = JwtUtils.getUserKey(token);
                user = redisService.getCacheObject(getTokenKey(userkey));
                return user;
            }
@@ -171,7 +167,7 @@
        LoginOperationUser user = null;
        try {
            if (StringUtils.isNotEmpty(token)) {
                String userkey = JwtUtils.getOperationUserKey(token, secret);
                String userkey = JwtUtils.getOperationUserKey(token);
                user = redisService.getCacheObject(getTokenKey(userkey));
                return user;
            }
@@ -194,7 +190,7 @@
     */
    public void delLoginUser(String token) {
        if (StringUtils.isNotEmpty(token)) {
            String userkey = JwtUtils.getUserKey(token, secret);
            String userkey = JwtUtils.getUserKey(token);
            redisService.deleteObject(getTokenKey(userkey));
        }
    }
@@ -257,8 +253,4 @@
    private String getUserKey(Long userid) {
        return ACCESS_TOKEN + userid;
    }
    public String getSecret() {
        return secret;
    }
}
xp-robotaxi-gateway-boot/src/main/java/com/xiaopeng/gateway/filter/AuthFilter.java
@@ -5,7 +5,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
@@ -47,9 +46,6 @@
    @Autowired
    private RedisService redisService;
    @Value("${token.secret}")
    private String secret;
    
    
    
@@ -73,7 +69,7 @@
        String token = getToken(request);
        Claims claims = JwtUtils.parseToken(token, secret);
        Claims claims = JwtUtils.parseToken(token);
        String userkey = JwtUtils.getUserKey(claims);
        String userid = JwtUtils.getUserId(claims);
        String username = JwtUtils.getUserName(claims);
@@ -157,7 +153,7 @@
        if (StringUtils.isEmpty(token)) {
            throw new NotLoginException("令牌不能为空");
        }
        Claims claims = JwtUtils.parseToken(token, secret);
        Claims claims = JwtUtils.parseToken(token);
        if (claims == null) {
            throw new NotLoginException("令牌已过期或验证不正确!");
        }