From dc6ae735aa1014d3d07c048b0983d57db4eaebc4 Mon Sep 17 00:00:00 2001 From: Berend Weel Date: Wed, 15 Aug 2018 16:37:47 +0200 Subject: [PATCH] Updated way output folder is hosted --- .../config/TargetAdaptorConfig.java | 15 ------- .../computeservice/rest/Application.java | 42 ++++++++++++++----- .../service/staging/XenonStager.java | 4 +- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/main/java/nl/esciencecenter/computeservice/config/TargetAdaptorConfig.java b/src/main/java/nl/esciencecenter/computeservice/config/TargetAdaptorConfig.java index 3dfa299..876b35e 100644 --- a/src/main/java/nl/esciencecenter/computeservice/config/TargetAdaptorConfig.java +++ b/src/main/java/nl/esciencecenter/computeservice/config/TargetAdaptorConfig.java @@ -1,7 +1,5 @@ package nl.esciencecenter.computeservice.config; -import javax.validation.constraints.NotNull; - import com.fasterxml.jackson.annotation.JsonProperty; import nl.esciencecenter.xenon.credentials.Credential; @@ -21,19 +19,6 @@ public TargetAdaptorConfig(Credential credential) { super(credential); } - @NotNull - public String getBaseurl() { - return baseurl; - } - - public void setBaseurl(String baseurl) { - if (baseurl == null) { - this.baseurl = "output"; - } else { - this.baseurl = baseurl; - } - } - public boolean isHosted() { return hosted; } diff --git a/src/main/java/nl/esciencecenter/computeservice/rest/Application.java b/src/main/java/nl/esciencecenter/computeservice/rest/Application.java index c138a2b..c706798 100644 --- a/src/main/java/nl/esciencecenter/computeservice/rest/Application.java +++ b/src/main/java/nl/esciencecenter/computeservice/rest/Application.java @@ -33,6 +33,7 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; import org.springframework.transaction.annotation.EnableTransactionManagement; +import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -74,11 +75,15 @@ public class Application extends WebSecurityConfigurerAdapter implements WebMvcC @Value("${xenonflow.admin.location}") private String adminLocation; + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**"); + } + @Override protected void configure(HttpSecurity httpSecurity) throws Exception { APIKeyAuthFilter filter = new APIKeyAuthFilter(principalRequestHeader); filter.setAuthenticationManager(new AuthenticationManager() { - @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String principal = (String) authentication.getPrincipal(); @@ -102,10 +107,18 @@ public Authentication authenticate(Authentication authentication) throws Authent .antMatchers(HttpMethod.HEAD,"/jobs/**").permitAll() //allow CORS option calls .antMatchers(HttpMethod.OPTIONS,"/files/**").permitAll()//allow CORS option calls .antMatchers(HttpMethod.HEAD,"/files/**").permitAll() //allow CORS option calls + .antMatchers(HttpMethod.OPTIONS,"/output/**").permitAll()//allow CORS option calls + .antMatchers(HttpMethod.HEAD,"/output/**").permitAll() //allow CORS option calls + .antMatchers(HttpMethod.OPTIONS,"/status/**").permitAll()//allow CORS option calls + .antMatchers(HttpMethod.HEAD,"/status/**").permitAll() //allow CORS option calls .antMatchers("/jobs").authenticated() + .antMatchers("/jobs/**").authenticated() .antMatchers("/files").authenticated() .antMatchers("/files/**").authenticated() - .antMatchers("/jobs/**").authenticated() + .antMatchers("/output").authenticated() + .antMatchers("/output/**").authenticated() + .antMatchers("/status").authenticated() + .antMatchers("/status/**").authenticated() .antMatchers("/**").permitAll(); } @@ -132,8 +145,8 @@ public static XenonStager remoteToTargetStager(XenonService xenonService, JobRep return new XenonStager(jobService, repository, xenonService.getRemoteFileSystem(), xenonService.getTargetFileSystem(), xenonService); } - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { + @Bean + public TargetAdaptorConfig targetFileSystemConfig() { String xenonflowHome = System.getenv("XENONFLOW_HOME"); if (xenonflowHome == null) { @@ -142,16 +155,23 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) { ComputeServiceConfig config; try { config = ComputeServiceConfig.loadFromFile(xenonConfigFile, xenonflowHome); - TargetAdaptorConfig targetConfig = config.getTargetFilesystemConfig(); - - if (targetConfig.isHosted() && targetConfig.getAdaptor().equals("file")) { - String resourceLocation = targetConfig.getBaseurl() + "/**"; - logger.info("Adding resource location handler for: " + resourceLocation); - registry.addResourceHandler(resourceLocation).addResourceLocations("file:" + targetConfig.getLocation()); - } + return config.getTargetFilesystemConfig(); } catch (IOException e) { e.printStackTrace(); } + return null; + } + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + TargetAdaptorConfig targetConfig = targetFileSystemConfig(); + if (targetConfig.isHosted() && targetConfig.getAdaptor().equals("file")) { + String resourceLocation = "/output/**"; + logger.info("Adding resource location handler for: " + resourceLocation); + registry.addResourceHandler(resourceLocation) + .addResourceLocations("file:" + targetConfig.getLocation()); + } + registry.addResourceHandler("/swagger/**") .addResourceLocations("classpath:/META-INF/resources/"); diff --git a/src/main/java/nl/esciencecenter/computeservice/service/staging/XenonStager.java b/src/main/java/nl/esciencecenter/computeservice/service/staging/XenonStager.java index 62d40d6..5a73511 100644 --- a/src/main/java/nl/esciencecenter/computeservice/service/staging/XenonStager.java +++ b/src/main/java/nl/esciencecenter/computeservice/service/staging/XenonStager.java @@ -312,7 +312,7 @@ public WorkflowBinding postStageout(Job job, StagingManifest manifest) throws IO UriComponentsBuilder b; if (service.getConfig().getTargetFilesystemConfig().isHosted()) { b = UriComponentsBuilder.fromUriString(manifest.getBaseurl()); - b.pathSegment(service.getConfig().getTargetFilesystemConfig().getBaseurl()); + b.pathSegment("output/"); b.pathSegment(manifest.getTargetDirectory().resolve(object.getTargetPath()).toString()); } else { b = UriComponentsBuilder.fromUriString(targetFileSystem.getLocation().toString()); @@ -391,7 +391,7 @@ public void fixDirectoryStagingObject(Job job, StagingManifest manifest, UriComponentsBuilder b; if (service.getConfig().getTargetFilesystemConfig().isHosted()) { b = UriComponentsBuilder.fromUriString(manifest.getBaseurl()); - b.pathSegment(service.getConfig().getTargetFilesystemConfig().getBaseurl()); + b.pathSegment("output/"); b.pathSegment(manifest.getTargetDirectory().resolve(object.getTargetPath()).toString()); } else { b = UriComponentsBuilder.fromUriString(targetFileSystem.getLocation().toString());