2 Replies Latest reply on Jul 29, 2009 4:26 PM by jeanluc

    Getting FirstName from identity, extend Identity?

    mrlueck

      I would like to display 'FirstName LastName' in the 'signed in as' inside the menu.xhtml.  Do I need to extend Identity to include FirstName and LastName as accessible fields, or is there another way I can go about getting at the whole user account entity from the identity framework?

        • 1. Re: Getting FirstName from identity, extend Identity?
          cash1981

          There are many ways to do this.
          First of all you need to get the current logged in user. I am not sure how you have solved your solution, but if you have something like this, then you can just get the currentUser and in your User table you can create a


          @Transient
               public String getName() {
                    return this.firstname + " " + this.lastname;
               }



          and then in your menu.xhtml you can just write


          #{currentUser.getName()}



          or if you only want firstname


          #{currentUser.firstName}





          Hope this helps

          • 2. Re: Getting FirstName from identity, extend Identity?
            jeanluc

            Or you can have a session-scoped component that keeps your User entity. To load it, define a


            @AutoCreate
            @Scope(ScopeType.SESSION)
            @Startup
            ...
            
            private User user;
            
            @Observer("org.jboss.seam.security.postAuthenticate")
            public void loadUser(){
               String username = ((Identity)Component.getInstance(Identity.class)).getPrincipal().getName();
               //load the User entity here and store it in the user variable
            }
            



            Also make sure you clear the user when listening to org.jboss.seam.security.preAuthenticate and org.jboss.seam.security.loggedOut.