8000 [Security] Move AbstractListener abstract methods to the new FirewallListenerInterface by chalasr · Pull Request #38751 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Security] Move AbstractListener abstract methods to the new FirewallListenerInterface #38751

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
Oct 27, 2020

Conversation

chalasr
Copy link
Member
@chalasr chalasr commented Oct 25, 2020
Q A
Branch? 5.x
Bug fix? no
New feature? -
Deprecations? no
Tickets -
License MIT
Doc PR -

We added a FirewallListenerInterface in 5.2, let's make it complete to allow for cleaner firewall listener implementations.

@chalasr chalasr requested a review from wouterj as a code owner October 25, 2020 14:08
@chalasr chalasr force-pushed the complete-firewall-listener branch from 4b108ee to 170a564 Compare October 25, 2020 14:09
@chalasr chalasr added this to the 5.2 milestone Oct 25, 2020
@chalasr chalasr force-pushed the complete-firewall-listener branch from 170a564 to 7de8b4e Compare October 25, 2020 21:26
@chalasr chalasr force-pushed the complete-firewall-listener branch from 7de8b4e to 5dd70bd Compare October 25, 2020 21:42
@chalasr chalasr removed the Feature label Oct 25, 2020
@wouterj
Copy link
Member
wouterj commented Oct 26, 2020

Hmm, I'm not very sure about these changes. But the listener logic is quite complex, so I might completely miss something. What I see:

So, it should be possible to have a class with just an __invoke() and getPriority() method, right? AbstractListener is only relevant when you want your listener to support laziness.

@chalasr
Copy link
Member Author
chalasr commented Oct 26, 2020

AbstractListener is only relevant when you want your listener to support laziness.

Actually supports() is also relevant for listeners that don't need laziness (yet), as they can opt-in using the special null return type for this method.

At the time lazy firewalls were introduced, @nicolas-grekas and I talked about deprecating not extending AbstractListener at some point, so that we have a consistent API for firewall listeners (see https://github.com/orgs/symfony/projects/1#card-30499343).
I'm still a bit annoyed by the fact we need to rely on inheritance instead of a clear contract if we do so.

Meanwhile we are reintroducing an interface which, right now, only covers the priority feature.
This PR takes it as an opportunity to not force extending a base class, making the concept more structured and more flexible. That's worth the hassle to me.

About adding __invoke() to the contract, I'm mitigated: should we just accept callable|FirewallListenerinterface for firewall listeners?
The interface allows you to opt-in into more complex features like priority, laziness and the ability to separate concerns between the guard clause and the actual authentication logic.

Does this make sense?

Copy link
Member
@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

big 👍 on my side
this change enables lazy firewalls (but is not ad hoc for them) because it enables a better design, with a better split of the steps of a firewall

Copy link
Member
@wouterj wouterj left a comment

Choose a reason for hiding this comment

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

Ah sorry, I originally was looking at this PR as "purely simplifying" instead of moving to more consistency.

If I understand correctly, the contract already is callable|FirewallListenerInterface (it needs to be, for BC reasons IIRC). In that case 👍 and we might indeed want to deprecate callable in Symfony 5.3 (I don't think it's possible to introduce new deprecations after feature freeze?)

@nicolas-grekas
Copy link
Member

Thank you @chalasr.

@nicolas-grekas nicolas-grekas merged commit 824bc44 into symfony:5.x Oct 27, 2020
@chalasr chalasr deleted the complete-firewall-listener branch October 27, 2020 10:47
@fabpot fabpot mentioned this pull request Oct 28, 2020
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.

4 participants
0