我Spring Security core
在上安装了插件1.2.7.3 Grails 2.1.1
,运行s2-quickstart
命令,然后在bootstrap.groovy中初始化了初始用户和角色,但还是无法登录。相关部分的文本BootStrap.groovy
如下:
if (SecRole.count == 0) {
def fUserRole = SecRole.findByAuthority('ROLE_FlowUser') ?: new SecRole(authority: 'ROLE_FlowUser').save(failOnError: true, flush: true)
def fAdminRole = SecRole.findByAuthority('ROLE_FlowAdmin') ?: new SecRole(authority: 'ROLE_FlowAdmin').save(failOnError: true, flush: true)
def bf = SecUser.findByUsername('bill') ?: new SecUser(
username: 'bill',
password: 'eagle',
firstName: 'bill',
lastName: 'fly',
email: 'bill.fly@baylorhealth.edu',
accountExpired: false,
accountLocked: false,
passwordExpired: false,
enabled: true
).save(failOnError: true, flush: true)
if (!bf.authorities.contains(fAdminRole)) {
SecUserSecRole.create bf, fAdminRole, true
}
if (!bf.authorities.contains(fUserRole)) {
SecUserSecRole.create bf, fUserRole, true
}
}
我没有在引导程序中加密密码,这似乎是大多数此类问题的答案。所有四条记录都被写入数据库表,但当然,我无法判断密码是否正确加密。我的初始控制器在类语句之前有以下注释:
@Secured(['IS_AUTHENTICATED_FULLY'])
此外,我在 config.groovy 中添加了以下内容:
// 由 Spring Security Core 插件添加:
grails.plugins.springsecurity.userLookup.userDomainClassName = 'cocktail.SecUser'
grails.plugins.springsecurity.userLookup.authorityJoinClassName = 'cocktail.SecUserSecRole'
grails.plugins.springsecurity.authority.className = 'cocktail.SecRole'
grails.plugins.springsecurity.password.algorithm = 'SHA-256'