Search in sources :

Example 6 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)

Example 7 with MBeanPermission

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

the class ClassLoaderRepositorySupport method getClassLoader.

public final ClassLoader getClassLoader(ObjectName name) {
    ClassLoader instance = loadersWithNames.get(name);
    if (instance != null) {
        SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            Permission perm = new MBeanPermission(instance.getClass().getName(), null, name, "getClassLoader");
            sm.checkPermission(perm);
        }
    }
    return instance;
}
Also used : MBeanPermission(javax.management.MBeanPermission) Permission(java.security.Permission) MBeanPermission(javax.management.MBeanPermission) PrivateClassLoader(javax.management.loading.PrivateClassLoader)

Example 8 with MBeanPermission

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

the class MBeanInstantiator method checkMBeanPermission.

private static void checkMBeanPermission(String classname, String member, ObjectName objectName, String actions) throws SecurityException {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        Permission perm = new MBeanPermission(classname, member, objectName, actions);
        sm.checkPermission(perm);
    }
}
Also used : MBeanPermission(javax.management.MBeanPermission) MBeanPermission(javax.management.MBeanPermission) Permission(java.security.Permission)

Example 9 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 10 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)

Aggregations

MBeanPermission (javax.management.MBeanPermission)10 Permission (java.security.Permission)5 ReflectPermission (java.lang.reflect.ReflectPermission)2 AccessControlContext (java.security.AccessControlContext)2 Deployment (org.jboss.arquillian.container.test.api.Deployment)2 Permissions (java.security.Permissions)1 PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 ProtectionDomain (java.security.ProtectionDomain)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 IntrospectionException (javax.management.IntrospectionException)1 MBeanInfo (javax.management.MBeanInfo)1 MBeanOperationInfo (javax.management.MBeanOperationInfo)1 MBeanServer (javax.management.MBeanServer)1 MBeanServerPermission (javax.management.MBeanServerPermission)1 MBeanTrustPermission (javax.management.MBeanTrustPermission)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 ObjectInstance (javax.management.ObjectInstance)1 ObjectName (javax.management.ObjectName)1 ReflectionException (javax.management.ReflectionException)1