LdapAuth in cakephp 2.0

不想你离开。 提交于 2019-12-12 17:06:25

问题


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.


回答1:


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")



来源:https://stackoverflow.com/questions/9903787/ldapauth-in-cakephp-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!