AuthorizeTagLib
ifAllGranted
Will display inner body content only if all of the listed roles are granted:
<g:ifAllGranted role="ROLE_ADMIN,ROLE_SUPERVISOR">secure stuff here</g:ifAllGranted>
ifAnyGranted
Will display inner body content if any of the listed roles are granted:
<g:ifAnyGranted role="ROLE_ADMIN,ROLE_SUPERVISOR">secure stuff here</g:ifAnyGranted>
ifNotGranted
Will display inner body content if none of the listed roles are granted:
<g:ifNotGranted role="ROLE_USER">non-user stuff here</g:ifNotGranted>
loggedInUserInfo
Displays the value of the specified domain user class field if logged in. For example this will show the user's username property:
<g:loggedInUserInfo field="username"/>
isLoggedIn
Will display inner body content if the user is authenticated:
<g:isLoggedIn>content for logged in user</g:isLoggedIn>
isNotLoggedIn
Will display inner body content if the user is not authenticated:
<g:isNotLoggedIn>content for anonymous(not loggen in) user</g:isNotLoggedIn>
AuthBase
AuthBase.groovy is a sample Controller base class that can optionally be used to share common security-related functionality between secured controllers. Some features include:
- dependency injection for AuthenticateService
- allows specification per-controller of required roles to access the controller (see the 'requestAllowed' field)
- provides Locale resolution
- turns off caching
AuthenticateService
A Service class that provides some security utility functions. Has some (deprecated) overlap with AuthorizeTagLib, but also provides these methods:
- principal() to retrieve the currently logged in user's Principal
- userDomain() to retrieve the currently logged in user's Domain class
- getSecurityConfig() to retrieve the security configuration (DefaultSecurityConfig attributes merged with SecurityConfig attributes)
- passwordEncoder() to retrieve the current password encoder
Sample usage:
class SimpleController {
AuthenticateService authenticateService
def simpleAction = {
def principal = authenticateService.principal()
println principal.getUsername()//get username
println principal.getAuthorities()//get authorities
}
}