Skip to main content

Principal

Learn Principal (Spring MVC Security Integration, Spring MVC) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Fresher Notes Principal is the identity of the logged-in user; in Spring Security it is the object returned by Authentication.getPrincipal() , usually a UserDetails . In a controller : add a Principal parameter and Spring MVC fills it, so principal.getName() gives the username. Better : use @AuthenticationPrincipal UserDetails user to get your own user type directly.

More lessons in Spring MVC Security Integration