【问题标题】:Failed to get OAUTH2 tokens from JHipster UAA无法从 JHipster UAA 获取 OAUTH2 令牌
【发布时间】:2018-12-30 17:58:42
【问题描述】:

我使用 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,因为没有设置访问控制策略准备服务:coherence_uaa

2018-07-23 17:32:54.599 DEBUG 7228 --- [XNIO-2 task-12] cccagaAccessControlFilter:访问控制:允许访问 /coherence_uaa/api/account,因为没有设置访问控制策略准备服务:coherence_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() 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:联系 OAuth2 令牌端点以登录用户:admin

2018-07-23 17:33:00.588 ERROR 7228 --- [XNIO-2 task-14] c.c.c.a.s.o.OAuth2AuthenticationService : 无法从 UAA 获取 OAuth2 令牌

java.lang.IllegalStateException:请求 URI 不包含有效的主机名:http://coherence_uaa/oauth/token 在 org.springframework.util.Assert.state(Assert.java:73) 在 org.springframework.cloud.client.loadbalancer.RetryLoadBalancerInterceptor.intercept(RetryLoadBalancerInterceptor.java:63) 在 org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:92) 在 org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:76) 在 org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) 在 org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53) 在 org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:723) 在 org.springframework.web.client.RestTemplate.execute(RestTemplate.java:680) 在 org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:466) 在 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)

【问题讨论】:

  • 我只重新创建了名为“UAA”的UAA服务器,然后问题就解决了。似乎“UAA”这个名称在生成的网关中是硬编码的。

标签: jhipster


【解决方案1】:

Feign Client 的 URI 中的主机名不能包含下划线(coherence_uaa 就是这种情况)。

有一个related JHipster issue,其中_ 被限制在微服务的基本名称中,它也应该在UAA 中受到限制。 Pull Request fixing that is available here

【讨论】:

    猜你喜欢
    • 2015-07-27
    • 1970-01-01
    • 2015-02-11
    • 2019-04-24
    • 1970-01-01
    • 1970-01-01
    • 2016-11-25
    • 2011-10-04
    • 2016-06-22
    相关资源
    最近更新 更多