Skip to content

Commit

Permalink
Merge pull request #16 from overture-stack/feature/redirect
Browse files Browse the repository at this point in the history
Short URL Resolution
  • Loading branch information
andricDu authored Aug 28, 2018
2 parents 568b523 + fedbea9 commit 7638897
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<groupId>bio.overture</groupId>
<artifactId>riff</artifactId>
<version>1.0.2-SNAPSHOT</version>
<version>1.1.0</version>
<packaging>jar</packaging>

<name>riff</name>
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/bio/overture/riff/config/RiffConfig.java
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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;
}

}
2 changes: 2 additions & 0 deletions src/main/java/bio/overture/riff/config/WebSecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/bio/overture/riff/controller/RedirectController.java
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -21,11 +22,12 @@ spring:
username: postgres
password:
driver-class-name: org.postgresql.Driver

spring:
flyway:
enabled: false

riff:
urlKey: longUrl

---

spring:
Expand All @@ -51,3 +53,6 @@ spring.datasource:
max-active: 1000
max-idle: 10
min-idle: 1

riff:
urlKey: longUrl

0 comments on commit 7638897

Please sign in to comment.