Hi all,
This isn't really a Glassfish Persistence specific question, but, I'm
thinking that maybe someone has already done something this and might have
some suggestions. I'm trying to implement saving of audit information to a
table using PrePersist and PreUpdate. Currently, I have creation time and
modification time working. However, I also want to add creation user name
and modification user name. I've done something similar in .NET with
NHibernate. In that case, I was able to use Thread.CurrentPrincipal to get
the user name of the current user. Does anyone know if there is a similar
way to do this in Java? I want to work independent of the environment that
the code is running in. i.e. if it's running from a unit test or a
standalone application, it should use my user name, but, if it's running in
a web app, it should use the user name of the authenticated user, not the
user the web server is running as. I'm thinking I could store the
information in a thread local, but, I want to utilize whatever is built into
the platform already if I can.
http://msdn2.microsoft.com/en-us/library/system.threading.thread.currentprincipal.aspx
Jon