package com.systelab.seed.infrastructure.security;

import javax.servlet.annotation.WebFilter;
import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebFilter("/*")
public class XFrameOptionsFilter implements Filter {

    public XFrameOptionsFilter() {
    }

    public void init(FilterConfig fConfig) throws ServletException {
    }

    public void destroy() {
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        if (response instanceof HttpServletResponse) {
            HttpServletResponse httpResponse = (HttpServletResponse) response;
            httpResponse.addHeader("X-Frame-Options", "deny");
        }
        chain.doFilter(request, response);
    }
}
Add X-Frame-Options HTTP response header and set it to deny to reduce the risk of a clickjacking attack.