0

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); 
Darkstarone
  • 4,590
  • 8
  • 37
  • 74

2 Answers2

1

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)
 */
dbrumann
  • 16,803
  • 2
  • 42
  • 58
  • Thanks, the exact syntax is slightly different - [Inheritance Mapping](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/inheritance-mapping.html#overrides) overrides the `BaseUser` field. Directly adding the password field caused duplication errors. – Darkstarone Mar 30 '17 at 10:27
0

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.

Darkstarone
  • 4,590
  • 8
  • 37
  • 74