Search in sources :

Example 11 with MBeanPermission

use of javax.management.MBeanPermission in project wildfly by wildfly.

the class InfinispanResourceRefTestCase method deployment.

@Deployment
public static Archive<?> deployment() {
    WebArchive war = ShrinkWrap.create(WebArchive.class, "infinispan-resource-ref.war");
    war.addClasses(InfinispanBean.class, InfinispanResourceRefTestCase.class);
    war.addAsWebInfResource(getWebXml(), "web.xml");
    war.setManifest(new StringAsset(Descriptors.create(ManifestDescriptor.class).attribute("Dependencies", "org.infinispan export").exportAsString()));
    war.addAsManifestResource(createPermissionsXmlAsset(new MBeanPermission("-#-[-]", "queryNames"), new MBeanPermission("org.infinispan.*[jboss.infinispan:*,type=Cache]", "registerMBean"), new ReflectPermission("suppressAccessChecks"), new RuntimePermission("accessDeclaredMembers"), new RuntimePermission("getClassLoader")), "permissions.xml");
    return war;
}
Also used : StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) MBeanPermission(javax.management.MBeanPermission) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) ReflectPermission(java.lang.reflect.ReflectPermission) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 12 with MBeanPermission

use of javax.management.MBeanPermission in project wildfly by wildfly.

the class ServiceMBeanSupportTestCase method geTestMBeanSar.

@Deployment(name = ServiceMBeanSupportTestCase.UNMANAGED_SAR_DEPLOYMENT_NAME, managed = false)
public static JavaArchive geTestMBeanSar() {
    final JavaArchive sar = ShrinkWrap.create(JavaArchive.class, "service-mbean-support-test.sar");
    sar.addClasses(TestServiceMBean.class, TestService.class);
    sar.addAsManifestResource(ServiceMBeanSupportTestCase.class.getPackage(), "jboss-service.xml", "jboss-service.xml");
    sar.addAsManifestResource(createPermissionsXmlAsset(new JndiPermission("global/env/foo/legacy", "bind,unbind"), new MBeanPermission(TestResultService.class.getPackage().getName() + ".*", "*")), "permissions.xml");
    return sar;
}
Also used : MBeanPermission(javax.management.MBeanPermission) JndiPermission(org.wildfly.naming.java.permission.JndiPermission) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 13 with MBeanPermission

use of javax.management.MBeanPermission in project jdk8u_jdk by JetBrains.

the class DcmdMBeanPermissionsTest method main.

public static void main(final String[] args) {
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName on = null;
    try {
        on = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME);
    } catch (MalformedObjectNameException ex) {
        ex.printStackTrace();
        throw new RuntimeException("TEST FAILED");
    }
    MBeanInfo info = null;
    try {
        info = mbs.getMBeanInfo(on);
    } catch (InstanceNotFoundException | IntrospectionException | ReflectionException ex) {
        ex.printStackTrace();
        throw new RuntimeException("TEST FAILED");
    }
    CustomSecurityManager sm = new CustomSecurityManager();
    System.setSecurityManager(sm);
    // Set of permission required to run the test cleanly
    // Some permissions are required by the MBeanServer and other
    // platform services (RuntimePermission("createClassLoader"),
    // ReflectPermission("suppressAccessChecks"),
    // java.util.logging.LoggingPermission("control"),
    // RuntimePermission("exitVM.97")).
    // Other permissions are required by commands being invoked
    // in the test (for instance, RuntimePermission("modifyThreadGroup")
    // and RuntimePermission("modifyThread") are checked when
    // runFinalization() is invoked by the gcRunFinalization command.
    sm.grantPermission(new RuntimePermission("createClassLoader"));
    sm.grantPermission(new ReflectPermission("suppressAccessChecks"));
    sm.grantPermission(new java.util.logging.LoggingPermission("control", ""));
    sm.grantPermission(new java.lang.RuntimePermission("exitVM.97"));
    sm.grantPermission(new java.lang.RuntimePermission("modifyThreadGroup"));
    sm.grantPermission(new java.lang.RuntimePermission("modifyThread"));
    for (MBeanOperationInfo opInfo : info.getOperations()) {
        Permission opPermission = new MBeanPermission(info.getClassName(), opInfo.getName(), on, "invoke");
        sm.grantPermission(opPermission);
        testOperation(mbs, sm, on, opInfo);
        sm.denyPermission(opPermission);
    }
    System.out.println("TEST PASSED");
}
Also used : ReflectionException(javax.management.ReflectionException) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) MBeanPermission(javax.management.MBeanPermission) InstanceNotFoundException(javax.management.InstanceNotFoundException) IntrospectionException(javax.management.IntrospectionException) ObjectName(javax.management.ObjectName) ReflectPermission(java.lang.reflect.ReflectPermission) MBeanPermission(javax.management.MBeanPermission) Permission(java.security.Permission) ReflectPermission(java.lang.reflect.ReflectPermission) MBeanServer(javax.management.MBeanServer)

Example 14 with MBeanPermission

use of javax.management.MBeanPermission in project jdk8u_jdk by JetBrains.

the class MBeanPermissionTest method main.

public static void main(String[] args) {
    int error = 0;
    System.out.println(">>> MBeanPermissionTest");
    try {
        System.out.println("Create MBeanPermission(null,\"\")");
        MBeanPermission mbp = new MBeanPermission(null, "");
        System.out.println("Didn't get expected IllegalArgumentException");
        error++;
    } catch (IllegalArgumentException e) {
        System.out.println("Got expected exception = " + e);
    } catch (Exception e) {
        System.out.println("Got unexpected exception = " + e);
        error++;
    }
    try {
        System.out.println("Create MBeanPermission(\"\", null)");
        MBeanPermission mbp = new MBeanPermission("", null);
        System.out.println("Didn't get expected IllegalArgumentException");
        error++;
    } catch (IllegalArgumentException e) {
        System.out.println("Got expected exception = " + e);
    } catch (Exception e) {
        System.out.println("Got unexpected exception = " + e);
        error++;
    }
    if (error > 0) {
        final String msg = "Test FAILED! Got " + error + " error(s)";
        System.out.println(msg);
        throw new IllegalArgumentException(msg);
    } else {
        System.out.println("Test PASSED!");
    }
}
Also used : MBeanPermission(javax.management.MBeanPermission)

Example 15 with MBeanPermission

use of javax.management.MBeanPermission in project jdk8u_jdk by JetBrains.

the class ServerNotifForwarder method checkMBeanPermission.

static void checkMBeanPermission(final MBeanServer mbs, final ObjectName name, final String actions) throws InstanceNotFoundException, SecurityException {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        AccessControlContext acc = AccessController.getContext();
        ObjectInstance oi;
        try {
            oi = AccessController.doPrivileged(new PrivilegedExceptionAction<ObjectInstance>() {

                public ObjectInstance run() throws InstanceNotFoundException {
                    return mbs.getObjectInstance(name);
                }
            });
        } catch (PrivilegedActionException e) {
            throw (InstanceNotFoundException) extractException(e);
        }
        String classname = oi.getClassName();
        MBeanPermission perm = new MBeanPermission(classname, null, name, actions);
        sm.checkPermission(perm, acc);
    }
}
Also used : AccessControlContext(java.security.AccessControlContext) PrivilegedActionException(java.security.PrivilegedActionException) MBeanPermission(javax.management.MBeanPermission) ObjectInstance(javax.management.ObjectInstance) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction)

Aggregations

MBeanPermission (javax.management.MBeanPermission)24 Permission (java.security.Permission)6 ReflectPermission (java.lang.reflect.ReflectPermission)3 InstanceNotFoundException (javax.management.InstanceNotFoundException)3 ObjectName (javax.management.ObjectName)3 RuntimeOperationsException (javax.management.RuntimeOperationsException)3 Deployment (org.jboss.arquillian.container.test.api.Deployment)3 AccessControlContext (java.security.AccessControlContext)2 Permissions (java.security.Permissions)2 ProtectionDomain (java.security.ProtectionDomain)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 MBeanServerPermission (javax.management.MBeanServerPermission)2 MBeanTrustPermission (javax.management.MBeanTrustPermission)2 PrivateClassLoader (javax.management.loading.PrivateClassLoader)2 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)2 FilePermission (java.io.FilePermission)1 SerializablePermission (java.io.SerializablePermission)1 ManagementPermission (java.lang.management.ManagementPermission)1 MalformedURLException (java.net.MalformedURLException)1