2011-02-19 68 views
2

嗨即時嘗試使Facebook的登錄在Grails應用程序,我遇到的問題是,當用戶登錄Facebook時,彈簧安全核心不認識他,怎麼可以我手動設置了用戶的主體? 我可以尋找用戶對象,但我不知道如何設置,以獲得我的呼喚getAuthenticatedUser(真正的用戶)(現在它返回一個空的對象)提前Grails彈簧安全核心,如何設置主要手動

感謝, 問候

回答

4

不能說什麼關於Facebook的,但春季安全具有可用於操作認證(因此委託人)這樣的SecurityContextHolder

import org.springframework.security.core.context.SecurityContextHolder as SCH 
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken 


.... 
def securityContext = SCH.context 
def principal = <whatever you use as principal> 
def credentials = <...> 
securityContext.authentication = new PreAuthenticatedAuthenticationToken(principal, credentials) 

也許你就需要使用不同的實現作爲o的接口爲Authentication ne在示例中使用。

+0

非常感謝,我非常感謝你的幫助 – belcebuu 2011-03-21 07:02:56