diff --git a/Auth/SamlAuth.php b/Auth/SamlAuth.php index 48c58de..56c9c32 100644 --- a/Auth/SamlAuth.php +++ b/Auth/SamlAuth.php @@ -98,9 +98,9 @@ public function authenticate(){ //Check if username and email are set if (!empty($username) && !empty($email)) { - - //Create user by having email as username - $this->userInfo = new SamlUserProvider($username, $email, $fullname); + //Create user + $userProfile = $this->userCacheDecorator->getByUsername($username); + $this->userInfo = new SamlUserProvider($username, $email, $fullname, $userProfile ?: array()); return true; } else { diff --git a/User/SamlUserProvider.php b/User/SamlUserProvider.php index b790a56..3cf7869 100644 --- a/User/SamlUserProvider.php +++ b/User/SamlUserProvider.php @@ -30,18 +30,26 @@ class SamlUserProvider implements UserProviderInterface */ protected $name = ''; + /** + * User profile if the user already exists + * + * @access private + * @var array + */ + private $userProfile = array(); + /** * Constructor * * @access public * @param string $username */ - public function __construct($username, $email, $name, $role) + public function __construct($username, $email, $name, array $userProfile = array()) { $this->username = $username; $this->email = $email; $this->name = $name; - $this->role = $role; + $this->userProfile = $userProfile; } /** @@ -96,8 +104,10 @@ public function getExternalId() */ public function getRole() { - //return Role::APP_USER; - return $this->role; + if(isset($this->userProfile['role'])){ + return $this->userProfile['role']; + } + return Role::APP_USER; } /**