Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[SecurityBundle] Allow for custom request matchers #20272

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 3 commits into from
Closed

[SecurityBundle] Allow for custom request matchers #20272

wants to merge 3 commits into from

Conversation

ro0NL
Copy link
Contributor

@ro0NL ro0NL commented Oct 22, 2016

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes/no
Fixed tickets #20257
License MIT
Doc PR reference to the documentation PR, if any

Quick proof of concept to allow for custom request matchers in the security bundle.

This would allow for matching a request based on a route name (routing happens before security!).

With only this setting it would still be cumbersome to do it though;

access_control:
  - { matcher: service_matching_route1 }
  - { matcher: service_matching_route2 }
  # etc

To solve this we could allow arguments or have it built in:

access_control:
  - { matcher: generic_route_matcher, matcher_arguments: [route1] }
  - { route: route2 }

edit: added ChainRequestMatcher as it could be useful to have a complex matcher built from simple matchers. Allows to refactor the current RequestMatcher to be built from MethodRequestMatcher, SchemeRequestMatchter, etc. I would like this kind of reuseability a lot :)

edit2: added separated PR for it (#20274)

@ro0NL
Copy link
Contributor Author

ro0NL commented Oct 22, 2016

To clarify; the real issue is i want to target a specific controller/action, without depending on @Security() annotation.

Currently we need to duplicate a path definition as a regex ourselves (instead of relying on the compiled regex out-of-the-box) which is error prone.

->children()
->scalarNode('matcher')->defaultNUll()->end()
Copy link
Contributor

Choose a reason for hiding this comment

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

defaultNUll should be defaultNull 😄

/**
* @author Roland Franssen <[email protected]>
*/
class ChainRequestMatcher implements RequestMatcherInterface
Copy link
Member

Choose a reason for hiding this comment

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

Is this class related to this PR? It's not used anywhere?
About the name, "chain" usually means "delegation chain", ie the first applicable in the chain takes responsibility for the job. Here, this is something else, like AllMatchersRequestMatcher (dummy suggestion, I'm not really proud of it :) )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope. It's outdate-ish. I moved it to #20274.

@@ -180,9 +182,6 @@ private function addAccessControlSection(ArrayNodeDefinition $rootNode)
->prototype('scalar')->end()
->end()
->scalarNode('allow_if')->defaultNull()->end()
->end()
->fixXmlConfig('role')
Copy link
Member

Choose a reason for hiding this comment

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

this CS should be applied to a lower branch

$access['ips']
);
if (null !== $access['matcher']) {
$matcher = new Reference($access['matcher']);
Copy link
Member

Choose a reason for hiding this comment

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

the currently created matcher is configured by many props in $access. Thus, is this extension point really enough when you don't give it these parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Im not sure about the "right" approach here. Perhaps we should talk config/API first.

But we could do matcher|<combination of other keys>.

DX-wise i think - { route: foo, roles: [] } is best and probably same for firewalls? (using an array of routes).

As goes for - { expression: foo }. But that could work counter-intuitive with allow_if.

@ro0NL
Copy link
Contributor Author

ro0NL commented Dec 29, 2016

Closing in favor of #20274, im not sure about the matcher approach here. Maybe something better comes out. The integration is definitely missing though.

But, im going to experiment with path: '%route.name%' or so, keeping config as is, while still allowing me to reference a path regex (compiled i guess) by name. It would be the cleanest solution i think.

@ro0NL ro0NL closed this Dec 29, 2016
@ro0NL ro0NL deleted the security-bundle/custom-matchers branch December 29, 2016 08:44
@nicolas-grekas nicolas-grekas modified the milestones: 3.x, 3.3 Mar 24, 2017
@ro0NL ro0NL restored the security-bundle/custom-matchers branch April 28, 2017 19:52
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