|
|
|
|
@@ -21,9 +21,15 @@ import ognl.ObjectPropertyAccessor;
|
|
|
|
|
import ognl.OgnlException;
|
|
|
|
|
import ognl.PropertyAccessor;
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.BeanFactory;
|
|
|
|
|
import org.springframework.beans.factory.support.StaticListableBeanFactory;
|
|
|
|
|
import org.springframework.binding.collection.MapAdaptable;
|
|
|
|
|
import org.springframework.binding.expression.ognl.OgnlExpressionParser;
|
|
|
|
|
import org.springframework.security.context.SecurityContextHolder;
|
|
|
|
|
import org.springframework.util.ClassUtils;
|
|
|
|
|
import org.springframework.webflow.core.collection.MutableAttributeMap;
|
|
|
|
|
import org.springframework.webflow.engine.AnnotatedAction;
|
|
|
|
|
import org.springframework.webflow.execution.Action;
|
|
|
|
|
import org.springframework.webflow.execution.RequestContext;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -37,16 +43,12 @@ public class WebFlowOgnlExpressionParser extends OgnlExpressionParser {
|
|
|
|
|
* Creates a webflow-specific ognl expression parser.
|
|
|
|
|
*/
|
|
|
|
|
public WebFlowOgnlExpressionParser() {
|
|
|
|
|
addPropertyAccessor(RequestContext.class, new RequestContextPropertyAccessor(new ObjectPropertyAccessor()));
|
|
|
|
|
addPropertyAccessor(MapAdaptable.class, new MapAdaptablePropertyAccessor());
|
|
|
|
|
addPropertyAccessor(MutableAttributeMap.class, new MutableAttributeMapPropertyAccessor());
|
|
|
|
|
addPropertyAccessor(RequestContext.class, new RequestContextPropertyAccessor(new ObjectPropertyAccessor()));
|
|
|
|
|
addPropertyAccessor(Action.class, new ActionPropertyAccessor());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The {@link MapAdaptable} property accessor.
|
|
|
|
|
*
|
|
|
|
|
* @author Keith Donald
|
|
|
|
|
*/
|
|
|
|
|
private static class MapAdaptablePropertyAccessor implements PropertyAccessor {
|
|
|
|
|
public Object getProperty(Map context, Object target, Object name) throws OgnlException {
|
|
|
|
|
return ((MapAdaptable) target).asMap().get(name);
|
|
|
|
|
@@ -58,11 +60,6 @@ public class WebFlowOgnlExpressionParser extends OgnlExpressionParser {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The {@link MutableAttributeMap} property accessor.
|
|
|
|
|
*
|
|
|
|
|
* @author Keith Donald
|
|
|
|
|
*/
|
|
|
|
|
private static class MutableAttributeMapPropertyAccessor extends MapAdaptablePropertyAccessor {
|
|
|
|
|
public void setProperty(Map context, Object target, Object name, Object value) throws OgnlException {
|
|
|
|
|
((MutableAttributeMap) target).put((String) name, value);
|
|
|
|
|
@@ -70,6 +67,12 @@ public class WebFlowOgnlExpressionParser extends OgnlExpressionParser {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static class RequestContextPropertyAccessor implements PropertyAccessor {
|
|
|
|
|
|
|
|
|
|
private static boolean securityPresent = ClassUtils
|
|
|
|
|
.isPresent("org.springframework.security.context.SecurityContextHolder");
|
|
|
|
|
|
|
|
|
|
private static final BeanFactory EMPTY_BEAN_FACTORY = new StaticListableBeanFactory();
|
|
|
|
|
|
|
|
|
|
private PropertyAccessor delegate;
|
|
|
|
|
|
|
|
|
|
public RequestContextPropertyAccessor(PropertyAccessor delegate) {
|
|
|
|
|
@@ -79,6 +82,16 @@ public class WebFlowOgnlExpressionParser extends OgnlExpressionParser {
|
|
|
|
|
public Object getProperty(Map context, Object target, Object name) throws OgnlException {
|
|
|
|
|
String property = name.toString();
|
|
|
|
|
RequestContext requestContext = (RequestContext) target;
|
|
|
|
|
if (property.equals("flowRequestContext")) {
|
|
|
|
|
return requestContext;
|
|
|
|
|
}
|
|
|
|
|
if (securityPresent && property.equals("currentUser")) {
|
|
|
|
|
if (SecurityContextHolder.getContext() != null) {
|
|
|
|
|
return SecurityContextHolder.getContext().getAuthentication();
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (requestContext.getRequestScope().contains(property)) {
|
|
|
|
|
return requestContext.getRequestScope().get(property);
|
|
|
|
|
} else if (requestContext.getFlashScope().contains(property)) {
|
|
|
|
|
@@ -87,14 +100,39 @@ public class WebFlowOgnlExpressionParser extends OgnlExpressionParser {
|
|
|
|
|
return requestContext.getFlowScope().get(property);
|
|
|
|
|
} else if (requestContext.getConversationScope().contains(property)) {
|
|
|
|
|
return requestContext.getConversationScope().get(property);
|
|
|
|
|
} else {
|
|
|
|
|
return delegate.getProperty(context, target, name);
|
|
|
|
|
}
|
|
|
|
|
BeanFactory bf = getBeanFactory(requestContext);
|
|
|
|
|
if (bf.containsBean(property)) {
|
|
|
|
|
return bf.getBean(property);
|
|
|
|
|
}
|
|
|
|
|
return delegate.getProperty(context, target, name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setProperty(Map context, Object target, Object name, Object value) throws OgnlException {
|
|
|
|
|
delegate.setProperty(context, target, name, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private BeanFactory getBeanFactory(RequestContext requestContext) {
|
|
|
|
|
if (requestContext.getActiveFlow().getBeanFactory() != null) {
|
|
|
|
|
BeanFactory factory = requestContext.getActiveFlow().getBeanFactory();
|
|
|
|
|
return factory;
|
|
|
|
|
} else {
|
|
|
|
|
return EMPTY_BEAN_FACTORY;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static class ActionPropertyAccessor implements PropertyAccessor {
|
|
|
|
|
public Object getProperty(Map context, Object target, Object name) throws OgnlException {
|
|
|
|
|
Action action = (Action) target;
|
|
|
|
|
AnnotatedAction annotated = new AnnotatedAction(action);
|
|
|
|
|
annotated.setMethod(name.toString());
|
|
|
|
|
return annotated;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setProperty(Map context, Object target, Object name, Object value) throws OgnlException {
|
|
|
|
|
throw new OgnlException("Cannot set properties on a Action instance - operation not allowed");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|