-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Bust OAuth2 client cache for spring boot 3.3 (#36660)
- Loading branch information
1 parent
688324e
commit 40c4a66
Showing
2 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...rc/main/java/com/appsmith/server/migrations/db/ce/Migration063CacheBustSpringBoot3_3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, String> reactiveRedisOperations; | ||
|
||
@RollbackExecution | ||
public void rollbackExecution() {} | ||
|
||
@Execution | ||
public void execute() { | ||
doClearRedisOAuth2AuthClientKeys(reactiveRedisOperations); | ||
} | ||
|
||
public static void doClearRedisOAuth2AuthClientKeys( | ||
ReactiveRedisOperations<String, String> 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<Object> flushdb = reactiveRedisOperations.execute(RedisScript.of(script)); | ||
|
||
flushdb.blockLast(); | ||
} | ||
} |