Skip to content
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

[Security] Using of TargetPathTrait in a Controller #27835

Open
proArtex opened this Issue Jul 3, 2018 · 2 comments

Comments

Projects
None yet
4 participants
@proArtex
Copy link

proArtex commented Jul 3, 2018

Description
There is no easy way to use TargetPathTrait in a Controller, because of missing $providerKey that is current firewall name. There is no easy way to get FirewallMap or FirewallConfig to get the current firewall name.

Example
At least we can make FirewallMap service public to pass over Controller actions.

public function someAction(Request $request, FirewallMap $firewallMap)
{
    ...
    $currentFirewallName = $firewallMap->getFirewallConfig(request)->getName();
    ...
}

The case it would be useful:
A form has 2 routes with same path but different methods (GET to show, POST to submit). Showing form is public, but submitting is authorized. So I have to check in the beginning of POST action if user is granted some role (e.g. ROLE_USER). If not call saveTargetPath() and redirect to entry_point.
The access_control directive is useless there.

@proArtex proArtex changed the title [Security] Using of TargetPath trait in a Controller [Security] Using of TargetPathTrait in a Controller Jul 3, 2018

@chalasr

This comment has been minimized.

Copy link
Member

chalasr commented Jul 21, 2018

It does not need to be public for being injected in your controller actions.
What it needs is an alias corresponding to its type so that your argument matches an existing service:

services:
    # ...
    Symfony\Bundle\SecurityBundle\Security\FirewallMap: '@security.firewall.map'

I don't think we should do it in the core, first because it's not common enough, and because it's not an interface (getFirewallConfig() is not part of FirewallMapInterface).

@nicolas-grekas

This comment has been minimized.

Copy link
Member

nicolas-grekas commented Aug 9, 2018

Honestly, it feels awkward to type hint anything in a bundle namespace. A bundle is glue. Not abstraction...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.