【问题标题】:How to programmatically load a Spring webflow flow and get its content如何以编程方式加载 Spring webflow 流并获取其内容
【发布时间】:2017-03-16 22:33:58
【问题描述】:

我需要在 JAVA 中以编程方式加载现有的 Spring-webflow 流来检查它的安全标签。

我的目标是在特定事件后检查安全标签。

这里使用 Spring-webflow 2.4。我的流程看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:ns0="http://www.w3.org/2001/XMLSchema-instance"
ns0:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">


<secured attributes="RIGHT_1,RIGHT_2" />

<view-state id="someViewState">
[...]
</view-state>

[...]

</flow>

那么我怎样才能通过 Spring API 获得这个流的“内容”呢?我试图通过 org.springframework.webflow.config 包的类找到我的方式,但我没有找到干草中的针。我什至无法成功加载流。

我使用流有一段时间了,但我从来不需要在 Java 代码中访问它们。

谢谢,任何提示。

【问题讨论】:

    标签: java spring spring-mvc spring-webflow


    【解决方案1】:

    我自己弄的:

    在扩展 org.springframework.web.servlet.mvc.AbstractController 的类中,您可以这样做:

    // get the application Context
    ApplicationContext context = getApplicationContext();
    // get webflowController, must be configured in your webflowConfig file
    FlowController controller = (FlowController)context.getBean("flowController");
    FlowExecutorImpl flowExecutorImpl = (FlowExecutorImpl)controller.getFlowExecutor();
    FlowDefinitionRegistryImpl flowDefinitionRegistryImpl = (FlowDefinitionRegistryImpl)flowExecutorImpl.getDefinitionLocator();
    
    // flowId is the id of the flow you want to check
    FlowDefinition flowDefinition = flowDefinitionRegistryImpl.getFlowDefinition(flowId);
    
    MutableAttributeMap<Object> attributes = flowDefinition.getAttributes();
    
    // finally the SecurityRule Object that you can pass to a specific AccessDecisionManager
    SecurityRule securityRule = (SecurityRule)attributes.get("secured");
    

    【讨论】:

    • 你可以使用 FlowExecutionListener
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多