Tag Archives: cors

Spring security and Cors with angularjs

I used this as the basis of what I was doing with cors and angularjs.

Cors and Angularjs

I ran into the problem that I was also using Spring Security.

In my web.xml originally my cors filter was included after the spring security filter.

This stopped my filter from being called and returning the correct headers.

 

I corrected it by moving the cors filter above the security filter like below.

 

<filter>
        <filter-name>corsFilter</filter-name>
        <filter-class>com.myproject.config.CorsFilter</filter-class>
    </filter>

<filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

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

    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
Advertisements