嗨,我正在尝试在 Grails 应用程序中进行 facebook 登录,我遇到的问题是,当用户登录 facebook 时,spring security core 无法识别他,我如何手动设置用户的主体? 我可以查找用户对象,但我不知道如何设置它以便在调用 getAuthenticatedUser() 时获得真正的用户(现在它返回一个空对象)
提前致谢, 问候
最佳答案
不能对 facebook 说什么,但 Spring Security 有一个 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)
也许您需要使用 Authentication 的不同实现接口(interface)如示例中使用的接口(interface)。
关于Grails Spring安全核心,如何手动设置主体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5048851/