其不需要UserProvider定义身份验证 [英] Custom Authentication which doesn't need UserProvider

查看:183
本文介绍了其不需要UserProvider定义身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看了网上对我的配置上的解决方案,但我不能找到满足我的需求。
到目前为止,我一直在这个满3天了,我不能让它正常工作,我相信有几件事情,我不明白。

I looked for a solution on the web for my configuration but I can't find something which satisfies my needs. So far, I have been working on this for 3 full days, and I can't make it works properly, I am sure there are several things that I didn't understand.

我发展我的symfony应用程序的分支2.1。

I am developing my symfony application on the branch 2.1.

为了使这短暂的。我有我想要使用的身份验证的Web服务。

To make this short. I have a webservice which I want to use for the authentication.

这是我想要实现的流程:

This is the flow I want to implement:


  1. 用户提交的凭证

  2. 这些凭据(用户名和放大器;提供密码)发送到我的web服务

  3. 如果用户名/密码是正确的,web服务给人以用户名,角色和其他一些东西,但密码的数组。 (如果凭据不正确,有一个字段的数组将是回报)

  4. 一旦web服务给出了大数组,我想通过身份验证需要考虑的用户。

  5. 在角色的功能恢复,我想Symfony的安全组件给出了相应的授权用户。

  6. 我想避免做出web服务的浏览每一页的电话。

我不知道是否有可能使这种使用Symfony的,肯定这个工作流程似乎不是更安全,但我看不到另一种方式利用此WebService。

I don't know if it is possible to make this using Symfony, for sure this workflow seems not to be the more secure, but I can't see another way for using this webservice.

要完成,我并不需要有一个UserProvider因为我的身份验证的远程服务的。但很显然,Symfony的组件需要的用户提供者(doen't事项的类型)。

To finish, I don't need to have a UserProvider since my authentication is made on the remote service. But apparently, Symfony components requires an user provider (doen't matter its type).

我感谢你在前进

编辑:为了使它更简单,是有可能传递loadUserByUsername()函数不仅仅是变量$用户名更多的东西在UserProvider类(它实现UserProviderInterface)?我需要有除了他/她的用户名用户通过检索用户对象。

To make it simpler, is it possible to pass something more than just the variable $username in loadUserByUsername() function in the UserProvider class (which implements UserProviderInterface)? I need to have the user pass in addition to his/her username to retrieve the User Object.

推荐答案

使用AuthenticationProvider通常称之为UserProvider.loadUserByUsername。你的情况,也没有必要调用它。您的身份验证方法可以创建用户和回传令牌的照顾。

The AuthenticationProvider will normally call UserProvider.loadUserByUsername. In your case, there is no need to call it. Your authenticate method can take care of creating the user and passing back the token.

通过身份验证令牌最终在会话结束。

The authenticated token eventually ends up in the session.

问题是,默认情况下,当一个请求到来时,系统将检索从会话令牌/用户,然后调用UserProvider.refreshUser($用户)的,再由默认情况下,重新加载与loadUserByUsername用户。

The problem is that by default, when the next request comes in, the system will retrieve the token/user from the session and then call UserProvider.refreshUser($user) which, again by default, reloads the user with loadUserByUsername.

所以,你需要创建自己的用户提供,只是有refreshUser返回相同的用户。您将需要一个loadUserByUsername只是为了满足接口,但它不应该被调用。

So you need to create your own user provider and just have refreshUser return the same user. You will need a loadUserByUsername just to satisfy the interface but it should never be called.

如果你想定期刷新从Web服务用户,那么你就需要在自己的监听器添加到从会议加载令牌,并覆盖默认行为。

If you do want to periodically refresh your user from the web service then you will need to add in your own listener to load the token in from the session and override the default behavior.

这篇关于其不需要UserProvider定义身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆