Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/ca/uhn/fhir/jpa/starter/AppProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import ca.uhn.fhir.jpa.model.entity.NormalizedQuantitySearchLevel;
import ca.uhn.fhir.rest.api.EncodingEnum;
import com.google.common.collect.ImmutableList;
import org.hl7.davinci.ehrserver.ClientAuthorizationInterceptor;
import org.hl7.fhir.r4.model.Bundle;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
Expand Down Expand Up @@ -73,6 +75,11 @@ public class AppProperties {
private Boolean use_apache_address_strategy = false;
private Boolean use_apache_address_strategy_https = false;

@Bean
public ClientAuthorizationInterceptor clientAuthorizationInterceptor(){
return new ClientAuthorizationInterceptor();
}

public Boolean getUse_apache_address_strategy() {
return use_apache_address_strategy;
}
Expand Down
24 changes: 20 additions & 4 deletions src/main/java/ca/uhn/fhir/jpa/starter/BaseJpaRestfulServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@
import org.hl7.davinci.ehrserver.ServerConformanceR4;
import org.hl7.davinci.ehrserver.interceptor.OrderIdentifierAdditionInterceptor;
import org.hl7.davinci.ehrserver.interceptor.QuestionnaireResponseSearchParameterInterceptor;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Bundle.BundleType;
import org.hl7.fhir.r4.model.Meta;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpHeaders;
import org.springframework.web.cors.CorsConfiguration;

Expand All @@ -64,6 +67,7 @@
import java.util.stream.Collectors;



public class BaseJpaRestfulServer extends RestfulServer {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseJpaRestfulServer.class);

Expand Down Expand Up @@ -102,6 +106,10 @@ public class BaseJpaRestfulServer extends RestfulServer {
AppProperties appProperties;
@Autowired
ApplicationContext myApplicationContext;

@Autowired
ClientAuthorizationInterceptor interceptor;

@Autowired(required = false)
IRepositoryValidationInterceptorFactory factory;
// These are set only if the features are enabled
Expand Down Expand Up @@ -159,8 +167,9 @@ protected void initialize() throws ServletException {
setServerConformanceProvider(confProvider);
} else if (fhirVersion == FhirVersionEnum.R4) {

JpaCapabilityStatementProvider confProvider = new ServerConformanceR4(this, fhirSystemDao,
JpaCapabilityStatementProvider confProvider = createConformance(this, fhirSystemDao,
daoConfig, searchParamRegistry, myValidationSupport);

confProvider.setImplementationDescription("HAPI FHIR R4 Server");
setServerConformanceProvider(confProvider);
} else if (fhirVersion == FhirVersionEnum.R5) {
Expand Down Expand Up @@ -232,9 +241,7 @@ protected void initialize() throws ServletException {
loggingInterceptor.setErrorMessageFormat(appProperties.getLogger().getError_format());
loggingInterceptor.setLogExceptions(appProperties.getLogger().getLog_exceptions());
this.registerInterceptor(loggingInterceptor);

ClientAuthorizationInterceptor clientAuthorizationInterceptor = new ClientAuthorizationInterceptor();
this.registerInterceptor(clientAuthorizationInterceptor);
this.registerInterceptor(interceptor);


// import interceptor for adding order identifier
Expand Down Expand Up @@ -404,4 +411,13 @@ protected void initialize() throws ServletException {

daoConfig.getModelConfig().setIndexOnContainedResources(appProperties.getEnable_index_contained_resource());
}

@Bean
private ServerConformanceR4 createConformance(RestfulServer theRestfulServer, IFhirSystemDao<Bundle, Meta> theSystemDao, DaoConfig theDaoConfig, ISearchParamRegistry theSearchParamRegistry, IValidationSupport theValidationSupport){
ServerConformanceR4 con = new ServerConformanceR4(theRestfulServer, theSystemDao,
theDaoConfig, theSearchParamRegistry, theValidationSupport);
// this isnt autowiring so force it.
myApplicationContext.getAutowireCapableBeanFactory().autowireBean(con);
return con;
}
}
7 changes: 4 additions & 3 deletions src/main/java/ca/uhn/fhir/jpa/starter/JpaRestfulServer.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package ca.uhn.fhir.jpa.starter;

import org.hl7.davinci.ehrserver.Config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpHeaders;

import javax.servlet.ServletException;
Expand All @@ -14,10 +14,11 @@

@Import(AppProperties.class)
public class JpaRestfulServer extends BaseJpaRestfulServer {

@Autowired
AppProperties appProperties;

@Autowired
Environment env;
private static final long serialVersionUID = 1L;
static final Logger logger = LoggerFactory.getLogger(JpaRestfulServer.class);

Expand All @@ -26,7 +27,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)

if (request.getRequestURI().contains("/_services/smart/Launch")) {
// redirect calls to /_services/smart/Launch to the root /_services/smart/Launch
String redirectUrl = Config.get("redirect_post_launch");
String redirectUrl = env.getProperty("redirect_post_launch");
logger.info("JpaRestfulServer::doPost: redirect " + request.getRequestURI() + " to " + redirectUrl);
response.setHeader("Location", redirectUrl);
response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, String.join(", ", appProperties.getCors().getAllowed_origin()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,24 @@
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("ConstantConditions")
@Component
public class ClientAuthorizationInterceptor extends AuthorizationInterceptor {

String introspectUrl = "http://localhost:8180/auth/realms/"
+ Config.get("realm") + "/protocol/openid-connect/token/introspect";
@Autowired
private org.springframework.core.env.Environment environment;

@Override
public List<IAuthRule> buildRuleList(RequestDetails theRequestDetails) {
String useOauth = Config.get("use_oauth");
String useOauth = environment.getProperty("use_oauth");
if (!Boolean.parseBoolean(useOauth)) {
return new RuleBuilder()
.allowAll()
Expand All @@ -47,10 +50,10 @@ public List<IAuthRule> buildRuleList(RequestDetails theRequestDetails) {
}

String token = authHeader.split(" ")[1];
String secret = Config.get("client_secret");
String clientId = Config.get("client_id");
String secret = environment.getProperty("client_secret");
String clientId = environment.getProperty("client_id");

HttpPost httpPost = new HttpPost(introspectUrl);
HttpPost httpPost = new HttpPost(environment.getProperty("introspect_url"));
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("client_id", clientId));
params.add(new BasicNameValuePair("client_secret", secret));
Expand Down
93 changes: 0 additions & 93 deletions src/main/java/org/hl7/davinci/ehrserver/Config.java

This file was deleted.

11 changes: 7 additions & 4 deletions src/main/java/org/hl7/davinci/ehrserver/ServerConformanceR4.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
import org.hl7.fhir.r4.model.Extension;
import org.hl7.fhir.r4.model.Meta;
import org.hl7.fhir.r4.model.UriType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;


@Component
public class ServerConformanceR4 extends JpaCapabilityStatementProvider {

@Autowired
private org.springframework.core.env.Environment env;
public ServerConformanceR4(RestfulServer theRestfulServer, IFhirSystemDao<Bundle, Meta> theSystemDao, DaoConfig theDaoConfig, ISearchParamRegistry theSearchParamRegistry, IValidationSupport theValidationSupport) {
super(theRestfulServer, theSystemDao, theDaoConfig, theSearchParamRegistry, theValidationSupport);
}
Expand All @@ -28,10 +31,10 @@ public CapabilityStatement getServerConformance(HttpServletRequest theRequest, R
securityExtension.setUrl("http://fhir-registry.smarthealthit.org/StructureDefinition/oauth-uris");
securityExtension.addExtension()
.setUrl("authorize")
.setValue(new UriType(Config.get("proxy_authorize")));
.setValue(new UriType(env.getProperty("proxy_authorize")));
securityExtension.addExtension()
.setUrl("token")
.setValue(new UriType(Config.get("proxy_token")));
.setValue(new UriType(env.getProperty("proxy_token")));
CapabilityStatement.CapabilityStatementRestSecurityComponent securityComponent = new CapabilityStatement.CapabilityStatementRestSecurityComponent();
securityComponent.setCors(true);
securityComponent
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/org/hl7/davinci/ehrserver/authproxy/AuthProxy.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.hl7.davinci.ehrserver.authproxy;

import org.hl7.davinci.ehrserver.Config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -30,12 +29,13 @@

@RestController
public class AuthProxy {

static final Logger logger = LoggerFactory.getLogger(AuthProxy.class);

@Autowired

private PayloadDAOImpl payloadDAO;


@Autowired
private org.springframework.core.env.Environment environment;
/**
* Proxies the auth request, which returns the auth code. The proxy changes the redirect url to
* a different endpoint which will save the returned code and associate it with the launch id
Expand All @@ -49,7 +49,7 @@ public class AuthProxy {
public void getAuth(@RequestParam Map<String, String> reqParamValue, HttpServletResponse httpServletResponse, HttpServletRequest request) throws IOException {
//
String params = _parseRedirect(reqParamValue, request);
UriComponentsBuilder forwardUrl = UriComponentsBuilder.fromHttpUrl(Config.get("oauth_authorize"));
UriComponentsBuilder forwardUrl = UriComponentsBuilder.fromHttpUrl(environment.getProperty("oauth_authorize"));
String redirectUrl = forwardUrl.toUriString() + params;
logger.info("redirectUrl: " + redirectUrl);
httpServletResponse.setHeader("Location", redirectUrl);
Expand Down Expand Up @@ -82,7 +82,7 @@ public ResponseEntity<TokenResponse> getToken(TokenRequest body) {

RestTemplate restTemplate = new RestTemplate();
try {
ResponseEntity<TokenResponse> response = restTemplate.postForEntity(Config.get("oauth_token"), request, TokenResponse.class);
ResponseEntity<TokenResponse> response = restTemplate.postForEntity(environment.getProperty("oauth_token"), request, TokenResponse.class);
Objects.requireNonNull(response.getBody())
.setPatient(payload.getPatient())
.setAppContext(payload.getAppContext());
Expand Down Expand Up @@ -143,9 +143,12 @@ public void authSync(@PathVariable String launch, @RequestParam Map<String, Stri
*/
private String _parseRedirect(Map<String, String> reqParamValue, HttpServletRequest request) {
String currentRedirectURI = reqParamValue.get("redirect_uri");
String finalRedirectURI = "http://" + ((System.getenv("DOCKER_PROFILE") != null && (System.getenv("DOCKER_PROFILE").equals("docker-linux") || System.getenv("DOCKER_PROFILE").equals("docker-windows"))) && Config.get("auth_redirect_host") != null ? Config.get("auth_redirect_host") : request.getLocalName()) + ":" + request.getLocalPort() + "/test-ehr/_auth/" + reqParamValue.get("launch") + "?redirect_uri=" + currentRedirectURI;
String finalRedirectURI = environment.getProperty("redirect_base")
+ reqParamValue.get("launch")
+ "?redirect_uri=" + currentRedirectURI;
reqParamValue.put("redirect_uri", finalRedirectURI);
payloadDAO.updateRedirect(reqParamValue.get("launch"), finalRedirectURI);

return paramFormatter(reqParamValue);
}

Expand Down
14 changes: 14 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,17 @@ hapi:
# protocol: 'http'
# schema_management_strategy: CREATE
# username: SomeUsername
auth_base: http://localhost:8180/auth/realms/ClientFhirServer/protocol/openid-connect
ehr_base: http://localhost:8080/test-ehr
client_id: app-token
client_secret: #replaceMe#
realm: ClientFhirServer
use_oauth: false
oauth_token: ${auth_base}/token
oauth_authorize: ${auth_base}/auth
proxy_authorize: ${ehr_base}/auth
proxy_token: ${ehr_base}/token
redirect_post_launch: ${ehr_base}/_services/smart/Launch
redirect_post_token: ${ehr_base}/token
introspection_url: ${auth_base}/token/introspect
redirect_base: ${ehr_base}/_auth/
11 changes: 0 additions & 11 deletions src/main/resources/fhirServer.docker-windows.properties

This file was deleted.

11 changes: 0 additions & 11 deletions src/main/resources/fhirServer.docker.properties

This file was deleted.

Loading