Announcement Announcement Module
Collapse
No announcement yet.
SecurityContext not being populated with principal user Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SecurityContext not being populated with principal user

    I've got a spring MVC app that uses spring security and most of the time calling:

    Code:
    (XactAnalysisUser)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    Will give me back the currently logged in user. However, I have come across some cases where the Authentication object is null and the only way I can access the logged in user is by going through the session like so:

    Code:
    ((SecurityContext)session.getAttribute("SPRING_SECURITY_CONTEXT")).getAuthentication().getPrincipal();
    This is kind of a hacky way of doing it and I wanted to know if anyone can tell me why the securityContext doesn't get populated in certain cases? The only controller that currently doesn't work is my AjaxController which handles any ajax calls from the jsp pages and mostly returns json to jquery ajax calls. Thanks for any help.

  • #2
    Have you checked the FAQ?

    Comment

    Working...
    X