I\'m currently developing a menu for my application that should be able to display only the controllers that the current user can access (requestmap defined in the database).
Not sure of the situation when this question was originally asked, but now you can check to see if a user is in a specific role by using SpringSecurityUtils.ifAllGranted()
which takes a single String which is a comma delimited list of roles. It will return true if the current user belongs to all of them.
if(SpringSecurityUtils.ifAllGranted('ROLE_ADMIN,ROLE_USER')) {
Obviously, you can simply pass one role to the function if that is all you need. SpringSecurityUtils
also has methods like ifAnyGranted
, ifNotGranted
, etc, so it should work for whatever it is you are trying to accomplish.
SpringSecurityUtils
is a static API, so you don't need to create a private member named springSecurityUtils
or anything like that.