Announcement Announcement Module
Collapse
No announcement yet.
Assessing the user from within Spring webflow - how to? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Assessing the user from within Spring webflow - how to?

    I have tried every approach I can think of to access the currentUser from within Spring webflow.

    My user has authenticated via Spring Social LinkedIn.

    What would be the strategy?

    It is not, for me, <evaluate expression="currentUser" result="currentUser" result-type=""/>

    Greg

  • #2
    I'm not sure about 'social user', I'll face the issue later, but now for getting 'internal authenticated user' I have something like that in -flow.xml and in Controller class:
    Code:
        <on-start>
            <evaluate expression="myController.initializeForm(currentUser)" result="flowScope.myForm"/>
             ..........
        </on-start>
    ......
    
    @Controller
    public class MyController {
        @Autowired
        private YourUserService userService;
    
    ....
        public FormBeanClass initializeForm(Principal principal) {
    ......
            FormBeanClass myFormBean = new FormBeanClass()
            if (principal != null && principal.getName() != null) {
                UserXXClass user = userService.findByUserName(principal.getName());
                // most probably user will never be == null, otherwise it won't be authenticated
                ...............
               // do whenever you want
               myFormBean.setUser(...)
               myFormBean.setUserId(.......)
           }
           return myFormBean;
        }

    Comment


    • #3
      Nice

      Thanks blandger.

      I would never have thought of that. Firstly because I assume (and still do) that there must be a way to directly assess from webflow. But also I am not cleaver enough to think of using a controller like that. I presume @Controller means you get access to the principal.

      Thanks again.

      Comment


      • #4
        You are welcome.
        Originally posted by greg.soulsby View Post
        Thanks blandger.
        I would never have thought of that. ......... But also I am not cleaver enough to think of using a controller like that.
        I'm also not so clever as I wanted to be, I found it somewhere.
        Originally posted by greg.soulsby View Post
        I presume @Controller means you get access to the principal.Thanks again.
        Yes, that means...
        Code:
            @RequestMapping(value = "/profile", method = RequestMethod.GET)
            public String profile(Model model, Principal principal) {
        .....
        Originally posted by greg.soulsby View Post
        Thanks again.
        When you need to pass request parameter into web-flow (controller or service class) you can ask me how.

        Comment

        Working...
        X