Package javax.management

Examples of javax.management.MBeanServerPermission


     * @see javax.management.MBeanServerFactory#createMBeanServer
     */
    public static synchronized MBeanServer getPlatformMBeanServer() {
        SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            Permission perm = new MBeanServerPermission("createMBeanServer");
            sm.checkPermission(perm);
        }

        if (platformMBeanServer == null) {
            platformMBeanServer =


      SecurityManager sm = System.getSecurityManager();
      if (sm != null)
      {
         if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Checking permission to create MBeanServer...");
         sm.checkPermission(new MBeanServerPermission("newMBeanServer"));
      }

      if (defaultDomain == null) defaultDomain = "";
      this.defaultDomain = defaultDomain;

    Exception caught = null;

    // Check null name throws NullPointerException
    try
      {
  new MBeanServerPermission(null);
      }
    catch (Exception ex)
      {
  caught = ex;
      }
    h.check(caught instanceof NullPointerException, "Null name");
  
    caught = null;
    // Check "*" is a valid name
    try
      {
  new MBeanServerPermission("*");
      }
    catch (Exception ex)
      {
  caught = ex;
      }
    h.check(caught, null, "* is valid");
   
    // Check valid values are allowed
    String[] valid = new String[] { "createMBeanServer", "newMBeanServer",
            "findMBeanServer", "releaseMBeanServer" };
    // 1
    for (int a = 0; a < valid.length; ++a)
      {
  caught = null;
  try
    {
      new MBeanServerPermission(valid[a]);
    }
  catch (Exception ex)
    {
      caught = ex;
    }
  h.check(caught, null, valid[a] + " is valid");
      }
    // 2
    for (int a = 0; a < valid.length; ++a)
      for (int b = 0; b < valid.length; ++b)
  {
    caught = null;
    String permit = valid[a] + "," + valid[b];
    try
      {
        new MBeanServerPermission(permit);
      }
    catch (Exception ex)
      {
        caught = ex;
      }
    h.check(caught, null, permit + " is valid");
  }
    // 3
    for (int a = 0; a < valid.length; ++a)
      for (int b = 0; b < valid.length; ++b)
  for (int c = 0; c < valid.length; ++c)
    {
      caught = null;
      String permit = valid[a] + "," + valid[b] + "," + valid[c];
      try
        {
    new MBeanServerPermission(permit);
        }
      catch (Exception ex)
        {
    caught = ex;
        }
      h.check(caught, null, permit + " is valid");
    }
    // 4
    for (int a = 0; a < valid.length; ++a)
      for (int b = 0; b < valid.length; ++b)
  for (int c = 0; c < valid.length; ++c)
    for (int d = 0; d < valid.length; ++d)
      {
        caught = null;
        String permit = valid[a] + "," + valid[b] + "," + valid[c]
    + "," + valid[d];
        try
    {
      new MBeanServerPermission(permit);
    }
        catch (Exception ex)
    {
      caught = ex;
    }
        h.check(caught, null, permit + " is valid");
      }
   
    caught = null;
    // Check with spaces
    try
      {
  new MBeanServerPermission("     createMBeanServer   , newMBeanServer  ");
      }
    catch (Exception ex)
      {
  caught = ex;
      }
    h.check(caught, null, "spaces are valid");

    caught = null;
    // Check random stuff gets thrown out
    try
      {
  new MBeanServerPermission("fjafjlskjflka");
      }
    catch (Exception ex)
      {
  caught = ex;
      }
    h.check(caught instanceof IllegalArgumentException,
      "other names are invalid");
   
    caught = null;
    // Check non-null non-empty actions are caught
    try
      {
  new MBeanServerPermission("*","fishcakes");
      }
    catch (Exception ex)
      {
  caught = ex;
      }

      SecurityManager sm = System.getSecurityManager();
      if (sm != null)
      {
         if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Checking permission to create MBeanServer...");
         sm.checkPermission(new MBeanServerPermission("newMBeanServer"));
      }

      if (defaultDomain == null) defaultDomain = "DefaultDomain";
      this.defaultDomain = defaultDomain;

      return n;
   }

   public MBeanServerPermission createMBeanServerPermission()
   {
      return new MBeanServerPermission("newMBeanServer");
   }

     * @see javax.management.MBeanServerFactory#createMBeanServer
     */
    public static synchronized MBeanServer getPlatformMBeanServer() {
        SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            Permission perm = new MBeanServerPermission("createMBeanServer");
            sm.checkPermission(perm);
        }

        if (platformMBeanServer == null) {
            platformMBeanServer = MBeanServerFactory.createMBeanServer();

    }

    private static void checkNewMBeanServerPermission() {
        SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            Permission perm = new MBeanServerPermission("newMBeanServer");
            sm.checkPermission(perm);
        }
    }

      super(s);
   }

   public void testMBeanServerPermission()
   {
      MBeanServerPermission p0 = new MBeanServerPermission("newMBeanServer");
      MBeanServerPermission p1 = new MBeanServerPermission("createMBeanServer");
      assertTrue("createMBeanServer implies newMBeanServer", p1.implies(p0));
      assertTrue("createMBeanServer implies newMBeanServer", p0.implies(p1));

      PermissionCollection pc = p0.newPermissionCollection();
      pc.add(p0);
      assertTrue("PC(newMBeanServer) implies createMBeanServer", pc.implies(p1));

      return new HashMap();
   }

   public void testNewJMXConnectorServer() throws Exception
   {
      addPermission(new MBeanServerPermission("newMBeanServer"));

      JMXServiceURL url = createJMXConnectorServerAddress();
      JMXConnectorServer cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, createServerEnvironment(), newMBeanServer());

      try

      }
   }

   public void testStartJMXConnectorServer() throws Exception
   {
      addPermission(new MBeanServerPermission("newMBeanServer"));

      JMXServiceURL url = createJMXConnectorServerAddress();
      JMXConnectorServer cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, createServerEnvironment(), newMBeanServer());

      addPermission(new SocketPermission("localhost:" + url.getPort(), "listen"));

TOP

Related Classes of javax.management.MBeanServerPermission

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.