0

我对 Spring security 和 Spring social 比较陌生。我正在尝试使用标准 Spring Security 或 Spring social Facebook 实现混合身份验证。

因此,用户可以进行身份​​验证:

  • 使用标准 Spring 安全登录表单,如下所示:

我的 Thymeleaf 模板中的片段:

<form name="f" th:action="@{/resources/j_spring_security_check}" method="POST">
        <input id="j_username" type='text' name='j_username'/><br /> 
        <input id="j_password" type='password' name='j_password'/><br /> 
        <input id="proceed" type="submit" value="login" />
</form>

这可以正常工作,就像用户向受保护资源发送请求一样,例如www.example.com/memberArea/editMyProfile受以下拦截 URL 保护:

<intercept-url pattern="/memberArea/**" access="hasRole('ROLE_USER')" />

用户被重定向到登录表单,成功登录后,用户最终被重定向到受保护的资源,即www.example.com/memberArea/editMyProfile

  • 或者用户可以选择 Spring Social Facebook 并使用如下链接进行身份验证/登录:

我的 Thymeleaf 模板中的片段:

<a th:href="@{'https://www.facebook.com/dialog/oauth/?client_id=414113641982512&amp;redirect_uri=http://www.example.com/&amp;state=UNIQUE&amp;scope=read_stream'}">Login with facebook</a>

在这种情况下,用户当然会被重定向到www.example.com而不是www.example.com/memberArea/editMyProfile

那么我的问题是,我如何——仍然使用 Spring security 和 Spring Social Facebook——以某种方式检索请求的 URL(此处www.example.com/memberArea/editMyProfile)并最终将用户重定向到该 URL?

4

1 回答 1

2

您能帮我理解您尝试做的事情与 Spring Social 的 ProviderSignInController 的工作方式有何不同吗?具体来说,如果您查看 Spring Social Showcase (https://github.com/SpringSource/spring-social-samples/tree/master/spring-social-showcase) 或 Spring Social Quickstart (https://github.com /SpringSource/spring-social-samples/tree/master/spring-social-quickstart) 示例,它们都使用 ProviderSignInController 通过 Facebook 对用户进行身份验证。

在展示示例中,通过将用户的 FB 信息与先前建立的连接进行比较来完成身份验证。在快速入门示例中,它是通过“隐式身份验证”完成的,其中没有特定于应用程序的身份验证,而是 Facebook 授权足以用于应用程序身份验证。据我了解,您正在尝试做与展示相同的风格,但我可能会误解您正在尝试做的事情。

顺便说一句,请随时在 StackOverflow 继续讨论,但我鼓励您在 Spring Social 论坛 (http://forum.springsource.org/forumdisplay.php?82-Social) 上提出您的 Spring Social 问题,因为我监控那个论坛几乎每天都有,但每周左右只访问一次(如果经常访问的话)。

于 2012-09-15T21:15:48.717 回答