Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php FOSUserBundle忽略密码字段_Php_Symfony_Fosuserbundle_Symfony 3.2 - Fatal编程技术网

Php FOSUserBundle忽略密码字段

Php FOSUserBundle忽略密码字段,php,symfony,fosuserbundle,symfony-3.2,Php,Symfony,Fosuserbundle,Symfony 3.2,因此,我使用FOSUserBundle with LDAP作为身份验证方法,我想知道是否有一种方法可以删除/忽略FOSUser实体的密码字段 我意识到移除可能不太理想,因为它会扰乱内部逻辑,但该列从未使用过,当我从装置创建Fosuser时,我被迫填充它: $user = new FOSUser(); $user->setDn($item["dn"]); $user->setEnabled(1); $user->setUsername($item["samaccountname

因此,我使用FOSUserBundle with LDAP作为身份验证方法,我想知道是否有一种方法可以删除/忽略FOSUser实体的密码字段

我意识到移除可能不太理想,因为它会扰乱内部逻辑,但该列从未使用过,当我从装置创建Fosuser时,我被迫填充它:

$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); 

实际上,您可以删除密码,但必须保留UserInterface中定义的getPassword。如果您想保留它,例如,当您允许多种登录类型时,您将再次需要它。我建议将该字段设置为可空。如果您使用的是注释,只需将nullable=true添加到列即可:

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

因此,推翻纵队条令允许:


密码字段仍驻留在BaseUser中,但被@ORM\AttributeOverride注释覆盖

谢谢,确切的语法略有不同-覆盖BaseUser字段。直接添加密码字段会导致重复错误。
/**
 * @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.
}