Skip to content
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

EZP-24852: Add UserReference support in Authentication/User providers #1965

Merged
merged 6 commits into from
May 8, 2017

Conversation

andrerom
Copy link
Contributor

@andrerom andrerom commented Apr 21, 2017

JIRA: https://jira.ez.no/browse/EZP-24852

As we anyway always refresh APIUser on load, this changes our symfony User to not serialize APIUser to session anymore to reduce size of session being serialized back and forth.

On top of that make sure WrappedUser does not get self or User injected to avoid possibility of wrong use and bloated session value.

@andrerom andrerom force-pushed the sfuser_improvments branch 4 times, most recently from dd6a6d9 to 531c958 Compare April 24, 2017 15:37
…f or User

To protect against injecting api user several times bloating session value.
@andrerom andrerom force-pushed the sfuser_improvments branch 3 times, most recently from 081f5e5 to b5c3fe3 Compare April 27, 2017 20:33
@andrerom andrerom changed the title [WIP] EZP-24852: Add UserReference support in Authentication/User providers EZP-24852: Add UserReference support in Authentication/User providers Apr 27, 2017
@andrerom andrerom force-pushed the sfuser_improvments branch from c7ea670 to 5e83ce9 Compare April 27, 2017 20:52
@andrerom andrerom requested review from bdunogier and glye April 27, 2017 20:53
@andrerom
Copy link
Contributor Author

andrerom commented Apr 27, 2017

Review ping @lolautruche

NOTE: I assumed we kind of need to continue load users on load to make sure user is still existing and enabled (however not needed for permission checks), so only made sure user is no longer serialized to and from session, but that assumption might be wrong.

Copy link
Contributor

@lolautruche lolautruche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the UserReference class, is it already present somewhere?

I assumed we kind of need to continue load users on load to make sure user is still existing and enabled

This is indeed needed when user is refreshed from the session. It's not specific to eZ, but needed from the Security component

if (!$this->user instanceof APIUser) {
throw new \LogicException(
'Attempts to get APIUser before it has been set by UserProvider, APIUser is not serialized to session'
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exception needs to be documented in the phpdoc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re added in d6a6803

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth using an exception of our own ?

Copy link
Contributor Author

@andrerom andrerom May 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, maybe, however unsure what that should be and what it should extend, and it's not a condition that should happen for end users given provider deals with loading it before you typically get your hands on it.

As we always refresh APIUser on load anyway, changes our symfony User
to not serialize APIUser to session to reduce size of session being
serialized back and forth.

This approch assumed the refresh is needed for security reasons *(as in
check if user is still exists and is enabled, permissions lookup don't
need this)*. However if that is not the case this can be done closer
to how it is described in JIRA issue and aim to deprecate this logic instead.
Not a must, but test where failing since MVC User was calling method and this part of the code property.
@andrerom
Copy link
Contributor Author

andrerom commented Apr 28, 2017

but needed from the Security component

Maybe, this doc on UserProviderInterface::refreshUser() made it a bit unclear, and made it sound it depends on our domain needs:

     * It is up to the implementation to decide if the user data should be
     * totally reloaded (e.g. from the database), or if the UserInterface
     * object can just be merged into some internal array of users / identity
     * map.

I don't see the UserReference class, is it already present somewhere?

Depends on what you mean, you have:

Then in this PR there is ReferenceUserInterface which is implemented by eZ\Publish\Core\MVC\Symfony\Security\User.

@andrerom andrerom force-pushed the sfuser_improvments branch from 5e83ce9 to 1f50078 Compare April 28, 2017 09:16
@lolautruche
Copy link
Contributor

Maybe, this doc on UserProviderInterface::refreshUser() made it a bit unclear, and made it sound it depends on our domain needs

It indeed depends on our domain needs, but this is highly recommended and done in every implementation provided by Symfony. Only exception I can imagine would be stateless authentication.

As for UserReference, it is used in the Symfony user constructor, but I couldn't see it anywhere else, hence my question.

@andrerom
Copy link
Contributor Author

andrerom commented Apr 28, 2017

It indeed depends on our domain needs, but this is highly recommended and done in every implementation provided by Symfony. Only exception I can imagine would be stateless authentication.

ok, then approach here is at least going in the right direction, our old issue was implying to get rid of it, but then we aim to keep the object refresh, and instead look for way to make it lighter later in api.

As for UserReference, it is used in the Symfony user constructor, but I couldn't see it anywhere else, hence my question.

Actually it is used a few places already:
https://github.com/ezsystems/ezpublish-kernel/search?l=PHP&q=%22new+UserReference%22&type=&utf8=%E2%9C%93

@andrerom andrerom requested a review from alongosz April 30, 2017 08:05
Copy link
Member

@alongosz alongosz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, 2 not important nitpicks.

@@ -93,7 +96,11 @@ public function testIsNotEqualTo()
public function testIsEqualToNotSameUserType()
{
$user = new User();
$user2 = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
$user2 = $this->getMock('eZ\Publish\Core\MVC\Symfony\Security\ReferenceUserInterface');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: ReferenceUserInterface::class please :)

@@ -127,7 +129,7 @@ public function testRegularUser()

public function testIsEqualTo()
{
$originalUser = $this->getMock('eZ\Publish\Core\MVC\Symfony\Security\User');
$originalUser = $this->getMock('eZ\Publish\Core\MVC\Symfony\Security\Tests\UserEquatableInterface');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UserEquatableInterface::class

@andrerom andrerom merged commit 62c24a0 into master May 8, 2017
@andrerom andrerom deleted the sfuser_improvments branch May 8, 2017 13:47
emodric added a commit to netgen/NetgenEzSyliusBundle that referenced this pull request May 8, 2017
kemoc pushed a commit to kemoc/ezpublish-kernel that referenced this pull request May 10, 2017
…ezsystems#1965)

* Throw InvalidArgumentException if WrappedUser recives instance of self or User

To protect against injecting api user several times bloating session value.

* EZP-24852: Add UserReference support in Authentication/User providers

As we always refresh APIUser on load anyway, changes our symfony User
to not serialize APIUser to session to reduce size of session being
serialized back and forth.

This approch assumed the refresh is needed for security reasons *(as in
check if user is still exists and is enabled, permissions lookup don't
need this)*. However if that is not the case this can be done closer
to how it is described in JIRA issue and aim to deprecate this logic instead.

* [UnitTests] Adapt Tests for changes

* Adapt RestAuthenticator to use getUserId() also

Not a must, but test where failing since MVC User was calling method and this part of the code property.

* Deprecate UserInterface::setAPIUser() so update is not forgotten in 7.0

* CS
emodric added a commit to ezsystems/LegacyBridge that referenced this pull request Jun 21, 2017
andrerom pushed a commit to ezsystems/LegacyBridge that referenced this pull request Jun 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants