package wendelsilverio.security;

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.HttpServletResponse;

import org.springframework.stereotype.Component;

@Component
public class SimpleCORSFilter implements Filter {

	@Override
	public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {

		HttpServletResponse response = (HttpServletResponse) res;

		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Credentials", "true");
		response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
		response.setHeader("Access-Control-Max-Age", "3600");
		response.setHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With, remember-me");

		chain.doFilter(req, res);
	}

	@Override
	public void init(FilterConfig filterConfig) {
	}

	@Override
	public void destroy() {
	}

}
@@ -278,16 +278,63 @@
 ponse;%0D%0A
+import javax.servlet.http.HttpServletRequest;%0D%0A
 import j
@@ -628,16 +628,74 @@
 on %7B%0D%0A%0D%0A
+%09%09HttpServletRequest request = (HttpServletRequest) req;%0D%0A
 %09%09HttpSe
@@ -747,16 +747,57 @@
 ) res;%0D%0A
+%09%09System.out.println(%22Entrou no filter%22);
 %0D%0A%09%09resp
@@ -846,11 +846,35 @@
 n%22, 
-%22*%22
+request.getHeader(%22Origin%22)
 );%0D%0A

Teste de execução do filter