FOSUserBundle 忽略密码字段[英] FOSUserBundle ignore password field

本文是小编为大家收集整理的关于FOSUserBundle 忽略密码字段的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

因此,我正在使用带有LDAP的FosuserBundle作为我的身份验证方法,我想知道是否有一种方法可以删除/忽略我的FOSUser实体的password字段?

我意识到删除可能不是理想的(如果它与内部逻辑混乱),但是该列从未使用过,当我从固定装置中创建FOSUsers时,我被迫填充它:

$user = new FOSUser();

$user->setDn($item["dn"]);
$user->setEnabled(1);
$user->setUsername($item["samaccountname"][0]);
$user->setUsernameCanonical(strtolower($item["samaccountname"][0]));
$user->setEmail($item["mail"][0]);
$user->setEmailCanonical(strtolower($item["mail"][0]));
$user->setDepartment($ldap_groups[$matches[1]]);
$user->setDepartmentDn($group);
$user->setPassword('blank'); // Is there away to avoid this?

$manager->persist($user); 

推荐答案

您实际上可以删除密码,但是您必须保留getPassword(),因为在用户接口中定义了密码.如果您想保留它,例如当您允许多种登录类型再次需要它.我建议将字段设置为无效.如果您使用的注释就像在列中添加nullable=true一样简单:

/**
 * @ORM\Column(type="string", name="password", nullable=true)
 */

其他推荐答案

因此,覆盖列教义允许继承映射:

/**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 * @ORM\AttributeOverrides({
 *     @ORM\AttributeOverride(name="password",
 *          column=@ORM\Column(
 *              name     = "password",
 *              type     = "string",
 *              nullable=true
 *          )
 *      )
 * })
 */
class FOSUser extends BaseUser implements LdapUserInterface
{
  // Extended logic.
}

密码字段仍然存在于BaseUser中,但被@ORM\AttributeOverride注释所覆盖.

本文地址:https://www.itbaoku.cn/post/2090847.html

问题描述

So I'm using the FOSUserBundle with LDAP as my authentication method, and I'm wondering whether there is a way to remove/ignore the password field for my FOSUser entity?

I realize removal might not be ideal (in case it messes with internal logic), but the column is never used, and I'm forced to fill it when I'm creating FOSUsers from fixtures:

$user = new FOSUser();

$user->setDn($item["dn"]);
$user->setEnabled(1);
$user->setUsername($item["samaccountname"][0]);
$user->setUsernameCanonical(strtolower($item["samaccountname"][0]));
$user->setEmail($item["mail"][0]);
$user->setEmailCanonical(strtolower($item["mail"][0]));
$user->setDepartment($ldap_groups[$matches[1]]);
$user->setDepartmentDn($group);
$user->setPassword('blank'); // Is there away to avoid this?

$manager->persist($user); 

推荐答案

You could actually remove the password, but you have to keep a getPassword() as that is defined in the UserInterface. In case you want to keep it, e.g. when you allow for multiple login types where you will need it again. I recommend setting the field as nullable. If you are using annotations it's as simple as adding nullable=true to the column:

/**
 * @ORM\Column(type="string", name="password", nullable=true)
 */

其他推荐答案

So to override a column doctrine allows for Inheritance Mapping:

/**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 * @ORM\AttributeOverrides({
 *     @ORM\AttributeOverride(name="password",
 *          column=@ORM\Column(
 *              name     = "password",
 *              type     = "string",
 *              nullable=true
 *          )
 *      )
 * })
 */
class FOSUser extends BaseUser implements LdapUserInterface
{
  // Extended logic.
}

The password field still resides in BaseUser, but is overwritten by the @ORM\AttributeOverride annotation.