3

I created a UAA Server:

? (1/16) Which *type* of application would you like to create? [BETA] JHipster UAA server (for microservice OAuth2 authentication)

And I created a Microservicio Gateway:

? (1/16) Which *type* of application would you like to create? Microservice gateway
...
? (6/16) What is the folder path of your UAA application?. ../elseruaa
  • I created the docker containers, in "docker-compose", and creates well.
  • I have to add some extra configuration on the gateway to work with the server UAA?
  • I get the following error trace in the container gateway:

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.setFilterChainProxySecurityConfigurer(org.springframework.security.config.annotation.ObjectPostProcessor,java.util.List) throws java.lang.Exception; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.oauth2.provider.token.TokenStore org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfiguration.tokenStore; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tokenStore' defined in class path resource [com/abalia/elser/config/MicroserviceSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.oauth2.provider.token.TokenStore]: Factory method 'tokenStore' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jwtAccessTokenConverter' defined in class path resource [com/abalia/elser/config/MicroserviceSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter]: Factory method 'jwtAccessTokenConverter' threw exception; nested exception is java.lang.IllegalStateException: No instances available for elseruaa...

Thank you very much for your help.

Jose
  • 1,779
  • 4
  • 26
  • 50
  • Where is the end of the stack trace? It seems you truncated it before the root cause exception. – Gaël Marziou Jul 21 '16 at 15:06
  • See https://github.com/jhipster/generator-jhipster/issues/3863, uaa server support is in beta and may not work yet with docker compose – Gaël Marziou Jul 21 '16 at 15:45
  • https://docs.google.com/document/d/1HerIfBdnlStV5z_uwrYzBr3WxbUW5dxpKkR2onjSy2Q/edit?usp=sharing – Jose Jul 21 '16 at 16:05
  • Thank you very much for your help. Initially you do not need extra configuration to display the UAA and gateway. do not? – Jose Jul 21 '16 at 16:06

4 Answers4

3

I created a youtube screencast to show how to create jhipster (3.5.1) microservices with UAA. I believe the problems you are facing have to do with the order of startup of services or that old services were not regenerated with 3.5.0+ code. As you can see in the screencast and from the sourcecode on github, it works as is.

screencast

sdoxsee
  • 4,451
  • 1
  • 25
  • 60
1

I had the same issue. After spending hours, finally fixed the error by adding following in MicroserviceSecurityConfiguration.java:

Inject org.springframework.cloud.client.discovery.DiscoveryClient

 @Inject
private DiscoveryClient discoveryClient;

In any method of MicroserviceSecurityConfiguration.java (I choose getKeyFromAuthorizationServer method), add following:

discoveryClient.getServices();
Tyler Shao
  • 156
  • 1
  • 10
  • Isn't it better to add the `@EnableDiscoveryClient` to your Application(.java) and `@Inject` the `DiscoveryClient` in the `initApplication` method? Or do we need to call this every time we want to get a key to get the updated list. – bastijn Aug 17 '16 at 20:45
0

Caused by: java.lang.IllegalStateException: No instances available for elseruaa reported by RibbonLoadBalancerClient.

I'm not up to date with our uaa support but it seems that your gateway was unable to find a service named elseruaa in the list of Eureka clients that have registered to your JHipster registry (Eureka server). So either you forgot to start elseruaa or it registered with another name.

Gaël Marziou
  • 16,028
  • 4
  • 38
  • 49
  • I have got the same issue with 3.5.0 – Łukasz Woźniczka Jul 21 '16 at 20:13
  • Have you looked at the registry dashboard to see if uaa server has regsitered? – Gaël Marziou Jul 21 '16 at 20:36
  • I think @GaëlMarziou is right. UAA needs to be running and registered with the jhipster registry before the resources servers (or "microservices") because the resources servers ask the running UAA for the public key they need to validate JWTs. A simple "docker-compose up" won't work because of that sequence. You might need to create a script that sequences startups like: https://github.com/kbastani/spring-cloud-event-sourcing-example/blob/master/run.sh (note this example project is not a jhipster project). Also: https://github.com/jhipster/generator-jhipster/issues/3863#issuecomment-234383468 – sdoxsee Jul 22 '16 at 00:46
  • Yes its normal but even that i have got npe when i try connect gateway with uaa, and i do not use docker. And everything works on Jhipster 3.4.2 – Łukasz Woźniczka Jul 22 '16 at 07:36
  • There are changes to the gateway, uaa, and microservices wrt uaa since 3.4.2, have you upgraded all of them? – sdoxsee Jul 22 '16 at 12:11
  • In the end I decided to create a Gateway with JWT, since I was unable to do with UAA. Thanks everyone for your help. – Jose Jul 26 '16 at 10:49
  • Hi i have exactly the same issue here. So you said you decide to use jwt. Then can you still use the same oauth server? – Tyler Shao Jul 26 '16 at 19:52
0

Change your MobileSecurityConfiguration

@Inject
private DiscoveryClient discoveryClient;

private String getKeyFromAuthorizationServer() {
          List<String> services = discoveryClient.getServices();

          HttpEntity<Void> request = new HttpEntity<Void>(new HttpHeaders());
          String value = (String) this.keyUriRestTemplate
              .exchange("http://uaa/oauth/token_key", HttpMethod.GET, request, Map.class).getBody()
              .get("value");

          return value;
      }

so basically that one line :

List<String> services = discoveryClient.getServices();

fix that problem.

Łukasz Woźniczka
  • 1,625
  • 3
  • 28
  • 51