Commit 3f80678626db5ba0461e92a7e37a1091064468cb

Authored by 戈灵虎
1 parent d8de2406

fix(justauth): 修复授权请求超时

urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/framework/justauth/core/AuthRequestFactory.java
... ... @@ -63,7 +63,7 @@ public class AuthRequestFactory {
63 63 *
64 64 * @return Oauth列表
65 65 */
66   - @SuppressWarnings({"unchecked", "rawtypes"})
  66 + @SuppressWarnings({ "unchecked", "rawtypes" })
67 67 public List<String> oauthList() {
68 68 // 默认列表
69 69 List<String> defaultList = new ArrayList<>(properties.getType().keySet());
... ... @@ -100,9 +100,10 @@ public class AuthRequestFactory {
100 100 AuthRequest authRequest = getDefaultRequest(source);
101 101  
102 102 // 如果获取不到则尝试取自定义的
103   -// if (authRequest == null) {
104   -// authRequest = getExtendRequest(properties.getExtend().getEnumClass(), source);
105   -// }
  103 + // if (authRequest == null) {
  104 + // authRequest = getExtendRequest(properties.getExtend().getEnumClass(),
  105 + // source);
  106 + // }
106 107  
107 108 if (authRequest == null) {
108 109 throw new AuthException(AuthResponseStatus.UNSUPPORTED);
... ... @@ -118,7 +119,7 @@ public class AuthRequestFactory {
118 119 * @param source {@link AuthSource}
119 120 * @return {@link AuthRequest}
120 121 */
121   - @SuppressWarnings({"unchecked", "rawtypes"})
  122 + @SuppressWarnings({ "unchecked", "rawtypes" })
122 123 private AuthRequest getExtendRequest(Class clazz, String source) {
123 124 String upperSource = source.toUpperCase();
124 125 try {
... ... @@ -151,7 +152,6 @@ public class AuthRequestFactory {
151 152 return null;
152 153 }
153 154  
154   -
155 155 /**
156 156 * 获取默认的 Request
157 157 *
... ... @@ -272,13 +272,13 @@ public class AuthRequestFactory {
272 272 case "OKTA":
273 273 return new AuthOktaRequest(config, authStateCache);
274 274 case "PROGINN":
275   - return new AuthProginnRequest(config,authStateCache);
  275 + return new AuthProginnRequest(config, authStateCache);
276 276 case "AFDIAN":
277   - return new AuthAfDianRequest(config,authStateCache);
  277 + return new AuthAfDianRequest(config, authStateCache);
278 278 case "APPLE":
279   - return new AuthAppleRequest(config,authStateCache);
  279 + return new AuthAppleRequest(config, authStateCache);
280 280 case "FIGMA":
281   - return new AuthFigmaRequest(config,authStateCache);
  281 + return new AuthFigmaRequest(config, authStateCache);
282 282 case "WECHAT_MINI_PROGRAM":
283 283 config.setIgnoreCheckRedirectUri(true);
284 284 config.setIgnoreCheckState(true);
... ... @@ -300,23 +300,26 @@ public class AuthRequestFactory {
300 300 * @param authSource {@link AuthSource}
301 301 * @param authConfig {@link AuthConfig}
302 302 */
303   - private void configureHttpConfig(String authSource, AuthConfig authConfig, JustAuthProperties.JustAuthHttpConfig httpConfig) {
  303 + private void configureHttpConfig(String authSource, AuthConfig authConfig,
  304 + JustAuthProperties.JustAuthHttpConfig httpConfig) {
304 305 if (null == httpConfig) {
305 306 return;
306 307 }
307   - Map<String, JustAuthProperties.JustAuthProxyConfig> proxyConfigMap = httpConfig.getProxy();
308   - if (CollectionUtils.isEmpty(proxyConfigMap)) {
309   - return;
310   - }
311   - JustAuthProperties.JustAuthProxyConfig proxyConfig = proxyConfigMap.get(authSource);
312 308  
313   - if (null == proxyConfig) {
314   - return;
  309 + // 构建 HttpConfig,优先设置 timeout(独立于 proxy 配置)
  310 + HttpConfig.HttpConfigBuilder builder = HttpConfig.builder()
  311 + .timeout(httpConfig.getTimeout());
  312 +
  313 + // 如果有代理配置,则设置代理
  314 + Map<String, JustAuthProperties.JustAuthProxyConfig> proxyConfigMap = httpConfig.getProxy();
  315 + if (!CollectionUtils.isEmpty(proxyConfigMap)) {
  316 + JustAuthProperties.JustAuthProxyConfig proxyConfig = proxyConfigMap.get(authSource);
  317 + if (null != proxyConfig) {
  318 + builder.proxy(new Proxy(Proxy.Type.valueOf(proxyConfig.getType()),
  319 + new InetSocketAddress(proxyConfig.getHostname(), proxyConfig.getPort())));
  320 + }
315 321 }
316 322  
317   - authConfig.setHttpConfig(HttpConfig.builder()
318   - .timeout(httpConfig.getTimeout())
319   - .proxy(new Proxy(Proxy.Type.valueOf(proxyConfig.getType()), new InetSocketAddress(proxyConfig.getHostname(), proxyConfig.getPort())))
320   - .build());
  323 + authConfig.setHttpConfig(builder.build());
321 324 }
322 325 }
... ...