根据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
解决此问题的方法是实现自己的UserDetailsService并将值简单设置为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/