1 Reply Latest reply on Dec 15, 2006 3:46 AM by mimra

    how to get username of logged in user

    lorandsm_

      Hello,

      I use authentication in my application this way:

      Hashtable props = new Hashtable();
      
      props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
      props.put(Context.SECURITY_PRINCIPAL, user);
      props.put(Context.SECURITY_CREDENTIALS, password);
      props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.security.jndi.JndiLoginInitialContextFactory");
      props.put(Context.PROVIDER_URL, "jnp://" + readingPropertiesForConnection() + ":" + "1099");
      
      Context ctx = new InitialContext(props);
      
      dispecerat = (DispeceratEntityManager) ctx.lookup("capitol/DispeceratEntityManagerBean/remote");
      


      and define the users and roles in the user.properties and roles.properties property files. What I want is to log user actions on the server which is running jboss. So in the business methods of my session bean I want to find out what user is requesting the operation to log the user requesting the operation. How could I do this? Thanks.

        • 1. Re: how to get username of logged in user
          mimra

          In your session bean you can use the following to the user name:

          ejbContext.getCallerPrincipal()
          


          To get the EJB context you can inject it using:

           @Resource
           SessionContext ejbContext;
          


          You should really consider using an interceptor to perform audit logging to keep your business logic clean.

          /Michael