Skip to content
This repository was archived by the owner on Apr 5, 2022. It is now read-only.
This repository was archived by the owner on Apr 5, 2022. It is now read-only.

config property "security.resource.jwt.key-uri" caused UnknownHostException #227

Description

@AnnieCattice

Describe the bug
application ran failed with the message:

org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://data-auth-server:9000/oauth/token_key": data-auth-server; nested exception is java.net.UnknownHostException: data-auth-server

Sample

version describe:

<spring.boot.version>2.2.1.RELEASE</spring.boot.version>
<spring.cloud.version>Hoxton.RELEASE</spring.cloud.version>
  1. here is my configuaration of oauth2 server application:
server:
  port: 9000
spring:
  application:
    name: data-auth-server
  1. when i try to config security.resource.jwt.key-uri to my oauth2 client application,yml could be this:
security:
  oauth2: 
    resource:
      jwt:
        key-uri: http://data-auth-server:9000/oauth/token_key
  1. i started the application,and got the full trace stack info:
Caused by: org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://data-auth-server:9000/oauth/token_key": data-auth-server; nested exception is java.net.UnknownHostException: data-auth-server
	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:751) ~[spring-web-5.2.1.RELEASE.jar:5.2.1.RELEASE]
	at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:677) ~[spring-web-5.2.1.RELEASE.jar:5.2.1.RELEASE]
	at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:586) ~[spring-web-5.2.1.RELEASE.jar:5.2.1.RELEASE]
	at org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerTokenServicesConfiguration$JwtTokenServicesConfiguration.getKeyFromServer(ResourceServerTokenServicesConfiguration.java:318) ~[spring-security-oauth2-autoconfigure-2.1.2.RELEASE.jar:2.1.2.RELEASE]
	at org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerTokenServicesConfiguration$JwtTokenServicesConfiguration.jwtTokenEnhancer(ResourceServerTokenServicesConfiguration.java:283) ~[spring-security-oauth2-autoconfigure-2.1.2.RELEASE.jar:2.1.2.RELEASE]
	at org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerTokenServicesConfiguration$JwtTokenServicesConfiguration$$EnhancerBySpringCGLIB$$ead76d0e.CGLIB$jwtTokenEnhancer$1(<generated>) ~[spring-security-oauth2-autoconfigure-2.1.2.RELEASE.jar:2.1.2.RELEASE]
	at org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerTokenServicesConfiguration$JwtTokenServicesConfiguration$$EnhancerBySpringCGLIB$$ead76d0e$$FastClassBySpringCGLIB$$99bec3ca.invoke(<generated>) ~[spring-security-oauth2-autoconfigure-2.1.2.RELEASE.jar:2.1.2.RELEASE]
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.2.1.RELEASE.jar:5.2.1.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
	at org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerTokenServicesConfiguration$JwtTokenServicesConfiguration$$EnhancerBySpringCGLIB$$ead76d0e.jwtTokenEnhancer(<generated>) ~[spring-security-oauth2-autoconfigure-2.1.2.RELEASE.jar:2.1.2.RELEASE]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_162]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_162]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_162]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_162]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
	... 57 common frames omitted

by the way, if i use the following configuration for client application,it runs well:

security:
  oauth2: 
    resource:
      jwt:
        key-uri: http://localhost:9000/oauth/token_key

is there any way to solve this exception?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions