diff --git a/catalyst/api-bundle/Entity/User.php b/catalyst/api-bundle/Entity/User.php index 712b5d5d..d47d8892 100644 --- a/catalyst/api-bundle/Entity/User.php +++ b/catalyst/api-bundle/Entity/User.php @@ -49,6 +49,12 @@ class User extends BaseUser implements UserInterface */ protected $roles; + // enabled + /** + * @ORM\Column(type="boolean") + */ + protected $enabled; + public function __construct() { // generate keys @@ -57,8 +63,9 @@ class User extends BaseUser implements UserInterface // set date created $this->date_create = new DateTime(); - + $this->roles = new ArrayCollection(); + $this->enabled = true; } public function getID() @@ -99,20 +106,6 @@ class User extends BaseUser implements UserInterface return $this->name; } - //public function getRoles() - //{ - // $str_roles = []; - // foreach ($this->roles as $role) - // $str_roles[] = $role->getID(); - - // return $str_roles; - //} - - //public function getRoleObjects() - //{ - // return $this->roles; - //} - public function getDateCreate() { return $this->date_create; diff --git a/catalyst/api-bundle/Security/APIKeyAuthenticator.php b/catalyst/api-bundle/Security/APIKeyAuthenticator.php index f40728df..27d1eaf1 100644 --- a/catalyst/api-bundle/Security/APIKeyAuthenticator.php +++ b/catalyst/api-bundle/Security/APIKeyAuthenticator.php @@ -131,6 +131,12 @@ class APIKeyAuthenticator implements SimplePreAuthenticatorInterface, Authentica // check if signature is valid $this->validateSignature($creds, $user->getSecretKey()); + // check if user is enabled + if (!$user->isEnabled()) + { + throw new CustomUserMessageAuthenticationException('User account is disabled'); + } + // $user = $user_provider->loadUserByUsername($username); return new PreAuthenticatedToken( diff --git a/catalyst/auth-bundle/Entity/User.php b/catalyst/auth-bundle/Entity/User.php index fad0699c..ad05fb16 100644 --- a/catalyst/auth-bundle/Entity/User.php +++ b/catalyst/auth-bundle/Entity/User.php @@ -5,10 +5,12 @@ namespace Catalyst\AuthBundle\Entity; abstract class User { protected $roles; + protected $enabled; public function __construct() { $this->roles = new ArrayCollection(); + $this->enabled = true; } public function getRoles() @@ -25,4 +27,26 @@ abstract class User return $this->roles; } + public function addRole(Role $role) + { + $this->roles->add($role); + return $this; + } + + public function clearRoles() + { + $this->roles->clear(); + return $this; + } + + public function setEnabled($enabled = true) + { + $this->enabled = $enabled; + return $this; + } + + public function isEnabled() + { + return $this->enabled; + } } diff --git a/src/Entity/User.php b/src/Entity/User.php index bc106433..ccb4ddc8 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -153,33 +153,6 @@ class User extends BaseUser implements AdvancedUserInterface, Serializable return null; } - public function addRole(Role $role) - { - $this->roles->add($role); - return $this; - } - - public function clearRoles() - { - $this->roles->clear(); - return $this; - } - - //public function getRoles() - //{ - // // has to return set of strings because symfony is trying to move away from role objects - // $str_roles = []; - // foreach ($this->roles as $role) - // $str_roles[] = $role->getID(); - - // return $str_roles; - //} - - //public function getRoleObjects() - //{ - // return $this->roles; - //} - public function addHub(Hub $hub) { $this->hubs->add($hub); @@ -226,17 +199,6 @@ class User extends BaseUser implements AdvancedUserInterface, Serializable return true; } - public function setEnabled($enabled = true) - { - $this->enabled = $enabled; - return $this; - } - - public function isEnabled() - { - return $this->enabled; - } - public function serialize() { return serialize([