cakepphp 2.3:通过自定义BaseAuthenticate进行身份验证
我编写了一个类AlephBaseAuthenticate,用于扩展BaseAuthenticate,该类工作正常:cakepphp 2.3:通过自定义BaseAuthenticate进行身份验证,php,cakephp,authentication,Php,Cakephp,Authentication,我编写了一个类AlephBaseAuthenticate,用于扩展BaseAuthenticate,该类工作正常: <?php // Authentication against Aleph X-Service // user and password for x-service see aleph.ini App::uses('BaseAuthenticate', 'Controller/Component/Auth'); App::uses('IniReader', 'Co
<?php
// Authentication against Aleph X-Service
// user and password for x-service see aleph.ini
App::uses('BaseAuthenticate', 'Controller/Component/Auth');
App::uses('IniReader', 'Configure');
Configure::config('default', new IniReader());
class AlephAuthenticate extends BaseAuthenticate {
public function authenticate(CakeRequest $request, CakeResponse $response) {
// Do things for Aleph here.
// Return an array of user + group-id if they could authenticate the user,
// return false if not
// verification = empty works, so we have to check lenght of verification!
$configfile = Configure::read('configfile');
Configure::load($configfile, 'default');
$alephxurl = Configure::read('aleph.xurl');
$xlib = Configure::read('aleph.xlib');
$username = $request->data['Users']['username'];
$password = $request->data['Users']['password'];
$req = $alephxurl . 'library=' . $xlib . '&verification=' . $password . '&op=bor_info&bor_id=' . $username;
$userxml = file_get_contents($req);
$xml = simplexml_load_string($userxml);
$error = $xml->error;
if($error == 'Error retrieving Patron System Key' || strlen($password) == 0){
return FALSE;
} else {
$data['username'] = $xml->z303->{'z303-name'};
$data['group'] = $xml->z303->{'z303-profile-id'};
$data['id'] = $xml->z303->{'z303-id'};
return $data;
}
}
}
问题是:只有在UsersController.php中,操作“login”,我才能访问此->身份验证->用户('id'),并且,$this->身份验证->允许('index','login','logout')根本不起作用。登录后,通过“您无权访问该位置”访问每个操作。看来身份验证根本不起作用
你知道这是怎么回事吗
谢谢
Christoph当我返回$data时,我收到错误消息“注意(8):session_start():序列化数据[CORE/Cake/Model/Datasource/CakeSession.php,第661行]意外结束”。克里斯托菲解决了这个问题。$xml中的值必须通过(字符串)进行转换:(字符串)$xml->z303->{'z303-name'};
public $components = array(
'Session',
'Auth' => array(
'authenticate' => array(
'Aleph'
)
)
);
function beforeFilter(){
$this->Auth->allow('index', 'login', 'logout');
}