Hi Naveen
URL encoding on SAML_REQUEST_PATH cookie helped us resolving the issue,follow below code to implement the same.
package com.mycompany.myproject.impl;
import org.apache.felix.scr.annotations.*;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.auth.core.AuthUtil;
import org.apache.sling.auth.core.spi.AuthenticationInfo;
import org.apache.sling.auth.core.spi.AuthenticationInfoPostProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
@Component(immediate = true, metatype = true)
@Service
public class MyAuthInfoPostProcessor implements
AuthenticationInfoPostProcessor {
private static final String LOGIN_SUFFIX = "/saml_login";
private static final String REQUEST_PATH_COOKIE = "saml_request_path";
private final Logger log = LoggerFactory.getLogger(MyAuthInfoPostProcessor.class);
public void postProcess(AuthenticationInfo authenticationInfo, HttpServletRequest request, HttpServletResponse httpServletResponse) throws LoginException {
final String userID = authenticationInfo.getUser();
if(null !=userID && !userID.equals("anonymous")) {
if (request.getRequestURI().endsWith(LOGIN_SUFFIX)) {
try {
final Cookie[] cookies = request.getCookies();
if (null != cookies) {
for (Cookie cookie : cookies) {
if (REQUEST_PATH_COOKIE.equals(cookie.getName())) {
String url = URLDecoder.decode(cookie.getValue(), "UTF-8");
String loginInitUrl = "/system/sling/login?resource=";
if(url.contains(loginInitUrl)){
url = url.substring(loginInitUrl.length(), url.length());
cookie.setValue(url);
}
}
}
}
} catch (UnsupportedEncodingException e) {
log.error("Unsupported encoding", e);
}
}
}
}
}