I would suggest using a manager component:

@Name("currentUser")
  | @Scope(SESSION)
  | @Stateful
  | public class CurrentUserManagerBean implements CurrentUserManager {
  | 
  |    private User currentUser;
  | 
  |    @Create
  |    public void create() {
  |       // Initialise the user e.g. get username from JAAS, load user from 
Persistence Context
  |       currentUser = ...;
  |    }
  | 
  |    @Unwrap
  |    public User unwrap() {
  |       return currentUser;
  |    }
  | 
  | }

Alternatively you could make the manager stateful and do all the work in 
@Unwrap,

@Name("currentUser")
  | @Stateless
  | public class CurrentUserManagerBean implements CurrentUserManager {
  |  
  |    @Unwrap
  |    public User unwrap() {
  |        // Initialise the user e.g. get username from JAAS, load user from 
Persistence Context
  |       User currentUser = em.find(User.class, username);
  |       return currentUser;
  |    }
  | 
  | }


or implement a @Factory manager pattern.


@Name("currentUserManager")
  | @Stateless
  | public class CurrentUserManagerBean implements CurrentUserManager {
  |  
  |    @Factory("currentUser")
  |    public User unwrap() {
  |        // Initialise the user e.g. get username from JAAS, load user from 
Persistence Context
  |       User currentUser = em.find(User.class, username);
  |       return currentUser;
  |    }
  | 
  | }

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3985192#3985192

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3985192
_______________________________________________
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to