Commit a7a839af authored by Matija Obreza's avatar Matija Obreza
Browse files

Fixed issues with URL encoded paths

parent 1d1068d2
......@@ -17,9 +17,11 @@
package org.genesys2.server.servlet.controller.admin;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import java.util.UUID;
......@@ -49,6 +51,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springframework.web.util.UriUtils;
@Controller
@RequestMapping(RepositoryController.CONTROLLER_PATH)
......@@ -65,16 +68,22 @@ public class RepositoryController extends BaseController {
private ImageGalleryService imageGalleryService;
@RequestMapping(value = "/files/**", method = RequestMethod.GET)
public String listAllFiles(HttpServletRequest request, ModelMap model) {
public String listAllFiles(HttpServletRequest request, ModelMap model) throws UnsupportedEncodingException {
String fullpath = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
fullpath = fullpath.substring(CONTROLLER_PATH.length() + "/files".length());
// System.err.println(fullpath);
// The /** mapping does not decode the URL
fullpath=UriUtils.decode(fullpath, "UTF-8");
return listAllFiles(fullpath, model);
}
@RequestMapping(value = "/files", method = RequestMethod.GET)
public String listAllFiles(@RequestParam(defaultValue = "/") String repositoryPath, ModelMap model) {
if (LOG.isDebugEnabled()) {
LOG.debug("Listing files for path=" + repositoryPath);
}
List<RepositoryFile> fileList = repositoryService.getFiles(repositoryPath);
model.addAttribute("fileList", fileList);
model.addAttribute("currentPath", repositoryPath);
......
......@@ -34,6 +34,7 @@ import javax.servlet.http.HttpServletResponseWrapper;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.genesys2.spring.config.NewGUIViewResolver;
import org.springframework.web.util.UriUtils;
/**
* The {@code NewGUIFilter} allows for having URL-based versioned user
......@@ -75,6 +76,7 @@ public class NewGUIFilter implements Filter {
final HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
HttpServletResponse httpResponse = (HttpServletResponse) servletResponse;
final String originalUrl = httpRequest.getRequestURI().substring(httpRequest.getContextPath().length());
final String origianlUrlDecoded = UriUtils.decode(originalUrl, "UTF-8");
if (LOG.isTraceEnabled()) {
LOG.trace("Incoming URL: " + originalUrl);
......@@ -95,7 +97,8 @@ public class NewGUIFilter implements Filter {
@Override
public String getServletPath() {
String servletPath = super.getServletPath();
if (originalUrl.equals(servletPath)) {
// servletPath is URL decoded, must use origianlUrlDecoded.
if (origianlUrlDecoded.equals(servletPath)) {
if (LOG.isDebugEnabled())
LOG.debug("servletPath=" + servletPath + " remaining=" + remainingUrl);
return remainingUrl;
......@@ -106,6 +109,7 @@ public class NewGUIFilter implements Filter {
@Override
public String getRequestURI() {
String requestURI = super.getRequestURI();
// requestURI is URL encoded, must use originalUrl.
if (originalUrl.equals(requestURI)) {
if (LOG.isDebugEnabled())
LOG.debug("requestURI=" + requestURI + " remaining=" + remainingUrl);
......
......@@ -143,4 +143,17 @@ public class SpringServletConfig extends WebMvcConfigurerAdapter {
cookieThemeResolver.setDefaultThemeName(defaultThemeName);
return cookieThemeResolver;
}
// @Override
// public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
// configurer.favorPathExtension(false);
// }
//
// /**
// * http://stackoverflow.com/questions/16332092/spring-mvc-pathvariable-with-dot-is-getting-truncated
// */
// @Override
// public void configurePathMatch(PathMatchConfigurer configurer) {
// configurer.setUseSuffixPatternMatch(false);
// }
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment