2011年1月21日星期五

Re: [fw-mvc] Re: ACL stuck in a loop

-- Nathan Garlington <garlinto@gmail.com> wrote
(on Friday, 21 January 2011, 02:24 PM -0700):
> Alright, got it figured out! I thought that resetting the controller name
> and action name in the request object, and then setting isDispatched(false)
> caused the dispatcher to dispatch the request to the new controller and
> action. But such is not the case, at least not in the way I have implemented
> it above.
>
> What is the "proper" ZF way to go about handling a case where the user does
> not have access to the resource? I solved the problem using the Redirector
> action helper. Would this be using the redirector in line with it's intent,
> or is there another way using the methods exposed to the Controller Plugin
> itself?

I typically define a special exception, such as
"UnauthorizedAccessException", and throw that. In my ErrorController's
errorAction(), I add an additional case statement:

case ($errors->exception instanceof UnauthorizedAccessException):
$this->getResponse()->setHttpResponseCode(401);
$this->view->message = 'You do not have rights to perform this action.';
break;

This way, I don't need to do redirects, nor do I need to provide
additional logic in my actions if the user doesn't have permissions -- I
simply throw the exception, and know that the error controller will
notify them.


> On Fri, Jan 21, 2011 at 9:43 AM, Nathan Garlington <garlinto@gmail.com>wrote:
>
> > Thanks for the quick replies! Kevin, I would love to run Zend Server but
> > I'm running a this code on a production server, and don't have a test
> > machine atm. :(
> >
> > tendor wrote:
> > >Try this
> > >
> > >ACL Class:
> > > $this->add(new Zend_Acl_Resource('default'))
> > > ->add(new Zend_Acl_Resource('default:index'), 'default')
> > > ->add(new Zend_Acl_Resource('default:error'), 'default')
> > > ->add(new Zend_Acl_Resource('default:user'), 'default');
> > >
> >
> > So you think the problem may lie in the way the module is specified? I
> > guess I'll give that a try...
> >
> > --regards,
> > nathan
> >
> >
> >
> > On Fri, Jan 21, 2011 at 9:27 AM, tendor <marjarosz@gmail.com> wrote:
> >
> >>
> >> Try this
> >>
> >> ACL Class:
> >> $this->add(new Zend_Acl_Resource('default'))
> >> ->add(new Zend_Acl_Resource('default:index'), 'default')
> >> ->add(new Zend_Acl_Resource('default:error'), 'default')
> >> ->add(new Zend_Acl_Resource('default:user'), 'default');
> >>
> >> $this->allow('guest', 'default:error');
> >> $this->allow('guest', 'default:index', array('some action', '
> >> some
> >> action'));
> >> $this->allow('guest', 'default:user');
> >>
> >> Using simple:
> >>
> >> if(!$this->_acl->isAllowed(Zend_Registry::get('role'),
> >> $module.':'.$resource, $action)){
> >> $request->setControllerName('index')
> >> ->setActionName('login');
> >> }
> >> --
> >> View this message in context:
> >> http://zend-framework-community.634137.n4.nabble.com/ACL-stuck-in-a-loop-tp3230017p3230042.html
> >> Sent from the Zend MVC mailing list archive at Nabble.com.
> >>
> >
> >

--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

没有评论: