Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the role for current user with Spring Security

I'm trying to fetch all the roles for the current user who has been authenticated and show them in a JSP page.

I notice that there are some built-in expressions listed here: http://static.springsource.org/spring-security/site/docs/3.0.x/reference/el-access.html but I don't see any that would list all the roles.

like image 392
Omnipresent Avatar asked Feb 22 '13 00:02

Omnipresent


People also ask

What is SecurityContextHolder getContext () getAuthentication () getPrincipal ()?

The HttpServletRequest.getUserPrincipal() will return the result of SecurityContextHolder.getContext().getAuthentication() . This means it is an Authentication which is typically an instance of UsernamePasswordAuthenticationToken when using username and password based authentication.


1 Answers

You can use SecurityContextHolder.getContext().getAuthentication().getAuthorities() to obtain a collection of the currently logged in user's roles.

like image 113
zagyi Avatar answered Sep 29 '22 03:09

zagyi