Search in sources :

Example 1 with MBeanPermission

use of javax.management.MBeanPermission in project felix by apache.

the class MX4JMBeanServer method setAttributes.

public AttributeList setAttributes(ObjectName objectName, AttributeList attributes) throws InstanceNotFoundException, ReflectionException {
    if (attributes == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException("Invalid attribute list"));
    }
    objectName = secureObjectName(objectName);
    MBeanMetaData metadata = findMBeanMetaData(objectName);
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        // Must check if the user has the right to call this method, regardless of the attributes
        sm.checkPermission(new MBeanPermission(metadata.info.getClassName(), "-", objectName, "setAttribute"));
    }
    return getHeadInterceptor().setAttributes(metadata, attributes);
}
Also used : MBeanPermission(javax.management.MBeanPermission) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 2 with MBeanPermission

use of javax.management.MBeanPermission in project felix by apache.

the class MX4JMBeanServer method getClassLoaderFor.

public ClassLoader getClassLoaderFor(ObjectName name) throws InstanceNotFoundException {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        name = secureObjectName(name);
    }
    // If name is null, I get InstanceNotFoundException
    MBeanMetaData metadata = findMBeanMetaData(name);
    if (sm != null) {
        sm.checkPermission(new MBeanPermission(metadata.info.getClassName(), "-", name, "getClassLoaderFor"));
    }
    return metadata.mbean.getClass().getClassLoader();
}
Also used : MBeanPermission(javax.management.MBeanPermission)

Example 3 with MBeanPermission

use of javax.management.MBeanPermission in project felix by apache.

the class MX4JMBeanServer method queryMBeans.

public Set queryMBeans(ObjectName patternName, QueryExp filter) {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        patternName = secureObjectName(patternName);
        // Must check if the user has the right to call this method,
        // no matter which ObjectName has been passed.
        sm.checkPermission(new MBeanPermission("-#-[-]", "queryMBeans"));
    }
    Set match = queryObjectNames(patternName, filter, true);
    Set set = new HashSet();
    for (Iterator i = match.iterator(); i.hasNext(); ) {
        ObjectName name = (ObjectName) i.next();
        try {
            MBeanMetaData metadata = findMBeanMetaData(name);
            set.add(metadata.instance);
        } catch (InstanceNotFoundException ignored) {
        // A concurrent thread removed the MBean after queryNames, ignore
        }
    }
    return set;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) MBeanPermission(javax.management.MBeanPermission) InstanceNotFoundException(javax.management.InstanceNotFoundException) Iterator(java.util.Iterator) HashSet(java.util.HashSet) ObjectName(javax.management.ObjectName)

Example 4 with MBeanPermission

use of javax.management.MBeanPermission in project felix by apache.

the class MX4JMBeanServer method getClassLoader.

public ClassLoader getClassLoader(ObjectName name) throws InstanceNotFoundException {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        name = secureObjectName(name);
        if (name == null) {
            sm.checkPermission(new MBeanPermission("-#-[-]", "getClassLoader"));
        } else {
            MBeanMetaData metadata = findMBeanMetaData(name);
            sm.checkPermission(new MBeanPermission(metadata.info.getClassName(), "-", name, "getClassLoader"));
        }
    }
    return getClassLoaderImpl(name);
}
Also used : MBeanPermission(javax.management.MBeanPermission)

Example 5 with MBeanPermission

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

the class MBeanInstantiator method getClassLoader.

private ClassLoader getClassLoader(final ObjectName name) {
    if (clr == null) {
        return null;
    }
    // Restrict to getClassLoader permission only
    Permissions permissions = new Permissions();
    permissions.add(new MBeanPermission("*", null, name, "getClassLoader"));
    ProtectionDomain protectionDomain = new ProtectionDomain(null, permissions);
    ProtectionDomain[] domains = { protectionDomain };
    AccessControlContext ctx = new AccessControlContext(domains);
    ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {

        public ClassLoader run() {
            return clr.getClassLoader(name);
        }
    }, ctx);
    return loader;
}
Also used : ProtectionDomain(java.security.ProtectionDomain) AccessControlContext(java.security.AccessControlContext) MBeanPermission(javax.management.MBeanPermission) Permissions(java.security.Permissions)

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