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