Skip to content

Commit

Permalink
minor symfony#10066 Refactor a security code example to make it easie…
Browse files Browse the repository at this point in the history
…r to understand (javiereguiluz)

This PR was merged into the 2.8 branch.

Discussion
----------

Refactor a security code example to make it easier to understand

This replaces symfony#10064 and extracts the common code into a new method.

Commits
-------

e588401 Refactor a security code example to make it easier to understand
  • Loading branch information
javiereguiluz committed Jul 14, 2018
2 parents 2d1cecb + e588401 commit 5cb68fc
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions security/custom_provider.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,7 @@ Here's an example of how this might look::
{
public function loadUserByUsername($username)
{
// make a call to your webservice here
$userData = ...
// pretend it returns an array on success, false if there is no user

if ($userData) {
$password = '...';

// ...

return new WebserviceUser($username, $password, $salt, $roles);
}

throw new UsernameNotFoundException(
sprintf('Username "%s" does not exist.', $username)
);
return $this->fetchUser($username);
}

public function refreshUser(UserInterface $user)
Expand All @@ -158,13 +144,32 @@ Here's an example of how this might look::
);
}

return $this->loadUserByUsername($user->getUsername());
return $this->fetchUser($username);
}

public function supportsClass($class)
{
return WebserviceUser::class === $class;
}

private function fetchUser($username)
{
// make a call to your webservice here
$userData = ...
// pretend it returns an array on success, false if there is no user

if ($userData) {
$password = '...';

// ...

return new WebserviceUser($username, $password, $salt, $roles);
}

throw new UsernameNotFoundException(
sprintf('Username "%s" does not exist.', $username)
);
}
}

Create a Service for the User Provider
Expand Down

0 comments on commit 5cb68fc

Please sign in to comment.