Assigning roles programmatically in grails using acegi
could someone provide me with a snippet that assigns a given existing acegi role (Authority) to a Pe开发者_如何学Pythonrson in Grails ?
Thanks.
How's this to add a role to a user:
def role = Role.findByAuthority("ROLE_USER")
def user = User.findByUSername("bob")
userRole.addToPeople(user)
To delete a role from a user:
userRole.removeFromPeople(user)
Plus to delete a user you need to remove the user from all roles first:
Role.findAll().each { it.removeFromPeople(user) }
user.delete()
精彩评论