com.opensymphony.xwork2.interceptor.annotations
public class: AnnotationParameterFilterIntereptor [javadoc |
source]
java.lang.Object
com.opensymphony.xwork2.interceptor.AbstractInterceptor
com.opensymphony.xwork2.interceptor.annotations.AnnotationParameterFilterIntereptor
All Implemented Interfaces:
Interceptor
Annotation based version of
ParameterFilterInterceptor .
This
Interceptor must be placed in the stack before the
ParametersInterceptor
When a parameter matches a field that is marked
Blocked then it is removed from
the parameter map.
If an
Action class is marked with
BlockByDefault then all parameters are
removed unless a field on the Action exists and is marked with
Allowed
Method from com.opensymphony.xwork2.interceptor.annotations.AnnotationParameterFilterIntereptor Summary: |
---|
intercept |
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from com.opensymphony.xwork2.interceptor.annotations.AnnotationParameterFilterIntereptor Detail: |
public String intercept(ActionInvocation invocation) throws Exception {
final Object action = invocation.getAction();
Map< String, Object > parameters = invocation.getInvocationContext().getParameters();
boolean blockByDefault = action.getClass().isAnnotationPresent(BlockByDefault.class);
List< Field > annotatedFields = new ArrayList< Field >();
HashSet< String > paramsToRemove = new HashSet< String >();
if (blockByDefault) {
AnnotationUtils.addAllFields(Allowed.class, action.getClass(), annotatedFields);
for (String paramName : parameters.keySet()) {
boolean allowed = false;
for (Field field : annotatedFields) {
//TODO only matches exact field names. need to change to it matches start of ognl expression
//i.e take param name up to first . (period) and match against that
if (field.getName().equals(paramName)) {
allowed = true;
}
}
if (!allowed) {
paramsToRemove.add(paramName);
}
}
} else {
AnnotationUtils.addAllFields(Blocked.class, action.getClass(), annotatedFields);
for (String paramName : parameters.keySet()) {
for (Field field : annotatedFields) {
//TODO only matches exact field names. need to change to it matches start of ognl expression
//i.e take param name up to first . (period) and match against that
if (field.getName().equals(paramName)) {
paramsToRemove.add(paramName);
}
}
}
}
for (String aParamsToRemove : paramsToRemove) {
parameters.remove(aParamsToRemove);
}
return invocation.invoke();
}
|