2011-06-01 114 views
3

昨天我开始将我们的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不知道如何提取我们的域类。

我很乐意阅读任何见解!

+0

什么是帮助,类和select在约束条件中排序?谢谢? – 2011-06-01 20:16:32

回答

0

看起来该令牌无效,因此authenticate()调用失败并生成一个异常(IIRC它只在调用成功时返回一个值)。

我的第一个尝试是检查数据库是否有一行用户:'admin',密码:'admin'为环境。

经过一番思考,我会仔细检查Person类中的密码属性。要么通过域名类映射,要么通过更好地通过

userLookup.passwordPropertyName = "passwd" 

更新:第三件事要检查。

active = false 
+0

嗨,我只是测试了你的建议,但没有效果。但我确实认为错误地命名密码字段是一个问题,但不是我的主要问题。用户名/密码是正确的,算法也是如此(双重检查)。谢谢你的帮助! – 2011-06-01 21:37:02

+0

谢谢,活动设置没有被拾取,因为它不会附带grails.plugins.springsecurity。 (自Spring安全插件以来的一项要求),但我将其更改为主动,甚至进行了测试。可悲的是,这不是我正在狩猎的鬼魂...... – 2011-06-02 20:34:58

+0

好的。您是否在捕获AuthenticationException时尝试打印某些日志以查看发生的确切问题? – Gonfva 2011-06-03 09:35:38