Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to get current logged in user in JSP and Controller using Spring Security? Example Tutorial

How To Get Current Logged In User In JSP And Controller Using Spring Security? Example Tutorial
One of the common task while using Spring Security in a Java web application is getting the username of currently logged in user. Sometime, you need that in your controller class and sometime in JSP for view purpose, but the big question mark is how do you get the current user in Spring Security? Well, there are many ways to do it and depending upon whether you need it inside a JSP page or Controller class, you can choose them. The current user, also known as Principal in Spring Security can be obtained from the UserDetails class, which holds all details for currently logged in user. You can get this class from the SecurityContext, which in turn can be retrieved from SecurityContextHolder as shown below:


This post first appeared on Javarevisited: Blog About Java Programmin, please read the originial post: here

Share the post

How to get current logged in user in JSP and Controller using Spring Security? Example Tutorial

×

Subscribe to Javarevisited: Blog About Java Programmin

Get updates delivered right to your inbox!

Thank you for your subscription

×