Package javax.management

Examples of javax.management.MBeanPermission


   }

   public void testMBeanPermissionNilCardIsAlwaysImplied() throws Exception
   {
      String action = "queryNames";
      MBeanPermission nil = new MBeanPermission("-#-[-]", action);

      shouldImply(nil, nil);
      shouldImply(new MBeanPermission("com.package.MyClass#Attr[d:k=v]", action), nil);
   }
View Full Code Here


      shouldImply(new MBeanPermission("com.package.MyClass#Attr[d:k=v]", action), nil);
   }

   public void testMBeanPermissionQueryMBeansImpliesQueryNames() throws Exception
   {
      shouldImply(new MBeanPermission("*", "queryMBeans"), new MBeanPermission("*", "queryNames"));
      shouldNotImply(new MBeanPermission("*", "queryMBeans"), new MBeanPermission("*", "queryNames, invoke"));
   }
View Full Code Here

      shouldNotImply(new MBeanPermission("*", "queryMBeans"), new MBeanPermission("*", "queryNames, invoke"));
   }

   public void testMBeanPermissionShuffledActionsAreEquals() throws Exception
   {
      MBeanPermission mbp1 = new MBeanPermission("*", "addNotificationListener, removeNotificationListener");
      MBeanPermission mbp2 = new MBeanPermission("*", "removeNotificationListener, addNotificationListener");

      shouldBeEqual(mbp1, mbp2);
   }
View Full Code Here

      shouldBeEqual(mbp1, mbp2);
   }

   public void testMBeanPermissionImpliesOne() throws Exception
   {
      MBeanPermission implied = new MBeanPermission("mx4j.Foo#Bar[domain:k1=v1,k2=v2]", "invoke");
      MBeanPermission all = new MBeanPermission("*", "*");

      shouldImply(implied, implied);

      shouldImply(new MBeanPermission("mx4j.Foo#Bar[domain:k2=v2,k1=v1]", "invoke"), implied);
      shouldImply(new MBeanPermission("mx4j.Foo#Bar[domain:k1=v1,k2=v2]", "invoke,getAttribute"), implied);
      shouldImply(new MBeanPermission("mx4j.Foo#Bar[domain:k1=v1,k2=v2]", "setAttribute,invoke"), implied);
      shouldImply(new MBeanPermission("mx4j.Foo#Bar[domain:k1=v1,k2=v2]", "invoke,*"), implied);
      shouldImply(new MBeanPermission("mx4j.Foo#Bar[domain:k1=v1,k2=v2]", "*"), implied);

      shouldImply(new MBeanPermission("mx4j.Foo#Bar[domain:k1=v1,*]", "invoke"), implied);
      shouldImply(new MBeanPermission("mx4j.Foo#Bar[domain:k2=v2,*]", "invoke"), implied);
      shouldImply(new MBeanPermission("mx4j.Foo#Bar[domain:*]", "invoke"), implied);
      shouldImply(new MBeanPermission("mx4j.Foo#Bar[dom?in:k1=v1,k2=v2]", "invoke"), implied);
      shouldImply(new MBeanPermission("mx4j.Foo#Bar[do*in:k1=v1,k2=v2]", "invoke"), implied);
      shouldImply(new MBeanPermission("mx4j.Foo#Bar[*:k1=v1,k2=v2]", "invoke"), implied);
      shouldImply(new MBeanPermission("mx4j.Foo#Bar[*:*]", "invoke"), implied);
      shouldImply(new MBeanPermission("mx4j.Foo#Bar", "invoke"), implied);

      shouldImply(new MBeanPermission("mx4j.Foo#Bar*[domain:k1=v1,k2=v2]", "invoke"), implied);
      shouldImply(new MBeanPermission("mx4j.Foo#B*[domain:k1=v1,k2=v2]", "invoke"), implied);
      shouldImply(new MBeanPermission("mx4j.Foo#*[domain:k1=v1,k2=v2]", "invoke"), implied);
      shouldImply(new MBeanPermission("mx4j.Foo[domain:k1=v1,k2=v2]", "invoke"), implied);
      shouldImply(new MBeanPermission("mx4j.Foo#Bar*", "invoke"), implied);
      shouldImply(new MBeanPermission("mx4j.Foo#B*", "invoke"), implied);
      shouldImply(new MBeanPermission("mx4j.Foo#*", "invoke"), implied);
      shouldImply(new MBeanPermission("mx4j.Foo", "invoke"), implied);

      shouldImply(new MBeanPermission("mx4j.Foo*#Bar[domain:k1=v1,k2=v2]", "invoke"), implied);
      shouldImply(new MBeanPermission("mx4j.*#Bar[domain:k1=v1,k2=v2]", "invoke"), implied);
      shouldImply(new MBeanPermission("*#Bar[domain:k1=v1,k2=v2]", "invoke"), implied);
      shouldImply(new MBeanPermission("#Bar[domain:k1=v1,k2=v2]", "invoke"), implied);
      shouldImply(new MBeanPermission("mx4j.*#Bar", "invoke"), implied);
      shouldImply(new MBeanPermission("*#Bar", "invoke"), implied);
      shouldImply(new MBeanPermission("#Bar", "invoke"), implied);
      shouldImply(new MBeanPermission("mx4j.*", "invoke"), implied);
      shouldImply(new MBeanPermission("*", "invoke"), implied);

      shouldImply(new MBeanPermission("mx4j.Foo*#*[domain:k1=v1,k2=v2]", "invoke"), implied);
      shouldImply(new MBeanPermission("[domain:k1=v1,k2=v2]", "invoke"), implied);

      shouldImply(all, implied);

      shouldImply(new MBeanPermission("[]", "*"), all);
      shouldImply(implied, new MBeanPermission(null, null, null, "invoke"));
   }
View Full Code Here

      shouldImply(implied, new MBeanPermission(null, null, null, "invoke"));
   }

   public void testMBeanPermissionNotImpliesOne() throws Exception
   {
      MBeanPermission notImplied = new MBeanPermission("mx4j.Foo#Bar[d:k=v]", "invoke, getObjectInstance");

      // Different actions
      shouldNotImply(new MBeanPermission("mx4j.Foo#Bar[d:k=v]", "getAttribute"), notImplied);
      shouldNotImply(new MBeanPermission("mx4j.Foo#Bar[d:k=v]", "getAttribute,setAttribute"), notImplied);
      shouldNotImply(new MBeanPermission("mx4j.Foo#Bar[d:k=v]", "invoke,setAttribute"), notImplied);
      shouldNotImply(new MBeanPermission("mx4j.Foo#Bar[d:k=v]", "setAttribute,getObjectInstance"), notImplied);
      shouldNotImply(new MBeanPermission("mx4j.Foo#Bar[d:k=v]", "getObjectInstance,getAttribute"), notImplied);

      // Different objectname
      shouldNotImply(new MBeanPermission("mx4j.Foo#Bar[d:k=v1]", "invoke, getObjectInstance"), notImplied);
      shouldNotImply(new MBeanPermission("mx4j.Foo#Bar[d:k=v,k1=v1]", "invoke, getObjectInstance"), notImplied);
      shouldNotImply(new MBeanPermission("mx4j.Foo#Bar[:k=v]", "invoke, getObjectInstance"), notImplied);

      // Different attribute
      shouldNotImply(new MBeanPermission("mx4j.Foo#Baz[d:k=v]", "invoke, getObjectInstance"), notImplied);

      // Different class
      shouldNotImply(new MBeanPermission("mx4j.Foo.Baz#Bar[d:k=v]", "invoke, getObjectInstance"), notImplied);
      shouldNotImply(new MBeanPermission("mx4j.Foo$Inner#Bar[d:k=v]", "invoke, getObjectInstance"), notImplied);
      shouldNotImply(new MBeanPermission("dummy.Foo#Bar[d:k=v]", "invoke, getObjectInstance"), notImplied);
   }
View Full Code Here

      shouldNotImply(new MBeanPermission("dummy.Foo#Bar[d:k=v]", "invoke, getObjectInstance"), notImplied);
   }

   public void testMBeanPermissionSerialization() throws Exception
   {
      MBeanPermission permission = new MBeanPermission("mx4j.Foo#Bar[domain:key=value]", "invoke");

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream(baos);
      oos.writeObject(permission);
      oos.close();

      ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
      ObjectInputStream ois = new ObjectInputStream(bais);
      MBeanPermission deserialized = (MBeanPermission)ois.readObject();
      ois.close();

      if (!(deserialized.equals(permission))) fail("Serialization/Deserialization failed");
   }
View Full Code Here

      }
      catch (SecurityException ignored)
      {
      }

      addPermission(new MBeanPermission(className, "instantiate"));
      server.instantiate(className, null);

      // Check also the overloaded version, we need an MLet
      String mletClassName = "javax.management.loading.MLet";
      ObjectName name = new ObjectName(server.getDefaultDomain(), "mbean", "mlet");
      resetPermissions();
      addPermission(new MBeanPermission(mletClassName, "instantiate, registerMBean"));
      addPermission(new RuntimePermission("createClassLoader"));
      server.createMBean(mletClassName, name, null);

      try
      {
         server.instantiate(className, null);
         fail();
      }
      catch (SecurityException ignored)
      {
      }

      addPermission(new MBeanPermission(className, "instantiate"));
      server.instantiate(className, null);
   }
View Full Code Here

      }
      catch (SecurityException ignored)
      {
      }

      addPermission(new MBeanPermission(mbean.getClass().getName() + "[" + name.getCanonicalName() + "]", "registerMBean"));
      server.registerMBean(mbean, name);
   }
View Full Code Here

      // Needed to create an MLet, which is a ClassLoader
      addPermission(new RuntimePermission("createClassLoader"));
      ObjectName name = new ObjectName(server.getDefaultDomain(), "mbean", "mlet");
      MLet mlet = new MLet();
      addPermission(new MBeanPermission(mlet.getClass().getName(), "registerMBean"));
      server.registerMBean(mlet, name);

      try
      {
         server.getClassLoader(null);
         fail();
      }
      catch (SecurityException ignored)
      {
      }

      // Dummy class
      addPermission(new MBeanPermission("foo[" + name.getCanonicalName() + "]", "getClassLoader"));

      try
      {
         server.getClassLoader(name);
         fail();
      }
      catch (SecurityException ignored)
      {
      }

      addPermission(new MBeanPermission(mlet.getClass().getName() + "[" + name.getCanonicalName() + "]", "getClassLoader"));
      ClassLoader result = server.getClassLoader(name);
      assertSame(result, mlet);
   }
View Full Code Here

         fail();
      }
      catch (SecurityException x)
      {
      }
      addPermission(new MBeanPermission("[" + delegate.getCanonicalName() + "]", "getClassLoaderFor"));
      ClassLoader loader = server.getClassLoaderFor(delegate);
      assertNotNull(loader);
   }
View Full Code Here

TOP

Related Classes of javax.management.MBeanPermission

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.