Skip to content
Permalink
Browse files

minor #32353 [Security] Added type-hints to user providers (derrabus)

This PR was merged into the 5.0-dev branch.

Discussion
----------

[Security] Added type-hints to user providers

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #32179
| License       | MIT
| Doc PR        | N/A

This PR adds type declarations to user provider classes.

Commits
-------

62abb70 [Security] Added type-hints to user providers.
  • Loading branch information...
fabpot committed Jul 4, 2019
2 parents cc9778e + 62abb70 commit b163a95bd5c9b15924257e3017c4c809e3cd5ef1
@@ -44,7 +44,7 @@ public function __construct(ManagerRegistry $registry, string $classOrAlias, str
/**
* {@inheritdoc}
*/
public function loadUserByUsername($username)
public function loadUserByUsername(string $username)
{
$repository = $this->getRepository();
if (null !== $this->property) {
@@ -102,7 +102,7 @@ public function refreshUser(UserInterface $user)
/**
* {@inheritdoc}
*/
public function supportsClass($class)
public function supportsClass(string $class)
{
return $class === $this->getClass() || is_subclass_of($class, $this->getClass());
}
@@ -33,7 +33,7 @@
"symfony/property-access": "^4.4|^5.0",
"symfony/property-info": "^4.4|^5.0",
"symfony/proxy-manager-bridge": "^4.4|^5.0",
"symfony/security-core": "^4.4|^5.0",
"symfony/security-core": "^5.0",
"symfony/expression-language": "^4.4|^5.0",
"symfony/validator": "^4.4|^5.0",
"symfony/translation": "^4.4|^5.0",
@@ -49,7 +49,8 @@
"phpunit/phpunit": "<5.4.3",
"symfony/dependency-injection": "<4.4",
"symfony/form": "<4.4",
"symfony/messenger": "<4.4"
"symfony/messenger": "<4.4",
"symfony/security-core": "<5"
},
"suggest": {
"symfony/form": "",
@@ -49,7 +49,7 @@ public function getProviders()
/**
* {@inheritdoc}
*/
public function loadUserByUsername($username)
public function loadUserByUsername(string $username)
{
foreach ($this->providers as $provider) {
try {
@@ -94,7 +94,7 @@ public function refreshUser(UserInterface $user)
/**
* {@inheritdoc}
*/
public function supportsClass($class)
public function supportsClass(string $class)
{
foreach ($this->providers as $provider) {
if ($provider->supportsClass($class)) {
@@ -61,7 +61,7 @@ public function createUser(UserInterface $user)
/**
* {@inheritdoc}
*/
public function loadUserByUsername($username)
public function loadUserByUsername(string $username)
{
$user = $this->getUser($username);
@@ -85,7 +85,7 @@ public function refreshUser(UserInterface $user)
/**
* {@inheritdoc}
*/
public function supportsClass($class)
public function supportsClass(string $class)
{
return 'Symfony\Component\Security\Core\User\User' === $class;
}
@@ -99,7 +99,7 @@ public function supportsClass($class)
*
* @throws UsernameNotFoundException if user whose given username does not exist
*/
private function getUser($username)
private function getUser(string $username)
{
if (!isset($this->users[strtolower($username)])) {
$ex = new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
@@ -60,7 +60,7 @@ public function __construct(LdapInterface $ldap, string $baseDn, string $searchD
/**
* {@inheritdoc}
*/
public function loadUserByUsername($username)
public function loadUserByUsername(string $username)
{
try {
$this->ldap->bind($this->searchDn, $this->searchPassword);
@@ -109,20 +109,17 @@ public function refreshUser(UserInterface $user)
/**
* {@inheritdoc}
*/
public function supportsClass($class)
public function supportsClass(string $class)
{
return 'Symfony\Component\Security\Core\User\User' === $class;
}
/**
* Loads a user from an LDAP entry.
*
* @param string $username
* @param Entry $entry
*
* @return User
*/
protected function loadUser($username, Entry $entry)
protected function loadUser(string $username, Entry $entry)
{
$password = null;
$extraFields = [];
@@ -140,11 +137,8 @@ protected function loadUser($username, Entry $entry)
/**
* Fetches a required unique attribute value from an LDAP entry.
*
* @param Entry|null $entry
* @param string $attribute
*/
private function getAttributeValue(Entry $entry, $attribute)
private function getAttributeValue(Entry $entry, string $attribute)
{
if (!$entry->hasAttribute($attribute)) {
throw new InvalidArgumentException(sprintf('Missing attribute "%s" for user "%s".', $attribute, $entry->getDn()));
@@ -32,7 +32,7 @@ public function __construct(string $firewall)
/**
* {@inheritdoc}
*/
public function loadUserByUsername($username)
public function loadUserByUsername(string $username)
{
throw new \BadMethodCallException();
}
@@ -48,7 +48,7 @@ public function refreshUser(UserInterface $user)
/**
* {@inheritdoc}
*/
public function supportsClass($class)
public function supportsClass(string $class)
{
throw new \BadMethodCallException();
}
@@ -39,13 +39,11 @@ interface UserProviderInterface
* This method must throw UsernameNotFoundException if the user is not
* found.
*
* @param string $username The username
*
* @return UserInterface
*
* @throws UsernameNotFoundException if the user is not found
*/
public function loadUserByUsername($username);
public function loadUserByUsername(string $username);
/**
* Refreshes the user.
@@ -65,9 +63,7 @@ public function refreshUser(UserInterface $user);
/**
* Whether this provider supports the given user class.
*
* @param string $class
*
* @return bool
*/
public function supportsClass($class);
public function supportsClass(string $class);
}

0 comments on commit b163a95

Please sign in to comment.
You can’t perform that action at this time.