Adding realmName to be logged by jboss-logging event listener

closes #27506

Signed-off-by: mposolda <mposolda@gmail.com>
This commit is contained in:
mposolda 2024-05-28 10:57:56 +02:00 committed by Marek Posolda
parent 25548a7ccc
commit 49a2aaf7bc
8 changed files with 43 additions and 12 deletions

View file

@ -32,6 +32,7 @@ public class Event {
private EventType type; private EventType type;
private String realmId; private String realmId;
private String realmName;
private String clientId; private String clientId;
@ -77,6 +78,14 @@ public class Event {
this.realmId = maxLength(realmId, 255); this.realmId = maxLength(realmId, 255);
} }
public String getRealmName() {
return realmName;
}
public void setRealmName(String realmName) {
this.realmName = realmName;
}
public String getClientId() { public String getClientId() {
return clientId; return clientId;
} }
@ -131,6 +140,7 @@ public class Event {
clone.time = time; clone.time = time;
clone.type = type; clone.type = type;
clone.realmId = realmId; clone.realmId = realmId;
clone.realmName = realmName;
clone.clientId = clientId; clone.clientId = clientId;
clone.userId = userId; clone.userId = userId;
clone.sessionId = sessionId; clone.sessionId = sessionId;

View file

@ -104,11 +104,7 @@ public class EventBuilder {
public EventBuilder realm(RealmModel realm) { public EventBuilder realm(RealmModel realm) {
event.setRealmId(realm == null ? null : realm.getId()); event.setRealmId(realm == null ? null : realm.getId());
return this; event.setRealmName(realm == null ? null : realm.getName());
}
public EventBuilder realm(String realmId) {
event.setRealmId(realmId);
return this; return this;
} }

View file

@ -28,6 +28,8 @@ public class AdminEvent {
private String realmId; private String realmId;
private String realmName;
private AuthDetails authDetails; private AuthDetails authDetails;
/** /**
@ -48,6 +50,7 @@ public class AdminEvent {
this.id = toCopy.getId(); this.id = toCopy.getId();
this.time = toCopy.getTime(); this.time = toCopy.getTime();
this.realmId = toCopy.getRealmId(); this.realmId = toCopy.getRealmId();
this.realmName = toCopy.getRealmName();
this.authDetails = new AuthDetails(toCopy.getAuthDetails()); this.authDetails = new AuthDetails(toCopy.getAuthDetails());
this.resourceType = toCopy.getResourceTypeAsString(); this.resourceType = toCopy.getResourceTypeAsString();
this.operationType = toCopy.getOperationType(); this.operationType = toCopy.getOperationType();
@ -95,6 +98,17 @@ public class AdminEvent {
this.realmId = realmId; 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 * Returns authentication details
* *

View file

@ -23,6 +23,7 @@ package org.keycloak.events.admin;
public class AuthDetails { public class AuthDetails {
private String realmId; private String realmId;
private String realmName;
private String clientId; private String clientId;
@ -33,6 +34,7 @@ public class AuthDetails {
public AuthDetails() {} public AuthDetails() {}
public AuthDetails(AuthDetails toCopy) { public AuthDetails(AuthDetails toCopy) {
this.realmId = toCopy.getRealmId(); this.realmId = toCopy.getRealmId();
this.realmName = toCopy.getRealmName();
this.clientId = toCopy.getClientId(); this.clientId = toCopy.getClientId();
this.userId = toCopy.getUserId(); this.userId = toCopy.getUserId();
this.ipAddress = toCopy.getIpAddress(); this.ipAddress = toCopy.getIpAddress();
@ -46,6 +48,14 @@ public class AuthDetails {
this.realmId = realmId; this.realmId = realmId;
} }
public String getRealmName() {
return realmName;
}
public void setRealmName(String realmName) {
this.realmName = realmName;
}
public String getClientId() { public String getClientId() {
return clientId; return clientId;
} }

View file

@ -90,6 +90,8 @@ public class JBossLoggingEventListenerProvider implements EventListenerProvider
sanitize(sb, event.getType().toString()); sanitize(sb, event.getType().toString());
sb.append(", realmId="); sb.append(", realmId=");
sanitize(sb, event.getRealmId()); sanitize(sb, event.getRealmId());
sb.append(", realmName=");
sanitize(sb, event.getRealmName());
sb.append(", clientId="); sb.append(", clientId=");
sanitize(sb, event.getClientId()); sanitize(sb, event.getClientId());
sb.append(", userId="); sb.append(", userId=");
@ -145,6 +147,8 @@ public class JBossLoggingEventListenerProvider implements EventListenerProvider
sanitize(sb, adminEvent.getOperationType().toString()); sanitize(sb, adminEvent.getOperationType().toString());
sb.append(", realmId="); sb.append(", realmId=");
sanitize(sb, adminEvent.getAuthDetails().getRealmId()); sanitize(sb, adminEvent.getAuthDetails().getRealmId());
sb.append(", realmName=");
sanitize(sb, adminEvent.getAuthDetails().getRealmName());
sb.append(", clientId="); sb.append(", clientId=");
sanitize(sb, adminEvent.getAuthDetails().getClientId()); sanitize(sb, adminEvent.getAuthDetails().getClientId());
sb.append(", userId="); sb.append(", userId=");

View file

@ -103,11 +103,7 @@ public class AdminEventBuilder {
public AdminEventBuilder realm(RealmModel realm) { public AdminEventBuilder realm(RealmModel realm) {
adminEvent.setRealmId(realm.getId()); adminEvent.setRealmId(realm.getId());
return this; adminEvent.setRealmName(realm.getName());
}
public AdminEventBuilder realm(String realmId) {
adminEvent.setRealmId(realmId);
return this; return this;
} }
@ -173,6 +169,7 @@ public class AdminEventBuilder {
} else { } else {
authDetails.setRealmId(realm.getId()); authDetails.setRealmId(realm.getId());
} }
authDetails.setRealmName(realm.getName());
adminEvent.setAuthDetails(authDetails); adminEvent.setAuthDetails(authDetails);
return this; return this;
} }

View file

@ -497,7 +497,7 @@ public class RealmAdminResource {
// instead of the realm being deleted. // instead of the realm being deleted.
AdminEventBuilder deleteAdminEvent = new AdminEventBuilder(auth.adminAuth().getRealm(), auth.adminAuth(), session, connection); AdminEventBuilder deleteAdminEvent = new AdminEventBuilder(auth.adminAuth().getRealm(), auth.adminAuth(), session, connection);
deleteAdminEvent.operation(OperationType.DELETE).resource(ResourceType.REALM) deleteAdminEvent.operation(OperationType.DELETE).resource(ResourceType.REALM)
.realm(auth.adminAuth().getRealm().getId()).resourcePath(realm.getName()).success(); .realm(auth.adminAuth().getRealm()).resourcePath(realm.getName()).success();
} }
/** /**

View file

@ -154,7 +154,7 @@ public class RealmsAdminResource {
// The create event is associated with the realm of the user executing the operation, // The create event is associated with the realm of the user executing the operation,
// instead of the realm being created. // instead of the realm being created.
AdminEventBuilder adminEvent = new AdminEventBuilder(auth.getRealm(), auth, session, clientConnection); 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()) .resourcePath(realm.getName())
.representation(ModelToRepresentation.toRepresentation(session, realm, false)) .representation(ModelToRepresentation.toRepresentation(session, realm, false))
.success(); .success();