【问题标题】:Grails Spring Security SecUserGrails Spring Security SecUser
【发布时间】:2012-02-19 07:40:26
【问题描述】:

我可以创建两种不同类型的 secuser,例如 secuser 和 enduser 、SecRole 和 EndRole 我的 secuser 和 secrole 将提供给我医院的管理员和医生和最终用户,endrole 将提供给我医院项目的最终用户

我有 secuser 和 secrole 表,但是当我使用 s2-quickstart 命令创建最终用户和 endrole 时,我能够获取域类并且我没有覆盖我的登录和注销控制器现在无法创建最终用户对象我的引导带中的 endrole 对象

class BootStrap {
   def springSecurityService
   def init = { servletContext ->

      /*
      def userRole = EndRole.findByAuthority('ROLE_USER') ?: new EndRole(authority: 'ROLE_USER').save(failOnError: true)

      def endadminUser = EndUser.findByUsername('endadmin') ?: new EndUser(
         username: 'endadmin',
         password:'endadmin',enabled: true).save(failOnError: true)

      if (!endadminUser.authorities.contains(userRole)) {
         EndUserEndRole.create endadminUser, userRole
      }
      */

      def x= new EndRole(authority: 'ROLE_USER')
      println("    new fresh      "+x.authority)
   }
   def destroy = {
   }
}

【问题讨论】:

    标签: grails spring-security


    【解决方案1】:

    您可以拥有任意多类型的用户,但要支持这一点,您需要自定义UserDetailsService。这是很常见的事情,因此在文档中有一个部分。见http://grails-plugins.github.com/grails-spring-security-core/docs/manual/中的“11自定义UserDetailsS​​ervice”部分

    我不确定你为什么认为你需要不止一个角色类。只需为管理员和医生创建一个具有不同角色名称的 SecRole 实例,例如new SecRole(authority: 'ROLE_DOCTOR').save(), new SecRole(authority: 'ROLE_ADMIN').save().

    您可能根本不需要不同的用户类(至少出于安全考虑,您可能需要支持不同的属性,因为非安全原因)。只需创建 SecUser 实例并授予它们所需的任何角色(使用 EndUserEndRole.create),即 ROLE_DOCTOR 或 ROLE_ADMIN。

    帮自己一个忙,阅读插件文档,以及http://static.springsource.org/spring-security/site/docs/3.0.x/reference/springsecurity.html 上的 Spring Security 文档 - 如果您对如何保护网站不满意,那么实施这些东西太重要了。

    【讨论】:

    • 谢谢@Burt Beckwith 的回复我解决了这个问题,我的问题是我的班级之间的关系。我已经成功完成了一半的项目,但我成功了,请帮助我stackoverflow.com/questions/9046596/…
    猜你喜欢
    • 1970-01-01
    • 2019-05-09
    • 2012-09-09
    • 1970-01-01
    • 2016-05-24
    • 2015-05-04
    • 2023-03-24
    • 2015-08-12
    • 2017-06-20
    相关资源
    最近更新 更多