From aa04be49ed261c1a2b623c90cdeca857f9bbe6a7 Mon Sep 17 00:00:00 2001 From: kameshsr Date: Fri, 25 Oct 2024 19:02:57 +0530 Subject: [PATCH] MOSIP-31576 Fixed ida automation issue Signed-off-by: kameshsr --- .../config/TrailingSlashRedirectFilter.java | 65 ------------------- 1 file changed, 65 deletions(-) delete mode 100644 authentication/authentication-internal-service/src/main/java/io/mosip/authentication/internal/service/config/TrailingSlashRedirectFilter.java diff --git a/authentication/authentication-internal-service/src/main/java/io/mosip/authentication/internal/service/config/TrailingSlashRedirectFilter.java b/authentication/authentication-internal-service/src/main/java/io/mosip/authentication/internal/service/config/TrailingSlashRedirectFilter.java deleted file mode 100644 index 26c85f9012..0000000000 --- a/authentication/authentication-internal-service/src/main/java/io/mosip/authentication/internal/service/config/TrailingSlashRedirectFilter.java +++ /dev/null @@ -1,65 +0,0 @@ -package io.mosip.authentication.internal.service.config; - -import java.io.IOException; - -import io.mosip.authentication.core.dto.ObjectWithMetadata; -import jakarta.servlet.Filter; -import jakarta.servlet.FilterChain; -import jakarta.servlet.ServletException; -import jakarta.servlet.ServletRequest; -import jakarta.servlet.ServletResponse; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletRequestWrapper; -import org.springframework.stereotype.Component; - -@Component -public class TrailingSlashRedirectFilter implements Filter { - - @Override - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) - throws IOException, ServletException { - - HttpServletRequest httpRequest = (HttpServletRequest) request; - String path = httpRequest.getRequestURI(); - - // Check if request is of type ObjectWithMetadata, preserve it unchanged - if (request instanceof ObjectWithMetadata) { - // Continue with the filter chain, pass the original request unchanged - chain.doFilter(request, response); - return; - } - - // For other types of requests, handle the trailing slash redirection - if (path.endsWith("/")) { - String newPath = path.substring(0, path.length() - 1); - HttpServletRequest newRequest = new CustomHttpServletRequestWrapper(httpRequest, newPath); - chain.doFilter(newRequest, response); - } else { - chain.doFilter(request, response); - } - } - - // Custom wrapper to modify request URI without altering original request structure - private static class CustomHttpServletRequestWrapper extends HttpServletRequestWrapper { - - private final String newPath; - - public CustomHttpServletRequestWrapper(HttpServletRequest request, String newPath) { - super(request); - this.newPath = newPath; - } - - @Override - public String getRequestURI() { - return newPath; - } - - @Override - public StringBuffer getRequestURL() { - StringBuffer url = new StringBuffer(); - url.append(getScheme()).append("://").append(getServerName()).append(":").append(getServerPort()) - .append(newPath); - return url; - } - } -}