1

We wrote a custom ClientDetailsService for our OAuth2 authorization server:

public class MyClientDetailsService implements ClientDetailsService {

 @Override
 public ClientDetails loadClientByClientId(String clientId) {
 log.info("Got called!");
 ...
 }
}

The log looks like that:

... Got called!
... Got called!
... Got called!
... Got called!
... Got called!
... Got called!

Dependency:

    <dependency>
        <groupId>org.springframework.security.oauth</groupId>
        <artifactId>spring-security-oauth2</artifactId>
        <version>2.1.11.RELEASE</version>
    </dependency>

In the official git-hub the topic was already discussed, but until today nothing was fixed so far. (https://github.com/spring-projects/spring-security-oauth/issues/141)

My question is, does anybody know a workaround for this problem? We are accessing our database with every invocation and it is very memory consuming.

dso
  • 109
  • 10
  • can you add calls of loadClientByClientId method to your question? – Sergei Podlipaev Mar 13 '19 at 15:21
  • LoadClientByClientId is a framework method (see line 96): https://github.com/spring-projects/spring-security-oauth/blob/master/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/endpoint/TokenEndpoint.java – dso Mar 13 '19 at 15:39

1 Answers1

4

you need to use the cache provided by spring-boot2.

please enable the caching in springboot by @EnableCaching

@SpringBootApplication
@EnableCaching
class Starter {
   public static void main(String[] args) {
      SpringApplication.run(Starter.class, args);
   }
}

then cache the loadClientByClientId by using @Cacheable.

public class MyClientDetailsService implements ClientDetailsService {

  @Override
  @Cacheable("ClientDetails")
  public ClientDetails loadClientByClientId(String clientId) {
    log.info("Got called!");
    ...
  }
}
HuntsMan
  • 762
  • 5
  • 16