Interface

Symfony\Component\Security\Core\User\UserInterface

interface UserInterface

Represents the interface that all user classes must implement.

This interface is useful because the authentication layer can deal with the object through its lifecycle, using the object to get the encoded password (for checking against a submitted password), assigning roles and so on.

Regardless of how your user are loaded or where they come from (a database, configuration, web service, etc), you will have a class that implements this interface. Objects that implement this interface are created and loaded by different objects that implement UserProviderInterface

Methods

Role[] getRoles()

Returns the roles granted to the user.

string getPassword()

Returns the password used to authenticate the user.

string getSalt()

Returns the salt that was originally used to encode the password.

string getUsername()

Returns the username used to authenticate the user.

void eraseCredentials()

Removes sensitive data from the user.

Boolean equals(UserInterface $user)

Returns whether or not the given user is equivalent to this user.

Details

at line 50
public Role[] getRoles()

Returns the roles granted to the user.

public function getRoles() { return array('ROLE_USER'); }

Alternatively, the roles might be stored on a roles property, and populated in any number of different ways when the user object is created.

Return Value

Role[] The user roles

at line 60
public string getPassword()

Returns the password used to authenticate the user.

This should be the encoded password. On authentication, a plain-text password will be salted, encoded, and then compared to this value.

Return Value

string The password

at line 69
public string getSalt()

Returns the salt that was originally used to encode the password.

This can return null if the password was not encoded using a salt.

Return Value

string The salt

at line 76
public string getUsername()

Returns the username used to authenticate the user.

Return Value

string The username

at line 86
public void eraseCredentials()

Removes sensitive data from the user.

This is important if, at any given point, sensitive information like the plain-text password is stored on this object.

Return Value

void

at line 101
public Boolean equals(UserInterface $user)

Returns whether or not the given user is equivalent to this user.

The equality comparison should neither be done by referential equality nor by comparing identities (i.e. getId() === getId()).

However, you do not need to compare every attribute, but only those that are relevant for assessing whether re-authentication is required.

Parameters

UserInterface $user

Return Value

Boolean