5 Replies Latest reply on Jul 28, 2010 8:07 AM by daxxy

    Getting Seam component (Identity) in an entity listener

    monkeyden

      Is it possible to get access to the Identity object from within an entity listener?  I'm trying to implement an audit trail for some entities but Identity is always null.  Seems like it would be pretty simple.  My entity bean is annotated with:


      @EntityListeners({JPAValidateListener.class, AuditableListener.class})
      



      And my AuditableListener


      public class AuditableListener {
          @PrePersist
          public void prePersist(Auditable auditable) {
              String username = "ADMIN_SYSTEM";
              Identity identity = (Identity)Component.getInstance("org.jboss.seam.security.identity");
              if (identity.getUsername() != null) {
                  username = identity.getUsername();
              }
              auditable.setLastUpdatedBy(username);
          }
      }
      



      Thanks