Skip to content

Refactor a security code example to make it easier to understand #10066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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