@Bean public Filter security(){ return new GenericFilterBean() { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest servletRequest = (HttpServletRequest) request; HttpServletResponse servletResponse = (HttpServletResponse) response; if (!servletRequest.getRequestURI().startsWith("/ui/")){ chain.doFilter(request , response); return; } String sessionId = servletRequest.getSession(true).getId(); if (!usersManager.findUserBySessionId(sessionId).isPresent()){ servletResponse.sendError(401); }else{ chain.doFilter(request , response); } } }; }
private GenericFilterBean createFilter() { return new GenericFilterBean() { public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { } }; }
@Bean public FilterRegistrationBean turnOnStackUnderOperationService() { FilterRegistrationBean registration = new FilterRegistrationBean(); registration.setFilter(new GenericFilterBean() { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { stackUnderOperationService.on(); chain.doFilter(request, response); stackUnderOperationService.off(); } }); registration.addUrlPatterns("/*"); return registration; }