How can i enable a CORS in Spring Security label i.e. in token url. I am using spring security 3.1 and spring mvc 4.3.12. I have successfully generated a token to secure API but can't enable CORS in token url.
I have used the following code for generating access token
spring-security.xml
<http pattern="/oauth/token" create-session="stateless"
authentication-manager-ref="clientAuthenticationManager"
xmlns="http://www.springframework.org/schema/security">
<intercept-url pattern="/oauth/token" access="IS_AUTHENTICATED_FULLY" />
<anonymous enabled="false" />
<http-basic entry-point-ref="clientAuthenticationEntryPoint" />
<!-- include this only if you need to authenticate clients via request
parameters -->
<custom-filter ref="clientCredentialsTokenEndpointFilter"
after="BASIC_AUTH_FILTER" />
<access-denied-handler ref="oauthAccessDeniedHandler" />
</http>
And this is how i have enabled a CORS but doesn't work
dispatcher-servlet.xml
<mvc:cors>
<mvc:mapping path="/oauth/token" allowed-origins="http://localhost:4200"
allowed-methods="GET" allowed-headers="Access-Control-Allow-Origin" />
</mvc:cors>
And this is the error that i got
login:1 Failed to load http://localhost:8080/M.S.-Handloom-Fabrics/oauth/token?grant_type=password&client_id=restapp&client_secret=restapp&username=nishan&password=nishan: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 400.