From 31d8a927ff3f9737a59a10d72218c21dc7468bc3 Mon Sep 17 00:00:00 2001 From: Satria Hu Date: Tue, 2 Nov 2021 09:19:31 +0700 Subject: [PATCH] KEYCLOAK-19602 moved create/update admin console event after commit, to prevent false alarm to event listeners --- .../org/keycloak/services/resources/admin/UserResource.java | 3 +-- .../org/keycloak/services/resources/admin/UsersResource.java | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/services/src/main/java/org/keycloak/services/resources/admin/UserResource.java b/services/src/main/java/org/keycloak/services/resources/admin/UserResource.java index 23ba34ad90..b39e93e3c4 100755 --- a/services/src/main/java/org/keycloak/services/resources/admin/UserResource.java +++ b/services/src/main/java/org/keycloak/services/resources/admin/UserResource.java @@ -188,11 +188,10 @@ public class UserResource { session.getProvider(BruteForceProtector.class).cleanUpPermanentLockout(session, realm, user); } - adminEvent.operation(OperationType.UPDATE).resourcePath(session.getContext().getUri()).representation(rep).success(); - if (session.getTransactionManager().isActive()) { session.getTransactionManager().commit(); } + adminEvent.operation(OperationType.UPDATE).resourcePath(session.getContext().getUri()).representation(rep).success(); return Response.noContent().build(); } catch (ModelDuplicateException e) { return ErrorResponse.exists("User exists with same username or email"); diff --git a/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java b/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java index 8734cd4a9d..f930980ecd 100755 --- a/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java +++ b/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java @@ -161,12 +161,11 @@ public class UsersResource { RepresentationToModel.createGroups(rep, realm, user); RepresentationToModel.createCredentials(rep, session, realm, user, true); - adminEvent.operation(OperationType.CREATE).resourcePath(session.getContext().getUri(), user.getId()).representation(rep).success(); if (session.getTransactionManager().isActive()) { session.getTransactionManager().commit(); } - + adminEvent.operation(OperationType.CREATE).resourcePath(session.getContext().getUri(), user.getId()).representation(rep).success(); return Response.created(session.getContext().getUri().getAbsolutePathBuilder().path(user.getId()).build()).build(); } catch (ModelDuplicateException e) { if (session.getTransactionManager().isActive()) {