@Bean protected UserInfoTokenServices tokenServices() { final UserInfoTokenServices tokenServices = new UserInfoTokenServices(resourceServerProperties.getUserInfoUri(), authorizationCodeResourceDetails.getClientId()); tokenServices.setRestTemplate(oAuth2RestTemplate()); final AuthoritiesExtractor authoritiesExtractor; if (StringUtils.isEmpty(authorizationProperties.getExternalAuthoritiesUrl())) { authoritiesExtractor = new DefaultAuthoritiesExtractor(); } else { authoritiesExtractor = new ExternalOauth2ResourceAuthoritiesExtractor( oAuth2RestTemplate(), URI.create(authorizationProperties.getExternalAuthoritiesUrl())); } tokenServices.setAuthoritiesExtractor(authoritiesExtractor); return tokenServices; }