【问题标题】:Grails spring security core, how to set principal manuallyGrails spring安全核心,如何手动设置主体
【发布时间】:2011-02-19 04:31:43
【问题描述】:

您好,我试图在 grails 应用程序中登录 facebook,我遇到的问题是当用户登录 facebook 时,spring security core 无法识别他,我该如何手动设置用户的主体? 我可以查找用户对象,但我不知道如何设置它以便在我调用 getAuthenticatedUser() 时获得真正的用户(现在它返回一个空对象)

提前致谢, 问候

【问题讨论】:

    标签: grails grails-plugin


    【解决方案1】:

    不能说任何关于 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 接口实现。

    【讨论】:

      猜你喜欢
      • 2012-06-01
      • 2016-06-12
      • 2011-10-19
      • 2015-12-09
      • 2018-11-02
      • 1970-01-01
      • 2016-04-16
      • 2015-04-09
      • 2012-08-17
      相关资源
      最近更新 更多