Spring security accessing principal

Posted by wuntee on Stack Overflow See other posts from Stack Overflow or by wuntee
Published on 2010-03-27T12:16:45Z Indexed on 2010/03/27 12:23 UTC
Read the original article Hit count: 405

Filed under:
|

When using spring security, specifically with @notation; what is the proper way to access the principal in a Controller? Lets say the following is my controller, but I would like to access the principal in the secure() method somewhere...

@Controller
public class LoginController {

    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String login(ModelMap map, @RequestParam(value="fail" , required=false) String fail){
        map.addAttribute("title", "Login: AD Credentials");
        if(fail != null){
            map.addAttribute("error", "Invalid credentials");
        }
        return("login");
    }

    @RequestMapping("/secure")
    @PreAuthorize("isAuthenticated()")
    public String secure(ModelMap map, String principal){
        System.out.println(principal);
        return("secure");
    }


}

© Stack Overflow or respective owner

Related posts about spring-security

Related posts about principal