2017-03-16 46 views
0

我需要在JAVA中以編程方式加載現有的Spring-webflow流來檢查它的安全標記。如何以編程方式加載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代碼中訪問它們。

Thx,對於任何提示。

回答

0

我得到了它的自己:

在擴展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"); 
+1

你可以使用一個FlowExecutionListener – rptmat57

相關問題