+ Reply to Thread
Results 1 to 7 of 7

Thread: Zend Auth [1.8] With Bootstrap

  1. #1
    anticucho is offline Junior Member
    Join Date
    May 2009
    Posts
    4

    Default Zend Auth [1.8] With Bootstrap

    I've read through the quick start and documentation but I'm having a tough time figuring out where the best place would be to place the verification code (hasIdentity) in the new boot strap framework. For example, in my "Bootstrap extends Zend_Application_Bootstrap_Bootstrap" class I was thinking of adding a protected method "_initAuth". But I'm struggling to figure out if this is the best place to check authorization for is it still having a BaseController:reDispatch method as I had before.

    Basically, assuming I am using Zend_Auth and I want to protect my entire application, where now is the best place to put the validation code, and how best to redirect the user back to the login page? Any simple example code would be much appreciated. Thanks!

  2. #2
    cjp
    cjp is offline Junior Member
    Join Date
    May 2009
    Posts
    1

    Default bump

    I'm wondering much the same thing so would like to repeat the request for some opinions on this.

  3. #3
    whisher is offline Member
    Join Date
    May 2009
    Location
    Kakiland
    Posts
    32

    Default

    Quote Originally Posted by anticucho View Post
    I've read through the quick start and documentation but I'm having a tough time figuring out where the best place would be to place the verification code (hasIdentity) in the new boot strap framework. For example, in my "Bootstrap extends Zend_Application_Bootstrap_Bootstrap" class I was thinking of adding a protected method "_initAuth". But I'm struggling to figure out if this is the best place to check authorization for is it still having a BaseController:reDispatch method as I had before.

    Basically, assuming I am using Zend_Auth and I want to protect my entire application, where now is the best place to put the validation code, and how best to redirect the user back to the login page? Any simple example code would be much appreciated. Thanks!
    Hi.
    This tutorial
    http://akrabat.com/wp-content/upload...d-auth_108.pdf
    set up the mehod preDispatch in the
    indexController
    [PHP]
    function preDispatch()
    {
    $auth = Zend_Auth::getInstance();
    if (!$auth->hasIdentity()) {
    $this->_redirect('auth/login');
    }
    }
    [/PHP]

    but I figure out you should set up
    it in all your controller
    so it'd be far better if you could
    set up it in Zend_Application_Bootstrap_Bootstrap.
    I tried with _initAuth and it seems to work fine
    I'm also new at zf so I form a queue .

    Bye.

  4. #4
    Rhino's Avatar
    Rhino is offline Senior Member
    Join Date
    Feb 2009
    Location
    Lost Angeles, CA
    Posts
    105

    Default

    I would recommend putting your access control into a plugin so that it's decoupled from the rest of your logic, otherwise you are asking for a world of hurt as your application grows and roles are added / changed due to business requirements.

    A good starting point is outlined in this tutorial: Zend_Acl / Zend_Auth Example Scenario . The logic outlined here should get you going but you will probably have to change a few things to make it compatible with 1.8.

  5. #5
    whisher is offline Member
    Join Date
    May 2009
    Location
    Kakiland
    Posts
    32

    Default

    I'm taking a look at your useful link
    and just playing around with it so ....
    It's right to set up the plugin
    in the bootstrap in this way

    [PHP]
    protected function _initAcl()
    {
    $front = Zend_Controller_Front::getInstance();
    $plugIn = new Plugin_Acl(new Zend_Acl());
    $front->registerPlugin($plugIn);
    }
    [/PHP]
    Last edited by whisher; 05-31-2009 at 11:20 AM.

  6. #6
    whisher is offline Member
    Join Date
    May 2009
    Location
    Kakiland
    Posts
    32

  7. #7
    whisher is offline Member
    Join Date
    May 2009
    Location
    Kakiland
    Posts
    32

    Default

    Quote Originally Posted by whisher View Post
    [PHP]
    protected function _initAcl()
    {
    $front = Zend_Controller_Front::getInstance();
    $plugIn = new Plugin_Acl(new Zend_Acl());
    $front->registerPlugin($plugIn);
    }
    [/PHP]
    It's far better to get the
    frontcontroller in this way:

    [PHP]
    $this->bootstrap('frontController');
    $front = $this->getResource('frontController');
    [/PHP]

+ Reply to Thread

Similar Threads

  1. zend auth help
    By Aero in forum General Q&A on Zend Framework
    Replies: 1
    Last Post: 03-03-2010, 04:18 PM
  2. Reload Zend Auth Identity?
    By jonno in forum Authentication & Authorization
    Replies: 4
    Last Post: 10-27-2009, 10:13 AM
  3. Zend auth username same not login !
    By stvlinux in forum Authentication & Authorization
    Replies: 0
    Last Post: 01-22-2009, 02:06 PM
  4. Getting a Session set by Zend Auth
    By madmaxious in forum Authentication & Authorization
    Replies: 3
    Last Post: 05-28-2008, 09:18 AM
  5. how to set timeout in zend Auth
    By cc96ai in forum Authentication & Authorization
    Replies: 2
    Last Post: 04-25-2008, 04:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts