| | |
| | | package com.xiaopeng.gateway.filter; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.xiaopeng.common.core.exception.auth.NotLoginException; |
| | | import com.xiaopeng.gateway.config.properties.AntiShakeProperties; |
| | | import org.apache.commons.lang3.RandomStringUtils; |
| | | 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; |
| | |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | |
| | | |
| | | /** |
| | |
| | | |
| | | @Autowired |
| | | private RedisService redisService; |
| | | |
| | | @Value("${xiaopeng.xtiger.sso.issuer}") |
| | | private String issuer; |
| | | |
| | | @Value("${xiaopeng.xtiger.sso.appId}") |
| | | private String appId; |
| | | |
| | | @Value("${xiaopeng.xtiger.sso.serverHost}") |
| | | private String serverHost; |
| | | |
| | | |
| | | |
| | |
| | | |
| | | private Mono<Void> unauthorizedResponse(ServerWebExchange exchange, String msg) { |
| | | log.error("[鉴权异常处理]请求路径:{}", exchange.getRequest().getPath() + "\n" + msg); |
| | | return ServletUtils.webFluxResponseWriter(exchange.getResponse(), msg, HttpStatus.UNAUTHORIZED); |
| | | 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 + "/dashboard&state=" + state1 + "&nonce=" + nonce + "&client_id=" + appId + "\",\n" + |
| | | " \"logoutUrl\": null,\n" + |
| | | " \"callbackUrl\": \"" + serverHost + "/dashboard?state=" + state2 + "\"\n" + |
| | | " }"); |
| | | return ServletUtils.webFluxResponseWriter(exchange.getResponse(), jsonObject.toString(), HttpStatus.UNAUTHORIZED); |
| | | } |
| | | |
| | | |
| | |
| | | return token; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |