title: CORS problems with spring boot security
body: <p>I use spring boot, spring security and want to avoid any cors actions. Im trying  the second answer from here (<a href="https://stackoverflow.com/questions/44697883/can-you-completely-disable-cors-support-in-spring">Can you completely disable CORS support in Spring?</a>) where I need to add custom filter to cors, here is the filter:</p>
  
  <pre><code>@Component
  public class CorsFilter extends OncePerRequestFilter {
  
      @Override
      protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response,
                                      final FilterChain filterChain) throws ServletException, IOException {
  
          response.addHeader("Access-Control-Allow-Origin", "*");
          response.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT, PATCH, HEAD");
          response.addHeader("Access-Control-Allow-Headers", "Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers");
          response.addHeader("Access-Control-Expose-Headers", "Access-Control-Allow-Origin, Access-Control-Allow-Credentials");
          response.addHeader("Access-Control-Allow-Credentials", "true");
          response.addIntHeader("Access-Control-Max-Age", 10);
          filterChain.doFilter(request, response);
      }
  }
  </code></pre>
  
  <p>So Ive created the class insert there CorsFilter and I got the mistake:</p>
  
  <pre><code>'springSecurityFilterChain' threw exception; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'corsFilter' is expected to be of type 'org.springframework.web.filter.CorsFilter' but was actually of type 'fa.backend.core.security.CorsFilter'
  </code></pre>
  
  <p>My security configuration looks like this:</p>
  
  <pre><code> @Override
      protected void configure(HttpSecurity http) throws Exception {
          http.cors().and().antMatcher("/users").authorizeRequests()
                  .antMatchers(HttpMethod.POST, "/login").permitAll()
                  .and()
                  .addFilterBefore(
                          new JWTLoginFilter(tokenAuthentication, authenticationManagerBean()),
                          UsernamePasswordAuthenticationFilter.class)
                  .addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
      }
  </code></pre>
  
  <p>Could you tell me how to fix it? My aim is to disable any cors actions, because from frontend I recieve:</p>
  
  <pre><code>No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8081' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
  </code></pre>