昨天我开始将我们的Grails应用从Acegi插件0.5.2升级到Spring安全插件。我遇到了几个问题,也许任何人都可以在这里帮忙?Grails,从Acegi升级到Spring安全插件
在做了必要的修改之后(如Burt Beckwith在Migrating from the Acegi Plugin上所记录),我能够再次启动Grails应用程序(woohoo!)。但是,登录无效了。
我们的情况如下:我们将Grails应用程序纯粹用于其应用程序逻辑。身份验证是通过webservices使用用户名和密码完成的。作为后端,我们使用应用程序的数据库(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.springf[email protected]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;
}
}
而且我们的人域类:
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不知道如何提取我们的域类。
我很乐意阅读任何见解!
什么是帮助,类和select在约束条件中排序?谢谢? – 2011-06-01 20:16:32