From 2d768feb0e9eca3b6c4b3973caccbccaa407c0ac Mon Sep 17 00:00:00 2001 From: HETRU Mathieu Date: Fri, 27 Jul 2018 13:46:13 +0200 Subject: [PATCH] modif --- Entity/UidUser.php | 4 ++-- README.md | 32 +++++++++++++++++++++++++++----- Services/UidUserProvider.php | 10 ++++++++-- composer.json | 6 +++--- 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/Entity/UidUser.php b/Entity/UidUser.php index b2370e4..addc1d5 100644 --- a/Entity/UidUser.php +++ b/Entity/UidUser.php @@ -11,8 +11,8 @@ class UidUser implements UserInterface { protected $uid; private $roles = array(); - public function updateRoles() { - $this->roles = array('ROLE_USER'); + public function updateRoles(array $rolesConfig = array()) { + $this->roles = $rolesConfig; return; } diff --git a/README.md b/README.md index 697d8d0..071a66f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ User Provider for CAS -Allow use only UID for application Symfony2 +Allow use only UID (returned by CasBundle) for application Symfony2, Symfony3 and Symfony4 +(uid is the id user returned by jasig cas sso server and by the l3-team/CasBundle (repository github) or l3/cas-bundle (repository packagist)) Installation of the Bundle --- @@ -8,7 +9,9 @@ Simple add this line in the require in your composer.json : ``` "l3/uid-user-bundle": "~1.0" ``` -Launch the command **composer update** to install the package and add the Bundle in the AppKernel.php file. +Launch the command **composer update** to install the package. + +For Symfony 2 and 3 : add the Bundle in the AppKernel.php file. ``` ['all' => true], +... +``` + Configuration of the bundle --- -In the firewall of your application, use the Bundle : + +For Symfony 2 and 3 : in the firewall of your application, use the Bundle : ``` # app/config/security.yml security: providers: - ldap: - id: uid_user_provider + uid: + id: uid_user_provider +``` + +For Symfony 4 : in the firewall of your application, use the Bundle : +``` +# config/packages/security.yaml +security: + providers: + uid: + id: uid_user_provider ``` diff --git a/Services/UidUserProvider.php b/Services/UidUserProvider.php index 99c596d..2bf10ea 100644 --- a/Services/UidUserProvider.php +++ b/Services/UidUserProvider.php @@ -11,9 +11,15 @@ class UidUserProvider implements UserProviderInterface { public function __construct() {} public function loadUserByUsername($username) { - $user = $user = new UidUser(); + $user = new UidUser(); $user->setUid($username); - $user->updateRoles(); + $roles = Array(); + if ($username === '__NO_USER__') { + $roles = array('ROLE_ANON'); + } else { + $roles = array('ROLE_ANON', 'ROLE_USER'); + } + $user->updateRoles($roles); return $user; } diff --git a/composer.json b/composer.json index 913dd9e..52deeb1 100644 --- a/composer.json +++ b/composer.json @@ -2,12 +2,12 @@ "name": "l3/uid-user-bundle", "type": "symfony-bundle", "description": "User Provider for CAS (return only the UID)", - "homepage": "https://github.com/mhetru/UidUserBundle", - "license": "(c) Copyright Universite Lille3 - Charles de Gaulle", + "homepage": "https://github.com/l3-team/UidUserBundle", + "license": "LGPL-3.0-or-later", "authors": [ { "name": "Mathieu Hétru", - "email": "mathieu.hetru@univ-lille3.fr" + "email": "mathieu.hetru@univ-lille.fr" } ], "require": {