web-services - Symfony2 自定义认证 : user logged but not authenticated

标签 web-services security authentication symfony symfony-2.1

我一直在使用 Symfony 2.1 开发自定义身份验证系统。在与 Symfony 进行了大量的战斗之后,我得到了一些可以工作但不完全......

问题:登录后(通过表单),用户已登录但未通过身份验证。

上下文:由于用户必须通过 HTML 表单提交其凭据,因此我必须创建一个扩展 AbstractAuthenticationListener 的监听器。

问题:监听器不应该自动将 token 添加到 SecurityContext 吗?如果不是这种情况,我应该手动执行吗?

过程:

User submits his credentials through HTML form

Listener intercepts request and runs attemptAuthentication

Listener calls AuthenticationManager's (implements AuthenticationProviderInterface) authenticate method

AuthenticationManager calls the UserProvider (implements UserProviderInterface) to retrieve user's data from my webservice.

UserProvider returns a User class implementing UserInterface

AuthenticationManager 创建一个 Token 实现 TokenInterface。

AuthenticationManager 将 token 返回给监听器。

Listener 的 attemptAuthentication 从 AuthenticationManager 的方法返回 token :authenticate

用户已登录但未通过身份验证。

我没有展示代码示例以避免帖子过载。如果需要,我会编辑帖子。

最佳答案

我发现我的错误...

登录后,AuthenticationSuccessHandler 将用户重定向到我想要的 url。此操作会触发来自 UserProvider 的 refreshUser。

此函数是硬编码的,测试用户与我登录时使用的用户不同。一旦该函数返回一个等于存储在 token 中的用户,问题就解决了。

关于web-services - Symfony2 自定义认证 : user logged but not authenticated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15642699/

相关文章:

android - Android 中的安全功能

Python套接字安全

iphone - iOS 应用程序和 Windows 身份验证

java - 使用 Jersey 测试 RESTful Web 服务时出现 HTTP 状态 404

java - 我如何使用 Spring Ws marshall 调用 Paypal ws?

iphone - 同一 viewController iphone 上的多个 Web 服务调用

java - 使用 REST 和 SOAP 验证空字段的方法相同

javascript - 这有多糟糕?在javascript中存储密码

安全模型 : log in to third-party site with user's credentials

c# - 使用 oAuth 构建 C#/ASP.NET API 进行 API 身份验证