I'm migrating an application from EAP 6 to Wildfly 24. We are using hibernate. We have a base domain class that, upon prepersist or preupdate populate a couple of fields with the username taken from the user principal. I see that with Wildfly that is no longer possible. I've searched all over and have not found a solution. Can someone here help? Here is the sample code I'm migrating:
I don't know what EAP is and attempts to resolve that name only come up with things like "Employee Assistance Program".
However, I can tell you this. The JEE UserPrincipal object (Interface) is constructed when a remote user logs in using JEE Container-Managed Security. Since it's only an Interface, the exact contents of that object are not directly knowable with the exception of the user's loginId. You obtain the UserPrincipal from the HttpServletRequest object passed in when a servlet or JSP is invoked. Or you can just invoke getRemoteUser() to obtain just the userID. If a user has not been logged in, you'll get back null as the userID.
Hibernate is a general-purpose ORM and has no particular interest specifically in whether it's running in a webapp or not (in which case JEE UserPrincipal wouldn't exist). I think what you are actually looking at is not Wildfly-related but a Spring webapp object, possibly related to Spring Boot (which doesn't normally run under Wildfly, since Spring Boot normally has its own embedded webapp server - typically Tomcat).
Sometimes the only way things ever got fixed is because people became uncomfortable.
I see that with Wildfly that is no longer possible.
As Tim mentioned the JEE api provides a UserPrincipal object. That hasn't changed in Wildfly24.
Yes in EAP6.x your code would rely on SecurityContextAssociation to access above interface.
Wildfly24 it is still possible and relies on Context Dependency Injection (CDI) to expose objects and methods you need.
Take a look at this Wildfly 24 quickstart example that uses the JEE Security api.