1 Reply Latest reply on Mar 23, 2006 5:38 PM by Gavin King

    @Factory Method invoked from Seam Component @In (injection)

    js8523 Novice

      Dear All

      I am using Louis security @Factory (thankyou) method for placing the user information into 'Seam' space from JAAS. (with the addition of the JBPM actor stuff).

      The method looks like this

      @In
      User currentUser

       @Factory("currentUser")
       public void loadCurrentUser() {
       log.info("**** FACTORY ****** currentUser is " + currentUser);
       try {
       String username = new String("unknown");
      
       FacesContext facesContext = FacesContext.getCurrentInstance();
       if ( facesContext.getExternalContext().getUserPrincipal() == null ) {
       currentUser = null;
       log.info("not logged in");
       return;
       }
      
       //
       // get security login name
       //
       username = facesContext.getExternalContext().getUserPrincipal().getName().toString();
      
       //
       // create DB query
       //
       String query = new String("FROM " + User.class.getName() + " where username='" + username + "'");
       //
       // get user from db
       //
       List list = em.createQuery(query).getResultList();
       if ( list != null && list.size() > 0 ) {
       Object obj = list.get(0);
       if ( obj instanceof User ){
       currentUser = (User) obj;
       Contexts.getSessionContext().set("currentUser",currentUser);
      
       actor.setId(currentUser.getActorId());
       actor.getGroupActorIds().addAll(currentUser.getGroupActorIds());
      
       Contexts.getSessionContext().set( LOGIN_KEY, true );
       }
       }
       }
      
       catch ( Throwable t ) {
       log.error("currentUser factory throws " + t);
       currentUser = null;
       }
       }


      This factory method is only invoked when i do this on a faces page

      #{currentUser.username}
      or something similar.

      What I am requesting is that when a component request to inject the currentUser via

      
      @In(create=true)
      User currentUser
      


      That it also should invoke the @Factory method, becuase currently I don't think it does (please correct me if I'm wrong).

      If this is so shall I add a JIRA for this, or will this change impact other uses of the @Factory method, that I am unaware of.

      Many thanks,

      James