Настраиваемое пользовательское кэширование TTL для токена Spring-boot-starter-oauth2-clientJAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Настраиваемое пользовательское кэширование TTL для токена Spring-boot-starter-oauth2-client

Сообщение Anonymous »

Я надеюсь, что смогу кэшировать токен на основе настраиваемого TTL
У меня есть простой код, такой как:

Код: Выделить всё

spring:
application:
name: client-application
security:
oauth2:
client:
registration:
hello-client:
provider: hello-provider
client-id: someusername
client-secret: somepassword
authorization-grant-type: client_credentials
scope: resolve
hi-client:
provider: hi-provider
client-id: anotherusername
client-secret: anotherpassword
authorization-grant-type: client_credentials
scope: download
provider:
hello-provider:
token-uri: https://tokenprovider.com/token
hi-provider:
token-uri: https://secureservice.com/token

application:
url:
hello: https://somecoolcompany.com/api/v1.0/hello
hi: https://veryawsomeendpoint.com/v2/hi

Код: Выделить всё

@Service
public class HelloServiceClient {

private static final Logger log = LoggerFactory.getLogger(HelloServiceClient.class);

private final RestClient restClient;

public HelloServiceClient(RestClient.Builder builder, @Value("${application.url.hello}") String urlHello) {
this.restClient = builder
.baseUrl(urlHello)
.requestInterceptor(
(request, body, execution) -> {
log.info("Lambda Interceptor: modifying before sending request");
ClientHttpResponse response = execution.execute(request, body);
log.info("Lambda Interceptor: modifying after receiving response");
return response;
}
)
.build();
}

public String hello() {
return this.restClient.get()
.uri("/hello")
.attributes(clientRegistrationId("hello-client"))
.retrieve()
.body(String.class);
}

}

Код: Выделить всё

package vn.cloud.restclientdemo.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClient;

import static org.springframework.security.oauth2.client.web.client.RequestAttributeClientRegistrationIdResolver.clientRegistrationId;

@Service
public class HiServiceClient {

private final RestClient restClient;

public HiServiceClient(RestClient.Builder builder, @Value("${application.url.hi}") String urlHi) {
this.restClient = builder
.baseUrl(urlHi)
.build();
}

public String hi() {
return this.restClient.get()
.uri("/hi")
.attributes(clientRegistrationId("hi-client"))
.retrieve()
.body(String.class);
}

}

Обратите внимание, что здесь 4 разных URL-адреса.
Бизнес-логика проста: вызовите конечную точку A, но для этой конечной точки A нужен токен из токена. поставщика B.
Затем вызовите конечную точку ресурса C, которой также нужен еще один токен от поставщика токенов D.
всего 4.
Приложение находится под высокой нагрузкой. И политики токенов разные.
Например, первый токен действителен 9 минут, а второй токен действителен только 1 минуту.
Кэширование здесь имеет решающее значение, поскольку при высокой нагрузке мы хотели бы избегайте ненужных запросов на получение токена, пока он еще активен. Было бы здорово его кешировать.
Но не только кешировать, еще и уметь настраивать.
Я на что-то надеялся вот так:

Код: Выделить всё

spring:
application:
name: client-application
security:
oauth2:
client:
registration:
hello-client:
provider: hello-provider
client-id: someusername
client-secret: somepassword
authorization-grant-type: client_credentials
scope: resolve
TTL: 9m
hi-client:
provider: hi-provider
client-id: anotherusername
client-secret: anotherpassword
authorization-grant-type: client_credentials
scope: download
TTL: 1m
provider:
hello-provider:
token-uri: https://tokenprovider.com/token
hi-provider:
token-uri: https://secureservice.com/token

application:
url:
hello: https://somecoolcompany.com/api/v1.0/hello
hi: https://veryawsomeendpoint.com/v2/hi
Вопрос: как заставить Spring-boot-starter-oauth2-client кэшировать токен в течение настраиваемого периода времени?

Подробнее здесь: https://stackoverflow.com/questions/793 ... ient-token
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Используйте Spring-boot-starter-oauth2-client для передачи токена в Spring Framework версии 6 HttpInterface @HttpExchang
    Anonymous » » в форуме JAVA
    0 Ответы
    8 Просмотры
    Последнее сообщение Anonymous
  • Spring-Boot-Starter-AMQP с использованием Spring-Boot-Starter-AMQP
    Anonymous » » в форуме JAVA
    0 Ответы
    38 Просмотры
    Последнее сообщение Anonymous
  • Spring-Boot-Starter-AMQP с использованием Spring-Boot-Starter-AMQP
    Anonymous » » в форуме JAVA
    0 Ответы
    33 Просмотры
    Последнее сообщение Anonymous
  • Spring-Boot-Starter-AMQP с использованием Spring-Boot-Starter-AMQP
    Anonymous » » в форуме JAVA
    0 Ответы
    15 Просмотры
    Последнее сообщение Anonymous
  • Spring-Boot-Starter-AMQP с использованием Spring-Boot-Starter-AMQP
    Anonymous » » в форуме JAVA
    0 Ответы
    21 Просмотры
    Последнее сообщение Anonymous

Вернуться в «JAVA»