-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[SecurityBundle] Link UserProviderListener to correct firewall dispatcher #41509
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
+157
−2
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[SecurityBundle] Link UserProviderListener to correct firewall dispat…
…cher
- Loading branch information
commit 46bdeb8507a0f5cd0bfdd56cee5da1c44fcd8812
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...dle/SecurityBundle/Tests/Functional/Bundle/AuthenticatorBundle/LoginFormAuthenticator.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\AuthenticatorBundle; | ||
|
||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; | ||
use Symfony\Component\Security\Core\Security; | ||
use Symfony\Component\Security\Http\Authenticator\AbstractLoginFormAuthenticator; | ||
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge; | ||
use Symfony\Component\Security\Http\Authenticator\Passport\Credentials\PasswordCredentials; | ||
use Symfony\Component\Security\Http\Authenticator\Passport\Passport; | ||
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface; | ||
use Symfony\Component\Security\Http\Util\TargetPathTrait; | ||
|
||
class LoginFormAuthenticator extends AbstractLoginFormAuthenticator | ||
{ | ||
use TargetPathTrait; | ||
|
||
/** @var UrlGeneratorInterface */ | ||
private $urlGenerator; | ||
|
||
public function __construct(UrlGeneratorInterface $urlGenerator) | ||
{ | ||
$this->urlGenerator = $urlGenerator; | ||
} | ||
|
||
public function authenticate(Request $request): PassportInterface | ||
{ | ||
$username = $request->request->get('_username', ''); | ||
|
||
$request->getSession()->set(Security::LAST_USERNAME, $username); | ||
|
||
return new Passport( | ||
new UserBadge($username), | ||
new PasswordCredentials($request->request->get('_password', '')), | ||
[] | ||
); | ||
} | ||
|
||
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $firewallName): ?Response | ||
{ | ||
return new RedirectResponse($this->urlGenerator->generate('security_'.$firewallName.'_profile')); | ||
} | ||
|
||
protected function getLoginUrl(Request $request): string | ||
{ | ||
return strpos($request->getUri(), 'main') ? | ||
$this->urlGenerator->generate('security_main_login') : | ||
$this->urlGenerator->generate('security_custom_login') | ||
; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
.../Bundle/SecurityBundle/Tests/Functional/Bundle/AuthenticatorBundle/SecurityController.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\AuthenticatorBundle; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class SecurityController extends AbstractController | ||
{ | ||
public function checkAction() | ||
{ | ||
return new Response('OK'); | ||
} | ||
|
||
public function profileAction() | ||
{ | ||
return new Response('Welcome '.$this->getUser()->getUsername().'!'); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...dle/SecurityBundle/Tests/Functional/app/Authenticator/multiple_firewall_user_provider.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
imports: | ||
- { resource: ./config.yml } | ||
- { resource: ./security.yml } | ||
|
||
security: | ||
firewalls: | ||
main: | ||
pattern: ^/main | ||
provider: in_memory | ||
custom_authenticator: Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\AuthenticatorBundle\LoginFormAuthenticator | ||
custom: | ||
pattern: ^/custom | ||
provider: in_memory2 | ||
custom_authenticator: Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\AuthenticatorBundle\LoginFormAuthenticator |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.