anarsultanov / keycloak-multi-tenancy

Keycloak extension for creating multi-tenant IAM for B2B SaaS applications.
Apache License 2.0
103 stars 11 forks source link

Unable to remove membership #2

Closed oleaasbo closed 10 months ago

oleaasbo commented 10 months ago

I get "Internal Server Error" when using the DELETE /tenants/${tenantId}/memberships/${memberId} endpoint on a fresh member.

Keycloak version 22.0.1 Keycloak-multi-tenancy version 22.0.0

Steps to reproduce:

  1. Create new tenant
  2. Invite new user
  3. User accepts invitation and login to the app
  4. Delete user

The keycloak logs shows error log:

Detail: Key (id)=(df2c5d55-5361-4b6a-85c7-42d624acc4c1) is still referenced from table "user_role_mapping".] [delete from USER_ENTITY where ID=?]
2023-08-30T09:35:26.906617491+02:00     at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:95)
2023-08-30T09:35:26.906633630+02:00     at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:56)
2023-08-30T09:35:26.906647820+02:00     at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:108)
2023-08-30T09:35:26.906659930+02:00     at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:278)
2023-08-30T09:35:26.906672940+02:00     at org.hibernate.engine.jdbc.mutation.internal.AbstractMutationExecutor.performNonBatchedMutation(AbstractMutationExecutor.java:108)
2023-08-30T09:35:26.906686583+02:00     at org.hibernate.engine.jdbc.mutation.internal.MutationExecutorSingleNonBatched.performNonBatchedOperations(MutationExecutorSingleNonBatched.java:40)
    at org.hibernate.engine.jdbc.mutation.internal.AbstractMutationExecutor.execute(AbstractMutationExecutor.java:53)
2023-08-30T09:35:26.906714353+02:00     at org.hibernate.persister.entity.mutation.DeleteCoordinator.doStaticDelete(DeleteCoordinator.java:300)
    at org.hibernate.persister.entity.mutation.DeleteCoordinator.coordinateDelete(DeleteCoordinator.java:87)
    at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2867)
    at org.hibernate.action.internal.EntityDeleteAction.execute(EntityDeleteAction.java:131)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:606)
2023-08-30T09:35:26.906801047+02:00     at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:475)
2023-08-30T09:35:26.906807420+02:00     at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:358)
2023-08-30T09:35:26.906813900+02:00     at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
2023-08-30T09:35:26.906820329+02:00     at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:127)
2023-08-30T09:35:26.906832786+02:00     at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1412)
2023-08-30T09:35:26.906839187+02:00     at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:485)
2023-08-30T09:35:26.906845574+02:00     at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:2301)
2023-08-30T09:35:26.906851874+02:00     at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:1966)
    at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:439)
2023-08-30T09:35:26.906864606+02:00     at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.beforeCompletion(JtaTransactionCoordinatorImpl.java:336)
    at org.hibernate.resource.transaction.backend.jta.internal.synchronization.SynchronizationCallbackCoordinatorNonTrackingImpl.beforeCompletion(SynchronizationCallbackCoordinatorNonTrackingImpl.java:47)
2023-08-30T09:35:26.906877791+02:00     at org.hibernate.resource.transaction.backend.jta.internal.synchronization.RegisteredSynchronization.beforeCompletion(RegisteredSynchronization.java:37)
2023-08-30T09:35:26.906884098+02:00     at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:76)
    at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:360)
    at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:91)
    at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:162)
    at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1295)
2023-08-30T09:35:26.906921505+02:00     at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:128)
2023-08-30T09:35:26.906929133+02:00     at io.quarkus.narayana.jta.runtime.NotifyingTransactionManager.commit(NotifyingTransactionManager.java:70)
2023-08-30T09:35:26.907007242+02:00     at org.keycloak.transaction.JtaTransactionWrapper.commit(JtaTransactionWrapper.java:90)
    at org.keycloak.services.DefaultKeycloakTransactionManager.commit(DefaultKeycloakTransactionManager.java:136)
2023-08-30T09:35:26.907046884+02:00     at org.keycloak.services.DefaultKeycloakSession.closeTransactionManager(DefaultKeycloakSession.java:407)
2023-08-30T09:35:26.907061449+02:00     at org.keycloak.services.DefaultKeycloakSession.close(DefaultKeycloakSession.java:372)
2023-08-30T09:35:26.907081949+02:00     at org.keycloak.quarkus.runtime.transaction.TransactionalSessionHandler.close(TransactionalSessionHandler.java:56)
    at org.keycloak.quarkus.runtime.integration.jaxrs.TransactionalResponseFilter.filter(TransactionalResponseFilter.java:48)
2023-08-30T09:35:26.907144683+02:00     at org.jboss.resteasy.core.interception.jaxrs.ContainerResponseContextImpl.filter(ContainerResponseContextImpl.java:329)
2023-08-30T09:35:26.907155941+02:00     at org.jboss.resteasy.core.ServerResponseWriter.executeFilters(ServerResponseWriter.java:243)
    at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:100)
2023-08-30T09:35:26.907172239+02:00     at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:73)
    at org.jboss.resteasy.core.SynchronousDispatcher.writeResponse(SynchronousDispatcher.java:518)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:458)
    at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:240)
2023-08-30T09:35:26.907223528+02:00     at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:154)
2023-08-30T09:35:26.907237010+02:00     at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:321)
2023-08-30T09:35:26.907246066+02:00     at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:157)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:229)
    at io.quarkus.resteasy.runtime.standalone.RequestDispatcher.service(RequestDispatcher.java:82)
2023-08-30T09:35:26.907265424+02:00     at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.dispatch(VertxRequestHandler.java:147)
    at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.handle(VertxRequestHandler.java:84)
    at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.handle(VertxRequestHandler.java:44)
2023-08-30T09:35:26.907288254+02:00     at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1284)
2023-08-30T09:35:26.907302823+02:00     at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:177)
2023-08-30T09:35:26.907316462+02:00     at io.vertx.ext.web.impl.RoutingContextWrapper.next(RoutingContextWrapper.java:200)
    at io.quarkus.vertx.http.runtime.options.HttpServerCommonHandlers$1.handle(HttpServerCommonHandlers.java:58)
2023-08-30T09:35:26.907347717+02:00     at io.quarkus.vertx.http.runtime.options.HttpServerCommonHandlers$1.handle(HttpServerCommonHandlers.java:36)
    at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1284)
2023-08-30T09:35:26.907362099+02:00     at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:177)
2023-08-30T09:35:26.907368520+02:00     at io.vertx.ext.web.impl.RoutingContextWrapper.next(RoutingContextWrapper.java:200)
2023-08-30T09:35:26.907375185+02:00     at org.keycloak.quarkus.runtime.integration.web.QuarkusRequestFilter.lambda$createBlockingHandler$0(QuarkusRequestFilter.java:82)
2023-08-30T09:35:26.907381602+02:00     at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:576)
2023-08-30T09:35:26.907390737+02:00     at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
2023-08-30T09:35:26.907410302+02:00     at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
2023-08-30T09:35:26.907424069+02:00     at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
2023-08-30T09:35:26.907454306+02:00     at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
2023-08-30T09:35:26.907468905+02:00     at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.base/java.lang.Thread.run(Thread.java:833)
2023-08-30T09:35:26.907484513+02:00 Caused by: org.postgresql.util.PSQLException: ERROR: update or delete on table "user_entity" violates foreign key constraint "fk_c4fqv34p1mbylloxang7b1q3l" on table "user_role_mapping"
2023-08-30T09:35:26.907490814+02:00   Detail: Key (id)=(df2c5d55-5361-4b6a-85c7-42d624acc4c1) is still referenced from table "user_role_mapping".
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2713)
2023-08-30T09:35:26.907503696+02:00     at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2401)
2023-08-30T09:35:26.907545680+02:00     at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:368)
2023-08-30T09:35:26.907564595+02:00     at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:498)
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:415)
2023-08-30T09:35:26.907590673+02:00     at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:190)
    at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:152)
    at jdk.internal.reflect.GeneratedMethodAccessor127.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.postgresql.ds.PGPooledConnection$StatementHandler.invoke(PGPooledConnection.java:441)
2023-08-30T09:35:26.907647045+02:00     at jdk.proxy2/jdk.proxy2.$Proxy93.executeUpdate(Unknown Source)
    at io.agroal.pool.wrapper.PreparedStatementWrapper.executeUpdate(PreparedStatementWrapper.java:88)
2023-08-30T09:35:26.907673292+02:00     at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:275)
    ... 64 more
2023-08-30T09:35:26.907686485+02:00 
2023-08-30T09:35:26.908045499+02:00 2023-08-30 07:35:26,907 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (executor-thread-127) Uncaught server error: org.keycloak.models.ModelException: org.postgresql.util.PSQLException: ERROR: update or delete on table "user_entity" violates foreign key constraint "fk_c4fqv34p1mbylloxang7b1q3l" on table "user_role_mapping"
  Detail: Key (id)=(df2c5d55-5361-4b6a-85c7-42d624acc4c1) is still referenced from table "user_role_mapping".
    at org.keycloak.connections.jpa.PersistenceExceptionConverter.convert(PersistenceExceptionConverter.java:99)
    at org.keycloak.connections.jpa.JpaExceptionConverter.convert(JpaExceptionConverter.java:33)
2023-08-30T09:35:26.908088993+02:00     at org.keycloak.transaction.JtaTransactionWrapper.lambda$handleException$0(JtaTransactionWrapper.java:65)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
    at java.base/java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1779)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
2023-08-30T09:35:26.908135216+02:00     at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
2023-08-30T09:35:26.908142729+02:00     at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
    at org.keycloak.transaction.JtaTransactionWrapper.handleException(JtaTransactionWrapper.java:67)
    at org.keycloak.transaction.JtaTransactionWrapper.commit(JtaTransactionWrapper.java:92)
2023-08-30T09:35:26.908180667+02:00     at org.keycloak.services.DefaultKeycloakTransactionManager.commit(DefaultKeycloakTransactionManager.java:136)
    at org.keycloak.services.DefaultKeycloakSession.closeTransactionManager(DefaultKeycloakSession.java:407)
    at org.keycloak.services.DefaultKeycloakSession.close(DefaultKeycloakSession.java:372)
    at org.keycloak.quarkus.runtime.transaction.TransactionalSessionHandler.close(TransactionalSessionHandler.java:56)
    at org.keycloak.quarkus.runtime.integration.jaxrs.TransactionalResponseFilter.filter(TransactionalResponseFilter.java:48)
2023-08-30T09:35:26.908212169+02:00     at org.jboss.resteasy.core.interception.jaxrs.ContainerResponseContextImpl.filter(ContainerResponseContextImpl.java:329)
2023-08-30T09:35:26.908218676+02:00     at org.jboss.resteasy.core.ServerResponseWriter.executeFilters(ServerResponseWriter.java:243)
2023-08-30T09:35:26.908224840+02:00     at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:100)
2023-08-30T09:35:26.908231177+02:00     at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:73)
    at org.jboss.resteasy.core.SynchronousDispatcher.writeResponse(SynchronousDispatcher.java:518)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:458)
2023-08-30T09:35:26.908249803+02:00     at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:240)
2023-08-30T09:35:26.908256127+02:00     at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:154)
2023-08-30T09:35:26.908262423+02:00     at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:321)
2023-08-30T09:35:26.908292255+02:00     at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:157)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:229)
    at io.quarkus.resteasy.runtime.standalone.RequestDispatcher.service(RequestDispatcher.java:82)
2023-08-30T09:35:26.908311775+02:00     at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.dispatch(VertxRequestHandler.java:147)
2023-08-30T09:35:26.908318071+02:00     at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.handle(VertxRequestHandler.java:84)
2023-08-30T09:35:26.908324394+02:00     at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.handle(VertxRequestHandler.java:44)
2023-08-30T09:35:26.908331087+02:00     at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1284)
    at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:177)
    at io.vertx.ext.web.impl.RoutingContextWrapper.next(RoutingContextWrapper.java:200)
    at io.quarkus.vertx.http.runtime.options.HttpServerCommonHandlers$1.handle(HttpServerCommonHandlers.java:58)
2023-08-30T09:35:26.908396442+02:00     at io.quarkus.vertx.http.runtime.options.HttpServerCommonHandlers$1.handle(HttpServerCommonHandlers.java:36)
    at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1284)
    at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:177)
2023-08-30T09:35:26.908422719+02:00     at io.vertx.ext.web.impl.RoutingContextWrapper.next(RoutingContextWrapper.java:200)
2023-08-30T09:35:26.908429966+02:00     at org.keycloak.quarkus.runtime.integration.web.QuarkusRequestFilter.lambda$createBlockingHandler$0(QuarkusRequestFilter.java:82)
    at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:576)
2023-08-30T09:35:26.908443252+02:00     at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
2023-08-30T09:35:26.908449809+02:00     at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
2023-08-30T09:35:26.908456034+02:00     at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
2023-08-30T09:35:26.908462350+02:00     at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
2023-08-30T09:35:26.908468669+02:00     at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
2023-08-30T09:35:26.908475370+02:00     at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: org.postgresql.util.PSQLException: ERROR: update or delete on table "user_entity" violates foreign key constraint "fk_c4fqv34p1mbylloxang7b1q3l" on table "user_role_mapping"
2023-08-30T09:35:26.908488516+02:00   Detail: Key (id)=(df2c5d55-5361-4b6a-85c7-42d624acc4c1) is still referenced from table "user_role_mapping".
2023-08-30T09:35:26.908494729+02:00     at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2713)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2401)
2023-08-30T09:35:26.908511510+02:00     at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:368)
    at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:498)
2023-08-30T09:35:26.908525196+02:00     at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:415)
2023-08-30T09:35:26.908531506+02:00     at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:190)
2023-08-30T09:35:26.908537825+02:00     at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:152)
2023-08-30T09:35:26.908544101+02:00     at jdk.internal.reflect.GeneratedMethodAccessor127.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2023-08-30T09:35:26.908557113+02:00     at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.postgresql.ds.PGPooledConnection$StatementHandler.invoke(PGPooledConnection.java:441)
2023-08-30T09:35:26.908569895+02:00     at jdk.proxy2/jdk.proxy2.$Proxy93.executeUpdate(Unknown Source)
    at io.agroal.pool.wrapper.PreparedStatementWrapper.executeUpdate(PreparedStatementWrapper.java:88)
2023-08-30T09:35:26.908582587+02:00     at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:275)
    at org.hibernate.engine.jdbc.mutation.internal.AbstractMutationExecutor.performNonBatchedMutation(AbstractMutationExecutor.java:108)
    at org.hibernate.engine.jdbc.mutation.internal.MutationExecutorSingleNonBatched.performNonBatchedOperations(MutationExecutorSingleNonBatched.java:40)
2023-08-30T09:35:26.908614467+02:00     at org.hibernate.engine.jdbc.mutation.internal.AbstractMutationExecutor.execute(AbstractMutationExecutor.java:53)
2023-08-30T09:35:26.908620777+02:00     at org.hibernate.persister.entity.mutation.DeleteCoordinator.doStaticDelete(DeleteCoordinator.java:300)
2023-08-30T09:35:26.908627084+02:00     at org.hibernate.persister.entity.mutation.DeleteCoordinator.coordinateDelete(DeleteCoordinator.java:87)
    at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2867)
    at org.hibernate.action.internal.EntityDeleteAction.execute(EntityDeleteAction.java:131)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:606)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:475)
    at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:358)
    at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
    at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:127)
2023-08-30T09:35:26.908677110+02:00     at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1412)
2023-08-30T09:35:26.908683432+02:00     at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:485)
    at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:2301)
2023-08-30T09:35:26.908719397+02:00     at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:1966)
    at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:439)
2023-08-30T09:35:26.908740284+02:00     at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.beforeCompletion(JtaTransactionCoordinatorImpl.java:336)
2023-08-30T09:35:26.908747329+02:00     at org.hibernate.resource.transaction.backend.jta.internal.synchronization.SynchronizationCallbackCoordinatorNonTrackingImpl.beforeCompletion(SynchronizationCallbackCoordinatorNonTrackingImpl.java:47)
2023-08-30T09:35:26.908753716+02:00     at org.hibernate.resource.transaction.backend.jta.internal.synchronization.RegisteredSynchronization.beforeCompletion(RegisteredSynchronization.java:37)
2023-08-30T09:35:26.908759948+02:00     at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:76)
    at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:360)
    at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:91)
2023-08-30T09:35:26.908778714+02:00     at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:162)
2023-08-30T09:35:26.908784937+02:00     at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1295)
2023-08-30T09:35:26.908791171+02:00     at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:128)
    at io.quarkus.narayana.jta.runtime.NotifyingTransactionManager.commit(NotifyingTransactionManager.java:70)
2023-08-30T09:35:26.908831433+02:00     at org.keycloak.transaction.JtaTransactionWrapper.commit(JtaTransactionWrapper.java:90)
anarsultanov commented 10 months ago

Hi @oleaasbo

Thank you for reporting this issue. I've reproduced the problem, and it seems that the error is happening because the extension is trying to delete a user when they're not part of any other tenants.

However, I'm not entirely certain if this is the expected behavior. There are cases where users might not be associated with any specific tenant, like for system-wide purposes. To fix the problem, I'll remove the user deletion during the membership removal process.

Still, I'd like to hear your thoughts on this. If you have any suggestions or insights, please share them.

anarsultanov commented 10 months ago

Please take a look at the recent updates made to resolve this issue. If these changes resolve the problem for you, I'll create a new release version. Currently, I'll keep this issue open.

oleaasbo commented 10 months ago

My issue has been resolved! I don't want the user to be deleted. I have none tenant users as well!