diff --git a/pom.xml b/pom.xml index f3d98e3..8cbffa2 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ bio.overture riff - 1.0.2-SNAPSHOT + 1.1.0 jar riff diff --git a/src/main/java/bio/overture/riff/config/RiffConfig.java b/src/main/java/bio/overture/riff/config/RiffConfig.java new file mode 100644 index 0000000..75e0963 --- /dev/null +++ b/src/main/java/bio/overture/riff/config/RiffConfig.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018. The Ontario Institute for Cancer Research. All rights reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package bio.overture.riff.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class RiffConfig { + + @Value("${riff.urlKey}") + private String urlKey; + + public String getUrlKey() { + return urlKey; + } + +} diff --git a/src/main/java/bio/overture/riff/config/WebSecurityConfig.java b/src/main/java/bio/overture/riff/config/WebSecurityConfig.java index 13d4e71..34b0c0a 100644 --- a/src/main/java/bio/overture/riff/config/WebSecurityConfig.java +++ b/src/main/java/bio/overture/riff/config/WebSecurityConfig.java @@ -68,6 +68,8 @@ public void configure(HttpSecurity http) { .authorizeRequests() .antMatchers(HttpMethod.OPTIONS, "/riff/*").permitAll() .antMatchers(HttpMethod.GET, "/riff/*").permitAll() + .antMatchers(HttpMethod.OPTIONS, "/s/*").permitAll() + .antMatchers(HttpMethod.GET, "/s/*").permitAll() .antMatchers("/health").permitAll() .antMatchers("/isAlive").permitAll() .antMatchers("/upload/**").permitAll() diff --git a/src/main/java/bio/overture/riff/controller/RedirectController.java b/src/main/java/bio/overture/riff/controller/RedirectController.java new file mode 100644 index 0000000..20d7ee1 --- /dev/null +++ b/src/main/java/bio/overture/riff/controller/RedirectController.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2018. The Ontario Institute for Cancer Research. All rights reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package bio.overture.riff.controller; + +import bio.overture.riff.config.RiffConfig; +import bio.overture.riff.jwt.JWTFacadeInterface; +import bio.overture.riff.service.RiffService; +import lombok.SneakyThrows; +import lombok.val; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; + +@RestController +@RequestMapping("/s") +public class RedirectController { + + private RiffService service; + private RiffConfig config; + + @Autowired + public RedirectController(RiffService service, RiffConfig config) { + this.service = service; + this.config = config; + } + + @GetMapping("/{id}") + @SneakyThrows + public void handleResolution(HttpServletResponse response, @PathVariable("id") String id) { + val key = config.getUrlKey(); + val riff = service.getRiff(id); + response.sendRedirect(riff.getContent().get(key).toString()); + } + +} diff --git a/src/main/java/bio/overture/riff/controller/RiffController.java b/src/main/java/bio/overture/riff/controller/RiffController.java index ab680fc..cd76505 100644 --- a/src/main/java/bio/overture/riff/controller/RiffController.java +++ b/src/main/java/bio/overture/riff/controller/RiffController.java @@ -17,16 +17,20 @@ package bio.overture.riff.controller; +import bio.overture.riff.config.RiffConfig; import bio.overture.riff.jwt.JWTFacadeInterface; import bio.overture.riff.model.RiffResponse; import bio.overture.riff.model.ShortenRequest; import bio.overture.riff.service.RiffService; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import lombok.val; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException; import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpServletResponse; import java.util.List; @Slf4j @@ -37,6 +41,7 @@ public class RiffController { private JWTFacadeInterface jwtFacade; private RiffService service; + @Autowired public RiffController(JWTFacadeInterface jwtFacade, RiffService service) { this.jwtFacade = jwtFacade; this.service = service; diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 84278fd..bde2856 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -3,7 +3,8 @@ server: auth: jwt: - publicKeyUrl: "https://demo.ego.kfdrc.org/oauth/token/public_key" + # publicKeyUrl: "https://demo.ego.kfdrc.org/oauth/token/public_key" + publicKeyUrl: https://ego.kids-first.io/oauth/token/public_key spring: jpa: @@ -21,11 +22,12 @@ spring: username: postgres password: driver-class-name: org.postgresql.Driver - -spring: flyway: enabled: false +riff: + urlKey: longUrl + --- spring: @@ -51,3 +53,6 @@ spring.datasource: max-active: 1000 max-idle: 10 min-idle: 1 + +riff: + urlKey: longUrl