From 40c4a6684408d8e6ff9e81b529cebb1e218a3770 Mon Sep 17 00:00:00 2001 From: Nidhi Date: Wed, 2 Oct 2024 20:06:40 +0530 Subject: [PATCH] chore: Bust OAuth2 client cache for spring boot 3.3 (#36660) --- .../server/configurations/RedisConfig.java | 2 +- .../Migration063CacheBustSpringBoot3_3.java | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration063CacheBustSpringBoot3_3.java diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/RedisConfig.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/RedisConfig.java index 8b255dea33f5..6a8a6cc6c7b2 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/RedisConfig.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/RedisConfig.java @@ -215,7 +215,7 @@ public byte[] serialize(Object t) { boolean allValuesAreClientDTOs = true; for (final LoginSource loginSource : LoginSource.oauthSources) { final Object value = data.get(loginSource.name().toLowerCase()); - if (value != null && !(value instanceof OAuth2AuthorizedClientDTO)) { + if (value != null && !(value instanceof OAuth2AuthorizedClient)) { allValuesAreClientDTOs = false; break; } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration063CacheBustSpringBoot3_3.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration063CacheBustSpringBoot3_3.java new file mode 100644 index 000000000000..61936af057f5 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration063CacheBustSpringBoot3_3.java @@ -0,0 +1,38 @@ +package com.appsmith.server.migrations.db.ce; + +import io.mongock.api.annotations.ChangeUnit; +import io.mongock.api.annotations.Execution; +import io.mongock.api.annotations.RollbackExecution; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.redis.core.ReactiveRedisOperations; +import org.springframework.data.redis.core.script.RedisScript; +import reactor.core.publisher.Flux; + +@RequiredArgsConstructor +@Slf4j +@ChangeUnit(order = "063", id = "reset_session_oauth2_spring_3_3") +public class Migration063CacheBustSpringBoot3_3 { + + private final ReactiveRedisOperations reactiveRedisOperations; + + @RollbackExecution + public void rollbackExecution() {} + + @Execution + public void execute() { + doClearRedisOAuth2AuthClientKeys(reactiveRedisOperations); + } + + public static void doClearRedisOAuth2AuthClientKeys( + ReactiveRedisOperations reactiveRedisOperations) { + final String authorizedClientsKey = + "sessionAttr:org.springframework.security.oauth2.client.web.server.WebSessionServerOAuth2AuthorizedClientRepository.AUTHORIZED_CLIENTS"; + final String script = + "for _,k in ipairs(redis.call('keys','spring:session:sessions:*')) do local fieldExists = redis.call('hexists', k, '" + + authorizedClientsKey + "'); if fieldExists == 1 then redis.call('del', k) end end"; + final Flux flushdb = reactiveRedisOperations.execute(RedisScript.of(script)); + + flushdb.blockLast(); + } +}