grails - Grails Spring Security必填字段

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

String username
String password
boolean enabled

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

groovy.lang.MissingPropertyException: No such property: accountExpired for class: doit.recruiter.User



这使我认为实际上需要accountExpired,accountLocked和passwordExpired。如何使我的User域类仅与用户名/密码/启用一起使用?

最佳答案

是的,这有点误导。插件的默认实现在Spring Security中为用户界面使用实现类User周围的grails包装器。这个介面需要三个您不想拥有的栏位,因此整个插件也实现了这个功能。

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

    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硬编码。另外,只要在您的域类中将这些字段作为 transient 属性,并且将getter返回false即可。

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

https://stackoverflow.com/questions/7470124/

相关文章:

ruby-on-rails - Rails 4.1:Rails:Module的未定义方法 `appl

inheritance - Grails/GORM:继承的域类的行为不一致(测试VS Bootstr

hibernate - Grails渴望通过滚动获取

grails - grails控制列表方法的外观

grails - Grails中的String的默认数据库映射类型是什么?

git - "Permission denied (publickey)."Git错误

ajax - 在Grails中使用Ajax动态刷新图像

command-line - SSH与FTP:通过终端将本地文件推送到服务器

shell - 在每行的开头添加文本

grails - 使用 resources.groovy 定义服务