grails - Grails Spring Security必填字段

标签 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

关于grails - Grails Spring Security必填字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7470124/

相关文章:

hibernate - Grails/hibernate : Controller 中的乐观锁定

jquery - 将多个表单中的字段提交到一个 Grails Controller

java - 无需 Java 即可验证 Md5PasswordEncoder 哈希值?

java - 配置问题(HttpSecurity http)错误 : Can't configure antMatchers after anyRequest

java - 使用 Spring Mvc 测试测试 Spring Security Controller

css - Grails Bootstrap 插件找不到 Bootstrap 资源

grails - Spring 转换器内的Grails自动接线

grails - 使用Crystal:1.0-RC1插件的Grails 1.3.7依赖项解析错误

grails - 登录失败后,使用参数自定义URL重定向

java - Spring 启动 : Customize API response based on the User Roles