CORS moved to domain project (to be used in dispatcherrest and
queryrest), buildship / gradle wrapper upgrades
This commit is contained in:
27
.classpath
27
.classpath
@ -1,27 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="FROM_GRADLE_MODEL" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="FROM_GRADLE_MODEL" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="FROM_GRADLE_MODEL" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="FROM_GRADLE_MODEL" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="src" path="src/main/java"/>
|
||||
<classpathentry kind="src" path="src/main/resources"/>
|
||||
<classpathentry kind="src" path="src/test/java"/>
|
||||
<classpathentry kind="src" path="src/test/resources"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
|
||||
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
|
||||
<classpathentry exported="true" kind="con" path="org.springsource.ide.eclipse.gradle.classpathcontainer"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
13
.project
13
.project
@ -5,21 +5,11 @@
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.springframework.ide.eclipse.core.springbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||
<arguments>
|
||||
@ -27,10 +17,7 @@
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.springframework.ide.eclipse.core.springnature</nature>
|
||||
<nature>org.springsource.ide.eclipse.gradle.core.nature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
@ -51,6 +51,10 @@ uploadArchives {
|
||||
}
|
||||
}
|
||||
|
||||
task dropIt(dependsOn: build) << {
|
||||
exec{ executable "curl"; args "-X", "POST", "-F", "file=@build/libs/ch.psi.daq.queryrest-" + version + ".jar", "https://dropit.psi.ch/upload"; }
|
||||
|
||||
task dropIt(dependsOn: build) {
|
||||
doLast {
|
||||
exec{ executable "curl"; args "-X", "POST", "-F", "file=@build/libs/ch.psi.daq.queryrest-" + version + ".jar", "https://dropit.psi.ch/upload"; }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@ import com.fasterxml.jackson.dataformat.smile.SmileFactory;
|
||||
|
||||
import ch.psi.daq.common.statistic.Statistics;
|
||||
import ch.psi.daq.domain.DataEvent;
|
||||
import ch.psi.daq.domain.config.DomainConfigCORS;
|
||||
import ch.psi.daq.domain.query.backend.BackendQuery;
|
||||
import ch.psi.daq.domain.query.backend.analyzer.BackendQueryAnalyzer;
|
||||
import ch.psi.daq.domain.query.operation.Aggregation;
|
||||
@ -53,7 +54,7 @@ import ch.psi.daq.queryrest.response.smile.SmileResponseStreamWriter;
|
||||
import ch.psi.daq.queryrest.response.smile.SmileTableResponseStreamWriter;
|
||||
|
||||
@Configuration
|
||||
@Import(value = QueryRestConfigCORS.class)
|
||||
@Import(value = DomainConfigCORS.class)
|
||||
@PropertySource(value = {"classpath:queryrest.properties"})
|
||||
@PropertySource(value = {"file:${user.home}/.config/daq/queryrest.properties"}, ignoreResourceNotFound = true)
|
||||
public class QueryRestConfig extends WebMvcConfigurerAdapter {
|
||||
@ -61,8 +62,6 @@ public class QueryRestConfig extends WebMvcConfigurerAdapter {
|
||||
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_CORS_ALLOWEDORIGINS = "queryrest.cors.allowedorigins";
|
||||
private static final String QUERYREST_CORS_FORCEALLHEADERS = "queryrest.cors.forceallheaders";
|
||||
|
||||
// a nested configuration
|
||||
// this guarantees that the ordering of the properties file is as expected
|
||||
@ -82,8 +81,8 @@ public class QueryRestConfig extends WebMvcConfigurerAdapter {
|
||||
|
||||
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_CORS_ALLOWEDORIGINS = "corsAllowedorigins";
|
||||
public static final String BEAN_NAME_CORS_FORCEALLHEADERS = "corsForceallheaders";
|
||||
// public static final String BEAN_NAME_CORS_ALLOWEDORIGINS = "corsAllowedorigins";
|
||||
// public static final String BEAN_NAME_CORS_FORCEALLHEADERS = "corsForceallheaders";
|
||||
|
||||
@Resource
|
||||
private Environment env;
|
||||
@ -224,18 +223,4 @@ public class QueryRestConfig extends WebMvcConfigurerAdapter {
|
||||
public Validator queryValidator() {
|
||||
return new QueryValidator();
|
||||
}
|
||||
|
||||
@Bean(name = BEAN_NAME_CORS_ALLOWEDORIGINS)
|
||||
public String allowedOrigins() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1,69 +0,0 @@
|
||||
package ch.psi.daq.queryrest.config;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
|
||||
@Configuration
|
||||
@PropertySource(value = {"classpath:queryrest.properties"})
|
||||
@PropertySource(value = {"file:${user.home}/.config/daq/queryrest.properties"}, ignoreResourceNotFound = true)
|
||||
public class QueryRestConfigCORS extends WebMvcConfigurerAdapter {
|
||||
|
||||
@Resource
|
||||
private Environment env;
|
||||
|
||||
@Resource(name = QueryRestConfig.BEAN_NAME_CORS_ALLOWEDORIGINS)
|
||||
private String configuredOrigins;
|
||||
|
||||
@Resource(name = QueryRestConfig.BEAN_NAME_CORS_FORCEALLHEADERS)
|
||||
private Boolean forceAllHeaders;
|
||||
|
||||
private String[] allowedOrigins;
|
||||
|
||||
@PostConstruct
|
||||
public void afterPropertiesSet() {
|
||||
Set<String> origs = Arrays.stream(configuredOrigins.split(",")).map(s -> s.trim()).collect(Collectors.toSet());
|
||||
allowedOrigins = origs.toArray(new String[origs.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
|
||||
boolean corsEnabled = Boolean.valueOf(env.getProperty("queryrest.cors.enable", "false"));
|
||||
boolean forceAll = Boolean.valueOf(env.getProperty("queryrest.cors.forceallheaders", "false"));
|
||||
|
||||
if (corsEnabled) {
|
||||
|
||||
if (forceAll) {
|
||||
registry
|
||||
.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
|
||||
.allowedHeaders("Origin", "Accept", "X-Requested-With", "Content-Type", "Access-Control-Request-Method",
|
||||
"Access-Control-Request-Headers")
|
||||
.allowCredentials(true)
|
||||
.maxAge(1800);
|
||||
} else if (!forceAll) {
|
||||
// see https://spring.io/blog/2015/06/08/cors-support-in-spring-framework
|
||||
registry
|
||||
.addMapping("/**")
|
||||
.allowedOrigins(allowedOrigins)
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
|
||||
.allowedHeaders("Origin", "Accept", "X-Requested-With", "Content-Type", "Access-Control-Request-Method",
|
||||
"Access-Control-Request-Headers")
|
||||
.allowCredentials(true)
|
||||
.maxAge(1800);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,15 +4,3 @@ queryrest.default.response.fields=channel,backend,pulseId,globalSeconds,iocSecon
|
||||
|
||||
# aggregation which are included in the response by default if aggregation is enabled for a given query
|
||||
queryrest.default.response.aggregations=min,mean,max
|
||||
|
||||
# enables / disables the CORS servlet filter. Adds multiple CORS headers to the response
|
||||
queryrest.cors.enable=true
|
||||
|
||||
# Includes the CORS headers no matter what request or preflight was sent. If an Origin header is set, this header will be used.
|
||||
# If no Origin header is set, '*' will be used.
|
||||
queryrest.cors.forceallheaders=false
|
||||
|
||||
# Defines the allowed origins for CORS requests. Only relevant if queryrest.enableCORS==true (see above).
|
||||
# If this is set to '*', then all requests are allowed, from any source. If it's set to, say, http://ui-data-api.psi.ch, then only requests
|
||||
# originating from that domain (Origin header set to that value) will be allowed. Otherwise a 403 error will be returned.
|
||||
queryrest.cors.allowedorigins=*
|
||||
|
Reference in New Issue
Block a user