Cakephp 3.X et Authentification CAS
Bonjour à tous.
Sur cakephp 3.0, j'essaie d'intégrer l'authentification CAS. Malheureusement j'obtiens l'erreur suivante :
Code:
1 2 3
| Error: Call to a member function checkAuthenticate() on boolean
File C:\xampp\htdocs\synchro-mdp\src\Controller\AppController.php
Line: 69 |
Etant nouveau sur cakephp, je ne sais pas trop quoi faire.
Tout d'abord, j'ai installé la librairie phpCAS
Voici l'architecture du projet :
Code:
1 2 3 4 5 6 7 8 9 10 11
|
-- mon-projet
-- vendor
-- CAS
-- src
-- CAS.php et son dossier (Librairie phpCAS)
-- plugins
-- AuthCas
-- src
-- Auth
-- CasAuthenticate.php (Mon authentification) |
Maintenant voici le contenu des fichiers :
CasAuthenticate.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
<?php
namespace AuthCas\Auth;
use Cake\Auth\BaseAuthenticate;
use Cake\Core\Configure;
require_once ROOT . DS . 'vendor' . DS . 'CAS' . DS . 'src' . DS . 'CAS.php';
class CasAuthenticate extends BaseAuthenticate
{
private $_userId = NULL;
public function authenticate(Request $request, Response $response)
{
phpCAS::forceAuthentication();
return array('username' => phpCAS::getUser());
}
public function checkAuthenticate()
{
// debugging
phpCAS::setDebug();
// initialize phpCAS
phpCAS::client(CAS_VERSION_2_0,
Configure::read('CAS.hostname'),
Configure::read('CAS.port'),
Configure::read('CAS.uri'));
// no SSL validation for the CAS server
phpCAS::setNoCasServerValidation();
if(phpCAS::checkAuthentication())
{
$this->_userId = phpCAS::getUser();
return true;
}
return false;
} |
Dans bootstrap.php, j'ai rajouté les lignes suivantes :
Code:
1 2 3 4 5 6 7 8 9 10
|
Plugin::load('AuthCas');
/**
* CAS config
*/
Configure::write('CAS.hostname', 'cas.insa-cvl.fr');
Configure::write('CAS.port', 443);
Configure::write('CAS.uri', '/');
Configure::write('CAS.cert_path', '');
Configure::write('CAS.debug_log_enabled', FALSE); |
Et enfin dans AppController.php :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
<?php
namespace App\Controller;
use Cake\Controller\Controller;
use Cake\Event\Event;
use AuthCas\Auth;
class AppController extends Controller
{
/**
* Initialization hook method.
*
* Use this method to add common initialization code like loading components.
*
* @return void
*/
public function initialize()
{
parent::initialize();
$this->loadComponent('Flash');
$this->loadComponent('Auth', [
'loginRedirect' => [
'controller' => 'Articles',
'action' => 'index'
],
'logoutRedirect' => [
'controller' => 'Pages',
'action' => 'display',
'home'
]
]);
}
public function beforeFilter(Event $event)
{
// $this->Auth->allow(['index', 'view', 'display']);
$this->Auth->config('authenticate', [
'Cas' => [userModel => 'Members'],
'Form',
]);
$session = $this->request->session();
// vérification de la connexion
if(!$session->check('User.id'))
{
if($this->Cas->checkAuthenticate())
{
}
// sinon on redirige vers la page de connexion pour utilisateurs locaux
elseif($this->name != 'users' && $this->action != 'log_in')
{
$this->redirect(array('controller' => 'users', 'action' => 'log_in'));
exit();
}
}
else
{
// id de l'utilisateur
$this->user_id = $session->read('User.id');
}
}
} |
Si besoin je peux transmettre l'intégralité du code, j'ai seulement sélectionner les parties qui me semblait importante.
Je suis preneur pour toute information, merci d'avance.
Peruvio