> true that Catalina can use Realm methods, but webapps can't?

Yoav Shapira offered this answer:


"Sometimes access directly into the Tomcat realm object is needed; to
do, this the following code can be used. Be aware, however, that by
using this, your application is relying on a Tomcat extension and is
therefore non-standard.

Note that in order for this to work the Context of the web application
in question needs to have its privileged attribute set to "true",
otherwise web apps do not have access to the Tomcat classes."

  Server server = ServerFactory.getServer();
  //Note, this assumes the Container is "Catalina"
  Service service = server.findService("Catalina");
  Engine engine = (Engine) service.getContainer();
  Host host = (Host) engine.findChild(engine.getDefaultHost());
  //Note, this assumes your context is "myContext"
  Context context = (Context) host.findChild("myContext");
  Realm realm = context.getRealm();



> use reflection interface to get a method from a class & invoke..

No need to. Declare the Principal, cast it into a GenericPrincipal
object, then invoke the GP methods:

  Principal pri = request.getUserPrincipal();
  GenericPrincipal gp = (GenericPrincipal) pri;

  String name = gp.getName();
  String pwd = gp.getPassword();
  String rlm = gp.getRealm().toString();
  String[] roles = gp.getRoles();
  boolean admin_role = gp.hasRole("admin");




----------------------------------------------------------------
for list details see
http://www.magnolia.info/en/magnolia/developer.html
----------------------------------------------------------------

Reply via email to