调整资源客户端token的请求地址,可以不走外网

This commit is contained in:
wanggeng888 2021-05-22 09:19:06 +08:00
parent 717628ed54
commit 45aee17e43
2 changed files with 10 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package com.cm.common.plugin.oauth.token; package com.cm.common.plugin.oauth.token;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.cm.common.config.properties.ApiPathProperties;
import com.cm.common.config.properties.OauthClientProperties; import com.cm.common.config.properties.OauthClientProperties;
import com.cm.common.config.properties.OauthProperties; import com.cm.common.config.properties.OauthProperties;
import com.cm.common.plugin.pojo.bos.ClientTokenBO; import com.cm.common.plugin.pojo.bos.ClientTokenBO;
@ -30,6 +31,7 @@ public class ClientTokenManager {
private RestTemplateUtil restTemplateUtil; private RestTemplateUtil restTemplateUtil;
private OauthProperties oauthProperties; private OauthProperties oauthProperties;
private OauthClientProperties oauthClientProperties; private OauthClientProperties oauthClientProperties;
private ApiPathProperties apiPathProperties;
private ClientTokenManager() { private ClientTokenManager() {
} }
@ -50,7 +52,7 @@ public class ClientTokenManager {
params.put("client_id", oauthClientProperties.getClientId()); params.put("client_id", oauthClientProperties.getClientId());
params.put("client_secret", oauthClientProperties.getClientSecret()); params.put("client_secret", oauthClientProperties.getClientSecret());
params.put("scope", "all"); params.put("scope", "all");
String result = restTemplateUtil.doPostFormNormal(String.format("%s/oauth_client/token", oauthProperties.getOauthServer()), params); String result = restTemplateUtil.doPostFormNormal(String.format("%s/oauth_client/token", apiPathProperties.getUserCenter()), params);
if (StringUtils.isBlank(result)) { if (StringUtils.isBlank(result)) {
LOG.error("客户端获取token失效"); LOG.error("客户端获取token失效");
} else { } else {
@ -95,4 +97,7 @@ public class ClientTokenManager {
public static ClientTokenManager clientTokenManager = new ClientTokenManager(); public static ClientTokenManager clientTokenManager = new ClientTokenManager();
} }
public void setApiPathProperties(ApiPathProperties apiPathProperties) {
this.apiPathProperties = apiPathProperties;
}
} }

View File

@ -1,5 +1,6 @@
package com.cm.common.plugin.startup; package com.cm.common.plugin.startup;
import com.cm.common.config.properties.ApiPathProperties;
import com.cm.common.config.properties.OauthClientProperties; import com.cm.common.config.properties.OauthClientProperties;
import com.cm.common.config.properties.OauthProperties; import com.cm.common.config.properties.OauthProperties;
import com.cm.common.plugin.oauth.token.ClientTokenManager; import com.cm.common.plugin.oauth.token.ClientTokenManager;
@ -27,6 +28,8 @@ public class OAuthStartUp implements ApplicationRunner {
@Autowired @Autowired
private OauthProperties oauthProperties; private OauthProperties oauthProperties;
@Autowired @Autowired
private ApiPathProperties apiPathProperties;
@Autowired
private RestTemplateUtil restTemplateUtil; private RestTemplateUtil restTemplateUtil;
@Override @Override
@ -35,5 +38,6 @@ public class OAuthStartUp implements ApplicationRunner {
clientTokenManager.setRestTemplateUtil(restTemplateUtil); clientTokenManager.setRestTemplateUtil(restTemplateUtil);
clientTokenManager.setOauthProperties(oauthProperties); clientTokenManager.setOauthProperties(oauthProperties);
clientTokenManager.setOauthClientProperties(oauthClientProperties); clientTokenManager.setOauthClientProperties(oauthClientProperties);
clientTokenManager.setApiPathProperties(apiPathProperties);
} }
} }