Skip to content

Commit

Permalink
Merge pull request keycloak#4594 from hmlnarik/KEYCLOAK-5688-External…
Browse files Browse the repository at this point in the history
…izer-for-entities-shared-across-DC-2

KEYCLOAK-5688 Externalizers for cluster messages and predicates
  • Loading branch information
mposolda authored Oct 24, 2017
2 parents 8e0cc2a + faf830d commit a7bc294
Show file tree
Hide file tree
Showing 48 changed files with 1,821 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@
package org.keycloak.cluster.infinispan;

import org.keycloak.cluster.ClusterEvent;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import org.infinispan.commons.marshall.Externalizer;
import org.infinispan.commons.marshall.MarshallUtil;
import org.infinispan.commons.marshall.SerializeWith;

/**
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
*/
@SerializeWith(WrapperClusterEvent.ExternalizerImpl.class)
public class WrapperClusterEvent implements ClusterEvent {

private String eventKey;
Expand Down Expand Up @@ -83,4 +90,46 @@ public void setDelegateEvent(ClusterEvent delegateEvent) {
public String toString() {
return String.format("WrapperClusterEvent [ eventKey=%s, sender=%s, senderSite=%s, delegateEvent=%s ]", eventKey, sender, senderSite, delegateEvent.toString());
}

public static class ExternalizerImpl implements Externalizer<WrapperClusterEvent> {

private static final int VERSION_1 = 1;

@Override
public void writeObject(ObjectOutput output, WrapperClusterEvent obj) throws IOException {
output.writeByte(VERSION_1);

MarshallUtil.marshallString(obj.eventKey, output);
MarshallUtil.marshallString(obj.sender, output);
MarshallUtil.marshallString(obj.senderSite, output);
output.writeBoolean(obj.ignoreSender);
output.writeBoolean(obj.ignoreSenderSite);

output.writeObject(obj.delegateEvent);
}

@Override
public WrapperClusterEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException {
switch (input.readByte()) {
case VERSION_1:
return readObjectVersion1(input);
default:
throw new IOException("Unknown version");
}
}

public WrapperClusterEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException {
WrapperClusterEvent res = new WrapperClusterEvent();

res.eventKey = MarshallUtil.unmarshallString(input);
res.sender = MarshallUtil.unmarshallString(input);
res.senderSite = MarshallUtil.unmarshallString(input);
res.ignoreSender = input.readBoolean();
res.ignoreSenderSite = input.readBoolean();

res.delegateEvent = (ClusterEvent) input.readObject();

return res;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@
package org.keycloak.keys.infinispan;

import org.keycloak.models.cache.infinispan.events.InvalidationEvent;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import org.infinispan.commons.marshall.Externalizer;
import org.infinispan.commons.marshall.MarshallUtil;
import org.infinispan.commons.marshall.SerializeWith;

/**
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
*/
@SerializeWith(PublicKeyStorageInvalidationEvent.ExternalizerImpl.class)
public class PublicKeyStorageInvalidationEvent extends InvalidationEvent {

private String cacheKey;
Expand All @@ -45,4 +52,34 @@ public String getCacheKey() {
public String toString() {
return "PublicKeyStorageInvalidationEvent [ " + cacheKey + " ]";
}

public static class ExternalizerImpl implements Externalizer<PublicKeyStorageInvalidationEvent> {

private static final int VERSION_1 = 1;

@Override
public void writeObject(ObjectOutput output, PublicKeyStorageInvalidationEvent obj) throws IOException {
output.writeByte(VERSION_1);

MarshallUtil.marshallString(obj.cacheKey, output);
}

@Override
public PublicKeyStorageInvalidationEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException {
switch (input.readByte()) {
case VERSION_1:
return readObjectVersion1(input);
default:
throw new IOException("Unknown version");
}
}

public PublicKeyStorageInvalidationEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException {
PublicKeyStorageInvalidationEvent res = new PublicKeyStorageInvalidationEvent();
res.cacheKey = MarshallUtil.unmarshallString(input);

return res;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,19 @@

import org.keycloak.models.cache.infinispan.authorization.StoreFactoryCacheManager;
import org.keycloak.models.cache.infinispan.events.InvalidationEvent;
import org.keycloak.models.sessions.infinispan.util.KeycloakMarshallUtil;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.HashSet;
import org.infinispan.commons.marshall.Externalizer;
import org.infinispan.commons.marshall.MarshallUtil;
import org.infinispan.commons.marshall.SerializeWith;

/**
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
*/
@SerializeWith(PolicyRemovedEvent.ExternalizerImpl.class)
public class PolicyRemovedEvent extends InvalidationEvent implements AuthorizationCacheInvalidationEvent {

private String id;
Expand Down Expand Up @@ -59,4 +68,43 @@ public String toString() {
public void addInvalidations(StoreFactoryCacheManager cache, Set<String> invalidations) {
cache.policyRemoval(id, name, resources, resourceTypes, scopes, serverId, invalidations);
}

public static class ExternalizerImpl implements Externalizer<PolicyRemovedEvent> {

private static final int VERSION_1 = 1;

@Override
public void writeObject(ObjectOutput output, PolicyRemovedEvent obj) throws IOException {
output.writeByte(VERSION_1);

MarshallUtil.marshallString(obj.id, output);
MarshallUtil.marshallString(obj.name, output);
KeycloakMarshallUtil.writeCollection(obj.scopes, KeycloakMarshallUtil.STRING_EXT, output);
KeycloakMarshallUtil.writeCollection(obj.resources, KeycloakMarshallUtil.STRING_EXT, output);
KeycloakMarshallUtil.writeCollection(obj.resourceTypes, KeycloakMarshallUtil.STRING_EXT, output);
MarshallUtil.marshallString(obj.serverId, output);
}

@Override
public PolicyRemovedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException {
switch (input.readByte()) {
case VERSION_1:
return readObjectVersion1(input);
default:
throw new IOException("Unknown version");
}
}

public PolicyRemovedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException {
PolicyRemovedEvent res = new PolicyRemovedEvent();
res.id = MarshallUtil.unmarshallString(input);
res.name = MarshallUtil.unmarshallString(input);
res.scopes = KeycloakMarshallUtil.readCollection(input, KeycloakMarshallUtil.STRING_EXT, HashSet::new);
res.resources = KeycloakMarshallUtil.readCollection(input, KeycloakMarshallUtil.STRING_EXT, HashSet::new);
res.resourceTypes = KeycloakMarshallUtil.readCollection(input, KeycloakMarshallUtil.STRING_EXT, HashSet::new);
res.serverId = MarshallUtil.unmarshallString(input);

return res;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,25 @@
import org.keycloak.models.cache.infinispan.authorization.StoreFactoryCacheManager;
import org.keycloak.models.cache.infinispan.events.InvalidationEvent;

import org.keycloak.models.sessions.infinispan.util.KeycloakMarshallUtil;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.HashSet;
import java.util.Set;
import org.infinispan.commons.marshall.Externalizer;
import org.infinispan.commons.marshall.MarshallUtil;
import org.infinispan.commons.marshall.SerializeWith;

/**
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
*/
@SerializeWith(PolicyUpdatedEvent.ExternalizerImpl.class)
public class PolicyUpdatedEvent extends InvalidationEvent implements AuthorizationCacheInvalidationEvent {

private String id;
private String name;
private static Set<String> resources;
private Set<String> resources;
private Set<String> resourceTypes;
private Set<String> scopes;
private String serverId;
Expand Down Expand Up @@ -59,4 +68,43 @@ public String toString() {
public void addInvalidations(StoreFactoryCacheManager cache, Set<String> invalidations) {
cache.policyUpdated(id, name, resources, resourceTypes, scopes, serverId, invalidations);
}

public static class ExternalizerImpl implements Externalizer<PolicyUpdatedEvent> {

private static final int VERSION_1 = 1;

@Override
public void writeObject(ObjectOutput output, PolicyUpdatedEvent obj) throws IOException {
output.writeByte(VERSION_1);

MarshallUtil.marshallString(obj.id, output);
MarshallUtil.marshallString(obj.name, output);
KeycloakMarshallUtil.writeCollection(obj.resources, KeycloakMarshallUtil.STRING_EXT, output);
KeycloakMarshallUtil.writeCollection(obj.resourceTypes, KeycloakMarshallUtil.STRING_EXT, output);
KeycloakMarshallUtil.writeCollection(obj.scopes, KeycloakMarshallUtil.STRING_EXT, output);
MarshallUtil.marshallString(obj.serverId, output);
}

@Override
public PolicyUpdatedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException {
switch (input.readByte()) {
case VERSION_1:
return readObjectVersion1(input);
default:
throw new IOException("Unknown version");
}
}

public PolicyUpdatedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException {
PolicyUpdatedEvent res = new PolicyUpdatedEvent();
res.id = MarshallUtil.unmarshallString(input);
res.name = MarshallUtil.unmarshallString(input);
res.resources = KeycloakMarshallUtil.readCollection(input, KeycloakMarshallUtil.STRING_EXT, HashSet::new);
res.resourceTypes = KeycloakMarshallUtil.readCollection(input, KeycloakMarshallUtil.STRING_EXT, HashSet::new);
res.scopes = KeycloakMarshallUtil.readCollection(input, KeycloakMarshallUtil.STRING_EXT, HashSet::new);
res.serverId = MarshallUtil.unmarshallString(input);

return res;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@
import org.keycloak.models.cache.infinispan.authorization.StoreFactoryCacheManager;
import org.keycloak.models.cache.infinispan.events.InvalidationEvent;

import org.keycloak.models.sessions.infinispan.util.KeycloakMarshallUtil;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.HashSet;
import java.util.Set;
import org.infinispan.commons.marshall.Externalizer;
import org.infinispan.commons.marshall.MarshallUtil;
import org.infinispan.commons.marshall.SerializeWith;

/**
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
*/
@SerializeWith(ResourceRemovedEvent.ExternalizerImpl.class)
public class ResourceRemovedEvent extends InvalidationEvent implements AuthorizationCacheInvalidationEvent {

private String id;
Expand Down Expand Up @@ -61,4 +70,45 @@ public String toString() {
public void addInvalidations(StoreFactoryCacheManager cache, Set<String> invalidations) {
cache.resourceRemoval(id, name, type, uri, owner, scopes, serverId, invalidations);
}

public static class ExternalizerImpl implements Externalizer<ResourceRemovedEvent> {

private static final int VERSION_1 = 1;

@Override
public void writeObject(ObjectOutput output, ResourceRemovedEvent obj) throws IOException {
output.writeByte(VERSION_1);

MarshallUtil.marshallString(obj.id, output);
MarshallUtil.marshallString(obj.name, output);
MarshallUtil.marshallString(obj.type, output);
MarshallUtil.marshallString(obj.uri, output);
MarshallUtil.marshallString(obj.owner, output);
KeycloakMarshallUtil.writeCollection(obj.scopes, KeycloakMarshallUtil.STRING_EXT, output);
MarshallUtil.marshallString(obj.serverId, output);
}

@Override
public ResourceRemovedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException {
switch (input.readByte()) {
case VERSION_1:
return readObjectVersion1(input);
default:
throw new IOException("Unknown version");
}
}

public ResourceRemovedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException {
ResourceRemovedEvent res = new ResourceRemovedEvent();
res.id = MarshallUtil.unmarshallString(input);
res.name = MarshallUtil.unmarshallString(input);
res.type = MarshallUtil.unmarshallString(input);
res.uri = MarshallUtil.unmarshallString(input);
res.owner = MarshallUtil.unmarshallString(input);
res.scopes = KeycloakMarshallUtil.readCollection(input, KeycloakMarshallUtil.STRING_EXT, HashSet::new);
res.serverId = MarshallUtil.unmarshallString(input);

return res;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@
import org.keycloak.models.cache.infinispan.authorization.StoreFactoryCacheManager;
import org.keycloak.models.cache.infinispan.events.InvalidationEvent;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Set;
import org.infinispan.commons.marshall.Externalizer;
import org.infinispan.commons.marshall.MarshallUtil;
import org.infinispan.commons.marshall.SerializeWith;

/**
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
*/
@SerializeWith(ResourceServerRemovedEvent.ExternalizerImpl.class)
public class ResourceServerRemovedEvent extends InvalidationEvent implements AuthorizationCacheInvalidationEvent {

private String id;
Expand All @@ -51,4 +58,35 @@ public String toString() {
public void addInvalidations(StoreFactoryCacheManager cache, Set<String> invalidations) {
cache.resourceServerRemoval(id, invalidations);
}

public static class ExternalizerImpl implements Externalizer<ResourceServerRemovedEvent> {

private static final int VERSION_1 = 1;

@Override
public void writeObject(ObjectOutput output, ResourceServerRemovedEvent obj) throws IOException {
output.writeByte(VERSION_1);

MarshallUtil.marshallString(obj.id, output);
MarshallUtil.marshallString(obj.clientId, output);
}

@Override
public ResourceServerRemovedEvent readObject(ObjectInput input) throws IOException, ClassNotFoundException {
switch (input.readByte()) {
case VERSION_1:
return readObjectVersion1(input);
default:
throw new IOException("Unknown version");
}
}

public ResourceServerRemovedEvent readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException {
ResourceServerRemovedEvent res = new ResourceServerRemovedEvent();
res.id = MarshallUtil.unmarshallString(input);
res.clientId = MarshallUtil.unmarshallString(input);

return res;
}
}
}
Loading

0 comments on commit a7bc294

Please sign in to comment.