当前位置:网站首页>统一认证中心 Oauth2 高可用坑
统一认证中心 Oauth2 高可用坑
2022-06-11 23:56:00 【InfoQ】
user-info-uritoken-info-uricas-server-url: http://cas-server
security:
path:
ignores: /,/index,/static/**,/css/**, /image/**, /favicon.ico, /js/**,/plugin/**,/avue.min.js,/img/**,/fonts/**
oauth2:
client:
client-id: rest-service
client-secret: rest-service-123
user-authorization-uri: ${cas-server-url}/oauth/authorize
access-token-uri: ${cas-server-url}/oauth/token
resource:
loadBalanced: true
id: rest-service
prefer-token-info: true
token-info-uri: ${cas-server-url}/oauth/check_token
authorization:
check-token-access: ${cas-server-url}/oauth/check_token
/oauth/check_token2021-11-03 16:40:09.057 DEBUG 24652 --- [io2-2001-exec-4] o.s.web.client.RestTemplate : HTTP POST http://cas-server/oauth/check_token
2021-11-03 16:40:09.060 DEBUG 24652 --- [io2-2001-exec-4] o.s.web.client.RestTemplate : Accept=[application/json, application/*+json]
2021-11-03 16:40:09.062 DEBUG 24652 --- [io2-2001-exec-4] o.s.web.client.RestTemplate : Writing [{token=[b34841b4-61fa-4dbb-9e2b-76496deb27b4]}] as "application/x-www-form-urlencoded"
2021-11-03 16:40:11.332 ERROR 24652 --- [io2-2001-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://cas-server/oauth/check_token": cas-server; nested exception is java.net.UnknownHostException: cas-server
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:746)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:672)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:581)
at org.springframework.security.oauth2.provider.token.RemoteTokenServices.postForMap(RemoteTokenServices.java:149)
cas-server
private Map<String, Object> postForMap(String path, MultiValueMap<String, String> formData, HttpHeaders headers) {
if (headers.getContentType() == null) {
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
}
@SuppressWarnings("rawtypes")
Map map = restTemplate.exchange(path, HttpMethod.POST,
new HttpEntity<MultiValueMap<String, String>>(formData, headers), Map.class).getBody();
@SuppressWarnings("unchecked")
Map<String, Object> result = map;
return result;
}
@LoadBalanced
@Bean
public RestTemplate restTemplate() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setReadTimeout(env.getProperty("client.http.request.readTimeout", Integer.class, 15000));
requestFactory.setConnectTimeout(env.getProperty("client.http.request.connectTimeout", Integer.class, 3000));
RestTemplate rt = new RestTemplate(requestFactory);
return rt;
}
@LoadBalancedcom.netflix.loadbalancer.IRule@Bean
public IRule ribbonRule(IClientConfig config){
//return new AvailabilityFilteringRule();
return new RoundRobinRule();//轮询
//return new RetryRule();//重试
//return new RandomRule();//这里配置策略,和配置文件对应
//return new WeightedResponseTimeRule();//这里配置策略,和配置文件对应
//return new BestAvailableRule();//选择一个最小的并发请求的server
//return new MyProbabilityRandomRule();//自定义
}


@Autowired(required = true)
private RemoteTokenServices remoteTokenServices;
@Autowired
RestTemplate restTemplate;
@Override
public void configure(ResourceServerSecurityConfigurer resource) throws Exception {
super.configure(resource);
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
@Override
// Ignore 400
public void handleError(ClientHttpResponse response) throws IOException {
if (response.getRawStatusCode() != 400) {
super.handleError(response);
}
}
});
if (Objects.nonNull(remoteTokenServices)) {
remoteTokenServices.setRestTemplate(restTemplate);
resource.tokenServices(remoteTokenServices);
}
resource
//.tokenStore(tokenStore)
//.tokenServices(tokenServices)
.authenticationEntryPoint(customAuthenticationEntryPoint)
.accessDeniedHandler(customAccessDeniedHandler)
//.tokenExtractor(new BearerTokenExtractor())
;
}
2021-11-03 16:57:50.476 INFO 81424 --- [io2-2001-exec-3] o.s.web.servlet.DispatcherServlet : Completed initialization in 12 ms
2021-11-03 16:57:50.522 DEBUG 81424 --- [io2-2001-exec-3] o.s.web.client.RestTemplate : HTTP POST http://cas-server/oauth/check_token
2021-11-03 16:57:50.526 DEBUG 81424 --- [io2-2001-exec-3] o.s.web.client.RestTemplate : Accept=[application/json, application/*+json]
2021-11-03 16:57:50.528 DEBUG 81424 --- [io2-2001-exec-3] o.s.web.client.RestTemplate : Writing [{token=[b34841b4-61fa-4dbb-9e2b-76496deb27b4]}] as "application/x-www-form-urlencoded"
2021-11-03 16:57:50.635 DEBUG 81424 --- [io2-2001-exec-3] o.s.web.client.RestTemplate : Response 200 OK
200
边栏推荐
- 【juc学习之路第7天】ReentrantLock与ReentrantReadWriteLock
- How many steps does it take for C language to become Fibonacci number
- A new product with advanced product power, the new third generation Roewe rx5 blind subscription is opened
- loading
- 显示商品详情【项目 商城】
- 多路查找树
- 移印工艺流程及应用注意事项
- What is bom? And knowledge points
- WALLYS Qualcomm-Atheros-QCA9882-2T2R-MIMO-802.11ac-Mini-PCIe-WiFi 6E-Module-5G-high-power
- (linear DP | monotone queue) acwing 895 Longest ascending subsequence
猜你喜欢
![[signals and systems] (XXI) Laplace transform and complex frequency domain analysis -- Laplace transform and its properties](/img/aa/821804e951e2fbb63c72f4e28756a1.jpg)
[signals and systems] (XXI) Laplace transform and complex frequency domain analysis -- Laplace transform and its properties

Custom JSP tag - > concept - > lifecycle

Test case design method

oracle使用Navicat工具导入导出数据

HMS core shows the latest open capabilities in mwc2022, helping developers build high-quality applications

(linear DP) acwing 898 Number triangle
![[flume] notes](/img/33/50f14b0267c5e502970cee0278aa71.jpg)
[flume] notes

In order to stimulate inspiration and creativity, Shanghai daoning united with XMIND to bring you full-featured mind mapping and brainstorming software

(greedy + longest ascending subsequence) acwing 896 Longest ascending subsequence II

解决IDEA下载插件慢的问题
随机推荐
Beginner JS BOM implementation window centered
m-way search trees
MySQL some simple commands
二叉排序树
Balanced binary tree (AVL tree)
How many steps does it take for C language to become Fibonacci number
C collection of questions for project review
Remix localization, loading local contract file, local link Remix
Divide the array into three equal parts [problem analysis]
Collation of common array functions
Redis的主从复制、哨兵模式和集群
解决IDEA下载插件慢的问题
Mysql5 and mysql8 are installed at the same time
10. logical statement
On the knowledge points of cookie attributes and the differences between webstorage and cookies?
Les produits antigéniques entrent dans la famille et les entreprises chinoises de dispositifs médicaux accueillent un nouvel océan bleu
Convert VOC data format to coco data format
NFS quotas:Cannot register service: RPC: Authentication error
require. context
Antigen products enter the family, and Chinese medical device enterprises usher in a new blue ocean