Add the enabled flag to the api user and base user. Remove the enabled methods from site user since base class has them. Add checking if user account is enabled during authentication of api user. #194

This commit is contained in:
Korina Cordero 2019-05-08 08:25:11 +00:00
parent 3c236d0ab4
commit ecec2d07d7
4 changed files with 38 additions and 53 deletions

View file

@ -49,6 +49,12 @@ class User extends BaseUser implements UserInterface
*/
protected $roles;
// enabled
/**
* @ORM\Column(type="boolean")
*/
protected $enabled;
public function __construct()
{
// generate keys
@ -59,6 +65,7 @@ class User extends BaseUser implements UserInterface
$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;

View file

@ -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(

View file

@ -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;
}
}

View file

@ -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([