Skip to content

Commit

Permalink
remove proxy/** endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
onursumer committed Jul 10, 2024
1 parent 766f4f5 commit 7376a09
Showing 1 changed file with 0 additions and 43 deletions.
43 changes: 0 additions & 43 deletions src/main/java/org/cbioportal/proxy/ProxyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.regex.Pattern;

// TODO Consider creating separate DispatcherServlets as in the original web.xml
Expand Down Expand Up @@ -64,33 +63,6 @@ public class ProxyController {

@Value("${darwin.regex:Test}")
private String darwinRegex;


@RequestMapping("/**")
public String proxy(
@RequestBody(required = false) String body,
HttpMethod method,
HttpServletRequest request
) throws URISyntaxException {
HttpHeaders httpHeaders = initHeaders(request);

// TODO when reimplemeting different dispatcherservlets with different context roots
// reset this to 'String requestPathInfo = request.getPathInfo();'
String requestPathInfo = request.getPathInfo() == null? request.getServletPath() : request.getPathInfo();
requestPathInfo = requestPathInfo.replace("proxy/", "");

// only allow known hosts
if (!this.isKnownHost(requestPathInfo)) {
throw new UnknownHostException();
}

return exchangeData(body,
buildUri(requestPathInfo, request.getQueryString(), false),
method,
httpHeaders,
String.class
).getBody();
}

/**
* This dev endpoint can be used (with a personal access token) instead of the production endpoint.
Expand Down Expand Up @@ -213,21 +185,6 @@ private <T> ResponseEntity<T> exchangeData(String body, URI uri, HttpMethod meth
return restTemplate.exchange(uri, method, new HttpEntity<>(body, httpHeaders), responseType);
}

private boolean isKnownHost(String pathInfo) {
String[] knownHosts = {
this.genomeNexusUrl,
this.genomeNexusGrch38Url,
"http://mutationaligner.org/api",
"http://docs.cbioportal.org/news"
};

return Arrays
.stream(knownHosts)
.filter(url -> !url.isEmpty())
.map(url -> "/" + url.replaceFirst("http://", "").replaceFirst("https://", ""))
.anyMatch(pathInfo::startsWith);
}

@ResponseStatus(code = HttpStatus.NOT_FOUND, reason = "OncoKB service is disabled")
public class OncoKBServiceIsDisabledException extends RuntimeException {
}
Expand Down

0 comments on commit 7376a09

Please sign in to comment.