diff --git a/server-spi-private/src/main/java/org/keycloak/events/Event.java b/server-spi-private/src/main/java/org/keycloak/events/Event.java index 5da17d138d..80fae506a0 100644 --- a/server-spi-private/src/main/java/org/keycloak/events/Event.java +++ b/server-spi-private/src/main/java/org/keycloak/events/Event.java @@ -32,6 +32,7 @@ public class Event { private EventType type; private String realmId; + private String realmName; private String clientId; @@ -77,6 +78,14 @@ public class Event { this.realmId = maxLength(realmId, 255); } + public String getRealmName() { + return realmName; + } + + public void setRealmName(String realmName) { + this.realmName = realmName; + } + public String getClientId() { return clientId; } @@ -131,6 +140,7 @@ public class Event { clone.time = time; clone.type = type; clone.realmId = realmId; + clone.realmName = realmName; clone.clientId = clientId; clone.userId = userId; clone.sessionId = sessionId; diff --git a/server-spi-private/src/main/java/org/keycloak/events/EventBuilder.java b/server-spi-private/src/main/java/org/keycloak/events/EventBuilder.java index aa682b5ad6..fe308b2bff 100755 --- a/server-spi-private/src/main/java/org/keycloak/events/EventBuilder.java +++ b/server-spi-private/src/main/java/org/keycloak/events/EventBuilder.java @@ -104,11 +104,7 @@ public class EventBuilder { public EventBuilder realm(RealmModel realm) { event.setRealmId(realm == null ? null : realm.getId()); - return this; - } - - public EventBuilder realm(String realmId) { - event.setRealmId(realmId); + event.setRealmName(realm == null ? null : realm.getName()); return this; } diff --git a/server-spi-private/src/main/java/org/keycloak/events/admin/AdminEvent.java b/server-spi-private/src/main/java/org/keycloak/events/admin/AdminEvent.java index 6c6fb3aff7..1c2883f615 100644 --- a/server-spi-private/src/main/java/org/keycloak/events/admin/AdminEvent.java +++ b/server-spi-private/src/main/java/org/keycloak/events/admin/AdminEvent.java @@ -28,6 +28,8 @@ public class AdminEvent { private String realmId; + private String realmName; + private AuthDetails authDetails; /** @@ -48,6 +50,7 @@ public class AdminEvent { this.id = toCopy.getId(); this.time = toCopy.getTime(); this.realmId = toCopy.getRealmId(); + this.realmName = toCopy.getRealmName(); this.authDetails = new AuthDetails(toCopy.getAuthDetails()); this.resourceType = toCopy.getResourceTypeAsString(); this.operationType = toCopy.getOperationType(); @@ -95,6 +98,17 @@ public class AdminEvent { this.realmId = realmId; } + /** + * @return the name of the realm + */ + public String getRealmName() { + return realmName; + } + + public void setRealmName(String realmName) { + this.realmName = realmName; + } + /** * Returns authentication details * diff --git a/server-spi-private/src/main/java/org/keycloak/events/admin/AuthDetails.java b/server-spi-private/src/main/java/org/keycloak/events/admin/AuthDetails.java index 4dc7782961..5d88ebea3a 100644 --- a/server-spi-private/src/main/java/org/keycloak/events/admin/AuthDetails.java +++ b/server-spi-private/src/main/java/org/keycloak/events/admin/AuthDetails.java @@ -23,6 +23,7 @@ package org.keycloak.events.admin; public class AuthDetails { private String realmId; + private String realmName; private String clientId; @@ -33,6 +34,7 @@ public class AuthDetails { public AuthDetails() {} public AuthDetails(AuthDetails toCopy) { this.realmId = toCopy.getRealmId(); + this.realmName = toCopy.getRealmName(); this.clientId = toCopy.getClientId(); this.userId = toCopy.getUserId(); this.ipAddress = toCopy.getIpAddress(); @@ -46,6 +48,14 @@ public class AuthDetails { this.realmId = realmId; } + public String getRealmName() { + return realmName; + } + + public void setRealmName(String realmName) { + this.realmName = realmName; + } + public String getClientId() { return clientId; } diff --git a/services/src/main/java/org/keycloak/events/log/JBossLoggingEventListenerProvider.java b/services/src/main/java/org/keycloak/events/log/JBossLoggingEventListenerProvider.java index fa9b665e3b..0286d62efc 100755 --- a/services/src/main/java/org/keycloak/events/log/JBossLoggingEventListenerProvider.java +++ b/services/src/main/java/org/keycloak/events/log/JBossLoggingEventListenerProvider.java @@ -90,6 +90,8 @@ public class JBossLoggingEventListenerProvider implements EventListenerProvider sanitize(sb, event.getType().toString()); sb.append(", realmId="); sanitize(sb, event.getRealmId()); + sb.append(", realmName="); + sanitize(sb, event.getRealmName()); sb.append(", clientId="); sanitize(sb, event.getClientId()); sb.append(", userId="); @@ -145,6 +147,8 @@ public class JBossLoggingEventListenerProvider implements EventListenerProvider sanitize(sb, adminEvent.getOperationType().toString()); sb.append(", realmId="); sanitize(sb, adminEvent.getAuthDetails().getRealmId()); + sb.append(", realmName="); + sanitize(sb, adminEvent.getAuthDetails().getRealmName()); sb.append(", clientId="); sanitize(sb, adminEvent.getAuthDetails().getClientId()); sb.append(", userId="); diff --git a/services/src/main/java/org/keycloak/services/resources/admin/AdminEventBuilder.java b/services/src/main/java/org/keycloak/services/resources/admin/AdminEventBuilder.java index 99ce3c4fc2..6f4bd48df9 100644 --- a/services/src/main/java/org/keycloak/services/resources/admin/AdminEventBuilder.java +++ b/services/src/main/java/org/keycloak/services/resources/admin/AdminEventBuilder.java @@ -103,11 +103,7 @@ public class AdminEventBuilder { public AdminEventBuilder realm(RealmModel realm) { adminEvent.setRealmId(realm.getId()); - return this; - } - - public AdminEventBuilder realm(String realmId) { - adminEvent.setRealmId(realmId); + adminEvent.setRealmName(realm.getName()); return this; } @@ -173,6 +169,7 @@ public class AdminEventBuilder { } else { authDetails.setRealmId(realm.getId()); } + authDetails.setRealmName(realm.getName()); adminEvent.setAuthDetails(authDetails); return this; } diff --git a/services/src/main/java/org/keycloak/services/resources/admin/RealmAdminResource.java b/services/src/main/java/org/keycloak/services/resources/admin/RealmAdminResource.java index 42222e5fa2..9d13b1722e 100644 --- a/services/src/main/java/org/keycloak/services/resources/admin/RealmAdminResource.java +++ b/services/src/main/java/org/keycloak/services/resources/admin/RealmAdminResource.java @@ -497,7 +497,7 @@ public class RealmAdminResource { // instead of the realm being deleted. AdminEventBuilder deleteAdminEvent = new AdminEventBuilder(auth.adminAuth().getRealm(), auth.adminAuth(), session, connection); deleteAdminEvent.operation(OperationType.DELETE).resource(ResourceType.REALM) - .realm(auth.adminAuth().getRealm().getId()).resourcePath(realm.getName()).success(); + .realm(auth.adminAuth().getRealm()).resourcePath(realm.getName()).success(); } /** diff --git a/services/src/main/java/org/keycloak/services/resources/admin/RealmsAdminResource.java b/services/src/main/java/org/keycloak/services/resources/admin/RealmsAdminResource.java index 138a18b951..86f30fa9e8 100755 --- a/services/src/main/java/org/keycloak/services/resources/admin/RealmsAdminResource.java +++ b/services/src/main/java/org/keycloak/services/resources/admin/RealmsAdminResource.java @@ -154,7 +154,7 @@ public class RealmsAdminResource { // The create event is associated with the realm of the user executing the operation, // instead of the realm being created. AdminEventBuilder adminEvent = new AdminEventBuilder(auth.getRealm(), auth, session, clientConnection); - adminEvent.resource(ResourceType.REALM).realm(auth.getRealm().getId()).operation(OperationType.CREATE) + adminEvent.resource(ResourceType.REALM).realm(auth.getRealm()).operation(OperationType.CREATE) .resourcePath(realm.getName()) .representation(ModelToRepresentation.toRepresentation(session, realm, false)) .success();