Search in sources :

Example 6 with ResourcePermission

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));
}
Also used : ResourcePermission(org.apache.geode.security.ResourcePermission)

Example 7 with ResourcePermission

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;
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) ResourcePermission(org.apache.geode.security.ResourcePermission)

Example 8 with ResourcePermission

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;
}
Also used : ResourcePermission(org.apache.geode.security.ResourcePermission)

Example 9 with ResourcePermission

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;
}
Also used : GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) MBeanInfo(javax.management.MBeanInfo) IntrospectionException(javax.management.IntrospectionException) ResourcePermission(org.apache.geode.security.ResourcePermission) MBeanFeatureInfo(javax.management.MBeanFeatureInfo)

Example 10 with ResourcePermission

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());
}
Also used : ResourcePermission(org.apache.geode.security.ResourcePermission) UnitTest(org.apache.geode.test.junit.categories.UnitTest) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test)

Aggregations

ResourcePermission (org.apache.geode.security.ResourcePermission)12 SecurityTest (org.apache.geode.test.junit.categories.SecurityTest)5 UnitTest (org.apache.geode.test.junit.categories.UnitTest)5 Test (org.junit.Test)5 WildcardPermission (org.apache.shiro.authz.permission.WildcardPermission)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 AttributeNotFoundException (javax.management.AttributeNotFoundException)1 IntrospectionException (javax.management.IntrospectionException)1 MBeanFeatureInfo (javax.management.MBeanFeatureInfo)1 MBeanInfo (javax.management.MBeanInfo)1 GemFireSecurityException (org.apache.geode.security.GemFireSecurityException)1