最终引导.groovy

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了最终引导.groovy相关的知识,希望对你有一定的参考价值。

  1. class BootStrap {
  2.  
  3. def authenticateService
  4.  
  5. def init = { servletContext ->
  6.  
  7. //Adding Roles
  8. def roleAdmin = new Role(authority:'ROLE_ADMIN', description:'App admin').save()
  9. def roleUser = new Role(authority:'ROLE_USER', description:'App user').save()
  10.  
  11. //Adding Users
  12. def userGod = new User(username:'god',
  13. userRealName:'god almighty',
  14. enabled: true,
  15. emailShow: true,
  16. passwd: authenticateService.encodePassword('god')).save()
  17.  
  18. def userSlave = new User( username:'slave',
  19. userRealName:'poor slave',
  20. enabled: true,
  21. emailShow: true,
  22. passwd: authenticateService.encodePassword('slave')).save()
  23.  
  24. def secureUserEdit = new RequestMap(url: '/user/edit', configAttribute:'ROLE_ADMIN').save()
  25. def secureUserSave = new RequestMap(url: '/user/save', configAttribute:'ROLE_ADMIN').save()
  26. def secureUserCreate = new RequestMap(url: '/user/create', configAttribute:'ROLE_ADMIN').save()
  27.  
  28. def secureUserList = new RequestMap(url: '/user/list', configAttribute:'ROLE_ADMIN, ROLE_USER').save()
  29.  
  30.  
  31. //Note that here we associate users with their respective roles
  32. roleAdmin.addToPeople(userGod)
  33. roleUser.addToPeople(userGod)
  34. roleUser.addToPeople(userSlave)
  35.  
  36. }
  37. def destroy = {
  38. }
  39. }

以上是关于最终引导.groovy的主要内容,如果未能解决你的问题,请参考以下文章

向添加权限引导.groovy

将角色添加到引导.groovy

在引导程序中使用 groovy 元类模拟 Shiro SecurityUtils

使用 SpringSecurityCore 引导程序

JavaScript 什么 - 是 - OKR最最终引导到目标和钥匙,结果/

在引导程序中填充 List 的奇怪 Grails 行为