Symfony的安全/自定义用户提供:如何获得自定义用户提供内登录密码?

编程入门 行业动态 更新时间:2024-10-26 03:22:25
本文介绍了Symfony的安全/自定义用户提供:如何获得自定义用户提供内登录密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用Symfony的安全,在我的系统定制的用户提供。它通过Web服务提供的用户。结果我按照这个教程配置提供商( symfony/doc/电流/菜谱/安全/ custom_provider.html )。

I'm using Symfony Security with a custom User Provider in my system. It provide users via a web service. I configure the provider according to this tutorial (symfony/doc/current/cookbook/security/custom_provider.html).

下面是检查用户的功能:

Here is the function which check the user:

public function loadUserByUsername($username) { $userData = webServiceCheckUser($username); // return an array whit user credentials if ($userData) { $password = $userData['password']; $salt = $userData['salt']; $roles = $userData['roles']; $user = new WebserviceUser($username, $password, $salt, $roles); return $user; } throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username)); }

这工作得很好,功能 webServiceCheckUser()调用带有用户名的Web服务,然后将其返回用户数据的数组。但现在我需要通过需要用户名和用户的加密密码验证他的另一个Web服务来检查用户。我有一个像加密Web服务的明文密码在等待一个函数,但我不能让一个由在自定义用户提供类中的表单登录用户键入的密码。它是确定太多,如果我能得到的密码已被加密。任一个解决问题。

This works fine, the function webServiceCheckUser() call a web service with the username and then it return an array with user data. But now I need to check the user through another web service that requires the username and encrypted password of the user to authenticate him. I have a function that encrypts the plain text password like the web service is waiting, but I can't get the password that was typed by the user in the form login within the custom user provider class. It is ok too if I could get the password already encrypted. Either one solve the problem.

有是无论如何要做到这一点?

There is anyway to do this?

推荐答案

@Pazi是正确的在构建自己的定制身份验证提供者将工作。但是,这不是一件容易的事。

@Pazi is correct in that building your own custom authentication provider will work. However, it's not an easy task.

的另一种方法是重写DaoAuthenticationProvider的时候,并将它传递密码到loadUser功能。

An alternative approach is to override DaoAuthenticationProvider and have it pass the password to the loadUser function.

security_listeners.xml: <parameter key="security.authentication.provider.dao.class"> Symfony\Component\Security\Core\Authentication\Provider\DaoAuthenticationProvider </parameter>

一个黑客位,但也许它节省工作一个很好的协议。

Bit of a hack perhaps but it saves a good deal of work.

更多推荐

Symfony的安全/自定义用户提供:如何获得自定义用户提供内登录密码?

本文发布于:2023-11-11 17:54:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579153.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   用户提供   如何获得   密码   Symfony

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!