Announcement Announcement Module
Collapse
No announcement yet.
Spring webflow unit test with spring security on Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring webflow unit test with spring security on

    Greetings,

    I'm trying to test a webflow .xml with spring security on:
    Code:
    <action-state id="search">
        <secured attributes="ROLE_ADMIN"/>
    ...
    </action-state>
    I'm using AbstractXmlFlowExecutionTests subclass.

    Now, the test runs ok without the "secured" tag (I don't make any mocks for the security), but once I add the security tag, the test keeps finishing with success, although I anticipate a security exception to be thrown.
    Any ideas why it doesn't work and how should I configure it?
    Thanks in advance!
    Igor

  • #2
    Ok, I've found the solution: I needed to add a securityListener manually. Before startFlow:

    Code:
    setFlowExecutionListener(getSecurityListener(new String[] {"ROLE_ADMIN_FAKE"}));
    Where

    Code:
    private FlowExecutionListener getSecurityListener(String[] roles) {
        List<GrantedAuthority> result = new ArrayList<>();
        for (String role: roles) {
            SimpleGrantedAuthority authority = new SimpleGrantedAuthority(role);
            result.add(authority);
        }
        Authentication auth = new PreAuthenticatedAuthenticationToken("Igor", "", result);
        SecurityContextHolder.getContext().setAuthentication(auth);
        return new SecurityFlowExecutionListener();
    }

    Originally posted by ideruga View Post
    Greetings,

    I'm trying to test a webflow .xml with spring security on:
    Code:
    <action-state id="search">
        <secured attributes="ROLE_ADMIN"/>
    ...
    </action-state>
    I'm using AbstractXmlFlowExecutionTests subclass.

    Now, the test runs ok without the "secured" tag (I don't make any mocks for the security), but once I add the security tag, the test keeps finishing with success, although I anticipate a security exception to be thrown.
    Any ideas why it doesn't work and how should I configure it?
    Thanks in advance!
    Igor

    Comment

    Working...
    X