【问题标题】:Grails Spring Security required fieldsGrails Spring Security 必填字段
【发布时间】:2011-11-20 04:07:20
【问题描述】:

根据spring-security-core documentation,User 类中唯一需要的字段是

String username
String password
boolean enabled

但是,使用正确的用户名和密码登录后,我收到以下错误:

groovy.lang.MissingPropertyException:没有这样的属性:accountExpired 类:doit.recruiter.User

这让我觉得 accountExpiredaccountLockedpasswordExpired 实际上是必需的。如何使我的用户域类仅使用用户名/密码/启用?

【问题讨论】:

    标签: grails spring-security


    【解决方案1】:

    是的,这有点误导。该插件的默认实现使用 grails 包装器围绕实现类 User 用于 Spring Security 中的 User 接口。这个接口需要你不想拥有的三个字段,因此整个插件也实现了这个。

    对您而言失败的代码将在默认的用户详细信息实现中找到:

        boolean enabled = enabledPropertyName ? user."$enabledPropertyName" : true
        boolean accountExpired = accountExpiredPropertyName ? user."$accountExpiredPropertyName" : false
        boolean accountLocked = accountLockedPropertyName ? user."$accountLockedPropertyName" : false
        boolean passwordExpired = passwordExpiredPropertyName ? user."$passwordExpiredPropertyName" : false
    

    解决此问题的方法是实现您自己的 UserDetailsS​​ervice 并将值设置为 false 硬编码。或者,只需将字段作为域类中的瞬态属性,并使用返回 false 的 getter。

    可在此处找到自定义用户详细信息配方: http://burtbeckwith.github.com/grails-spring-security-core/docs/manual/guide/11%20Custom%20UserDetailsService.html

    【讨论】:

      猜你喜欢
      • 2012-01-15
      • 2015-04-10
      • 1970-01-01
      • 2016-05-20
      • 2017-10-09
      • 2019-05-09
      • 2012-02-19
      • 2012-09-09
      • 1970-01-01
      相关资源
      最近更新 更多