我需要在 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 代码中访问它们。
谢谢您的任何提示。
最佳答案
我自己得到的:
在扩展 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");
关于java - 如何以编程方式加载 Spring webflow 流并获取其内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42834547/