开发者

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()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜