Loading .gitignore 0 → 100644 +34 −0 Original line number Diff line number Diff line HELP.md target/ !.mvn/wrapper/maven-wrapper.jar !**/src/main/**/target/ !**/src/test/**/target/ ### STS ### .apt_generated .classpath .factorypath .project .settings .springBeans .sts4-cache ### IntelliJ IDEA ### .idea *.iws *.iml *.ipr ### NetBeans ### /nbproject/private/ /nbbuild/ /dist/ /nbdist/ /.nb-gradle/ build/ !**/src/main/**/build/ !**/src/test/**/build/ nbactions.xml ### VS Code ### .vscode/ README.md 0 → 100644 +5 −0 Original line number Diff line number Diff line # File service for VOSpace This service queries the same database used by VOSpace (`file_catalog`). It provides functionalities for downloading and uploading files. pom.xml 0 → 100644 +70 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.6.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>it.inaf.ia2</groupId> <artifactId>vospace-file-service</artifactId> <version>0.0.1-SNAPSHOT</version> <name>vospace-file-service</name> <description>VOSpace File service</description> <properties> <java.version>14</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>${project.groupId}</groupId> <artifactId>rap-client</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> src/main/java/it/inaf/ia2/transfer/FileServiceApplication.java 0 → 100644 +36 −0 Original line number Diff line number Diff line package it.inaf.ia2.transfer; import it.inaf.ia2.aa.jwt.JwksClient; import it.inaf.ia2.aa.jwt.TokenParser; import it.inaf.ia2.transfer.auth.TokenFilter; import java.net.URI; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; @SpringBootApplication public class FileServiceApplication { @Value("${jwks_uri}") private String jwksUri; public static void main(String[] args) { SpringApplication.run(FileServiceApplication.class, args); } @Bean public TokenParser tokenParser() { JwksClient jwksClient = new JwksClient(URI.create(jwksUri)); return new TokenParser(jwksClient); } @Bean public FilterRegistrationBean tokenFilterRegistration(TokenParser tokenParser) { FilterRegistrationBean registration = new FilterRegistrationBean(); registration.setFilter(new TokenFilter(tokenParser)); registration.addUrlPatterns("/*"); return registration; } } src/main/java/it/inaf/ia2/transfer/auth/GmsClient.java 0 → 100644 +48 −0 Original line number Diff line number Diff line package it.inaf.ia2.transfer.auth; import java.util.Collections; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.annotation.Cacheable; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; @Component public class GmsClient { @Value("${gms_base_url}") private String gmsBaseUrl; private final RestTemplate restTemplate; @Autowired public GmsClient() { restTemplate = new RestTemplate(); } @Cacheable("gms_cache") public boolean isMemberOf(String token, String group) { String url = gmsBaseUrl + "/vo/search/" + group; String gmsResponse = restTemplate.exchange(url, HttpMethod.GET, getEntity(token), String.class).getBody(); if (gmsResponse == null) { return false; } return group.equals(gmsResponse.replace("\n", "")); } private <T> HttpEntity<T> getEntity(String token) { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.TEXT_PLAIN)); headers.add("Authorization", "Bearer " + token); return new HttpEntity<>(null, headers); } } Loading
.gitignore 0 → 100644 +34 −0 Original line number Diff line number Diff line HELP.md target/ !.mvn/wrapper/maven-wrapper.jar !**/src/main/**/target/ !**/src/test/**/target/ ### STS ### .apt_generated .classpath .factorypath .project .settings .springBeans .sts4-cache ### IntelliJ IDEA ### .idea *.iws *.iml *.ipr ### NetBeans ### /nbproject/private/ /nbbuild/ /dist/ /nbdist/ /.nb-gradle/ build/ !**/src/main/**/build/ !**/src/test/**/build/ nbactions.xml ### VS Code ### .vscode/
README.md 0 → 100644 +5 −0 Original line number Diff line number Diff line # File service for VOSpace This service queries the same database used by VOSpace (`file_catalog`). It provides functionalities for downloading and uploading files.
pom.xml 0 → 100644 +70 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.6.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>it.inaf.ia2</groupId> <artifactId>vospace-file-service</artifactId> <version>0.0.1-SNAPSHOT</version> <name>vospace-file-service</name> <description>VOSpace File service</description> <properties> <java.version>14</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>${project.groupId}</groupId> <artifactId>rap-client</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
src/main/java/it/inaf/ia2/transfer/FileServiceApplication.java 0 → 100644 +36 −0 Original line number Diff line number Diff line package it.inaf.ia2.transfer; import it.inaf.ia2.aa.jwt.JwksClient; import it.inaf.ia2.aa.jwt.TokenParser; import it.inaf.ia2.transfer.auth.TokenFilter; import java.net.URI; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; @SpringBootApplication public class FileServiceApplication { @Value("${jwks_uri}") private String jwksUri; public static void main(String[] args) { SpringApplication.run(FileServiceApplication.class, args); } @Bean public TokenParser tokenParser() { JwksClient jwksClient = new JwksClient(URI.create(jwksUri)); return new TokenParser(jwksClient); } @Bean public FilterRegistrationBean tokenFilterRegistration(TokenParser tokenParser) { FilterRegistrationBean registration = new FilterRegistrationBean(); registration.setFilter(new TokenFilter(tokenParser)); registration.addUrlPatterns("/*"); return registration; } }
src/main/java/it/inaf/ia2/transfer/auth/GmsClient.java 0 → 100644 +48 −0 Original line number Diff line number Diff line package it.inaf.ia2.transfer.auth; import java.util.Collections; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.annotation.Cacheable; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; @Component public class GmsClient { @Value("${gms_base_url}") private String gmsBaseUrl; private final RestTemplate restTemplate; @Autowired public GmsClient() { restTemplate = new RestTemplate(); } @Cacheable("gms_cache") public boolean isMemberOf(String token, String group) { String url = gmsBaseUrl + "/vo/search/" + group; String gmsResponse = restTemplate.exchange(url, HttpMethod.GET, getEntity(token), String.class).getBody(); if (gmsResponse == null) { return false; } return group.equals(gmsResponse.replace("\n", "")); } private <T> HttpEntity<T> getEntity(String token) { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.TEXT_PLAIN)); headers.add("Authorization", "Bearer " + token); return new HttpEntity<>(null, headers); } }