From 494d9973a6b51ce24b926b0b565ac2dc2847ece3 Mon Sep 17 00:00:00 2001 From: mposolda Date: Tue, 23 Aug 2016 14:57:31 +0200 Subject: [PATCH] KEYCLOAK-3460 Support for ClientUpdatedEvent --- .../org/keycloak/models/jpa/ClientAdapter.java | 12 ++++++++++++ .../mongo/keycloak/adapters/ClientAdapter.java | 15 +++++++++++++-- .../main/java/org/keycloak/models/RealmModel.java | 6 ++++++ .../models/utils/RepresentationToModel.java | 6 +++--- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/ClientAdapter.java b/model/jpa/src/main/java/org/keycloak/models/jpa/ClientAdapter.java index 8e126e5698..e1a546e272 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/ClientAdapter.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/ClientAdapter.java @@ -498,6 +498,18 @@ public class ClientAdapter implements ClientModel, JpaModel { @Override public void updateClient() { em.flush(); + session.getKeycloakSessionFactory().publish(new RealmModel.ClientUpdatedEvent() { + + @Override + public ClientModel getUpdatedClient() { + return ClientAdapter.this; + } + + @Override + public KeycloakSession getKeycloakSession() { + return session; + } + }); } @Override diff --git a/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/ClientAdapter.java b/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/ClientAdapter.java index f4983f98a3..5d6e0532d1 100755 --- a/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/ClientAdapter.java +++ b/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/ClientAdapter.java @@ -17,8 +17,6 @@ package org.keycloak.models.mongo.keycloak.adapters; -import com.mongodb.DBObject; -import com.mongodb.QueryBuilder; import org.keycloak.connections.mongo.api.context.MongoStoreInvocationContext; import org.keycloak.models.ClientModel; import org.keycloak.models.ClientTemplateModel; @@ -65,6 +63,19 @@ public class ClientAdapter extends AbstractMongoAdapter imple @Override public void updateClient() { updateMongoEntity(); + + session.getKeycloakSessionFactory().publish(new RealmModel.ClientUpdatedEvent() { + + @Override + public ClientModel getUpdatedClient() { + return ClientAdapter.this; + } + + @Override + public KeycloakSession getKeycloakSession() { + return session; + } + }); } diff --git a/server-spi/src/main/java/org/keycloak/models/RealmModel.java b/server-spi/src/main/java/org/keycloak/models/RealmModel.java index 04f1476716..61dc9c10f8 100755 --- a/server-spi/src/main/java/org/keycloak/models/RealmModel.java +++ b/server-spi/src/main/java/org/keycloak/models/RealmModel.java @@ -56,6 +56,12 @@ public interface RealmModel extends RoleContainerModel { ClientModel getCreatedClient(); } + // Called also during client creation after client is fully initialized (including all attributes etc) + interface ClientUpdatedEvent extends ProviderEvent { + ClientModel getUpdatedClient(); + KeycloakSession getKeycloakSession(); + } + interface ClientRemovedEvent extends ProviderEvent { ClientModel getClient(); KeycloakSession getKeycloakSession(); diff --git a/server-spi/src/main/java/org/keycloak/models/utils/RepresentationToModel.java b/server-spi/src/main/java/org/keycloak/models/utils/RepresentationToModel.java index f36f010410..d1d5b059d7 100755 --- a/server-spi/src/main/java/org/keycloak/models/utils/RepresentationToModel.java +++ b/server-spi/src/main/java/org/keycloak/models/utils/RepresentationToModel.java @@ -943,7 +943,6 @@ public class RepresentationToModel { } else { client.setNodeReRegistrationTimeout(-1); } - client.updateClient(); if (resourceRep.getNotBefore() != null) { client.setNotBefore(resourceRep.getNotBefore()); @@ -1043,6 +1042,8 @@ public class RepresentationToModel { if (resourceRep.isUseTemplateMappers() != null) client.setUseTemplateMappers(resourceRep.isUseTemplateMappers()); else client.setUseTemplateMappers(resourceRep.getClientTemplate() != null); + client.updateClient(); + return client; } @@ -1066,7 +1067,6 @@ public class RepresentationToModel { if (rep.isSurrogateAuthRequired() != null) resource.setSurrogateAuthRequired(rep.isSurrogateAuthRequired()); if (rep.getNodeReRegistrationTimeout() != null) resource.setNodeReRegistrationTimeout(rep.getNodeReRegistrationTimeout()); if (rep.getClientAuthenticatorType() != null) resource.setClientAuthenticatorType(rep.getClientAuthenticatorType()); - resource.updateClient(); if (rep.getProtocol() != null) resource.setProtocol(rep.getProtocol()); if (rep.getAttributes() != null) { @@ -1122,7 +1122,7 @@ public class RepresentationToModel { } } - + resource.updateClient(); } // CLIENT TEMPLATES