首页 > 解决方案 > 无法从 JHipster UAA 获取 OAUTH2 令牌

问题描述

我用 JHipster 5.1.0 生成了一个 UAA 服务器。我选择 PostgreSQL 作为数据库类型。

它连接到我的 jhipster 注册表,然后我生成了一个微服务和一个网关,如下所示:

$ 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

启动用户登录网关后,无法获取访问令牌并抛出错误:

2018-07-23 17:32:53.378 DEBUG 7228 --- [XNIO-2 task-10] cccagaAccessControlFilter:访问控制:允许访问 /coherence_uaa/api/account,因为没有为服务设置访问控制策略:连贯性_uaa

2018-07-23 17:32:54.599 DEBUG 7228 --- [XNIO-2 task-12] cccagaAccessControlFilter:访问控制:允许访问 /coherence_uaa/api/account,因为没有为服务设置访问控制策略:连贯性_uaa

2018-07-23 17:33:00.566 DEBUG 7228 --- [XNIO-2 task-14] cccadmin.aop.logging.LoggingAspect:输入:com.crimsonlogic.coherence.admin.web.rest.AuthResource.authenticate()带参数[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] casoOAuth2TokenEndpointClientAdapter:联系 OAuth2 令牌端点以登录用户:管理员

2018-07-23 17:33:00.588 错误 7228 --- [XNIO-2 task-14] cccasoOAuth2AuthenticationService:无法从 UAA 获取 OAuth2 令牌

java.lang.IllegalStateException:请求 URI 不包含有效的主机名: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 ) 在 org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:723) 在 org.springframework.org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)。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) 在 com.crimsonlogic.coherence.admin.security.oauth2.OAuth2AuthenticationService.authenticate(OAuth2AuthenticationService.java:65) 在 com.crimsonlogic.coherence.admin.web.rest.AuthResource.authenticate(AuthResource.java: 51)crimsonlogic.coherence.admin.security.oauth2.OAuth2AuthenticationService.authenticate(OAuth2AuthenticationService.java:65) 在 com.crimsonlogic.coherence.admin.web.rest.AuthResource.authenticate(AuthResource.java:51)crimsonlogic.coherence.admin.security.oauth2.OAuth2AuthenticationService.authenticate(OAuth2AuthenticationService.java:65) 在 com.crimsonlogic.coherence.admin.web.rest.AuthResource.authenticate(AuthResource.java:51)

标签: jhipster

解决方案


Feign Client 的 URI 中的主机名不能包含下划线(与 一样coherence_uaa)。

有一个相关的 JHipster 问题_在微服务的基本名称中受到限制,它也应该在 UAA 中受到限制。 此处提供的拉取请求修复


推荐阅读