昨天我開始將我們的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