RedirectCookieService redirectCookieService = (RedirectCookieService) container
.getComponentInstanceOfType(RedirectCookieService.class);
// Determine the URL for the site so we can use this for the cookie path
PortalURLContext urlContext = new PortalURLContext(context, SiteKey.portal(origin.getName()));
NodeURL url = urlFactory.newURL(NodeURL.TYPE, urlContext);
String path = url.setResource(new NavigationResource(SiteType.PORTAL, origin.getName(), "")).toString();
// We have to check for the '/' at the end of the path since the portal could be accessed under /portal/classic or
// /portal/classic/
// Removing the tailing slash means both urls will see the cookie.
if (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}
Cookie redirectCookie = redirectCookieService.createCookie(origin.getName(), redirect, path);
response.addCookie(redirectCookie);
// In order to make sure we don't create an infinite redirect loop, we should update the cookie for the redirect site to
// specify that site is the prefered site and no redirect should be performed
if (redirect.getType() != RedirectType.NOREDIRECT && redirect.getRedirect() != null) {
// Determine the URL for the redirect site so we can use this for the cookie path
String redirectPath = url.setResource(new NavigationResource(SiteType.PORTAL, redirect.getRedirect(), ""))
.toString();
// We have to check for the '/' at the end of the path since the portal could be accessed under /portal/classic or
// /portal/classic/
// Removing the tailing slash means both urls will see the cookie.
if (redirectPath.endsWith("/")) {