【发布时间】:2011-09-06 06:53:37
【问题描述】:
昨天我开始将我们的 Grails 应用程序从 Acegi 插件 0.5.2 升级到 Spring 安全插件。我遇到了一些问题,也许有人可以在这里提供帮助?
进行必要的更改后(如 Burt Beckwith 在 Migrating from the Acegi Plugin 上记录的那样),我能够再次启动 Grails 应用程序(哇哦!)。但是,登录不再起作用。
我们的情况如下:我们使用我们的 Grails 应用程序 pure 作为其应用程序逻辑。身份验证是通过网络服务使用用户名和密码完成的。作为后端,我们使用应用程序 (dao) 的数据库和 LDAP 后端。目前,我们已禁用 LDAP,以简化测试。
这是进行身份验证的代码:
def authenticate(String username, String password) {
try {
println "Trying authentication with user " + username + " and password " + password + "."
def tempToken = new UsernamePasswordAuthenticationToken(username, password)
println "Temptoken is " + tempToken
def token = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password))
println "Authentication token received was: " + token
} catch (AuthenticationException authenticationException) {
return false
}
return true
}
这会打印到日志中:
Trying authentication with user admin and password admin.
Temptoken is org.springframework.security.providers.UsernamePasswordAuthenticationToken@1f: Principal: admin; Password: [PROTECTED]; Authenticated: false; Details: null; Not granted any authorities
然后一切都停止了。
我们使用的领域类相当简单。我们不使用诸如用户角色之类的类来连接人员及其权限。相反,我们使用多对多映射,因为这对我们一直有效且易于维护。
我们的权威域类:
class Authority {
static hasMany = [people: Person]
/** description */
String description
/** ROLE String */
String authority = ''
String authorityType
static constraints = {
authority(help:'x',class:'wide',blank: false,unique:true)
description(help:'x',class:'extrawide')
authorityType(help:'x',class:'wide')
people(help:'x',selectSort:'username',display:false)
}
String toString() {
return authority;
}
}
还有我们的 Person 域类:
class Person {
static hasMany = [authorities: Authority]
static belongsTo = Authority
//Authority primaryGroup
/** Username */
String username
/** User Real Name*/
String userRealName
String familyName
String givenName
/** MD5 Password */
String passwd
/** enabled */
boolean enabled
String email
boolean emailShow
/** description */
String description = ''
static constraints = {
username(blank: false, unique: true,help:'x',class:'wide')
userRealName(blank: false,help:'x',class:'wide')
familyName(blank: false,help:'x',class:'wide')
givenName(blank: false,help:'x',class:'wide')
email(help:'x',class:'wide')
emailShow(help:'x')
enabled(help:'x')
passwd(blank: false,password:true,show:false,help:'x',class:'wide')
authorities(nullable:true,help:'x',sortable:true,selectSort:'authority')
}
String toString() {
return username;
}
}
在 Config.Groovy 中,我们定义了:
security {
active = false
cacheUsers = false
grails.plugins.springsecurity.providerNames = ['daoAuthenticationProvider', 'anonymousAuthenticationProvider', 'rememberMeAuthenticationProvider']
grails.plugins.springsecurity.userLookUp.userDomainClassName = "Person"
grails.plugins.springsecurity.authority.className = "Authority"
就文档而言,这应该可以正常工作(对于“旧”Acegi 设置也是如此)。
为了收集更多信息,我短暂激活了 LDAP 并发现了同样的问题。 WireShark 告诉我在登录过程中没有进行任何 LDAP 调用。我的猜测是 Authenticate 函数中的代码有问题,或者 SpringSecurity 不知道如何获取我们的域类。
我很乐意阅读任何见解!
【问题讨论】:
-
约束中的 help、class 和 selectSort 是什么?谢谢?
标签: security spring grails groovy spring-security