|
|
|
@ -52,15 +52,30 @@ class RedirectSubscriber implements EventSubscriberInterface { |
|
|
|
$host = $request->getHost(); |
|
|
|
$host = $request->getHost(); |
|
|
|
$config = $this->configFactory->get('url_permission_redirect.settings'); |
|
|
|
$config = $this->configFactory->get('url_permission_redirect.settings'); |
|
|
|
$protectedDomain = $config->get('protected_domain') ?? FALSE; |
|
|
|
$protectedDomain = $config->get('protected_domain') ?? FALSE; |
|
|
|
|
|
|
|
$uri = $request->getRequestUri(); |
|
|
|
|
|
|
|
|
|
|
|
if (protectedDomain && $this->currentUser->isAuthenticated() && |
|
|
|
// Redirect logged-in users with permission. |
|
|
|
$this->currentUser->hasPermission('access protected domain')) { |
|
|
|
if ($protectedDomain && $this->currentUser->isAuthenticated() && |
|
|
|
|
|
|
|
$this->currentUser->hasPermission('access protected domain')) { |
|
|
|
if ($host !== $protectedDomain) { |
|
|
|
if ($host !== $protectedDomain) { |
|
|
|
$uri = $request->getRequestUri(); |
|
|
|
|
|
|
|
$redirect_url = 'https://' . $protectedDomain . $uri; |
|
|
|
$redirect_url = 'https://' . $protectedDomain . $uri; |
|
|
|
$event->setResponse(new TrustedRedirectResponse($redirect_url, 302)); |
|
|
|
$event->setResponse(new TrustedRedirectResponse($redirect_url, 302)); |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Redirect anonymous users trying to log in via the public domain. |
|
|
|
|
|
|
|
if ($host !== $protectedDomain && $uri === '/user/login') { |
|
|
|
|
|
|
|
$destination = $request->query->get('destination'); |
|
|
|
|
|
|
|
$redirect_url = 'https://' . $protectedDomain . '/user/login'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Preserve destination if it exists. |
|
|
|
|
|
|
|
if ($destination) { |
|
|
|
|
|
|
|
$redirect_url .= '?destination=' . urlencode($destination); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$event->setResponse(new TrustedRedirectResponse($redirect_url, 302)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|