Repository navigation
Description
Describe the bug
Calling session.getTransactionManager().setRollbackOnly() during user creation via the admin api does not cause the transaction to get rolled back.
Version
15.1 - also present in 16.1
Expected behavior
Neither the attribute added from within the event listener nor the user should be persisted. The whole transaction should fail. Maybe there should also be a log indicating this.
Actual behavior
Instead the user gets created successfully and also an attribute set from within the event listener is persistent as well. There is no error message on the log.
How to Reproduce?
- Build and deploy my example event listener from here https://github.com/gitreelike/keycloak-quickstarts/blob/latest/event-listener-sysout/src/main/java/org/keycloak/quickstart/event/listener/SysoutEventListenerProvider.java
- Configure keycloak to use the event listener. Note: The event listener id is "sysout".
- Add a user via the admin console.
Anything else?
While creating a user via OIDC will not be successful this way and calling setRollbackOnly on EventType.REGISTER, and also having configured email verification - there is a NullPointerException in VerifyEMail. I'm not sure if the transaction works or doesn't work as expected in this case. At least there is transaction related log message.
Either way, I think DefaultKeycloakTransactionManager::commit really should check if the transaction is set to rollback only. Which as of my current understanding it does not do.
Also throwing an exception from within the event listener will not cause the transaction to fail. The exception is only logged. While this might be debatable I root for the EJB concept of the application exception. At least the behaviour should be documented.
Last but not least: When building the event listener as an EJB and calling ejbContext.setRollbackOnly() the transaction appears to get rolled back properly.
Activity
mposolda commentedon Mar 28, 2023
Preliminary adding to Backlog. We may need to triage it later.