ATEST-224
This commit is contained in:
@ -55,6 +55,8 @@ public class QueryRestConfig extends WebMvcConfigurerAdapter {
|
|||||||
private static final String QUERYREST_DEFAULT_RESPONSE_AGGREGATIONS = "queryrest.default.response.aggregations";
|
private static final String QUERYREST_DEFAULT_RESPONSE_AGGREGATIONS = "queryrest.default.response.aggregations";
|
||||||
|
|
||||||
private static final String QUERYREST_DEFAULT_RESPONSE_FIELDS = "queryrest.default.response.fields";
|
private static final String QUERYREST_DEFAULT_RESPONSE_FIELDS = "queryrest.default.response.fields";
|
||||||
|
private static final String QUERYREST_CORS_ALLOWEDORIGINS = "queryrest.cors.allowedorigins";
|
||||||
|
private static final String QUERYREST_CORS_FORCEALLHEADERS = "queryrest.cors.forceallheaders";
|
||||||
|
|
||||||
// a nested configuration
|
// a nested configuration
|
||||||
// this guarantees that the ordering of the properties file is as expected
|
// this guarantees that the ordering of the properties file is as expected
|
||||||
@ -69,6 +71,8 @@ public class QueryRestConfig extends WebMvcConfigurerAdapter {
|
|||||||
|
|
||||||
public static final String BEAN_NAME_DEFAULT_RESPONSE_FIELDS = "defaultResponseFields";
|
public static final String BEAN_NAME_DEFAULT_RESPONSE_FIELDS = "defaultResponseFields";
|
||||||
public static final String BEAN_NAME_DEFAULT_RESPONSE_AGGREGATIONS = "defaultResponseAggregations";
|
public static final String BEAN_NAME_DEFAULT_RESPONSE_AGGREGATIONS = "defaultResponseAggregations";
|
||||||
|
public static final String BEAN_NAME_CORS_ALLOWEDORIGINS = "corsAllowedorigins";
|
||||||
|
public static final String BEAN_NAME_CORS_FORCEALLHEADERS = "corsForceallheaders";
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private Environment env;
|
private Environment env;
|
||||||
@ -181,4 +185,18 @@ public class QueryRestConfig extends WebMvcConfigurerAdapter {
|
|||||||
public Filter corsFilter() {
|
public Filter corsFilter() {
|
||||||
return new CorsFilter();
|
return new CorsFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean(name = BEAN_NAME_CORS_ALLOWEDORIGINS)
|
||||||
|
public String configuredOrigins(){
|
||||||
|
String value = env.getProperty(QUERYREST_CORS_ALLOWEDORIGINS, "http://localhost:8080, *");
|
||||||
|
LOGGER.debug("Load '{}={}'", QUERYREST_CORS_ALLOWEDORIGINS, value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = BEAN_NAME_CORS_FORCEALLHEADERS)
|
||||||
|
public Boolean forceAllHeaders(){
|
||||||
|
Boolean value = env.getProperty(QUERYREST_CORS_FORCEALLHEADERS, Boolean.class, true);
|
||||||
|
LOGGER.debug("Load '{}={}'", QUERYREST_CORS_FORCEALLHEADERS, value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,23 +6,25 @@ import java.util.Set;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.FilterChain;
|
import javax.servlet.FilterChain;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.web.filter.OncePerRequestFilter;
|
import org.springframework.web.filter.OncePerRequestFilter;
|
||||||
|
|
||||||
|
import ch.psi.daq.queryrest.config.QueryRestConfig;
|
||||||
|
|
||||||
public class CorsFilter extends OncePerRequestFilter {
|
public class CorsFilter extends OncePerRequestFilter {
|
||||||
|
|
||||||
private static final String ALLOW_ORIGIN_HEADER = "Access-Control-Allow-Origin";
|
private static final String ALLOW_ORIGIN_HEADER = "Access-Control-Allow-Origin";
|
||||||
|
|
||||||
@Value("${queryrest.cors.allowedorigins}")
|
@Resource(name = QueryRestConfig.BEAN_NAME_CORS_ALLOWEDORIGINS)
|
||||||
private String configuredOrigins;
|
private String configuredOrigins;
|
||||||
|
|
||||||
@Value("${queryrest.cors.forceallheaders}")
|
@Resource(name = QueryRestConfig.BEAN_NAME_CORS_FORCEALLHEADERS)
|
||||||
private boolean forceAllHeaders;
|
private Boolean forceAllHeaders;
|
||||||
|
|
||||||
private Set<String> allowedOrigins;
|
private Set<String> allowedOrigins;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user