Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - Access-Control-Allow-Origin Multiple Origin Domains?

So I have read through the other threads regarding this and have not found a solution.

The problem Im having is because im setting "access-control-allow-methods" "true" I cant use setHeader("Access-Control-Allow-Origin", "*");

I need to set two specific domains...any help is appreciated.

like image 270
Doc Holiday Avatar asked Aug 16 '16 20:08

Doc Holiday


People also ask

Can you have multiple Access-Control allow origin?

More than one Access-Control-Allow-Origin header was sent by the server. This isn't allowed.

How do I set Access-Control allow origin in Java?

1.1. Access-Control-Allow-Origin : specifies the authorized domains to make cross-domain request. Use “*” as value if there is no restrictions. Access-Control-Allow-Credentials : specifies if cross-domain requests can have authorization credentials or not.

How do I turn on all Access-Control allow origin?

Limiting the possible Access-Control-Allow-Origin values to a set of allowed origins requires code on the server side to check the value of the Origin request header, compare that to a list of allowed origins, and then if the Origin value is in the list, set the Access-Control-Allow-Origin value to the same value as ...


1 Answers

public class CorsInterceptor implements ContainerResponseFilter {
    @Override
    public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
            throws IOException {
        //When we send the http-only cookie the 'Access-Control-Allow-Origin' header cannot be *
        responseContext.getHeaders().putSingle("Access-Control-Allow-Origin", requestContext.getHeaderString("origin"));
    }
}
like image 61
Jose Boretto Blengino Avatar answered Oct 13 '22 09:10

Jose Boretto Blengino