liujie
2026-05-12 560be817c1342d4da523760ba38433c4c0f52983
xp-robotaxi-common/xp-common-security/src/main/java/com/xiaopeng/common/security/handler/GlobalExceptionHandler.java
@@ -1,5 +1,7 @@
package com.xiaopeng.common.security.handler;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xiaopeng.common.core.constant.HttpStatus;
@@ -13,6 +15,7 @@
import com.xiaopeng.common.core.utils.StringUtils;
import com.xiaopeng.common.core.web.domain.AjaxResult;
import feign.FeignException;
import org.apache.commons.lang3.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -27,6 +30,7 @@
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import javax.servlet.http.HttpServletRequest;
import java.util.UUID;
/**
 * 全局异常处理器
@@ -41,6 +45,15 @@
    private String maxFileSize;
    @Value("${spring.servlet.multipart.max-request-size:100MB}")
    private String maxRequestSize;
    @Value("${xiaopeng.xtiger.sso.issuer}")
    private String issuer;
    @Value("${xiaopeng.xtiger.sso.appId}")
    private String appId;
    @Value("${xiaopeng.xtiger.sso.serverHost}")
    private String serverHost;
    @Autowired
    private MessageSource messageSource;
@@ -76,7 +89,19 @@
    public AjaxResult notLoginException(NotLoginException e, HttpServletRequest request) {
        String requestURI = request.getRequestURI();
        log.error("请求地址'{}',登录校验失败'{}'", requestURI, e.getMessage());
        return AjaxResult.error(HttpStatus.UNAUTHORIZED, e.getMessage());
        String s = UUID.randomUUID().toString();
        String state1 = s.substring(0, 8) + s.substring(9, 13) + s.substring(14, 18) + s.substring(19, 23) + s.substring(24);
        String s1 = UUID.randomUUID().toString();
        String state2 = s1.substring(0, 8) + s.substring(9, 13) + s.substring(14, 18) + s.substring(19, 23) + s.substring(24);
        String nonce = RandomStringUtils.randomAlphanumeric(6);
        JSONObject jsonObject = JSON.parseObject("{\n" +
                "    \"uid\": null,\n" +
                "    \"username\": null,\n" +
                "    \"authUrl\": \"" + issuer + "/oidc/auth?scope=openid+profile+offline_access+phone+email&response_type=code&redirect_uri=" + serverHost + "/ssoAuthSdk/callback&state=" + state1 + "&nonce=" + nonce + "&client_id=" + appId + "\",\n" +
                "    \"logoutUrl\": null,\n" +
                "    \"callbackUrl\": \"" + serverHost + "/ssoAuthSdk/callback?state=" + state2 + "\"\n" +
                "  }");
        return AjaxResult.error(HttpStatus.UNAUTHORIZED, e.getMessage(), jsonObject);
    }
    /**