@Test @WithMockUser(username = "user") void testDoFilterIgnoreOwnUri() throws IOException, ServletException { request.setRequestURI("/account/password/change"); filter.doFilter(request, response, chain); verify(chain).doFilter(request, response); }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication instanceof UsernamePasswordAuthenticationToken && authentication.isAuthenticated() && !authentication.getName().equals(ANONYMOUS_USERNAME) && !httpRequest.getRequestURI().equalsIgnoreCase(CHANGE_PASSWORD_URI)) { User user = userService.getUser(authentication.getName()); if (user == null) { throw new RuntimeException("Unknown username [" + authentication.getName() + "]"); } if (user.isChangePassword() != null && user.isChangePassword()) { redirectStrategy.sendRedirect(httpRequest, httpResponse, CHANGE_PASSWORD_URI); return; } } chain.doFilter(request, response); }
MolgenisChangePasswordFilter extends GenericFilterBean { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication instanceof UsernamePasswordAuthenticationToken && authentication.isAuthenticated() && !authentication.getName().equals(ANONYMOUS_USERNAME) && !httpRequest.getRequestURI().equalsIgnoreCase(CHANGE_PASSWORD_URI)) { User user = userService.getUser(authentication.getName()); if (user == null) { throw new RuntimeException("Unknown username [" + authentication.getName() + "]"); } if (user.isChangePassword() != null && user.isChangePassword()) { redirectStrategy.sendRedirect(httpRequest, httpResponse, CHANGE_PASSWORD_URI); return; } } chain.doFilter(request, response); } }
MolgenisChangePasswordFilter extends GenericFilterBean { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication instanceof UsernamePasswordAuthenticationToken && authentication.isAuthenticated() && !authentication.getName().equals(ANONYMOUS_USERNAME) && !httpRequest.getRequestURI().equalsIgnoreCase(CHANGE_PASSWORD_URI)) { User user = userService.getUser(authentication.getName()); if (user == null) { throw new RuntimeException("Unknown username [" + authentication.getName() + "]"); } if (user.isChangePassword() != null && user.isChangePassword()) { redirectStrategy.sendRedirect(httpRequest, httpResponse, CHANGE_PASSWORD_URI); return; } } chain.doFilter(request, response); } MolgenisChangePasswordFilter(UserService userService, RedirectStrategy redirectStrategy); }
MolgenisChangePasswordFilter extends GenericFilterBean { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication instanceof UsernamePasswordAuthenticationToken && authentication.isAuthenticated() && !authentication.getName().equals(ANONYMOUS_USERNAME) && !httpRequest.getRequestURI().equalsIgnoreCase(CHANGE_PASSWORD_URI)) { User user = userService.getUser(authentication.getName()); if (user == null) { throw new RuntimeException("Unknown username [" + authentication.getName() + "]"); } if (user.isChangePassword() != null && user.isChangePassword()) { redirectStrategy.sendRedirect(httpRequest, httpResponse, CHANGE_PASSWORD_URI); return; } } chain.doFilter(request, response); } MolgenisChangePasswordFilter(UserService userService, RedirectStrategy redirectStrategy); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); }
MolgenisChangePasswordFilter extends GenericFilterBean { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication instanceof UsernamePasswordAuthenticationToken && authentication.isAuthenticated() && !authentication.getName().equals(ANONYMOUS_USERNAME) && !httpRequest.getRequestURI().equalsIgnoreCase(CHANGE_PASSWORD_URI)) { User user = userService.getUser(authentication.getName()); if (user == null) { throw new RuntimeException("Unknown username [" + authentication.getName() + "]"); } if (user.isChangePassword() != null && user.isChangePassword()) { redirectStrategy.sendRedirect(httpRequest, httpResponse, CHANGE_PASSWORD_URI); return; } } chain.doFilter(request, response); } MolgenisChangePasswordFilter(UserService userService, RedirectStrategy redirectStrategy); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain);  }