returning after calling Zend_Acl's isAllowed

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

returning after calling Zend_Acl's isAllowed

jordi
when I call Zend_Acl's isAllowed(..) method with a role, resource, or privilege that is not specified I would say it would return false, but that does not seem to happen. It does not seem to return at all, or am I doing something wrong?

my code:

echo 'one';
if(!$this->_acl->isAllowed('blabla' ,'auth', 'login')){
     echo 'two';
     $request->setControllerName('authentication')->setActionName('unauthorized');
}
echo 'three';

// one is shown, two and three not
Reply | Threaded
Open this post in threaded view
|

Re: returning after calling Zend_Acl's isAllowed

Christian Proske
hi,

do u have error reporting turned on?

Try:

error_reporting(E_ALL);
ini_set('display_errors','On');

before my code;

ciao

Am 18.02.2011 um 21:01 schrieb jordi:

>
> when I call Zend_Acl's isAllowed(..) method with a role, resource, or
> privilege that is not specified I would say it would return false, but that
> does not seem to happen. It does not seem to return at all, or am I doing
> something wrong?
>
> my code:
>
> echo 'one';
> if(!$this->_acl->isAllowed('blabla' ,'auth', 'login')){
>     echo 'two';
>
> $request->setControllerName('authentication')->setActionName('unauthorized');
> }
> echo 'three';
>
> // one is shown, two and three not
>
> --
> View this message in context: http://zend-framework-community.634137.n4.nabble.com/returning-after-calling-Zend-Acl-s-isAllowed-tp3313453p3313453.html
> Sent from the Zend Auth mailing list archive at Nabble.com.
>

Reply | Threaded
Open this post in threaded view
|

Re: returning after calling Zend_Acl's isAllowed

Jurian Sluiman-4
In reply to this post by jordi
On Friday 18 Feb 2011 21:01:54 jordi wrote:

> when I call Zend_Acl's isAllowed(..) method with a role, resource, or
> privilege that is not specified I would say it would return false, but that
> does not seem to happen. It does not seem to return at all, or am I doing
> something wrong?
>
> my code:
>
> echo 'one';
> if(!$this->_acl->isAllowed('blabla' ,'auth', 'login')){
>      echo 'two';
>
> $request->setControllerName('authentication')->setActionName('unauthorized'
> ); }
> echo 'three';
>
> // one is shown, two and three not

Afaik throws Zend_Acl an exception when you're trying to get allowance for a
role and/or resource that is not set. The proper flag whether you can continue
is this:

($acl->hasRole($role) && $acl->has($resource) && $acl->isAllowed($role,
$resource, $permission))

The combined check of role, resource and isAllowed gives the final true/false.

In this case you got an exception and probably saw nothing because you do not
catch this exception properly.

Regards, Jurian
--
Jurian Sluiman
Soflomo - http://soflomo.com
Reply | Threaded
Open this post in threaded view
|

Re: returning after calling Zend_Acl's isAllowed

jordi
Thank you both for these answers!
I indeed didn't turn on errors (which i now did in config.ini)
And i also did'nt caught the exception, which i now solved.

So : problem solved

Would you people advise to always deal with every possible exception in Zend, this is often not done in the tutorials?

Ow and btw: i am a beginner zend programmer, but have Qt(C++) en Java experience.
Reply | Threaded
Open this post in threaded view
|

Re: returning after calling Zend_Acl's isAllowed

Jurian Sluiman-4
On Saturday 19 Feb 2011 11:46:55 jordi wrote:

> Thank you both for these answers!
> I indeed didn't turn on errors (which i now did in config.ini)
> And i also did'nt caught the exception, which i now solved.
>
> So : problem solved
>
> Would you people advise to always deal with every possible exception in
> Zend, this is often not done in the tutorials?
>
> Ow and btw: i am a beginner zend programmer, but have Qt(C++) en Java
> experience.

If you use a Zend_Application instance, you automatically wrap all dispatch
calls and its hooks inside a try/catch. Every exception is then forwarded to
the errorController to display a user friendly error message.

Only if you use the Zend_Acl component as standalone, you need to take care of
the exceptions yourself.

Regards, Jurian
--
Jurian Sluiman
Soflomo - http://soflomo.com