Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revisit condition to create a OAuth2RestTemplate #5202

Closed
snicoll opened this issue Feb 23, 2016 · 3 comments
Closed

Revisit condition to create a OAuth2RestTemplate #5202

snicoll opened this issue Feb 23, 2016 · 3 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@snicoll
Copy link
Member

snicoll commented Feb 23, 2016

The doc currently states:

To make your webapp into an OAuth2 client you can simply add @EnableOAuth2Client and Spring Boot will create an OAuth2RestTemplate for you to @autowire.

That's actually inaccurate. The mere presence of security.oauth2.client.* is enough to create the template. If you have those settings on the side in case you want to test OAuth, you can easily become in a situation where OAuth is "half-configured".

Also, the documentation should clearly explain the impacts of having such template as it is flagged @Primary and would replace any vanilla RestTemplate that was configured by the user.

@dsyer
Copy link
Member

dsyer commented Feb 23, 2016

Actually there are 2 conditions: one on the security.oauth2.client.* properties and one on the classpath (to ensure that OAuth2 is available).

To narrow the condition we would need to detect any intention by the user to have an OAuth2ClientContext. One signal for that would be a user config bean with @EnableOAuth2Client (or @EnableOAuth2Sso). Another would be the use of @EnableResourceServer when a UserInfoTokenServices was going to be used to validate tokens. There is an existing condition that detects that, so probably it can all work out if the configs are ordered properly.

The @Primary thing is strange, but I guess we should keep it for consistency (and document it).

@dsyer
Copy link
Member

dsyer commented Apr 26, 2016

I can't find the discussion now, but I'm sure we talked about it the other day, so this is what I remember: Spring Cloud stopped creating @Beans of type RestTemplate (the user has to choose to create one, and it will then be enhanced if it is annotated). We should do the same here (if the user creates a @Bean of type OAuth2RestTemplate, maybe with an annotation, we can enhance it). The @Primary thing was a mistake.

dsyer pushed a commit to dsyer/spring-boot that referenced this issue May 10, 2016
* Removes the OAuth2RestTemplate bean (user should define his own)
* Adds @userinfo qualifier for the template that is needed by the
UserInfoTokenServices

Still for discussion:

* How to prevent the user app blowing up when he needs to autowire
a RestTemplate and spring-boot-test wants to add a one as well (the
github sample in this change shows that you can create a @primary one
to work around that)
* Do we need to further abstract the user info rest template. Most of
the time the user won't care about it and it doesn't need to be a
@bean. Perhaps it could be provided by a @bean that has an explicit
factory contract?

See spring-projectsgh-5507, spring-projectsgh-5202
@snicoll snicoll added the type: enhancement A general enhancement label May 13, 2016
@snicoll snicoll added this to the 1.4.0.M3 milestone May 13, 2016
@snicoll snicoll self-assigned this May 13, 2016
@snicoll
Copy link
Member Author

snicoll commented May 13, 2016

I went ahead and removed the 2 lines bean definition. If a user needs that infrastructure, they can create it easily in their own config.

When #5507 is implemented we should revisit this change to provide something similar for OAuth2RestTemplate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants