OtBackendUserAuthenticator.php 1.1 KB

12345678910111213141516171819202122232425262728293031
  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, something like '
  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 && $ipAllowed) {
  25. return true;
  26. }
  27. return parent::isLoggedInBackendUserRequired($routePath);
  28. }
  29. }