[keycloak-user] Why does KeycloakRestTemplate Bean needs to be Prototype scoped?

Dominik Guhr pinguwien at gmail.com
Wed Sep 6 07:02:29 EDT 2017


Hi all,

I hope I am right here. I am doing a blog-series in german about 
Keycloak (3.2.1 Final) and its integration in Spring Boot and Spring 
Security.

Everything is good so far, but there's one Thing that bothers me.

As the subject states: Why does KeycloakRestTemplate Bean needs to be 
Prototype scoped?

The docs say in 4.2.1.8:
"To simplify communication between clients, Keycloak provides an 
extension of Spring’s RestTemplate that handles bearer token 
authentication for you. To enable this feature your security 
configuration must add the KeycloakRestTemplate bean. Note that it must 
be scoped as a prototype to function correctly."

So, I don't just want to give my readers something they could read out 
of the docs, so I looked for the standard Scope of RestTemplate, which 
seems to be Singleton, for RestTemplate seems to be threadsafe and 
creation of resttemplates is somewhat costly (source: 
https://stackoverflow.com/questions/22989500/is-resttemplate-thread-safe 
and links/comments)

I hope someone could give me more insights here.

Best regards,
Dominik


More information about the keycloak-user mailing list