public class GroovyValueFilter extends GroovyInterceptor
GroovyInterceptor
that looks at individual values that are coming into/out of a call,
without regard to any context.
One of the common strategies for filtering is to ensure that the sandboxed script don't acquire a reference to objects that they are not supposed to. This implementation works as a convenient base class for such interceptor by providing a smaller number of methods that can be overridden.
GroovyInterceptor.Invoker
Constructor and Description |
---|
GroovyValueFilter() |
Modifier and Type | Method and Description |
---|---|
Object |
filter(Object o)
All the specific
filterXXX() methods delegate to this method. |
Object |
filterArgument(Object arg)
Called for every argument to method/constructor calls.
|
Object |
filterIndex(Object index)
Called for every index of the array get/set access.
|
Object |
filterReceiver(Object receiver)
Called for every receiver.
|
Object |
filterReturnValue(Object returnValue)
Called for a return value of a method call, newly created object, retrieve property/attribute values.
|
Object |
onGetArray(GroovyInterceptor.Invoker invoker,
Object receiver,
Object index)
Intercepts an array access, like "z=foo[bar]"
|
Object |
onGetAttribute(GroovyInterceptor.Invoker invoker,
Object receiver,
String attribute)
Intercepts an attribute access, like "z=foo.@bar"
|
Object |
onGetProperty(GroovyInterceptor.Invoker invoker,
Object receiver,
String property)
Intercepts a property access, like "z=foo.bar"
|
Object |
onMethodCall(GroovyInterceptor.Invoker invoker,
Object receiver,
String method,
Object... args)
Intercepts an instance method call on some object of the form "foo.bar(...)"
|
Object |
onNewInstance(GroovyInterceptor.Invoker invoker,
Class receiver,
Object... args)
Intercepts an object instantiation, like "new Receiver(...)"
|
Object |
onSetArray(GroovyInterceptor.Invoker invoker,
Object receiver,
Object index,
Object value)
Intercepts an attribute assignment like "foo[bar]=z"
|
Object |
onSetAttribute(GroovyInterceptor.Invoker invoker,
Object receiver,
String attribute,
Object value)
Intercepts an attribute assignment like "foo.@bar=z"
|
Object |
onSetProperty(GroovyInterceptor.Invoker invoker,
Object receiver,
String property,
Object value)
Intercepts a property assignment like "foo.bar=z"
|
Object |
onStaticCall(GroovyInterceptor.Invoker invoker,
Class receiver,
String method,
Object... args)
Intercepts a static method call on some class, like "Class.forName(...)".
|
getApplicableInterceptors, register, unregister
public Object filterReturnValue(Object returnValue)
public Object filterArgument(Object arg)
public Object filterIndex(Object index)
public Object onMethodCall(GroovyInterceptor.Invoker invoker, Object receiver, String method, Object... args) throws Throwable
GroovyInterceptor
onMethodCall
in class GroovyInterceptor
Throwable
public Object onStaticCall(GroovyInterceptor.Invoker invoker, Class receiver, String method, Object... args) throws Throwable
GroovyInterceptor
Class
can invoke static methods, too
(that is, x=Integer.class;x.valueOf(5)
results in onMethodCall(invoker,Integer.class,"valueOf",5)
onStaticCall
in class GroovyInterceptor
Throwable
public Object onNewInstance(GroovyInterceptor.Invoker invoker, Class receiver, Object... args) throws Throwable
GroovyInterceptor
onNewInstance
in class GroovyInterceptor
Throwable
public Object onGetProperty(GroovyInterceptor.Invoker invoker, Object receiver, String property) throws Throwable
GroovyInterceptor
onGetProperty
in class GroovyInterceptor
receiver
- 'foo' in the above example, the object whose property is accessed.property
- 'bar' in the above example, the name of the propertyThrowable
public Object onSetProperty(GroovyInterceptor.Invoker invoker, Object receiver, String property, Object value) throws Throwable
GroovyInterceptor
onSetProperty
in class GroovyInterceptor
receiver
- 'foo' in the above example, the object whose property is accessed.property
- 'bar' in the above example, the name of the propertyvalue
- The value to be assigned.value
.Throwable
public Object onGetAttribute(GroovyInterceptor.Invoker invoker, Object receiver, String attribute) throws Throwable
GroovyInterceptor
onGetAttribute
in class GroovyInterceptor
receiver
- 'foo' in the above example, the object whose attribute is accessed.attribute
- 'bar' in the above example, the name of the attributeThrowable
public Object onSetAttribute(GroovyInterceptor.Invoker invoker, Object receiver, String attribute, Object value) throws Throwable
GroovyInterceptor
onSetAttribute
in class GroovyInterceptor
receiver
- 'foo' in the above example, the object whose attribute is accessed.attribute
- 'bar' in the above example, the name of the attributevalue
- The value to be assigned.value
.Throwable
public Object onGetArray(GroovyInterceptor.Invoker invoker, Object receiver, Object index) throws Throwable
GroovyInterceptor
onGetArray
in class GroovyInterceptor
receiver
- 'foo' in the above example, the array-like object.index
- 'bar' in the above example, the object that acts as an index.Throwable
public Object onSetArray(GroovyInterceptor.Invoker invoker, Object receiver, Object index, Object value) throws Throwable
GroovyInterceptor
onSetArray
in class GroovyInterceptor
receiver
- 'foo' in the above example, the array-like object.index
- 'bar' in the above example, the object that acts as an index.value
- The value to be assigned.value
.Throwable
Copyright © 2015. All rights reserved.