package org.mifosng.platform.filters;

import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;

import com.sun.jersey.spi.container.ContainerRequest;
import com.sun.jersey.spi.container.ContainerResponse;
import com.sun.jersey.spi.container.ContainerResponseFilter;

/**
 * General approach to turn back-end capabilities exposed through resource-oriented API as Cross-Origin-Request complaint.
 */
public class ResponseCorsFilter implements ContainerResponseFilter {

	@Override
	public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {

		ResponseBuilder resp = Response.fromResponse(response.getResponse());
		
		resp.header("Access-Control-Allow-Origin", "*").header("Access-Control-Expose-Headers", "X-Mifos-Platform-TenantId").header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");

		String reqHead = request.getHeaderValue("Access-Control-Request-Headers");

		if (null != reqHead && !reqHead.equals(null)) {
			resp.header("Access-Control-Allow-Headers", reqHead);
		}

		response.setResponse(resp.build());
		
		return response;
	}
}
@@ -299,95 +299,67 @@
 %0A * 
-General approach to turn back-end capabilities ex
+Filter that returns a res
 po
+n
 se
-d through resource-oriented API as
+ with headers that allows for
  Cro
@@ -371,26 +371,65 @@
 igin
--
+ 
 Request
- complaint
+s (CORs) to be performed against the platform API
 .%0A *
@@ -725,16 +725,21 @@
 n%22, %22*%22)
+%0A//%09%09
 .header(
@@ -799,16 +799,19 @@
 nantId%22)
+%0A%09%09
 .header(

update comments