Search in sources :

Example 16 with MBeanPermission

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

the class MX4JMBeanServer method getAttributes.

public AttributeList getAttributes(ObjectName objectName, String[] attributes) throws InstanceNotFoundException, ReflectionException {
    if (attributes == null || attributes.length == 0) {
        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, "getAttribute"));
    }
    return getHeadInterceptor().getAttributes(metadata, attributes);
}
Also used : MBeanPermission(javax.management.MBeanPermission) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 17 with MBeanPermission

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

the class MX4JMBeanServer method getObjectInstance.

public ObjectInstance getObjectInstance(ObjectName objectName) throws InstanceNotFoundException {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        objectName = secureObjectName(objectName);
    }
    MBeanMetaData metadata = findMBeanMetaData(objectName);
    if (sm != null) {
        sm.checkPermission(new MBeanPermission(metadata.info.getClassName(), "-", objectName, "getObjectInstance"));
    }
    return metadata.instance;
}
Also used : MBeanPermission(javax.management.MBeanPermission)

Example 18 with MBeanPermission

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

the class MX4JMBeanServer method queryNames.

public Set queryNames(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("-#-[-]", "queryNames"));
    }
    return queryObjectNames(patternName, filter, false);
}
Also used : MBeanPermission(javax.management.MBeanPermission)

Example 19 with MBeanPermission

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

the class MX4JMBeanServer method filterMBeansBySecurity.

/**
 * Filters the given set of ObjectNames following the permission that client code has granted.
 * Returns a set containing the allowed ObjectNames.
 */
private Set filterMBeansBySecurity(Set mbeans, boolean instances) {
    SecurityManager sm = System.getSecurityManager();
    if (sm == null)
        return mbeans;
    HashSet set = new HashSet();
    for (Iterator i = mbeans.iterator(); i.hasNext(); ) {
        ObjectName name = (ObjectName) i.next();
        try {
            MBeanMetaData metadata = findMBeanMetaData(name);
            String className = metadata.info.getClassName();
            sm.checkPermission(new MBeanPermission(className, "-", name, instances ? "queryMBeans" : "queryNames"));
            set.add(name);
        } catch (InstanceNotFoundException ignored) {
            // A concurrent thread removed this MBean, continue
            continue;
        } catch (SecurityException ignored) {
        // Don't add the name to the list, and go on.
        }
    }
    return set;
}
Also used : MBeanPermission(javax.management.MBeanPermission) InstanceNotFoundException(javax.management.InstanceNotFoundException) Iterator(java.util.Iterator) HashSet(java.util.HashSet) ObjectName(javax.management.ObjectName)

Example 20 with MBeanPermission

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

the class MX4JMBeanServer method isInstanceOf.

public boolean isInstanceOf(ObjectName objectName, String className) throws InstanceNotFoundException {
    if (className == null || className.trim().length() == 0) {
        throw new RuntimeOperationsException(new IllegalArgumentException("Invalid class name"));
    }
    objectName = secureObjectName(objectName);
    MBeanMetaData metadata = findMBeanMetaData(objectName);
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(new MBeanPermission(metadata.info.getClassName(), "-", objectName, "isInstanceOf"));
    }
    try {
        ClassLoader loader = metadata.classloader;
        Class cls = null;
        if (loader != null)
            cls = loader.loadClass(className);
        else
            cls = Class.forName(className, false, null);
        if (metadata.mbean instanceof StandardMBean) {
            Object impl = ((StandardMBean) metadata.mbean).getImplementation();
            return cls.isInstance(impl);
        } else {
            return cls.isInstance(metadata.mbean);
        }
    } catch (ClassNotFoundException x) {
        return false;
    }
}
Also used : StandardMBean(javax.management.StandardMBean) MBeanPermission(javax.management.MBeanPermission) PrivateClassLoader(javax.management.loading.PrivateClassLoader) RuntimeOperationsException(javax.management.RuntimeOperationsException)

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