Spring cloud loadBalanced userInfoUri problems

553 views Asked by At

Im using spring cloud, in the following layout:

  • registry server
  • oauth2 server
  • zuul proxy
  • a simple crud microservice

On the crud service, Im trying to authenticate against my oauth2 server using

security:
   oauth2:
     resource:
       loadBalanced: true
       userInfoUri: http://auth_service/users/current

I can fetch the token from the oauthserver, but when I use the token to request the crud service I got

2017-01-07 10:46:02.638  INFO 16186 --- [nio-9001-exec-4] o.s.b.a.s.o.r.UserInfoTokenServices      : Getting user info from:    http://auth_service/users/current
2017-01-07 10:46:02.639  INFO 16186 --- [nio-9001-exec-4] o.s.b.a.s.o.r.UserInfoTokenServices      : Could not fetch user details: class java.lang.NullPointerException, null

If I change the oauth client to hit the oauth server without the loadBalanced option, it works fine

security:
  oauth2:
    resource:
      userInfoUri: http://localhost:4444/auth_service/users/current #through zuul proxy

I tried to debug, but this nullpointer exception occurs very deep on rest template implementations. Please, I need some help here.

2

There are 2 answers

0
Grinish Nepal On

I have something like this in mine try this configuration to see if it might work.

zuul:
  routes:
    user-service:
      path: /user/**
      stripPrefix: false

security:
  # Disable Spring Boot basic authentication
  basic:
    enabled: false
  oauth2:
    client:
      accessTokenUri: http://<zuulHostname>/user/oauth/token
      userAuthorizationUri: http://<zuulHostname>/user/oauth/authorize
      ...
0
Ravik On

Kindly check the token that you are getting does it have complete information about the user. Most importantly the userName. It should be set when you generate the token. You can see what information is in the token by parsing the token here