use of org.apache.geode.security.ResourcePermission in project geode by apache.
the class IntegratedSecurityService method authorize.
public void authorize(String resource, String operation, String regionName, String key) {
regionName = StringUtils.stripStart(regionName, "/");
authorize(new ResourcePermission(resource, operation, regionName, key));
}
use of org.apache.geode.security.ResourcePermission in project geode by apache.
the class MBeanServerWrapper method getAttribute.
@Override
public Object getAttribute(ObjectName name, String attribute) throws MBeanException, InstanceNotFoundException, ReflectionException {
ResourcePermission ctx = getOperationContext(name, attribute, false);
this.securityService.authorize(ctx);
Object result;
try {
result = mbs.getAttribute(name, attribute);
} catch (AttributeNotFoundException nex) {
return null;
}
return result;
}
use of org.apache.geode.security.ResourcePermission in project geode by apache.
the class MBeanServerWrapper method invoke.
@Override
public Object invoke(ObjectName name, String operationName, Object[] params, String[] signature) throws InstanceNotFoundException, MBeanException, ReflectionException {
ResourcePermission ctx = getOperationContext(name, operationName, true);
this.securityService.authorize(ctx);
Object result = mbs.invoke(name, operationName, params, signature);
return result;
}
use of org.apache.geode.security.ResourcePermission in project geode by apache.
the class MBeanServerWrapper method getOperationContext.
// TODO: cache this
private ResourcePermission getOperationContext(ObjectName objectName, String featureName, boolean isOp) throws InstanceNotFoundException, ReflectionException {
MBeanInfo beanInfo = null;
try {
beanInfo = mbs.getMBeanInfo(objectName);
} catch (IntrospectionException e) {
throw new GemFireSecurityException("error getting beanInfo of " + objectName, e);
}
// If there is no annotation defined either in the class level or method level, we should
// consider this operation/attribute freely accessible
ResourcePermission result = null;
// find the context in the beanInfo if defined in the class level
result = getOperationContext(beanInfo.getDescriptor(), result);
MBeanFeatureInfo[] featureInfos = null;
if (isOp) {
featureInfos = beanInfo.getOperations();
} else {
featureInfos = beanInfo.getAttributes();
}
// still look into the attributes/operations to see if it's defined in the method level
for (MBeanFeatureInfo info : featureInfos) {
if (info.getName().equals(featureName)) {
// found the featureInfo of this method on the bean
result = getOperationContext(info.getDescriptor(), result);
break;
}
}
return result;
}
use of org.apache.geode.security.ResourcePermission in project geode by apache.
the class ResourcePermissionTest method testConstructor.
@Test
public void testConstructor() {
context = new ResourcePermission();
assertEquals(Resource.NULL, context.getResource());
assertEquals(Operation.NULL, context.getOperation());
assertEquals(ResourcePermission.ALL_REGIONS, context.getRegionName());
context = new ResourcePermission();
assertEquals(Resource.NULL, context.getResource());
assertEquals(Operation.NULL, context.getOperation());
assertEquals(ResourcePermission.ALL_REGIONS, context.getRegionName());
context = new ResourcePermission("DATA", null, null);
assertEquals(Resource.DATA, context.getResource());
assertEquals(Operation.NULL, context.getOperation());
assertEquals(ResourcePermission.ALL_REGIONS, context.getRegionName());
context = new ResourcePermission("CLUSTER", null, null);
assertEquals(Resource.CLUSTER, context.getResource());
assertEquals(Operation.NULL, context.getOperation());
assertEquals(ResourcePermission.ALL_REGIONS, context.getRegionName());
context = new ResourcePermission(null, "MANAGE", "REGIONA");
assertEquals(Resource.NULL, context.getResource());
assertEquals(Operation.MANAGE, context.getOperation());
assertEquals("REGIONA", context.getRegionName());
context = new ResourcePermission("DATA", "MANAGE", "REGIONA");
assertEquals(Resource.DATA, context.getResource());
assertEquals(Operation.MANAGE, context.getOperation());
assertEquals("REGIONA", context.getRegionName());
}
Aggregations