Spring rest模板中IP地址和域名的不同场景
我有一个rest模板代码,如下所示:Spring rest模板中IP地址和域名的不同场景,spring,resttemplate,Spring,Resttemplate,我有一个rest模板代码,如下所示: HttpHeaders headers = new HttpHeaders(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if(authentication != null) { Collection<? extends GrantedAuthority> authoritie
HttpHeaders headers = new HttpHeaders();
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if(authentication != null) {
Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
if (!authorities.contains(new SimpleGrantedAuthority(ROLE_ANONYMOUS_USER))) {
OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) authentication.getDetails();
OAuth2AccessToken accessToken = tokenStore.readAccessToken(details.getTokenValue());
headers.set(AUTHORIZATION, BEARER + accessToken);
}
}
ResponseEntity<Foo> responseEntity = restTemplate.exchange(<Domain name> + "/foo/1"
, HttpMethod.GET, new HttpEntity(headers) , Foo.class);
HttpHeaders=newhttpheaders();
身份验证=SecurityContextHolder.getContext().getAuthentication();
if(身份验证!=null){
收集
<Domain name> + "/foo/1"