[Security] Use auth trust resolver to determine anonymous in ContextListener#18211
Closed
wouterj wants to merge 2 commits intosymfony:masterfrom
Closed
[Security] Use auth trust resolver to determine anonymous in ContextListener#18211wouterj wants to merge 2 commits intosymfony:masterfrom
wouterj wants to merge 2 commits intosymfony:masterfrom
Conversation
| use Symfony\Component\HttpKernel\KernelEvents; | ||
| use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolver; | ||
| use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface; | ||
| use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken; |
c2e4d54 to
a695652
Compare
| $session = $request->getSession(); | ||
|
|
||
| if ((null === $token = $this->tokenStorage->getToken()) || ($token instanceof AnonymousToken)) { | ||
| if ((null === $token = $this->tokenStorage->getToken()) || ($this->trustResolver->isAnonymous($token))) { |
Member
There was a problem hiding this comment.
We can remove one pair of parentheses here.
| $this->sessionKey = '_security_'.$contextKey; | ||
| $this->logger = $logger; | ||
| $this->dispatcher = $dispatcher; | ||
| $this->trustResolver = $trustResolver ?: new AuthenticationTrustResolver('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken', 'Symfony\Component\Security\Core\Authentication\Token\RememberMeToken'); |
Member
There was a problem hiding this comment.
You could use ::class constants here
Member
|
👍 |
1 similar comment
Member
|
👍 |
Member
|
Thanks @wouterj |
fabpot
added a commit
that referenced
this pull request
Mar 23, 2016
…ous in ContextListener (WouterJ) This PR was squashed before being merged into the 3.1-dev branch (closes #18211). Discussion ---------- [Security] Use auth trust resolver to determine anonymous in ContextListener | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | not done yet There is a nice class in Symfony that is used to check whether a token is anonymously: `AuthenticationTrustResolver`. However, its logic was still hard coded in the `ContextListener`, making it impossible to customize it (e.g. using another anonymous token class). I think it makes lots of sense to use the dedicated class. Commits ------- ab5578e [Security] Use auth trust resolver to determine anonymous in ContextListener
nicolas-grekas
added a commit
that referenced
this pull request
Mar 23, 2016
This PR was merged into the 3.1-dev branch. Discussion ---------- use class constants instead of FQCN strings | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #18211 (comment) | License | MIT | Doc PR | Commits ------- d4ec7dd use class constants instead of FQCN strings
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There is a nice class in Symfony that is used to check whether a token is anonymously:
AuthenticationTrustResolver. However, its logic was still hard coded in theContextListener, making it impossible to customize it (e.g. using another anonymous token class). I think it makes lots of sense to use the dedicated class.