This may require a custom service to handle the Gated content.
In AEM - when dealing Gated content / Login Page with redirects - The ACS Commons Redirect Manager uses Sling's ResourceResolver to resolve the redirect mappings, which doesn't take into account any session or cookie information. This means that if a page is gated and requires a login cookie to access, the Redirect Manager won't be able to resolve the redirect.
Try with Custom OSGi service - which can handle - redirect handler that checks for the login cookie and handles the redirect accordingly.
Create custom OSGi service that implements the com.day.cq.wcm.api.WCMMode.UrlHandler interface and overriding the map(String, HttpServletRequest) method.
@1790552
@8220494(immediate = true)
public class CustomGatedContentRedirectHandler implements UrlHandler {
@3214626
private SlingSettingsService slingSettingsService;
@9944223
public String map(String url, HttpServletRequest request) {
// Check if the request has the login cookie
Cookie[] cookies = request.getCookies();
for (Cookie cookie : cookies) {
if ("login-cookie".equals(cookie.getName())) {
// If the login cookie is present, resolve the redirect using the Redirect Manager
return resolveRedirect(url, request);
}
}
// If the login cookie is not present, fall back to the default behavior
return url;
}
private String resolveRedirect(String url, HttpServletRequest request) {
// Implement this method to resolve the redirect using the Redirect Manager
}
}
Or
Create a Servlet Filter - This filter will intercept all incoming requests and check for the presence of the login cookie.
@8220494(
service = Filter.class,
property = {
"sling.filter.scope=request",
"service.ranking:Integer=-700"
}
)
public class CustomRedirectFilter implements Filter {
// Implementation goes here
}