我正在开发一个 Grails 遗留项目。存在一个名为 User 的域类。它包含密码、用户名、角色等。
该项目使用 Spring Security 进行角色管理。我想添加凭据过期(强制用户更新其密码)。
我修改了 User 类。不是它实现了用户详情界面 http://www.chibi.ubc.ca/maven2/jars.to.deploy/spring-security-2.0.5/docs/apidocs/org/springframework/security/userdetails/User.html.
但是,当我启动服务器时,出现此错误>
org.springframework.beans.factory.BeanCreationException:
使用名称创建 bean 时出错
“messageSource”:初始化
豆失败;嵌套异常是
org.springframework.beans.factory.BeanCreationException:
使用名称创建 bean 时出错
“transactionManager”:无法解析
引用 bean 'sessionFactory'
设置bean属性时
'会话工厂';嵌套异常是
org.springframework.beans.factory.BeanCreationException:
使用名称创建 bean 时出错
'sessionFactory':调用 init
方法失败;嵌套异常是
org.hibernate.PropertyNotFoundException:
找不到财产设置者
课堂上的 accountNonExpired
com.company.app.user.User
我必须注册一些bean吗?我发现这个错误非常令人困惑,因为该接口不需要设置方法。
update
经过更多调查后,我遇到了我的 SecurityConfig.groovy,看起来A LOT像这样 (Acegi安全插件 http://www.grails.org/AcegiSecurity+Plugin+-+Basic+Tutorial+with+standard+string+mapping):
security {
// see DefaultSecurityConfig.groovy for all settable/overridable properties
active = true
loginUserDomainClass = "User"
authorityDomainClass = "Role"
....
}
我的用户类也看起来A LOT像这样:
/**
* User domain class.
*/
class User {
static transients = ['pass','passwordExpired','credentialsNonExpired']
static hasMany = [authorities: Role]
static belongsTo = Role
/** Username */
String username
/** User Real Name*/
String userRealName
/** MD5 Password */
String passwd
/** enabled */
boolean enabled
String email
boolean emailShow
/** description */
String description = ''
/** plain password to create a MD5 password */
String pass = '[secret]'
static constraints = {
username(blank: false, unique: true)
userRealName(blank: false)
passwd(blank: false)
enabled()
}
public boolean isCredentialsNonExpired() {
return true;
}
}
我添加了一个方法来检查此类的密码是否应该过期(isCredentialsNonExpired)
。我需要这个方法在登录时执行。现在还不是。
所以看起来这是我应该采取的 Acegi 方法。有什么想法吗?据我了解,Acegi 使用 Spring Security,对吧?