Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Security] Deprecate remaining anonymous checks #42510

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

Merged
merged 1 commit into from
Aug 14, 2021

Conversation

wouterj
Copy link
Member

@wouterj wouterj commented Aug 12, 2021

Q A
Branch? 5.4
Bug fix? no
New feature? yes
Deprecations? yes
Tickets Ref #41613
License MIT
Doc PR tbd

Deprecates the remaining checks for anonymous found in #41613. It's WIP because the tests are failing until #42423 is merged and this PR is rebased (didn't update one test to avoid merge conflicts).

Besides this, it also introduced IS_AUTHENTICATED and AuthenticationTrustResolver::isAutenticated(). Previously, IS_AUTHENTICATED_ANONYMOUSLY was considered to be the "bottom type" for authenticated requests. As this is no longer true, IS_AUTHENTICATED_REMEMBERME is now the new "bottom type". I suggest we use an explicit bottom type (the ones introduced) instead to avoid another such update if we change something with remember me. It's also more clear on the exact intent of the check.

@wouterj wouterj requested a review from chalasr as a code owner August 12, 2021 16:55
@chalasr chalasr changed the title [Security] [WIP] Deprecate removing anonymous checks [Security] [WIP] Deprecate relai anonymous checks Aug 12, 2021
@chalasr chalasr changed the title [Security] [WIP] Deprecate relai anonymous checks [Security] [WIP] Deprecate remaining anonymous checks Aug 12, 2021
Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

Thank you. Well done

After first review, It looks good. Just waiting for it to remove WIP.

@wouterj
Copy link
Member Author

wouterj commented Aug 12, 2021

Thanks for the reviews @Nyholm!

Just waiting for it to remove WIP

The WIP is just because of the intentionally broken tests. Everything except ExpressionLanguageTest is in the final state as far as I'm concerned.

@chalasr
Copy link
Member

chalasr commented Aug 13, 2021

The most common usage of IS_AUTHENTICATED_ANONYMOUSLY looks like:

firewalls:
    main:
        pattern: ^/
        form_login:
            login_path: login
            check_path: login

access_control:
    - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/another_public_resource, roles: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/, roles: IS_AUTHENTICATED_FULLY }

What is the new way to achieve that? How should one allow a single route to be accessed without being authenticated?
I think having such before/after example in the UPGRADE file would be useful.

@fabpot
Copy link
Member

fabpot commented Aug 13, 2021

#42423 has been merged now.

@wouterj wouterj force-pushed the pull-41613/anon branch 2 times, most recently from d6de7d5 to ab23e6f Compare August 14, 2021 09:17
@wouterj
Copy link
Member Author

wouterj commented Aug 14, 2021

Good idea @chalasr. The great thing: this made me realize that I was suggesting a wrong replacement. I've added your example to the UPGRADE guide.

Meanwhile, I also fixed the tests and updated the isAuthenticated() check to take into account deprecated features (and also make sure to be forward compatible by returning false for anonymous).


I think I have to disagree with fabbot here, their suggestion doesn't make sense: (I know we like to use the pixels at the right side of the screen, but I'm going to need a much much wider screen to be able to read this line 😄 )

diff -ru src/Symfony/Component/Security/Http/Tests/Firewall/ContextListenerTest.php src/Symfony/Component/Security/Http/Tests/Firewall/ContextListenerTest.php
--- src/Symfony/Component/Security/Http/Tests/Firewall/ContextListenerTest.php	2021-08-14 09:17:15.170647398 +0000
+++ src/Symfony/Component/Security/Http/Tests/Firewall/ContextListenerTest.php	2021-08-14 09:17:18.381551885 +0000
@@ -416,11 +416,9 @@
 
         $tokenStorage = new TokenStorage();
         $usageIndex = $session->getUsageIndex();
-        $tokenStorage = new UsageTrackingTokenStorage($tokenStorage, new class(
-            (new \ReflectionClass(UsageTrackingTokenStorage::class))->hasMethod('getSession') ? [
-                'request_stack' => function () use ($requestStack) {
-                return $requestStack;
-            }] : [
+        $tokenStorage = new UsageTrackingTokenStorage($tokenStorage, new class((new \ReflectionClass(UsageTrackingTokenStorage::class))->hasMethod('getSession') ? ['request_stack' => function () use ($requestStack) {
+            return $requestStack;
+        }] : [
                 // BC for symfony/framework-bundle < 5.3
                 'session' => function () use ($session) {
                     return $session;

@wouterj wouterj changed the title [Security] [WIP] Deprecate remaining anonymous checks [Security] Deprecate remaining anonymous checks Aug 14, 2021
Copy link
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

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

👍

@fabpot
Copy link
Member

fabpot commented Aug 14, 2021

Thank you @wouterj.

nicolas-grekas added a commit that referenced this pull request Aug 20, 2021
…:isAuthenticated()` non-virtual (chalasr)

This PR was merged into the 6.0 branch.

Discussion
----------

[Security] Make `AuthenticationTrustResolverInterface::isAuthenticated()` non-virtual

| Q             | A
| ------------- | ---
| Branch?       | 6.0
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

The method has been added in #42510 (5.4) as a replacement for `isAnonymous()`.

Commits
-------

32952ca [Security] Make `AuthenticationTrustResolverInterface::isAuthenticated()` non-virtual
This was referenced Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.