Question

My scenario is this: I need to implement a type of authorization check to be made in multiple flows. Right now one of my flows looks like this:

<flow parent="myparent-flow">
    <decision-state id="checkAuthorization">
        <if test="bean.notAuthorized" 
            then="redirectToSomePage"
            else="view1" />
    </decision-state>
    <view-state id="view1" />
    <!-- ... -->
</flow>

I need to implement that same authorization check for a number of flows, and while I can copy-paste the same logic everywhere I would really like to, if possible, put this in the parent flow itself, which is already used to execute some logic on-start of each flow.

The problem here is the else-class in the decision-state. Since it is a parent flow to many subflows it will not know the name of the first state in the child flow. I would like to use it as such that it would somehow go ahead and execute the next state in the flow, which exists in the child flow. My optimal solution would be something like this:

<flow> <!-- flow name = myparent-flow -->
    <decision-state id="checkAuthorization">
        <if test="bean.notAuthorized"
            then="redirectToSomeFlow"
            else="continueExecutionInChildFlow" />
    </decision-state>
    <end-state id="redirectToSomeFlow" view="flowRedirect:someFlow" />
</flow>

This would then be defined as parent flow in all my flows so that I don't have to duplicate this logic. Is it possible to do such a thing with Spring?

Was it helpful?

Solution

One possible way to achieve it could be by setting a variable on the specific flow and use this variable for the end-state redirection afterwards, like:

<if test="bean.notAuthorized" 
    then="redirectToSomeFlow" 
    else="${conversationScope.resultView}" />

The variable could be set by using:

<set name="conversationScope.resultView" value="'viewName'" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top