Skip to content

[3.0 Cleanup] Removal of the SecurityContext #12445

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
wants to merge 0 commits into from
Closed

[3.0 Cleanup] Removal of the SecurityContext #12445

wants to merge 0 commits into from

Conversation

linaori
Copy link
Contributor

@linaori linaori commented Nov 10, 2014

Q A
Bug fix? no
New feature? no
BC breaks? yes
Deprecations? no
Tests pass? yes
Fixed tickets ~
License MIT
Doc PR ~

As follow up for PR #11690 in 2.6, I have removed the SecurityContext, SecurityContextInterface and security.context service. I have split the parts in separate commits to make it easier to review but I can squash them if desired.

I will submit the changes to the documentation when a branch is available to do so. Docs are already updated.

@linaori
Copy link
Contributor Author

linaori commented Nov 10, 2014

It's correct that the 5.3 and 5.4 tests fail. I have done this on purpose with ::class and []. 5.5 seems to be failing due to a caching issue:

1) Symfony\Bundle\SecurityBundle\Tests\Functional\AuthenticationCommencingTest::testAuthenticationIsCommencingIfAccessDeniedExceptionIsWrapped
RuntimeException: OUTPUT: 
Catchable fatal error: Argument 1 passed to Symfony\Component\Security\Http\Firewall\ContextListener::__construct() must be an instance of Symfony\Component\Security\Core\SecurityContextInterface, instance of Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage given, called in /tmp/2.6.0-DEV/StandardFormLogin/cache/securitybundleteststandardformlogin/appSecuritybundleteststandardformloginDebugProjectContainer.php on line 1767 and defined in /home/travis/build/symfony/symfony/src/Symfony/Bundle/SecurityBundle/vendor/symfony/security/Symfony/Component/Security/Http/Firewall/ContextListener.php on line 42

@javiereguiluz
Copy link
Member

@iltar thanks for preparing this PR and for your work on the security component of Symfony.

However, I'd like to ask you to reconsider the title of this PR. The use of the "Extermination" word feels extremely strong and disturbing to me. If you agree, you could replace it with Removal.

@linaori linaori changed the title [3.0 Cleanup] Extermination of the SecurityContext [3.0 Cleanup] Removal of the SecurityContext Nov 11, 2014
@linaori
Copy link
Contributor Author

linaori commented Nov 11, 2014

@javiereguiluz No problem! I've changed the title

@javiereguiluz
Copy link
Member

@iltar thanks for your quick response!

*
* @author Fabien Potencier <fabien@symfony.com>
*/
class SecurityExtension extends \Twig_Extension
{
private $context;
private $authorization;
Copy link
Member

Choose a reason for hiding this comment

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

it should be authorizationChecker, not authorization (it is not an authorization, it is a checker)

@stof
Copy link
Member

stof commented Nov 23, 2014

We should prepare the migration in a forward compatible way, to avoid people starting to work with 2.6 components to have to handle this BC break in 3.0. Constructors expecting a SecurityContextInterface should also accept a TokenStorageInterface or AuthorizationCheckerInterface (depending on the case), so that both the old and the new API are accepted.
then, 3.0 should only drop the support of the old one. See how we did it for the CSRF layer in Symfony 2.4

@linaori
Copy link
Contributor Author

linaori commented Nov 23, 2014

@stof to some degree I think it should be done. However, this will provide a lot of work for internal classes, that if overwritten by people, will only break things. Considering that just replacing it took me 8 hours, I don't mind keeping this PR open for a year for 3.0. I just don't think there will be any benefit doing this for 1 patch in 2.*.

@fabpot fabpot added the Security label Dec 7, 2014
@fabpot
Copy link
Member

fabpot commented Feb 5, 2015

@iltar We are now ready to merge such PRs. Can you rebase on current master? Thanks.

@linaori
Copy link
Contributor Author

linaori commented Feb 5, 2015

@fabpot I will start working on it

@fabpot
Copy link
Member

fabpot commented Feb 5, 2015

Thanks.

@linaori
Copy link
Contributor Author

linaori commented Feb 6, 2015

Seems like there are some unrelated test broken in the FrameworkBundle. As far as I can see, the tests and code I re-based is still working.

@@ -511,6 +512,27 @@ UPGRADE FROM 2.x to 3.0
### Security

* The `Resources/` directory was moved to `Core/Resources/`
* [BC BREAK] All usages of `SecurityContext` and `SecurityContextInterface` have been replaced by either the
`TokenStorageInterface` or `AuthorizationCheckerInterface`, this includes _all_ class.

Choose a reason for hiding this comment

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

Maybe change to "this includes all classes"?

Copy link
Member

Choose a reason for hiding this comment

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

What does this includes all class mean ?

@fabpot
Copy link
Member

fabpot commented Aug 1, 2015

@iltar Can you rebase so that we can merge it? Thanks.

@linaori
Copy link
Contributor Author

linaori commented Aug 3, 2015

@fabpot The tests are flaky. Sometimes it runs out of memory, sometimes I get failing tests and sometimes they all succeed. I think it might have been cache related, but not sure.

@fabpot
Copy link
Member

fabpot commented Sep 14, 2015

@iltar Sorry to ask you this again but can you rebase? Ping me when it's done and I will merge right away.

@linaori
Copy link
Contributor Author

linaori commented Sep 14, 2015

@fabpot rebase is done, I have no idea what phpunit did that made it unable to resolve a 2.8 dependency. I can't find the command that was executed that made fail so I cannot reproduce it myself, any way to find out which that was?

No idea why 3.0 is tested against a 2.8 dependency

@Tobion
Copy link
Contributor

Tobion commented Sep 14, 2015

* [BC BREAK] All usages of `SecurityContext` and `SecurityContextInterface` have been replaced by either the
`TokenStorageInterface` or `AuthorizationCheckerInterface`, this includes _all_ class.
* [BC BREAK] Removed the `SecurityContext` class and `SecurityContextInterface`
* [BC BREAK] Constants from `SecurityContextInterface` are removed in favor of the constants in `Security`
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe provide a Fully qualified class-name for Security?

@nicolas-grekas
Copy link
Member

@iltar changing the composer.json in 2.8 will fix the issue:

-        "symfony/http-kernel": "~2.2|~3.0.0"
+        "symfony/http-kernel": "~2.8"

this constraint should already come from framework-bundle since this is how it is there, but I guess composer has a bug here (mixing constraints from dev+not-dev+custom repository?)

@@ -1,6 +1,10 @@
CHANGELOG
=========

3.0.0
-----
* [BC BREAK] `SecurityExtension::__construct()` now uses `AuthorizationCheckerInterface` instead of `SecurityContextInterface`
Copy link
Member

Choose a reason for hiding this comment

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

2.8 already allows both though


return $mock;
}

protected function createPasswordEncoder($isPasswordValid = true)
{
return $this->getMock('Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface');
return $this->getMock(PasswordEncoderInterface::class);
Copy link
Member

Choose a reason for hiding this comment

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

this should be reverted. It makes merging branches harder (2.8 will keep using the string for the next 3 year of maintenance) and it does not add any real value to counterpart the maintenance pain

@stof
Copy link
Member

stof commented Sep 18, 2015

I think it would be much easier to recreate the PR from scratch: 90% of the changes done in this PR have to be reverted.

@linaori
Copy link
Contributor Author

linaori commented Sep 18, 2015

@stof I agree, it's becoming a mess because the PR is pretty old. I will get to this the start of next week.

@linaori linaori closed this Sep 21, 2015
fabpot added a commit that referenced this pull request Sep 22, 2015
This PR was merged into the 3.0-dev branch.

Discussion
----------

[3.0] Finish of the SecurityContext (follow-up pr)

| Q             | A
| ------------- | ---
| Fixed tickets | #12445
| License       | MIT
| Doc PR        | ~

Because the original PR was getting too big for pretty much nothing (everything was already done in smaller commits over time), I have opened just this PR to confirm the changes by adding it to the CHANGELOG.md files.

Commits
-------

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

Successfully merging this pull request may close these issues.

8 participants