Skip to content

Conversation

@pedroigor
Copy link
Contributor

Closes #33777

@pedroigor pedroigor requested a review from a team as a code owner October 10, 2024 13:49
Copy link
Member

@pruivo pruivo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Someone suggested to remove of all the InvalidationEvent implementations and using this event type everywhere. I would make this more future-proof to avoid future issues.
If you don't agree, the PR looks good to me!

public class CacheKeyInvalidatedEvent extends InvalidationEvent implements RealmCacheInvalidationEvent, UserCacheInvalidationEvent, AuthorizationCacheInvalidationEvent {

    @ProtoFactory
    public CacheKeyInvalidatedEvent(String id) {
        super(id);
    }

    @Override
    public void addInvalidations(RealmCacheManager realmCache, Set<String> invalidations) {
        addCacheKeyInvalidations(realmCache, invalidations);
    }

    @Override
    public void addInvalidations(StoreFactoryCacheManager storeFactoryCache, Set<String> invalidations) {
        addCacheKeyInvalidations(storeFactoryCache, invalidations);
    }

    @Override
    public void addInvalidations(UserCacheManager userCache, Set<String> invalidations) {
        addCacheKeyInvalidations(userCache, invalidations);
    }

    private void addCacheKeyInvalidations(CacheManager cacheManager, Set<String> invalidations) {
        cacheManager.invalidateCacheKey(getId(), invalidations);
    }
}

@sguilhen
Copy link
Contributor

I think it makes sense, and it would simplify the whole thing. Not sure if we should have that scoped in this PR, or open one just to handle the authorization events and do the necessary cleanup.

Copy link
Contributor

@ahus1 ahus1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving this one, and leaving it to the core-iam team to decide if they want to merge it as is, or create a follow-up PR.

@pedroigor
Copy link
Contributor Author

Someone suggested to remove of all the InvalidationEvent implementations and using this event type everywhere. I would make this more future-proof to avoid future issues. If you don't agree, the PR looks good to me!

public class CacheKeyInvalidatedEvent extends InvalidationEvent implements RealmCacheInvalidationEvent, UserCacheInvalidationEvent, AuthorizationCacheInvalidationEvent {

    @ProtoFactory
    public CacheKeyInvalidatedEvent(String id) {
        super(id);
    }

    @Override
    public void addInvalidations(RealmCacheManager realmCache, Set<String> invalidations) {
        addCacheKeyInvalidations(realmCache, invalidations);
    }

    @Override
    public void addInvalidations(StoreFactoryCacheManager storeFactoryCache, Set<String> invalidations) {
        addCacheKeyInvalidations(storeFactoryCache, invalidations);
    }

    @Override
    public void addInvalidations(UserCacheManager userCache, Set<String> invalidations) {
        addCacheKeyInvalidations(userCache, invalidations);
    }

    private void addCacheKeyInvalidations(CacheManager cacheManager, Set<String> invalidations) {
        cacheManager.invalidateCacheKey(getId(), invalidations);
    }
}

Sounds like a refactoring and I don't see any harm doing it here. But if you are not pushing for it I can send a separate PR.

@pedroigor pedroigor merged commit f4f3a7d into keycloak:main Oct 10, 2024
@pedroigor pedroigor deleted the issue-33777 branch October 10, 2024 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error when adding or removing a user from an organisation when there are 2 or more Keycloak servers in a cluster

4 participants