1 Reply Latest reply on Sep 8, 2005 10:44 AM by Alessandro Yoshi Polliotti

    Flush authentication cache

    Alessandro Yoshi Polliotti Newbie

      I have read many topics on the forums about this, but it seems that I can't get it work right. Here is my code:

      java.util.ArrayList servers=MBeanServerFactory.findMBeanServer(null);
      if (servers.size() != 1)
       System.out.println("uh-oh, etc");
      MBeanServer mbeanServer = (MBeanServer) servers.get(0);
      String[] mparams = { "myrealm" };
      String[] msignature = { "java.lang.String" };
       ObjectName name = new ObjectName("jboss.security:service=JaasSecurityManager");
       // the following call DOES work
       mbeanServer.invoke(name, "flushAuthenticationCache", mparams, msignature);
       String domain = "myrealm";
       Principal loggedUser=sessionctx.getCallerPrincipal();
       Principal userp = new org.jboss.security.SimplePrincipal(loggedUser.getName()); // tried with my own custom principal as well
       Object[] params = {domain, userp};
       String[] signature = {"java.lang.String", "java.security.Principal"};
       // the following call has NO effect whatsoever
       Object result=mbeanServer.invoke(name, "flushAuthenticationCache", params, signature);
      catch (Exception e)

      I've read in a topic that the method has to be called "as last operation in bean" or it behaves strangely. For one, I don't understand if "last" has some special meaning in this context, beyond "last call in my bean method" which is exactly where I have placed the call.

      The second call seems to work (no exception) but it has no effect, I don't see anything in console about cache being flushed (which I can read when I flush the entire cache or invoke the method from the jmx console via web).
      Any help is greatly appreciated.