Skip to content

Same identity from different namespaces #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
PavelWeirich opened this issue May 27, 2020 · 3 comments
Closed

Same identity from different namespaces #46

PavelWeirich opened this issue May 27, 2020 · 3 comments

Comments

@PavelWeirich
Copy link
Contributor

In version 3.03 (https://github.com/nette/security/releases/tag/v3.0.3) the identity and authenticated state are cached.
But it makes problem if you want to switch between namespaces.

For example in FrontModule\BasePresenter.php:
public function startup()
{
parent::startup();

$this->getUser()->getStorage()->setNamespace('admin');
$id = $this->getUser()->getId();

$this->getUser()->getStorage()->setNamespace('front');
$id = $this->getUser()->getId();

}

It always return ID from "admin" namespace.

@PavelWeirich PavelWeirich changed the title Same identity for different namespaces Same identity from different namespaces May 27, 2020
@dg
Copy link
Member

dg commented May 29, 2020

What about to add method User::refresh() to clear cache?

@PavelWeirich
Copy link
Contributor Author

PavelWeirich commented May 29, 2020

Yes it can be. But User::refresh() should run automatically when setNamespace() is called.

@PavelWeirich
Copy link
Contributor Author

PavelWeirich commented May 29, 2020

Or refactor
private $identity = false;
to
private $identity = [];

The same refactor for: private $authenticated = [];

Sample of method getIdentity():

final public function getIdentity(): ?IIdentity
{
    if (!array_key_exists($this->storage->getNamespace(), $this->identity)) {
        $this->identity[$this->storage->getNamespace()] = $this->storage->getIdentity();
    }
    return $this->identity[$this->storage->getNamespace()];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants