users@glassfish.java.net

Getting Principal inside JMX MBean

From: <glassfish_at_javadesktop.org>
Date: Thu, 10 Jul 2008 01:30:22 PDT

Hi, I have created some JMX MBeans during the READY_EVENT on a LifecycleListener. They are created ok. I have also created a new user through the GlassFish admin console.

I now use JConsole to connect to GlassFish. I use the service URL dumped out on the console when starting GlassFish, and the user and password just created. JConsole connects just fine and I can see all the MBeans.

In my MBeans I need to do additional authorization for the user by checking the Principal (=user) against a legacy authorization system (based on the attribute the user is interested in). So in my MBean I would like to do something like the following:

public class MyMBean implements DynamicMBean{
  ...
  public Object getAttribute(String attrname){

    Principal p = ????

    boolean allowGet = myLegacyAuthorizationService(p.getName(), attrname);
    if(allowGet){
      ...return data...
    } else {
      ...throw something relevant...
    }
  }

Question is how do I get the Principal? I have tried the following:

com.sun.enterprise.security.SecurityContext sc = SecurityContext.getCurrent();
Principal p = sc.getCallerPrincipal();

Sure enough, I get a Principal back. But it is ANONYMOUS and not the username I have used when connecting through JConsole. So how do I get my hands on the username?

Any other possible way of implementing this way of authorization?

Any help would be much appreciated.

Regards, Mark Hollmann
[Message sent by forum member 'markhollmann' (markhollmann)]

http://forums.java.net/jive/thread.jspa?messageID=285598