@@ -0,0 +1,1734 @@
+package slbedu.library.filters;%0D%0A%0D%0Aimport java.io.IOException;%0D%0A%0D%0Aimport javax.inject.Inject;%0D%0Aimport javax.servlet.Filter;%0D%0Aimport javax.servlet.FilterChain;%0D%0Aimport javax.servlet.FilterConfig;%0D%0Aimport javax.servlet.ServletException;%0D%0Aimport javax.servlet.ServletRequest;%0D%0Aimport javax.servlet.ServletResponse;%0D%0Aimport javax.servlet.annotation.WebFilter;%0D%0Aimport javax.servlet.http.HttpServletRequest;%0D%0Aimport javax.servlet.http.HttpServletResponse;%0D%0A%0D%0Aimport slbedu.library.model.User;%0D%0Aimport slbedu.library.services.UserContext;%0D%0A%0D%0A@WebFilter(%22/rest/book/borrow%22)%0D%0Apublic class ProtectedResourcesFilter implements Filter %7B%0D%0A%0D%0A    @Inject%0D%0A    UserContext userContext;%0D%0A%0D%0A    public void init(FilterConfig fConfig) throws ServletException %7B%0D%0A    %7D%0D%0A%0D%0A    public void doFilter(ServletRequest request, ServletResponse response,%0D%0A            FilterChain chain) throws IOException, ServletException %7B%0D%0A        if (!isHttpCall(request, response)) %7B%0D%0A            return;%0D%0A        %7D%0D%0A        HttpServletResponse httpServletResponse = (HttpServletResponse) response;%0D%0A        HttpServletRequest httpServletRequest = (HttpServletRequest) request;%0D%0A        User currentUser = userContext.getCurrentUser();%0D%0A        if (currentUser == null) %7B%0D%0A            String loginUrl = httpServletRequest.getContextPath()%0D%0A                    + %22/login.html%22;%0D%0A            httpServletResponse.sendRedirect(loginUrl);%0D%0A            return;%0D%0A        %7D%0D%0A        chain.doFilter(request, response);%0D%0A    %7D%0D%0A%0D%0A    private boolean isHttpCall(ServletRequest request, ServletResponse response) %7B%0D%0A        return (request instanceof HttpServletRequest)%0D%0A                && (response instanceof HttpServletResponse);%0D%0A    %7D%0D%0A%0D%0A    public void destroy() %7B%0D%0A    %7D%0D%0A%0D%0A%7D

Add web filter for protecting resources