OtBackendUserAuthenticator.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace Opentalent\OtAdmin\Middleware;
  3. use Opentalent\OtAdmin\Http\ApiController;
  4. use TYPO3\CMS\Backend\Middleware\BackendUserAuthenticator;
  5. /**
  6. * Overrides (XClass) the core BackendUserAuthenticator middleware to extend
  7. * the public routes to the /otadmin/* routes (only for authorized Ips)
  8. *
  9. * @internal
  10. */
  11. class OtBackendUserAuthenticator extends BackendUserAuthenticator
  12. {
  13. /**
  14. * Check if the user is required for the request
  15. * If we're trying to do a login or an ajax login, don't require a user
  16. *
  17. * @param string $routePath the Route path to check against
  18. * @return bool whether the request can proceed without a login required
  19. */
  20. protected function isLoggedInBackendUserRequired(string $routePath): bool
  21. {
  22. $isOtAdminRoute = (bool)preg_match('/\/otadmin\/.+/', $routePath);
  23. $ipAllowed = ApiController::isIpAllowed($_SERVER['REMOTE_ADDR']);
  24. if ($isOtAdminRoute) {
  25. if ($ipAllowed) {
  26. return true;
  27. } else {
  28. throw new \RuntimeException('An unauthorized IP (' . $_SERVER['REMOTE_ADDR'] . ') ' .
  29. 'tried to run the following ot-admin command: ' . $_SERVER['QUERY_STRING']);
  30. }
  31. }
  32. return parent::isLoggedInBackendUserRequired($routePath);
  33. }
  34. }