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);
}
}
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;
}
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);
}
}
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");
}
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!");
}
}
Aggregations