@Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
        HttpSession session = ((HttpServletRequest) servletRequest).getSession(false);
        String requestedUri = ((HttpServletRequest) servletRequest).getRequestURI();

        if ((session == null || session.getAttribute(Constants.AUTH_KEY) == null)
                && (requestedUri.contains("home") || requestedUri.contains("logout"))) {
            ((HttpServletResponse) servletResponse).sendRedirect("/login");
        } else if (session != null && session.getAttribute(Constants.AUTH_KEY) != null
                && (requestedUri.contains("login") || requestedUri.contains("register"))) {
            ((HttpServletResponse) servletResponse).sendRedirect("home");
        } else {
            chain.doFilter(servletRequest, servletResponse);
        }
    }