This repository has been archived by the owner on Dec 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add generic LdapUser class that supports custom properties via __call.
- Loading branch information
1 parent
5dd6178
commit 314d51f
Showing
3 changed files
with
95 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the LdapAuthentication service provider. | ||
* | ||
* (c) Martin Rademacher <mano@radebatz.net> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Radebatz\Silex\LdapAuth\Security\Core\User; | ||
|
||
use Symfony\Component\Security\Core\User\UserInterface; | ||
|
||
/** | ||
* Ldap user class that supports custom properties via magic methods. | ||
*/ | ||
class LdapUser implements UserInterface | ||
{ | ||
protected $username; | ||
protected $password; | ||
protected $firstName; | ||
protected $roles; | ||
protected $properties; | ||
|
||
public function __construct($username, $password, array $roles = array()) | ||
{ | ||
$this->username = $username; | ||
$this->password = $password; | ||
$this->roles = $roles; | ||
$this->properties = array(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getRoles() | ||
{ | ||
return $this->roles; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getPassword() | ||
{ | ||
return $this->password; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getSalt() | ||
{ | ||
return; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getUsername() | ||
{ | ||
return $this->username; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function eraseCredentials() | ||
{ | ||
} | ||
|
||
/** | ||
* Handle get/set property. | ||
*/ | ||
public function __call($method, array $args) | ||
{ | ||
$prefix = substr($method, 0, 3); | ||
if ('set' == $prefix && 1 == count($args)) { | ||
$property = lcfirst(substr($method, 3)); | ||
$this->properties[$property] = $args[0]; | ||
|
||
return; | ||
} elseif ('get' == $prefix) { | ||
$property = lcfirst(substr($method, 3)); | ||
|
||
return array_key_exists($property, $this->properties) ? $this->properties[$property] : null; | ||
} | ||
|
||
throw new \RuntimeException('Invalid method: '.$method); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.