Commit 5a2c2f71 authored by Administrator's avatar Administrator

Adds CORS configuration to the REST API

The REST API now supports cross-origin requests thanks to a new CORS
configuration.
parent 6bbdf414
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<groupId>es.uvigo.esei.daa</groupId> <groupId>es.uvigo.esei.daa</groupId>
<artifactId>example</artifactId> <artifactId>example</artifactId>
<packaging>war</packaging> <packaging>war</packaging>
<version>0.1.12</version> <version>0.1.13</version>
<name>DAA Example</name> <name>DAA Example</name>
<licenses> <licenses>
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1"> version="3.1">
<display-name>DAAExample</display-name> <display-name>DAAExample</display-name>
<welcome-file-list> <welcome-file-list>
<welcome-file>index.html</welcome-file> <welcome-file>index.html</welcome-file>
</welcome-file-list> </welcome-file-list>
<security-constraint> <filter>
<web-resource-collection> <filter-name>CorsFilter</filter-name>
<web-resource-name>Protected Area</web-resource-name> <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<url-pattern>/rest/*</url-pattern> <init-param>
<http-method>PUT</http-method> <param-name>cors.allowed.origins</param-name>
<http-method>DELETE</http-method> <param-value>*</param-value>
<http-method>GET</http-method> </init-param>
<http-method>POST</http-method> <init-param>
<http-method>OPTIONS</http-method> <param-name>cors.allowed.headers</param-name>
</web-resource-collection> <param-value>Authorization</param-value>
<auth-constraint> </init-param>
<role-name>ADMIN</role-name> <init-param>
<role-name>USER</role-name> <param-name>cors.allowed.methods</param-name>
</auth-constraint> <param-value>GET, POST, DELETE, PUT</param-value>
</security-constraint> </init-param>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/rest/*</url-pattern>
</filter-mapping>
<security-constraint> <security-constraint>
<web-resource-collection> <web-resource-collection>
<web-resource-name>Admin Area</web-resource-name> <web-resource-name>Protected Area</web-resource-name>
<url-pattern>/rest/people/*</url-pattern> <url-pattern>/rest/*</url-pattern>
<http-method>PUT</http-method> <http-method>PUT</http-method>
<http-method>DELETE</http-method> <http-method>DELETE</http-method>
<http-method>GET</http-method> <http-method>GET</http-method>
<http-method>POST</http-method> <http-method>POST</http-method>
<http-method>OPTIONS</http-method> </web-resource-collection>
</web-resource-collection> <auth-constraint>
<auth-constraint> <role-name>ADMIN</role-name>
<role-name>ADMIN</role-name> <role-name>USER</role-name>
</auth-constraint> </auth-constraint>
</security-constraint> </security-constraint>
<!-- Security roles referenced by this web application --> <security-constraint>
<security-role> <web-resource-collection>
<role-name>ADMIN</role-name> <web-resource-name>Admin Area</web-resource-name>
</security-role> <url-pattern>/rest/people/*</url-pattern>
<security-role> <http-method>GET</http-method>
<role-name>USER</role-name> <http-method>PUT</http-method>
</security-role> <http-method>DELETE</http-method>
<http-method>POST</http-method>
<login-config> </web-resource-collection>
<auth-method>BASIC</auth-method> <auth-constraint>
<realm-name>DAAExample</realm-name> <role-name>ADMIN</role-name>
</login-config> </auth-constraint>
</security-constraint>
<!-- Security roles referenced by this web application -->
<security-role>
<role-name>ADMIN</role-name>
</security-role>
<security-role>
<role-name>USER</role-name>
</security-role>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>DAAExample</realm-name>
</login-config>
</web-app> </web-app>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment