开发者

How to assign role to a new user in bootstrap with grails spring security?

In my grails app i am using spring security plugin..I have registration form and registered users will be stored in db table.

in bootstrap i have created new role as, def PhysicianRole = new Role(authority: 'ROLE_PHYSICIAN开发者_Go百科').save(flush: true)

Then i have another form where admin is enabling or disabling users from table.

now i want to assign physician role to all the users who are enabled.so i did as below in bootstrap, def physicians=Physician.findAllWhere(enabled:true) with this i am getting array list as,

physicians-------------->[com.HospitalManagement.User : 1, com.HospitalManagement.User : 2, com.HospitalManagement.User : 4, com.HospitalManagement.User : 5, com.HospitalManagement.User : 6, com.HospitalManagement.User : 7]

now how should i assign physician role to all the objects in this array list?


def physicianRole = Role.findByAuthority('ROLE_PHYSICIAN')

for (physician in Physician.findAllWhere(enabled:true)) {
   if (!PhysicianRole.findByPhysicianAndRole(physician, physicianRole)) {
      PhysicianRole.create physician, physicianRole 
   }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜