Skip to content

Commit

Permalink
chore: Bust OAuth2 client cache for spring boot 3.3 (#36660)
Browse files Browse the repository at this point in the history
  • Loading branch information
nidhi-nair authored Oct 2, 2024
1 parent 688324e commit 40c4a66
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
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();
}
}

0 comments on commit 40c4a66

Please sign in to comment.