Skip to content

Instantly share code, notes, and snippets.

@winkler1
Created September 4, 2012 17:43
Show Gist options
  • Select an option

  • Save winkler1/3624007 to your computer and use it in GitHub Desktop.

Select an option

Save winkler1/3624007 to your computer and use it in GitHub Desktop.
/**
* Renders the body if none of the specified roles are granted to the user. Roles are
* specified in the 'roles' attribute which is a comma-delimited string.
*
* @attr roles REQUIRED the role name(s)
*/
def ifNotGranted = { attrs, body ->
String roles = assertAttribute('roles', attrs, 'ifNotGranted')
if (SpringSecurityUtils.ifNotGranted(roles)) {
out << body()
}
}
protected assertAttribute(String name, attrs, String tag) {
if (!attrs.containsKey(name)) {
throwTagError "Tag [$tag] is missing required attribute [$name]"
}
attrs.remove name
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment