Connection refused - Could not fetch user details - when trying to access the Authentication Server
I want to point my Organization service to the Authentication server.
When I am trying to call the following request: GET http://localhost:8082/v1/organizations/
I am receiving the following WARNING
o.s.b.a.s.o.r.UserInfoTokenServices : Could not fetch user details: class org.springframework.web.client.ResourceAccessException, I/O error on GET request for "http://localhost:8901/auth/user": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
And I am also receiving the following response in POSTMAN
{ "error": "invalid_token", "error_description": "6afd2822-b23d-4421-9902-423f0934d385" }
However, when I am accesing GET http://localhost:8901/auth/user directly through Postman, without accesing it via my Organization service, the request works fine.
I am using Spring Cloud Hoxton SR11
My Authentication server has the following configuration:
@SpringBootApplication
@RestController
@EnableResourceServer
@EnableAuthorizationServer
public class AuthenticationServiceApplication {
private static final Logger LOGGER = LoggerFactory.getLogger(AuthenticationServiceApplication.class);
@RequestMapping(value = { "/user" }, produces = "application/json")
public Map<String, Object> user(OAuth2Authentication user) {
LOGGER.debug("Request to get user info");
Map<String, Object> userInfo = new HashMap<>();
userInfo.put("user", user.getUserAuthentication().getPrincipal());
userInfo.put("authorities", AuthorityUtils.authorityListToSet(user.getUserAuthentication().getAuthorities()));
return userInfo;
}
public static void main(String[] args) {
SpringApplication.run(AuthenticationServiceApplication.class, args);
}
}
application.yml
eureka:
instance:
preferIpAddress: true
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:8761/eureka/
server:
servlet:
context-path: /auth
@Configuration
public class OAuth2Config extends AuthorizationServerConfigurerAdapter {
@Autowired
private AuthenticationManager authenticationManager;
@Autowired
private UserDetailsService userDetailsService;
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("eagleeye")
.secret("{noop}thisissecret")
.authorizedGrantTypes("refresh_token", "password", "client_credentials")
.scopes("webclient", "mobileclient");
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints
.authenticationManager(authenticationManager)
.userDetailsService(userDetailsService);
}
}
@Configuration
public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
@Override
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Override
@Bean
@Primary
public UserDetailsService userDetailsServiceBean() throws Exception {
return super.userDetailsServiceBean();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("john.carnell").password("{noop}password1").roles("USER")
.and()
.withUser("william.woodward").password("{noop}password2").roles("USER", "ADMIN");
}
}
My Organization service has the following configuration
@SpringBootApplication
@EnableEurekaClient
@EnableCircuitBreaker
@RefreshScope
@EnableResourceServer
public class OrganizationServiceApplication {
public static void main(String[] args) {
SpringApplication.run(OrganizationServiceApplication.class, args);
}
}
@Configuration
public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception{
http
.authorizeRequests()
.antMatchers(HttpMethod.DELETE, "/v1/organizations/**")
.hasRole("ADMIN")
.anyRequest()
.authenticated();
}
}
application.yml
eureka:
instance:
preferIpAddress: true
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:8761/eureka/
security:
oauth2:
resource:
userInfoUri: http://localhost:8901/auth/user
Thank you!
from Recent Questions - Stack Overflow https://ift.tt/3ynsTKL
https://ift.tt/eA8V8J
Comments
Post a Comment