user3432316
user3432316

Reputation: 81

Failed to get OAUTH2 tokens from JHipster UAA

I generated a UAA server with JHipster 5.1.0. I have choose PostgreSQL as type of Database.

It connects to my jhipster registry and then I generated a microservice and a gateway as below:

$ mkdir coherence-uaa && cd coherence-uaa
$ yo jhipster
? Which *type* of application would you like to create? Microservice UAA service
? As you are running in a microservice architecture, on which port would like your server to run? It should be unique to avoid port conflicts. 9999
? What is your default Java package name? de.stytex.foobar
? Which *type* of database would you like to use? SQL (H2, MySQL, PostgreSQL, Oracle)
? Which *production* database would you like to use? PostgreSQL
? Which *development* database would you like to use? H2 with disk-based persistence
? Do you want to use Hibernate 2nd level cache? Hazelcast
? Do you want to use a search engine in your application? No
? Would you like to use Maven or Gradle for building the backend? Maven
? Would you like to enable internationalization support? Yes
? Please choose the native language of the application? English
? Please choose additional languages to install
? Which testing frameworks would you like to use?
[...]
$ ./mvnw

$ mkdir coherence-gateway && cd coherence-gateway
$ yo jhipster
? Which *type* of application would you like to create? Microservice gateway
? What is the base name of your application? gateway
? As you are running in a microservice architecture, on which port would like your server to run? It should be unique to avoid port conflicts. 8080
? What is your default Java package name? de.stytex.foobar
? Which service discovery server do you want to use? JHipster Registry (uses Eureka, provides Spring Cloud Config support and monitoring dashboards)
? Which *type* of authentication would you like to use? Authentication with JHipster UAA server (the server must be generated separately)
? What is the folder path of your UAA application? ../coherence-uaa
? Which *type* of database would you like to use? SQL (H2, MySQL, PostgreSQL, Oracle)
? Which *production* database would you like to use? PostgreSQL
? Which *development* database would you like to use? H2 with disk-based persistence
? Do you want to use Hibernate 2nd level cache? Hazelcast
? Do you want to use a search engine in your application? No
? Do you want to use clustered HTTP sessions? No
? Do you want to use WebSockets? No
? Would you like to use Maven or Gradle for building the backend? Gradle
? Would you like to use the LibSass stylesheet preprocessor for your CSS? No
? Would you like to enable internationalization support? Yes
? Please choose the native language of the application? English
? Please choose additional languages to install
? Which testing frameworks would you like to use?
[...]
./mvnw

after starting gateway for user login, it failed to get access token and throw errors:

2018-07-23 17:32:53.378 DEBUG 7228 --- [ XNIO-2 task-10] c.c.c.a.g.a.AccessControlFilter : Access Control: allowing access for /coherence_uaa/api/account, as no access control policy has been set up for service: coherence_uaa

2018-07-23 17:32:54.599 DEBUG 7228 --- [ XNIO-2 task-12] c.c.c.a.g.a.AccessControlFilter : Access Control: allowing access for /coherence_uaa/api/account, as no access control policy has been set up for service: coherence_uaa

2018-07-23 17:33:00.566 DEBUG 7228 --- [ XNIO-2 task-14] c.c.c.admin.aop.logging.LoggingAspect : Enter: com.crimsonlogic.coherence.admin.web.rest.AuthResource.authenticate() with argument[s] = [SecurityContextHolderAwareRequestWrapper[ FirewalledRequest[ HttpServletRequestImpl [ POST /auth/login ]]], com.codahale.metrics.servlet.AbstractInstrumentedFilter$StatusExposingServletResponse@7101e809, {username=admin, password=admin}]

2018-07-23 17:33:00.576 DEBUG 7228 --- [ XNIO-2 task-14] c.a.s.o.OAuth2TokenEndpointClientAdapter : contacting OAuth2 token endpoint to login user: admin

2018-07-23 17:33:00.588 ERROR 7228 --- [ XNIO-2 task-14] c.c.c.a.s.o.OAuth2AuthenticationService : failed to get OAuth2 tokens from UAA

java.lang.IllegalStateException: Request URI does not contain a valid hostname: http://coherence_uaa/oauth/token at org.springframework.util.Assert.state(Assert.java:73) at org.springframework.cloud.client.loadbalancer.RetryLoadBalancerInterceptor.intercept(RetryLoadBalancerInterceptor.java:63) at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:92) at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:76) at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53) at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:723) at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:680) at org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:466) at com.crimsonlogic.coherence.admin.security.oauth2.OAuth2TokenEndpointClientAdapter.sendPasswordGrant(OAuth2TokenEndpointClientAdapter.java:54) at com.crimsonlogic.coherence.admin.security.oauth2.OAuth2AuthenticationService.authenticate(OAuth2AuthenticationService.java:65) at com.crimsonlogic.coherence.admin.web.rest.AuthResource.authenticate(AuthResource.java:51)

Upvotes: 0

Views: 1176

Answers (1)

Jon Ruddell
Jon Ruddell

Reputation: 6362

The hostname in a URI for a Feign Client cannot contain an underscore (as is the case with coherence_uaa).

There's a related JHipster issue where _ was restricted from the base name of microservices, it should be also be restricted in UAAs. Pull Request fixing that is available here

Upvotes: 2

Related Questions