Grails Spring Security (Acegi) getting User Roles/Authorities


Using Spring Security you may need to allow access to certain criteria based on roles. Working on a Grails application recently I was able to get the Roles/Authorities of the user with the Groovy code below.

def principal = SCH?.context?.authentication?.principal

principal.authorities.each{
   println 'role='+it.authority
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s