Gated content in AEM sets login-cookie which blocks redirection on ACS Commons Redirect Manager | Community
Skip to main content
Level 4
March 13, 2024
Solved

Gated content in AEM sets login-cookie which blocks redirection on ACS Commons Redirect Manager

  • March 13, 2024
  • 1 reply
  • 556 views

Hi guys,

 

I am using ACS Commons Redirect Manager for redirections in AEM.

It is working fine for non-gated pages. But for gated pages the redirection is not happening via ACS Commons Redirect Manager.

 

The issue is due to login-cookie being set as part of the login via POST request to j_security_check.

Removing that cookie sets the redirection correctly but signs us out of the page as well.

 

Is there any way to set the cookie yet allow publish to follow the redirection rules (302) and not let it through (200)?

 

Thanks in advance,

@imran__khan@arunpatidar@aanchal-sikka@estebanbustamante, @sureshdhulipudi 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SureshDhulipudi

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
}

 

1 reply

SureshDhulipudi
Community Advisor
SureshDhulipudiCommunity AdvisorAccepted solution
Community Advisor
March 13, 2024

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
}