Commit 9919be14 authored by Bertrand Gauthier's avatar Bertrand Gauthier

Work in progress.

parent 48d5fa7f
......@@ -349,9 +349,7 @@ return [
'UnicaenAuth\View\RedirectionStrategy' => 'UnicaenAuth\View\RedirectionStrategy',
'UnicaenAuth\Service\UserContext' => 'UnicaenAuth\Service\UserContext',
'UnicaenAuth\Service\User' => 'UnicaenAuth\Service\User',
'UnicaenAuth\Service\Privilege' => 'UnicaenAuth\Service\PrivilegeService',
'UnicaenAuth\Service\CategoriePrivilege' => 'UnicaenAuth\Service\CategoriePrivilegeService',
'UnicaenAuth\Service\Role' => 'UnicaenAuth\Service\RoleService',
],
'abstract_factories' => [
'UnicaenAuth\Authentication\Adapter\AbstractFactory',
......@@ -367,6 +365,8 @@ return [
'UnicaenAuth\Provider\Role\Config' => 'UnicaenAuth\Provider\Role\ConfigServiceFactory',
'UnicaenAuth\Provider\Role\DbRole' => 'UnicaenAuth\Provider\Role\DbRoleServiceFactory',
'UnicaenAuth\Provider\Role\Username' => 'UnicaenAuth\Provider\Role\UsernameServiceFactory',
'UnicaenAuth\Service\Role' => 'UnicaenAuth\Service\RoleServiceFactory',
'UnicaenAuth\Service\Privilege' => 'UnicaenAuth\Service\PrivilegeServiceFactory',
'BjyAuthorize\Service\Authorize' => 'UnicaenAuth\Service\AuthorizeServiceFactory', // substituion
'zfcuser_redirect_callback' => 'UnicaenAuth\Authentication\RedirectCallbackFactory', // substituion
],
......
......@@ -67,6 +67,20 @@ $config = [
if ($settings['enable_privileges']) {
$privileges = [
'unicaen-auth' => [
/**
* Classes représentant les entités rôle et privilège.
* - Entité rôle : héritant de \UnicaenAuth\Entity\Db\AbstractRole ou implémentant \UnicaenAuth\Entity\Db\RoleInterface.
* - Entité privilège : héritant de \UnicaenAuth\Entity\Db\AbstractPrivilege ou implémentant \UnicaenAuth\Entity\Db\PrivilegeInterface.
*
* Valeurs par défaut :
* - 'role_entity_class' : 'UnicaenAuth\Entity\Db\Role'
* - 'privilege_entity_class' : 'UnicaenAuth\Entity\Db\Privilege'
*/
'role_entity_class' => 'UnicaenAuth\Entity\Db\Role',
'privilege_entity_class' => 'UnicaenAuth\Entity\Db\Privilege',
],
'bjyauthorize' => [
'resource_providers' => [
......
......@@ -9,11 +9,9 @@ use Zend\Form\Form;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
/**
* Description of DroitsController
*
*
* @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
*/
class DroitsController extends AbstractActionController
......@@ -22,19 +20,11 @@ class DroitsController extends AbstractActionController
use RoleFormAwareTrait;
use PrivilegeServiceAwareTrait;
/**
*
* @return type
*/
public function indexAction()
{
return [];
}
public function rolesAction()
{
$roles = $this->getServiceRole()->getList();
......@@ -42,8 +32,6 @@ class DroitsController extends AbstractActionController
return compact('roles');
}
public function roleEditionAction()
{
$roleId = $this->params()->fromRoute('role');
......@@ -77,8 +65,6 @@ class DroitsController extends AbstractActionController
return compact('form', 'title', 'errors');
}
public function roleSuppressionAction()
{
$roleId = $this->params()->fromRoute('role');
......@@ -99,8 +85,6 @@ class DroitsController extends AbstractActionController
return compact('role', 'title', 'form', 'errors');
}
public function privilegesAction()
{
$ps = $this->getServicePrivilege()->getList();
......@@ -121,8 +105,6 @@ class DroitsController extends AbstractActionController
return compact('privileges', 'roles');
}
public function privilegesModifierAction()
{
$roleId = $this->params()->fromPost('role');
......@@ -149,8 +131,6 @@ class DroitsController extends AbstractActionController
return $viewModel;
}
public function getFormSupprimer()
{
$form = new Form();
......
<?php
namespace UnicaenAuth\Entity\Db;
use Doctrine\Common\Collections\Collection;
use UnicaenAuth\Provider\Privilege\Privileges;
use Zend\Permissions\Acl\Resource\ResourceInterface;
use Doctrine\ORM\Mapping as ORM;
/**
* Privilege entity abstract mother class.
*
* @ORM\MappedSuperclass
*/
abstract class AbstractPrivilege implements PrivilegeInterface, ResourceInterface
{
/**
* @var int
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
* @ORM\Column(name="code", type="string", length=150, unique=false, nullable=false)
*/
protected $code;
/**
* @var string
* @ORM\Column(name="libelle", type="string", length=200, unique=false, nullable=false)
*/
protected $libelle;
/**
* @var int
* @ORM\Column(name="ordre", type="integer", unique=false, nullable=true)
*/
protected $ordre;
/**
* @var CategoriePrivilege
* @ORM\ManyToOne(targetEntity="CategoriePrivilege", inversedBy="privilege")
* @ORM\JoinColumn(name="categorie_id", referencedColumnName="id")
*/
protected $categorie;
/**
* @ORM\ManyToMany(targetEntity="UnicaenAuth\Entity\Db\Role",cascade={"all"})
* @ORM\JoinTable(
* name="role_privilege",
* joinColumns={@ORM\JoinColumn(name="privilege_id", referencedColumnName="id", onDelete="cascade")},
* inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id", onDelete="cascade")}
*
* )
*/
protected $role;
/**
* Constructor
*/
public function __construct()
{
$this->role = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Set code
*
* @param string $code
*
* @return Privilege
*/
public function setCode($code)
{
$this->code = $code;
return $this;
}
/**
* Get code
*
* @return string
*/
public function getCode()
{
return $this->code;
}
public function getFullCode()
{
return $this->getCategorie()->getCode() . '-' . $this->getCode();
}
/**
* Set libelle
*
* @param string $libelle
*
* @return Privilege
*/
public function setLibelle($libelle)
{
$this->libelle = $libelle;
return $this;
}
/**
* Get libelle
*
* @return string
*/
public function getLibelle()
{
return $this->libelle;
}
/**
*
* @return integer
*/
function getOrdre()
{
return $this->ordre;
}
/**
*
* @param integer $ordre
*
* @return self
*/
function setOrdre($ordre)
{
$this->ordre = $ordre;
return $this;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set categorie
*
* @param CategoriePrivilege $categorie
*
* @return self
*/
public function setCategorie(CategoriePrivilege $categorie = null)
{
$this->categorie = $categorie;
return $this;
}
/**
* Get categorie
*
* @return CategoriePrivilege
*/
public function getCategorie()
{
return $this->categorie;
}
/**
* Add role
*
* @param RoleInterface $role
*
* @return self
*/
public function addRole(RoleInterface $role)
{
$this->role->add($role);
return $this;
}
/**
* Remove role
*
* @param RoleInterface $role
*/
public function removeRole(RoleInterface $role)
{
$this->role->removeElement($role);
}
/**
* Get role
*
* @return Collection
*/
public function getRole()
{
return $this->role;
}
/**
* @return string
*/
public function __toString()
{
return $this->getLibelle();
}
/**
* @return string
*/
public function getResourceId()
{
return Privileges::getResourceId($this);
}
}
\ No newline at end of file
......@@ -2,7 +2,6 @@
namespace UnicaenAuth\Entity\Db;
use BjyAuthorize\Acl\HierarchicalRoleInterface;
use Doctrine\ORM\Mapping as ORM;
/**
......@@ -10,7 +9,7 @@ use Doctrine\ORM\Mapping as ORM;
*
* @ORM\MappedSuperclass
*/
abstract class AbstractRole implements HierarchicalRoleInterface
abstract class AbstractRole implements RoleInterface
{
/**
* @var int
......@@ -54,8 +53,6 @@ abstract class AbstractRole implements HierarchicalRoleInterface
*/
protected $users;
/**
* Get the id.
*
......@@ -66,8 +63,6 @@ abstract class AbstractRole implements HierarchicalRoleInterface
return $this->id;
}
/**
* Set the id.
*
......@@ -82,8 +77,6 @@ abstract class AbstractRole implements HierarchicalRoleInterface
return $this;
}
/**
* Get the role id.
*
......@@ -94,8 +87,6 @@ abstract class AbstractRole implements HierarchicalRoleInterface
return $this->roleId;
}
/**
* Set the role id.
*
......@@ -110,8 +101,6 @@ abstract class AbstractRole implements HierarchicalRoleInterface
return $this;
}
/**
* Is this role the default one ?
*
......@@ -122,8 +111,6 @@ abstract class AbstractRole implements HierarchicalRoleInterface
return $this->isDefault;
}
/**
* Set this role as the default one.
*
......@@ -138,8 +125,6 @@ abstract class AbstractRole implements HierarchicalRoleInterface
return $this;
}
/**
* Get the parent role
*
......@@ -150,24 +135,20 @@ abstract class AbstractRole implements HierarchicalRoleInterface
return $this->parent;
}
/**
* Set the parent role.
*
* @param Role $role
* @param RoleInterface $parent
*
* @return self
*/
public function setParent(Role $parent)
public function setParent(RoleInterface $parent = null)
{
$this->parent = $parent;
return $this;
}
/**
* @return string
*/
......@@ -176,8 +157,6 @@ abstract class AbstractRole implements HierarchicalRoleInterface
return $this->ldapFilter;
}
/**
* @param string $ldapFilter
*
......@@ -190,8 +169,6 @@ abstract class AbstractRole implements HierarchicalRoleInterface
return $this;
}
/**
* Get users.
*
......@@ -202,22 +179,18 @@ abstract class AbstractRole implements HierarchicalRoleInterface
return $this->users->getValues();
}
/**
* Add a user to the role.
*
* @param User $user
* @param UserInterface $user
*
* @return void
*/
public function addUser($user)
public function addUser(UserInterface $user)
{
$this->users[] = $user;
}
/**
*
* @return string
......
<?php
namespace UnicaenAuth\Entity\Db;
use BjyAuthorize\Provider\Role\ProviderInterface;
......@@ -205,7 +205,7 @@ abstract class AbstractUser implements UserInterface, ProviderInterface
/**
* Get role.
*
* @return Collection
* @return RoleInterface[]
*/
public function getRoles()
{
......@@ -215,17 +215,17 @@ abstract class AbstractUser implements UserInterface, ProviderInterface
/**
* Add a role to the user.
*
* @param Role $role
* @param RoleInterface $role
*
* @return void
*/
public function addRole(Role $role)
public function addRole(RoleInterface $role)
{
$this->roles->add($role);
}
/**
*
*
* @return string
*/
public function __toString()
......
......@@ -2,6 +2,7 @@
namespace UnicaenAuth\Entity\Db;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
......@@ -43,18 +44,14 @@ class CategoriePrivilege
*/
private $privilege;
/**
* Constructor
*/
public function __construct()
{
$this->privilege = new \Doctrine\Common\Collections\ArrayCollection();
$this->privilege = new ArrayCollection();
}
/**
* Set code
*
......@@ -69,8 +66,6 @@ class CategoriePrivilege
return $this;
}
/**
* Get code
*
......@@ -81,8 +76,6 @@ class CategoriePrivilege
return $this->code;
}
/**
* Set libelle
*
......@@ -97,8 +90,6 @@ class CategoriePrivilege
return $this;
}
/**
* Get libelle
*
......@@ -109,8 +100,6 @@ class CategoriePrivilege
return $this->libelle;
}
/**
*
* @return integer
......@@ -120,8 +109,6 @@ class CategoriePrivilege
return $this->ordre;
}
/**
*
* @param integer $ordre
......@@ -135,8 +122,6 @@ class CategoriePrivilege
return $this;
}
/**
* Get id
*
......@@ -147,8 +132,6 @@ class CategoriePrivilege
return $this->id;
}
/**
* Add privilege
*
......@@ -163,8 +146,6 @@ class CategoriePrivilege
return $this;
}
/**
* Remove privilege
*
......@@ -175,8 +156,6 @@ class CategoriePrivilege
$this->privilege->removeElement($privilege);
}
/**
* Get privilege
*
......@@ -187,8 +166,6 @@ class CategoriePrivilege
return $this->privilege;
}
/**
* @return string
*/
......@@ -196,4 +173,4 @@ class CategoriePrivilege
{
return $this->getLibelle();
}
}
}
\ No newline at end of file
......@@ -2,8 +2,6 @@
namespace UnicaenAuth\Entity\Db;
use UnicaenAuth\Provider\Privilege\Privileges;
use Zend\Permissions\Acl\Resource\ResourceInterface;
use Doctrine\ORM\Mapping as ORM;
/**
......@@ -11,248 +9,7 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Entity
* @ORM\Table(name="privilege")
*/
class Privilege implements ResourceInterface
class Privilege extends AbstractPrivilege
{
/**