Expand my Community achievements bar.

SOLVED

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

Avatar

Level 5

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 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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.

 

@service
@component(immediate = true)
public class CustomGatedContentRedirectHandler implements UrlHandler {
@reference
private SlingSettingsService slingSettingsService;

@Override
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.

@component(
service = Filter.class,
property = {
"sling.filter.scope=request",
"service.ranking:Integer=-700"
}
)
public class CustomRedirectFilter implements Filter {
// Implementation goes here
}

 

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

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.

 

@service
@component(immediate = true)
public class CustomGatedContentRedirectHandler implements UrlHandler {
@reference
private SlingSettingsService slingSettingsService;

@Override
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.

@component(
service = Filter.class,
property = {
"sling.filter.scope=request",
"service.ranking:Integer=-700"
}
)
public class CustomRedirectFilter implements Filter {
// Implementation goes here
}