Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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

Sign up
Appearance settings

[TwigBridge] Create impersonation_exit_path() and *_url() functions#24737

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@Simperfit
Copy link
Contributor

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#24676
LicenseMIT
Doc PRWill add
  • Add docs
  • Add test

I opened the PR in order to see if the implementation is right

@Simperfit
Copy link
ContributorAuthor

Status: Needs work
@javiereguiluz@nicolas-grekas could you please tell me if i'm in the right direction, I may update the SecurityDataCollector too since it share some code

@javiereguiluz
Copy link
Member

I haven't looked at the code yet ... but couldn't we move these functions toSymfony\Bridge\Twig\Extension\SecurityExtension? And yes, I also think thatLogoutUrlExtension shouldn't exist and their contents should be moved toSecurityExtension too.

@Simperfit
Copy link
ContributorAuthor

I guess we could move these ans Logout's one to the SecurityExtension, if it's ok, Ill do it

@nicolas-grekasnicolas-grekas added this to the4.1 milestoneOct 30, 2017
@Simperfit
Copy link
ContributorAuthor

@javiereguiluz Do we merge all in securityExtension ?

Copy link
Member

@ycerutoyceruto 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 👍

*
* @return string The Impersonate exit URL
*/
privatefunctiongenerateImpersonateExitUrl($referenceType)
Copy link
Member

Choose a reason for hiding this comment

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

we're in master so I guess we can use typehint everywhere?

if ($this->getImpersonatedUser() &&null !==$switchUserConfig =$firewallConfig->getSwitchUser()) {
$exitPath =$request->getRequestUri();
$exitPath .=null ===$request->getQueryString() ?'?' :'&';
$exitPath .=sprintf(
Copy link
Member

Choose a reason for hiding this comment

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

one line?


/**
* Generates the absolute logout path for the firewall.
**.
Copy link
Member

@ycerutoycerutoNov 1, 2017
edited
Loading

Choose a reason for hiding this comment

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

broken line.

return$url;
}

privatefunctiongetImpersonatedUser()
Copy link
Member

@ycerutoycerutoNov 1, 2017
edited
Loading

Choose a reason for hiding this comment

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

I think this function is useful only to know if the current user is being impersonated, thus it should return a boolean value always and should be named something likeisImpersonatedUser()?

private$tokenStorage;
private$firewallMap;

publicfunction__construct(RequestStack$requestStack =null,UrlGeneratorInterface$router =null,TokenStorageInterface$tokenStorage =null,FirewallMapInterface$firewallMap)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if making these arguments nullable is meaningful, because this service depends exclusively on them. Instead the service definition could be removed if some of them don't exists?

@javiereguiluzjaviereguiluz added the ❄️ Feature FreezeImportant Pull Requests to finish before the next Symfony "feature freeze" labelMar 12, 2018
@javiereguiluz
Copy link
Member

@Simperfit I know this feature is not a game-changer for Symfony ... but it improves DX a lot for this use case. Although it's almost finished, we'd need a final push before the "feature freeze" starts in 12 days. Thanks a lot 🙏

@Simperfit
Copy link
ContributorAuthor

I understand@javiereguiluz I'm going to finish this feature before the feature freeze. (This week-end I think).

xabbuh reacted with thumbs up emoji

@SimperfitSimperfitforce-pushed thefeature/add-impersonate-exit-extension branch 2 times, most recently fromc8186e6 to0296974CompareMarch 26, 2018 07:39
@Simperfit
Copy link
ContributorAuthor

I'm adding tests today.

fancyweb reacted with thumbs up emoji

@SimperfitSimperfit changed the title[TwigBridge] [WIP] Create impersonation_exit_path() and *_url() functions[TwigBridge] Create impersonation_exit_path() and *_url() functionsMar 26, 2018
@SimperfitSimperfitforce-pushed thefeature/add-impersonate-exit-extension branch from0296974 todbe432eCompareMarch 26, 2018 07:40
@SimperfitSimperfitforce-pushed thefeature/add-impersonate-exit-extension branch fromdbe432e to9e5ba7fCompareMarch 26, 2018 07:44
Copy link
Contributor

@ostroluckyostrolucky left a comment

Choose a reason for hiding this comment

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

I don't see why does this feature differentiate if current request is/ or not.

Also big flaw is assumption user wants to exit at current URL. I don't know how you guys do this, but I always exit impersonation at URL where impersonation was started (e.g. user edit page in admin section)

private$tokenStorage;
private$firewallMap;

publicfunction__construct(RequestStack$requestStack,UrlGeneratorInterface$router,TokenStorageInterface$tokenStorage =null,FirewallMapInterface$firewallMap)
Copy link
Contributor

Choose a reason for hiding this comment

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

This class does not work with other implementation than FirewallMap, so you can as well just require it, instead of interface and get rid of an instanceof check. Also not sure why is non-optional argument last.

$assignedRoles =$token->getRoles();

foreach ($assignedRolesas$role) {
if ($roleinstanceof SwitchUserRole) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than this mechanism to check if user is currently impersonating, shouldn't it be done the way docs recommend? That means checking if user has ROLE_PREVIOUS_ADMIN via AuthorizationChecker.

https://symfony.com/doc/current/security/impersonating_user.html

return$this->generateImpersonateExitUrl(UrlGeneratorInterface::ABSOLUTE_URL);
}

privatefunctiongenerateImpersonateExitUrl($referenceType):string
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be more flexible if this was public and twig functions would call this with correct parameters. We then wouldn't need two public methods. Also, missing typehint.

if ($this->isImpersonatedUser() &&null !==$switchUserConfig =$firewallConfig->getSwitchUser()) {
$exitPath =$request->getRequestUri();
$exitPath .=null ===$request->getQueryString() ?'?' :'&';
$exitPath .=sprintf('%s=%s',urlencode($switchUserConfig['parameter']), SwitchUserListener::EXIT_VALUE);
Copy link
Contributor

Choose a reason for hiding this comment

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

using http_build_query would be better

}

if ('/' ===$exitPath[0]) {
if (!$this->requestStack) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a dead code. RequestStack is required so will never be null

$url .='?'.http_build_query($parameters);
}
}else {
if (!$this->router) {
Copy link
Contributor

Choose a reason for hiding this comment

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

another dead path

thrownew \LogicException('Unable to generate the impersonate exit URL without a Router.');
}

$url =$this->router->generate($exitPath,array(),$referenceType);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is wrong, first parameter of route path is name of the route, query string is given instead

$container->removeDefinition('security.access.expression_voter');
}

if (!class_exists('Symfony\Component\HttpFoundation\RequestStack') || !class_exists('Symfony\Component\Routing\Generator\UrlGeneratorInterface')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why would RequestStack not exist? It's required by dependencies

@nicolas-grekasnicolas-grekas modified the milestones:4.1,nextApr 20, 2018
@javiereguiluzjaviereguiluz removed the ❄️ Feature FreezeImportant Pull Requests to finish before the next Symfony "feature freeze" labelApr 26, 2018
private$impersonateUrlGenerator;

publicfunction__construct(AuthorizationCheckerInterface$securityChecker =null)
publicfunction__construct(AuthorizationCheckerInterface$securityChecker =null,ImpersonateUrlGenerator$impersonateUrlGenerator)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think PHP strongly discourages non-optional arguments after optional

http://php.net/manual/en/functions.arguments.php

Note that when using default arguments, any defaults should be on the right side of any non-default arguments; otherwise, things will not work as expected.

@javiereguiluz
Copy link
Member

Could we please make an effort to finish this PR before this month's end so it can make it for Symfony 4.2? Thanks!

@fabpot
Copy link
Member

Let's close as there is not more activity here and it looks like it is far from being finished.

@fabpotfabpot closed thisOct 10, 2018
@nicolas-grekasnicolas-grekas modified the milestones:next,4.2Nov 1, 2018
fabpot added a commit that referenced this pull requestSep 6, 2020
… (dFayet)This PR was merged into the 5.2-dev branch.Discussion----------Create impersonation_exit_path() and *_url() functions| Q             | A| ------------- | ---| Branch?       | 4.4| Bug fix?      | no| New feature?  | yes <!-- please update src/**/CHANGELOG.md files -->| BC breaks?    | no     <!-- seehttps://symfony.com/bc -->| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->| Tests pass?   | yes (not added atm)   <!-- please add some, will be required by reviewers -->| Fixed tickets |#24676   <!-- #-prefixed issue number(s), if any -->| License       | MIT| Doc PR        | To come later <!-- symfony/symfony-docs#... --><!-- required for new features -->This is a relaunch of the PR#24737It adds more flexibility to the previous try.You have two twig functions `impersonation_exit_url()` and `impersonation_exit_path()`You can either leave on the same path, redirect to the path where was the user at the user switch, or to the path you want.Example:The following code```twig<p>{{ impersonation_exit_url() }}</p><p>{{ impersonation_exit_path() }}</p><p>&nbsp;</p><p>{{ impersonation_exit_url(path('app_default_other')) }}</p><p>{{ impersonation_exit_path(path('app_default_other')) }}</p><p>&nbsp;</p><p>{{ impersonation_exit_url('_use_impersonated_from_url') }}</p><p>{{ impersonation_exit_path('_use_impersonated_from_url') }}</p>```will output![Capture d’écran de 2019-07-31 20-58-42](https://user-images.githubusercontent.com/7721219/62239914-1482cb00-b3d6-11e9-9b58-ea8d30a2e28a.png)**Note:** If this proposal appears to be better, I'll add tests, update changelog, and prepare the doc.**Bonus:**As the "impersonated from url" is stored in the `SwitchUserToken` it might be possible to display it in the profiler:![Capture d’écran de 2019-07-31 21-04-50](https://user-images.githubusercontent.com/7721219/62240294-efdb2300-b3d6-11e9-911a-bec48fd75327.png)WDYT?<!--Replace this notice by a short README for your feature/bugfix. This will help peopleunderstand your PR and can be used as a start for the documentation.Additionally (seehttps://symfony.com/roadmap): - Bug fixes must be submitted against the lowest maintained branch where they apply   (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against branch 4.4. - Legacy code removals go to the master branch.-->Commits-------c1e3703 Create impersonation_exit_path() and *_url() functions
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@ycerutoycerutoyceruto left review comments

+2 more reviewers

@artursvondaartursvondaartursvonda left review comments

@ostroluckyostroluckyostrolucky requested changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.2

Development

Successfully merging this pull request may close these issues.

8 participants

@Simperfit@javiereguiluz@fabpot@artursvonda@ostrolucky@yceruto@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp