-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
[RTM] Use Symfony Security for authentication purposes in Contao #685
[RTM] Use Symfony Security for authentication purposes in Contao #685
Conversation
bf65103
to
b215304
Compare
8ac4255
to
f3c619d
Compare
c8f2f0d
to
09536d6
Compare
…symfony-authentication-2
…symfony-authentication-2
src/Resources/contao/dca/tl_user.php
Outdated
| */ | ||
| public function switchUser($row, $href, $label, $title, $icon) | ||
| { | ||
| @trigger_error('Using tl_user->switchUser() has been deprecated and will no longer work in Contao 5.0. Use the switch_user_button_generator service instead', E_USER_DEPRECATED); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of this method should be removed or replaces by the new switch user stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| /** @var BackendUser $targetUser */ | ||
| $targetUser = $event->getTargetUser(); | ||
|
|
||
| $this->logger->info(sprintf("User %s has switched to user %s.", $user->username, $targetUser->username)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only purpose of this listener is to log the action? If that's a replacement of an existing log, we should log with a ContaoContext to make it appear in the backend log.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should be the replacement of the existing log, but I didn't get it how it's done to make it appear in the backend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| $logger->log($level, $strText, array('contao' => new ContaoContext($strFunction, $strCategory))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thank you! I'll update it later.
src/Resources/config/services.yml
Outdated
| - "@contao.framework" | ||
|
|
||
| contao.security.switch_user_button_generator: | ||
| class: Contao\CoreBundle\Security\User\SwitchUserButtonGenerator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me this is an event (callback) listener and should be in the according namespace.
|
|
||
| if ($authorizationChecker->isGranted('ROLE_PREVIOUS_ADMIN')) { | ||
| $logoutLink = $router->generate('contao_backend', [ | ||
| '_switch_user' => '_exit', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a new feature, right? Previously a login just logged out whatever user was currently in. Might be confusing if we don't change the logout label to "switch back to X".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current label is Close the current session and thus not wrong in my opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed in e2bed63.
| $stmt->execute(); | ||
|
|
||
| if (0 === $stmt->rowCount()) { | ||
| throw new UserNotFoundException('Invalid user ID' . $row['id']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should never happen, so I would simply return empty string (remove action) in this case and not add a new exception for a never-happening case :)
| '_switch_user' => $user->username | ||
| ]); | ||
|
|
||
| return $this->twig->render('@ContaoCore/Backend/switch_user.html.twig', [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a twig template for this? Generally good, but there are so many places where we currently don't…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes IMHO we need exactly that. Otherwise we will end up like the DCA classes are right now with template code in the logic parts. And we have to start using (twig) templates at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, but then this should be a general button template, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Should be discussed with the others probably?
5cae2cf
to
7e9ecad
Compare
0424c9f
to
88860b8
Compare
| * | ||
| * @param DataContainer $dc | ||
| */ | ||
| public function checkRemoveSession($dc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No BC break if you remove a public method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a BC break for sure. The question is whether out BC promise includes DCA files, which I think they don't.
| @@ -1 +0,0 @@ | |||
| <a href="{{ url }}" title="{{ title }}">{{ image | raw }}</a> | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
| 'title' => $title, | ||
| 'image' => Image::getHtml($icon, $label), | ||
| ]); | ||
| return sprintf('<a href="%s" title="%s">%s</a>', $url, $title, Image::getHtml($icon, $label)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm totally against to remove the template. Now we have again html somewhere in the logic.
|
The PR is almost ready to merge. There are two open issues:
Regarding 1.: We are logging "switch user" actions but not "log in as member" actions. Is this ok or should we log both or none? |
|
| $objTemplate->user = \Input::post('user'); | ||
| /** @var User $user */ | ||
| $user = $token->getUser(); | ||
| $objUser = \MemberModel::findByUsername($user->getUsername()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also something that makes me wonder. Shouldn't $token->getUser() return the user object already? Why are we loading the member model?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The getUser() on the token can have a fully loaded user instance, but you cannot be sure.
Normally it holds only the unserialized data from the session storage.
| @@ -13,16 +13,19 @@ | |||
| <?php endif; ?> | |||
| <input type="hidden" name="FORM_SUBMIT" value="<?= $this->formId ?>"> | |||
| <input type="hidden" name="REQUEST_TOKEN" value="{{request_token}}"> | |||
| <?php if ($this->targetPath): ?> | |||
| <input type="hidden" name="<?= $this->targetName ?>" value="<?= $this->targetPath ?>"> | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also wonder if this is prone to manipulation? @ausi /cc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should check, if it's an existing page from the installation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know. It seems it is a hidden field in Symfony, too: https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/CsrfFormLoginBundle/Form/UserLoginType.php#L47
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well you can only manipulate it through the web inspector. Which means the redirect target after login is manipulated. Can't really see an issue in that, it does not send any data to that URL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
htmlspecialchars() is missing for $this->targetPath, either in the template or in ModuleLogin. As it is now it’s vulnerable to XSS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 975070e.
1c252ad
to
94916b8
Compare
|
Thank you, big time @bytehead. |
Functionality broke with contao/core-bundle#685 as User->logout uses a RedirectResponseException.
Functionality broke with contao/core-bundle#685 as User->logout uses a RedirectResponseException.
Description ----------- Functionality broke with contao/core-bundle#685 as `User->logout()` uses a RedirectResponseException. Fixes #93. Commits ------- 14f6a80 Respect jump to on close account. da85783 Use System::getContainer() instead of Controller::getContainer()
Description ----------- This is a follow-up on #657, #677 and #682. It implements the new template loading by looking up the keys in `TL_CTE`, `TL_FFL` and `FE_MOD` as discussed in Mumble on August 29th. Commits ------- de3089b7 Hide mod_article_list when searching for custom mod_article templates 7b6ce852 Replace "root template" with "bundle template" 1ee232da Support passing an additional mapper array as second argument
This is a working draft to replace the current
simple_preauthmechanism to login backend users and frontend members with theform_loginfrom the Symfony Security Component.Please review and mention all missed topics.
ToDos:
BackendUserframework.session.cookie_lifetime)contao_)FrontendUserpostAuthenticatepostLogincheckCredentials(needs a customAuthenticationProvider)importUserpostLogoutaccountLockedstuffpostAuthenticatehookcheckCredentialshookimportUserhookpostLogouthookFixes needed:
Backend login redirect: Simple test: login, go somewhere, delete your session cookie.Config,Environment)importUseronly onPOSTrequestUserCheckerinFrontendEquatableInterfaceon User to compare the token object and DB objectBackendUser::getInstancecheck if there is a valid_security_contao_backendtoken in the actual session to restore the user fromFrontendUser::getInstancecheck if there is a valid_security_contao_frontendtoken in the actual session to restore the user fromNice to have (possibly future PRs):
DoctrineTokenProviderfor persistent remember me tokensPossible new features (future PRs):
activate,change-passwordor similar