@Test public void testDoFilterWithUserNameInUri() throws Exception { expect(userRelatedRequest.getRequestURI()).andReturn("/test/users/testUserName/test1").anyTimes(); filterChain.doFilter(same(userRelatedRequest), same(response)); expectLastCall(); replayAll(); filter.doFilter(userRelatedRequest, response, filterChain); verifyAll(); }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest) { final HttpServletRequest httpServletRequest = (HttpServletRequest) request; Matcher userNameMatcher = getUserNameMatcher(httpServletRequest.getRequestURI()); if (userNameMatcher.find()) { String userNameFromUri = URLDecoder.decode(userNameMatcher.group("username"), "UTF-8"); final String userName = AuthorizationHelper.resolveLoginAliasToUserName(userNameFromUri); if (!userNameFromUri.equals(userName)) { final String requestUriOverride = String.format("%s%s%s", userNameMatcher.group("pre"), userName, userNameMatcher.group("post")); request = new HttpServletRequestWrapper(httpServletRequest) { @Override public String getRequestURI() { return requestUriOverride; } }; } } } chain.doFilter(request, response); }
UserNameOverrideFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest) { final HttpServletRequest httpServletRequest = (HttpServletRequest) request; Matcher userNameMatcher = getUserNameMatcher(httpServletRequest.getRequestURI()); if (userNameMatcher.find()) { String userNameFromUri = URLDecoder.decode(userNameMatcher.group("username"), "UTF-8"); final String userName = AuthorizationHelper.resolveLoginAliasToUserName(userNameFromUri); if (!userNameFromUri.equals(userName)) { final String requestUriOverride = String.format("%s%s%s", userNameMatcher.group("pre"), userName, userNameMatcher.group("post")); request = new HttpServletRequestWrapper(httpServletRequest) { @Override public String getRequestURI() { return requestUriOverride; } }; } } } chain.doFilter(request, response); } }
UserNameOverrideFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest) { final HttpServletRequest httpServletRequest = (HttpServletRequest) request; Matcher userNameMatcher = getUserNameMatcher(httpServletRequest.getRequestURI()); if (userNameMatcher.find()) { String userNameFromUri = URLDecoder.decode(userNameMatcher.group("username"), "UTF-8"); final String userName = AuthorizationHelper.resolveLoginAliasToUserName(userNameFromUri); if (!userNameFromUri.equals(userName)) { final String requestUriOverride = String.format("%s%s%s", userNameMatcher.group("pre"), userName, userNameMatcher.group("post")); request = new HttpServletRequestWrapper(httpServletRequest) { @Override public String getRequestURI() { return requestUriOverride; } }; } } } chain.doFilter(request, response); }  }
UserNameOverrideFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest) { final HttpServletRequest httpServletRequest = (HttpServletRequest) request; Matcher userNameMatcher = getUserNameMatcher(httpServletRequest.getRequestURI()); if (userNameMatcher.find()) { String userNameFromUri = URLDecoder.decode(userNameMatcher.group("username"), "UTF-8"); final String userName = AuthorizationHelper.resolveLoginAliasToUserName(userNameFromUri); if (!userNameFromUri.equals(userName)) { final String requestUriOverride = String.format("%s%s%s", userNameMatcher.group("pre"), userName, userNameMatcher.group("post")); request = new HttpServletRequestWrapper(httpServletRequest) { @Override public String getRequestURI() { return requestUriOverride; } }; } } } chain.doFilter(request, response); }  @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void destroy(); }
UserNameOverrideFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest) { final HttpServletRequest httpServletRequest = (HttpServletRequest) request; Matcher userNameMatcher = getUserNameMatcher(httpServletRequest.getRequestURI()); if (userNameMatcher.find()) { String userNameFromUri = URLDecoder.decode(userNameMatcher.group("username"), "UTF-8"); final String userName = AuthorizationHelper.resolveLoginAliasToUserName(userNameFromUri); if (!userNameFromUri.equals(userName)) { final String requestUriOverride = String.format("%s%s%s", userNameMatcher.group("pre"), userName, userNameMatcher.group("post")); request = new HttpServletRequestWrapper(httpServletRequest) { @Override public String getRequestURI() { return requestUriOverride; } }; } } } chain.doFilter(request, response); }  @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void destroy();  }