You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LoggedInCheckCommand.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OC\Authentication\Login;
  27. use OC\Authentication\Events\LoginFailed;
  28. use OC\Core\Controller\LoginController;
  29. use OCP\EventDispatcher\IEventDispatcher;
  30. use Psr\Log\LoggerInterface;
  31. class LoggedInCheckCommand extends ALoginCommand {
  32. /** @var LoggerInterface */
  33. private $logger;
  34. /** @var IEventDispatcher */
  35. private $dispatcher;
  36. public function __construct(LoggerInterface $logger,
  37. IEventDispatcher $dispatcher) {
  38. $this->logger = $logger;
  39. $this->dispatcher = $dispatcher;
  40. }
  41. public function process(LoginData $loginData): LoginResult {
  42. if ($loginData->getUser() === false) {
  43. $loginName = $loginData->getUsername();
  44. $password = $loginData->getPassword();
  45. $ip = $loginData->getRequest()->getRemoteAddress();
  46. $this->logger->warning("Login failed: $loginName (Remote IP: $ip)");
  47. $this->dispatcher->dispatchTyped(new LoginFailed($loginName, $password));
  48. return LoginResult::failure($loginData, LoginController::LOGIN_MSG_INVALIDPASSWORD);
  49. }
  50. return $this->processNextOrFinishSuccessfully($loginData);
  51. }
  52. }