文章標題

缺少X-Frame-Options頭
web.xml

<filter>
    <filter-name>authFilter</filter-name>
    <filter-class>
        com.server.web.filter.AuthFilter</filter-class>
</filter> 

<filter-mapping>
    <filter-name>authFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

AuthFilter.java

package com.server.web.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class AuthFilter implements Filter {
    protected static ApplicationContext ac;

    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain filterChain) throws IOException, ServletException {
        HttpServletResponse res = (HttpServletResponse)response;
        res.addHeader("x-frame-options","SAMEORIGIN"); 

        filterChain.doFilter(request, res);
    }

    public void init(FilterConfig fc) throws ServletException {
        ac = WebApplicationContextUtils.getRequiredWebApplicationContext(fc.getServletContext());
    }

    public void destroy() {

    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章