LdapAuth在cakephp 2.0 [英] LdapAuth in cakephp 2.0
问题描述
我需要在/ app / Controller /
中配置$ components Component / AppController.php
<?php
类AppController extends Controller {
var $ components = array('Auth'=> array(
'Ldap',
'authError'=>'不允许在这里',
'authenticate'=& > array(
'fields'=> array(
'username'=>'username',
'password'=>'password',
'domain '=>'domain'
)
)
),
'authorize'=> true,
),'Session');
}
?>
然后我创建一个LdapAuthorize.php,如
http://book.cakephp.org/2.0/en/core- libraries / components / authentication.html#creating-custom-authorize-objects
<?php
App :: uses('BaseAuthorize','Controller / Component / Auth');
class LdapAuthorize extends BaseAuthorize {
public function authorize($ user,CakeRequest $ request){
echotest;
}
}
?>
但是当我尝试使用
登录时 if($ this-> Auth-> login()){
return $ this-> redirect($ this-> Auth-> redirect );
} else {
$ this-> Session-> setFlash(__('Username或password'incorrect'),
'default',array(),'auth');
}
cakephp不使用授权功能。
我做错了什么?请帮助。
这是一个工作的2.0d的Ldap身份验证类
https://github.com/analogrithems/idbroker/tree/dev_cake2.0
/www.analogrithems.com/rant/2012/01/03/cakephp-2-0-ldapauth/rel =nofollow> http://www.analogrithems.com/rant/2012/01/03/cakephp- 2-0-ldapauth /
** ALSO **
您的验证配置错误 - authorize键接受一个字符串或数组 - 一个布尔值true不会做任何事情。
如果你想要检查控制器中的isAuthorized动作 - set它像这样:
<?php
...
public $ components = array Auth'=> array(
...
'authorize'=> array('Controller'),
...
));
?>
这里传递一个布尔参数,并且在AppController中没有isAuthorized函数。此外,您使用旧的php4语法声明您的成员变量(使用public,protected或private而不是var)
i try to program a LdapAuthentication and i need some help.
First i need to configure the "$components" in /app/Controller/ Component/AppController.php
<?php
class AppController extends Controller {
var $components = array('Auth' => array(
'Ldap',
'authError' => 'Not allowed here',
'authenticate' => array('Form' => array(
'fields' => array(
'username' => 'username',
'password' => 'password',
'domain' => 'domain'
)
)
),
'authorize' => true,
), 'Session');
}
?>
Then i create a LdapAuthorize.php like http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#creating-custom-authorize-objects
<?php
App::uses('BaseAuthorize', 'Controller/Component/Auth');
class LdapAuthorize extends BaseAuthorize {
public function authorize($user, CakeRequest $request) {
echo "test";
}
}
?>
But when i try to login with
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash(__('Username or password is incorrect'),
'default', array(), 'auth');
}
cakephp doesn't use my authorize function.
What i do wrong? Please help.
Here is a working Ldap Auth class for 2.0.x
https://github.com/analogrithems/idbroker/tree/dev_cake2.0
with a blog post detailing it here:
http://www.analogrithems.com/rant/2012/01/03/cakephp-2-0-ldapauth/
** ALSO **
Your Auth configuration is wrong - the authorize key takes a string or array - a boolean true isn't going to do anything.
If you want it to check an isAuthorized action in the controller - set it like so:
<?php
...
public $components = array( 'Auth' => array(
...
'authorize' => array( 'Controller' ),
...
));
?>
You are passing a boolean parameter here, and have no isAuthorized function in your AppController. Also, you are using old php4 syntax to declare your member variables (use public, protected or private instead of "var")
这篇关于LdapAuth在cakephp 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!