Results 1 to 2 of 2

Thread: SecurityContext not being populated with principal user

  1. #1
    Join Date
    Oct 2010
    Posts
    2

    Default 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. #2
    Luke Taylor is offline Senior Member Acegi Security System TeamSpring Team
    Join Date
    Aug 2004
    Location
    Glasgow, Scotland
    Posts
    3,449

    Default

    Have you checked the FAQ?
    Spring - by Pivotal
    twitter @tekul

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •