class CorsDomainResponseFilter implements ContainerResponseFilter {

    @Override
    public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
            throws IOException {

        final String origin = requestContext.getHeaderString("Origin");

        if (originMatchUtil.matches(origin)) {

            MultivaluedMap<String, Object> headers = responseContext.getHeaders();

            headers.add("Access-Control-Allow-Origin", origin);
            headers.add("Access-Control-Allow-Credentials", String.valueOf(corsConfig.getAllowCredentials()));
            headers.add("Access-Control-Allow-Methods", String.join(",", corsConfig.getAllowedMethods()));

            final String allowedHeaders;
            if (corsConfig.getAllowedHeaders() != null) {
                allowedHeaders = String.join(",", corsConfig.getAllowedHeaders());
            } else {
                allowedHeaders = requestContext.getHeaderString("Access-Control-Request-Headers");
            }

            headers.add("Access-Control-Allow-Headers", allowedHeaders);
        }
    }

    public  CorsDomainResponseFilter(CrossDomainConfig corsConfig);

}