Hallo,
I'm trying to update each entity with an own @EntityListeners({ ModelListener.class }).
ModelListener implements @PrePersist with a method like this:
My question is how to get the current user.
I already tried several things:
1) transport the information over EJB
The userModul is always null, when prePersist is called. It seems the EJB-context is not available.
2) Fill a static ThreadLocal<User>
static ThreadLocal<User> currentUser = new ThreadLocal<User>();
Because of the static attribute each classloader (each request in webservers) holds its own instance. I tried with a @WebFilter to fill the ThreadLocal. But it seems I have no faces context.
Also in request (com.sun.enterprise.web.pwc.connector.coyote.PwcCoyoteRequest) I don't find any information of loggedin user.
What is the most common way to save user information?
thanks Marco
I'm trying to update each entity with an own @EntityListeners({ ModelListener.class }).
ModelListener implements @PrePersist with a method like this:
Java:
@PrePersist
protected void prePersist(final ModelBase modelBase) {
modelBase.setUpdatedBy(currentUser);}
I already tried several things:
1) transport the information over EJB
Java:
@EJB
private UserModul userModul;
2) Fill a static ThreadLocal<User>
static ThreadLocal<User> currentUser = new ThreadLocal<User>();
Because of the static attribute each classloader (each request in webservers) holds its own instance. I tried with a @WebFilter to fill the ThreadLocal. But it seems I have no faces context.
Java:
public void doFilter(final ServletRequest request, ...){
FacesContext.getCurrentInstance();} //always null
What is the most common way to save user information?
thanks Marco