The documentation for nimble is not really all that good, however, the plugin is amazing. I feel lazy switching to spring security, so for the moment I'm sticking with nimble/shiro.
So I needed to create some default permissions, groups and roles in my application and it was taking me some time to figure out how to do this. What I had to do was to edit grails-app/conf/NimbleBootStrap.groovy and add them like this:
def adminOfficerRole = roleService.createRole('ADMIN_OFFICER','Administrative Offficers', false)
def basicMgmtGroup = groupService.createGroup('BASIC_MGMT','Group that does basic management',false)
roleService.addGroupMemeber(basicMgmtGroup,adminOfficerRole)
LevelPermission perm = new LevelPermission()
perm.populate('controller1,controller2','*',null,null,null,null)
perm.managed=false
permissionService.createPermission(perm,basicMgmtGroup)
//Add a user to a role
roleService.addMember(UserBase.findByUsername('username'),adminOfficerRole)
In our controllers we can now check for permissions as follows:
if(SecurityUtils.getSubject().isPermitted("controller:action")){
//DO SOMETHING HERE
}
Whew! Okay, now I shouldn't forget. :D
No comments:
Post a Comment