0

I have a class representing my identity that contains a few pieces of information. Here is the short version.

class Auth_User {

    private $id;
    private $current_role;

    public function __construct($id, $current_role) {
        $this->id = (int) $id;
        $this->current_role = (string) $current_role;
    }

    public function __wakeup() {
        if ( /*$current_role is not valid*/ ) {
            /*clear identity and redirect to login*/
        {
    }
}

My question how can I safely clear the identity and redirect to login in the wakeup method? If I do the following it seems to run in a infinite loop.

Zend_Auth::getInstance()->clearIdentity();
$this->_helper->redirector('index', 'index');
Jeremiah
  • 751
  • 9
  • 21
  • Well it should do the trick, could you provide a little more detail so that some one could give you a better solution. – ro ko Apr 05 '12 at 17:05
  • I think the issue is when I call Zend_Auth::getInsance()->clearIdentity(); its calling the __wakeup function again over and over. So its infinite recursion. – Jeremiah Apr 06 '12 at 12:19

1 Answers1

0

the fact that you have a __wakeup() method implies that you have a __sleep() method.

What I would probably look at doing in this situation, would be to set an expiration on Zend_Session_Namespace('Zend_Auth') in the __sleep() method.

Then test for __isset() against the namespace in the __wakeup() method. I think this approach might work.

If you just want to clear the identity at __sleep() that might be a good idea as well and then just redirect to login() on __wakeup().

Hope I'm not totally in left field...

RockyFord
  • 8,529
  • 1
  • 15
  • 21