2010-03-15 49 views
1

我正在使用acegi 0.5.2並啓用了OpenID支持。我想知道如何訪問由供應商(即Google,Yahoo!)返回的URL(或用戶名)。我找不到任何文檔有關,所以我跟蹤了Acegi的代碼,發現這GrailsOpenIdAuthenticationProvider:從Grails控制器/服務獲取OpenID URL

OpenIDAuthenticationToken response = (OpenIDAuthenticationToken) authentication 
OpenIDAuthenticationStatus status = response.status 

// handle the various possibilites 
if (status == OpenIDAuthenticationStatus.SUCCESS) { 
// Lookup user details 
UserDetails userDetails = _userDetailsService.loadUserByUsername(response.identityUrl) 
return new GrailsOpenIdAuthenticationToken(userDetails, response.status, response.identityUrl) 
} 

似乎response.identityUrl包含我需要什麼。如何從控制器(或服務)的空間獲得它?

謝謝。

回答

1

經過很長時間的研究和做了幾次試驗和錯誤,我找到了解決方案。

acegi插件爲您的項目提供了一個LoginController,它具有此操作:authfail。它的實現裏面,你可以檢查的OpenID值通過這個代碼:

println "openid = ${session['SPRING_SECURITY_LAST_EXCEPTION'].extraInformation}" 

用,那麼你可以自動創建新的用戶記錄,或做任何你想要與供應商提供的OpenID的。