@Test public void userInfoLoadBalancedNoRetry() throws Exception { this.context = new SpringApplicationBuilder(ClientConfiguration.class) .properties("spring.config.name=test", "server.port=0", "security.oauth2.resource.userInfoUri:http://nosuchservice", "security.oauth2.resource.loadBalanced=true") .run(); assertTrue(this.context.containsBean("loadBalancedUserInfoRestTemplateCustomizer")); assertFalse(this.context.containsBean("retryLoadBalancedUserInfoRestTemplateCustomizer")); OAuth2RestTemplate template = this.context .getBean(UserInfoRestTemplateFactory.class).getUserInfoRestTemplate(); ClientHttpRequest request = template.getRequestFactory() .createRequest(new URI("http://nosuchservice"), HttpMethod.GET); expected.expectMessage("No instances available for nosuchservice"); request.execute(); }
private OAuth2ClientAuthenticationProcessingFilter oauth2SsoFilter( OAuth2SsoProperties sso) { OAuth2RestOperations restTemplate = this.applicationContext .getBean(UserInfoRestTemplateFactory.class).getUserInfoRestTemplate(); ResourceServerTokenServices tokenServices = this.applicationContext .getBean(ResourceServerTokenServices.class); OAuth2ClientAuthenticationProcessingFilter filter = new OAuth2ClientAuthenticationProcessingFilter( sso.getLoginPath()); filter.setRestTemplate(restTemplate); filter.setTokenServices(tokenServices); filter.setApplicationEventPublisher(this.applicationContext); return filter; }
@Bean OAuth2RestTemplate restTemplate(UserInfoRestTemplateFactory templateFactory) { return templateFactory.getUserInfoRestTemplate(); }