Spring oauth default token caching?

Viewed 3730

I haven't been able to find the documentation for Spring-managed tokens, and how to cache them. The below code triggers an auth call to get the token EVERY time I call the remove service.

I'm using Spring OAuth with default configuration as follows:

@Bean(name="serviceRestTemplate")
public RestTemplate serviceRestTemplate(
    @Value("${authUri}") String authUri,
    @Value("${username}") String username,
    @Value("${password}") String password,
    @Value("${readTimeout}") int readTimeout,
    @Value("${connectTimeout}") int connectTimeout) {

ClientCredentialsResourceDetails details = new ClientCredentialsResourceDetails();
details.setAccessTokenUri(authUri);
    details.setClientId(username);
    details.setClientSecret(password);
RestTemplate restTemplate = new OAuth2RestTemplate(details, new DefaultOAuth2ClientContext(new DefaultAccessTokenRequest());
}

My questions are:

  • What is the default behavior? / Is there any kind of caching with the above?
  • Can I enable token caching through Spring?
0 Answers
Related