From fa3b6005ce3efa55d58f3903d12634d25b9c9690 Mon Sep 17 00:00:00 2001 From: Reham Muzzamil Date: Fri, 11 Jun 2021 12:50:51 +0500 Subject: [PATCH 1/7] 40 : Add keycloak authenticaon in jpa server starter --- pom.xml | 25 ++++++++++++++++--- .../ca/uhn/fhir/jpa/starter/Application.java | 8 +++++- src/main/resources/application.yaml | 24 ++++++++++++++---- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 765966fd003..880354f8fcd 100644 --- a/pom.xml +++ b/pom.xml @@ -88,7 +88,7 @@ ca.uhn.hapi.fhir hapi-fhir-jpaserver-base - ${project.version} + 5.4.1-PRE5-SNAPSHOT org.springframework @@ -116,17 +116,23 @@ ca.uhn.hapi.fhir hapi-fhir-testpage-overlay - ${project.version} + 5.4.1-PRE5-SNAPSHOT war provided ca.uhn.hapi.fhir hapi-fhir-testpage-overlay - ${project.version} + 5.4.1-PRE5-SNAPSHOT classes + + ca.uhn.hapi.fhir + hapi-fhir-opensrp-security-config + 5.4.0-PRE5-SNAPSHOT + + @@ -314,7 +320,17 @@ - + + + + + + + + + + + @@ -390,6 +406,7 @@ ca.uhn.hapi.fhir hapi-fhir-testpage-overlay + false diff --git a/src/main/java/ca/uhn/fhir/jpa/starter/Application.java b/src/main/java/ca/uhn/fhir/jpa/starter/Application.java index ea46049d161..c2a18a25979 100644 --- a/src/main/java/ca/uhn/fhir/jpa/starter/Application.java +++ b/src/main/java/ca/uhn/fhir/jpa/starter/Application.java @@ -1,5 +1,6 @@ package ca.uhn.fhir.jpa.starter; +import autoconfigure.KeycloakSecurityConfig; import ca.uhn.fhir.jpa.mdm.MdmConfig; import ca.uhn.fhir.jpa.starter.annotations.OnEitherVersion; import ca.uhn.fhir.jpa.subscription.channel.config.SubscriptionChannelConfig; @@ -9,8 +10,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientAutoConfiguration; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; +import org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.boot.web.servlet.ServletRegistrationBean; @@ -25,6 +30,7 @@ JpaRestfulServer.class}) @SpringBootApplication(exclude = {ElasticsearchRestClientAutoConfiguration.class}) @Import({SubscriptionSubmitterConfig.class, SubscriptionProcessorConfig.class, SubscriptionChannelConfig.class, WebsocketDispatcherConfig.class, MdmConfig.class}) +@EnableAutoConfiguration(exclude = {ErrorMvcAutoConfiguration.class}) public class Application extends SpringBootServletInitializer { public static void main(String[] args) { @@ -52,7 +58,7 @@ public ServletRegistrationBean hapiServletRegistration() { JpaRestfulServer jpaRestfulServer = new JpaRestfulServer(); beanFactory.autowireBean(jpaRestfulServer); servletRegistrationBean.setServlet(jpaRestfulServer); - servletRegistrationBean.addUrlMappings("/fhir/*"); + servletRegistrationBean.addUrlMappings("/fhir/rest/*"); servletRegistrationBean.setLoadOnStartup(1); return servletRegistrationBean; diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index a6e23f4407a..638899a248a 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -1,10 +1,12 @@ spring: + main: + allow-bean-definition-overriding: true datasource: - url: 'jdbc:h2:file:./target/database/h2' + url: 'jdbc:postgresql://localhost:5432/hapi_fhir' #url: jdbc:h2:mem:test_mem - username: sa - password: null - driverClassName: org.h2.Driver + username: postgres + password: root + driverClassName: org.postgresql.Driver max-active: 15 # database connection pool size @@ -110,7 +112,7 @@ hapi: tester: home: name: Local Tester - server_address: 'http://localhost:8080/fhir' + server_address: 'http://localhost:8080/fhir/rest' refuse_to_fetch_third_party_urls: false fhir_version: R4 global: @@ -153,3 +155,15 @@ hapi: # protocol: 'http' # schema_management_strategy: CREATE # username: SomeUsername +#security: +# ignored: none +keycloak: + auth-server-url: https://cc3ddc230510.ngrok.io/auth/ + realm: fhir-core + resource: fhir-core-server + credentials: + secret: b7747a19-f72f-4906-8892-8438ce2492be + ssl-required: external +# use-resource-role-mappings: true, +logging.level.org.springframework.web: trace +logging.level.org.apache: trace From 140a4982a4b5728e5224a9da1e90c8d7da2ce431 Mon Sep 17 00:00:00 2001 From: Reham Muzzamil Date: Fri, 11 Jun 2021 13:13:36 +0500 Subject: [PATCH 2/7] Fix import issue --- src/main/java/ca/uhn/fhir/jpa/starter/BaseJpaRestfulServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ca/uhn/fhir/jpa/starter/BaseJpaRestfulServer.java b/src/main/java/ca/uhn/fhir/jpa/starter/BaseJpaRestfulServer.java index 6af80850023..4363245b4a0 100644 --- a/src/main/java/ca/uhn/fhir/jpa/starter/BaseJpaRestfulServer.java +++ b/src/main/java/ca/uhn/fhir/jpa/starter/BaseJpaRestfulServer.java @@ -10,7 +10,7 @@ import ca.uhn.fhir.jpa.api.dao.DaoRegistry; import ca.uhn.fhir.jpa.api.dao.IFhirSystemDao; import ca.uhn.fhir.jpa.binstore.BinaryStorageInterceptor; -import ca.uhn.fhir.jpa.bulk.export.provider.BulkDataExportProvider; +import ca.uhn.fhir.jpa.bulk.provider.BulkDataExportProvider; import ca.uhn.fhir.jpa.interceptor.CascadingDeleteInterceptor; import ca.uhn.fhir.jpa.packages.IPackageInstallerSvc; import ca.uhn.fhir.jpa.packages.PackageInstallationSpec; From 959e4590ae95cd85eefb4681366326851bd8f980 Mon Sep 17 00:00:00 2001 From: Reham Muzzamil Date: Mon, 14 Jun 2021 14:19:45 +0500 Subject: [PATCH 3/7] 40 : Integrate Keycloak for Authentication --- pom.xml | 19 ++++--------------- .../ca/uhn/fhir/jpa/starter/Application.java | 3 --- .../jpa/starter/BaseJpaRestfulServer.java | 2 +- src/main/resources/application.yaml | 2 +- 4 files changed, 6 insertions(+), 20 deletions(-) diff --git a/pom.xml b/pom.xml index 880354f8fcd..e6a3be783d6 100644 --- a/pom.xml +++ b/pom.xml @@ -88,7 +88,7 @@ ca.uhn.hapi.fhir hapi-fhir-jpaserver-base - 5.4.1-PRE5-SNAPSHOT + ${project.version} org.springframework @@ -116,14 +116,14 @@ ca.uhn.hapi.fhir hapi-fhir-testpage-overlay - 5.4.1-PRE5-SNAPSHOT + ${project.version} war provided ca.uhn.hapi.fhir hapi-fhir-testpage-overlay - 5.4.1-PRE5-SNAPSHOT + ${project.version} classes @@ -320,17 +320,7 @@ - - - - - - - - - - - + @@ -406,7 +396,6 @@ ca.uhn.hapi.fhir hapi-fhir-testpage-overlay - false diff --git a/src/main/java/ca/uhn/fhir/jpa/starter/Application.java b/src/main/java/ca/uhn/fhir/jpa/starter/Application.java index c2a18a25979..5f1ad2a8e21 100644 --- a/src/main/java/ca/uhn/fhir/jpa/starter/Application.java +++ b/src/main/java/ca/uhn/fhir/jpa/starter/Application.java @@ -1,6 +1,5 @@ package ca.uhn.fhir.jpa.starter; -import autoconfigure.KeycloakSecurityConfig; import ca.uhn.fhir.jpa.mdm.MdmConfig; import ca.uhn.fhir.jpa.starter.annotations.OnEitherVersion; import ca.uhn.fhir.jpa.subscription.channel.config.SubscriptionChannelConfig; @@ -13,8 +12,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientAutoConfiguration; -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; -import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.ServletComponentScan; diff --git a/src/main/java/ca/uhn/fhir/jpa/starter/BaseJpaRestfulServer.java b/src/main/java/ca/uhn/fhir/jpa/starter/BaseJpaRestfulServer.java index 4363245b4a0..6af80850023 100644 --- a/src/main/java/ca/uhn/fhir/jpa/starter/BaseJpaRestfulServer.java +++ b/src/main/java/ca/uhn/fhir/jpa/starter/BaseJpaRestfulServer.java @@ -10,7 +10,7 @@ import ca.uhn.fhir.jpa.api.dao.DaoRegistry; import ca.uhn.fhir.jpa.api.dao.IFhirSystemDao; import ca.uhn.fhir.jpa.binstore.BinaryStorageInterceptor; -import ca.uhn.fhir.jpa.bulk.provider.BulkDataExportProvider; +import ca.uhn.fhir.jpa.bulk.export.provider.BulkDataExportProvider; import ca.uhn.fhir.jpa.interceptor.CascadingDeleteInterceptor; import ca.uhn.fhir.jpa.packages.IPackageInstallerSvc; import ca.uhn.fhir.jpa.packages.PackageInstallationSpec; diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 638899a248a..34eefb13097 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -158,7 +158,7 @@ hapi: #security: # ignored: none keycloak: - auth-server-url: https://cc3ddc230510.ngrok.io/auth/ + auth-server-url: http://localhost:8180/auth/ realm: fhir-core resource: fhir-core-server credentials: From 7259b632853adc74ae4739d1465ec60efc533110 Mon Sep 17 00:00:00 2001 From: Reham Muzzamil Date: Tue, 15 Jun 2021 16:38:32 +0500 Subject: [PATCH 4/7] 40 : Integrate Keycloak for Authentication --- pom.xml | 2 +- src/main/java/ca/uhn/fhir/jpa/starter/Application.java | 2 +- src/main/resources/application.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index e6a3be783d6..17c2c8a0531 100644 --- a/pom.xml +++ b/pom.xml @@ -130,7 +130,7 @@ ca.uhn.hapi.fhir hapi-fhir-opensrp-security-config - 5.4.0-PRE5-SNAPSHOT + 0.0.1-PRE5-SNAPSHOT + + + + - ca.uhn.hapi.fhir + org.smartregister hapi-fhir-opensrp-security-config - 0.0.1-PRE5-SNAPSHOT + 0.0.1-SNAPSHOT + From 928a9ae376379216a4f42f5633b119e1f72d4280 Mon Sep 17 00:00:00 2001 From: Reham Muzzamil Date: Thu, 17 Jun 2021 19:49:00 +0500 Subject: [PATCH 6/7] Updated dependency of auth package --- pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pom.xml b/pom.xml index c31cf1f164d..bbb9b3d35a3 100644 --- a/pom.xml +++ b/pom.xml @@ -127,18 +127,12 @@ classes - - - - - org.smartregister hapi-fhir-opensrp-security-config 0.0.1-SNAPSHOT - From ac76585cb4915662f8cb1a55636d00ced73faba7 Mon Sep 17 00:00:00 2001 From: Reham Muzzamil Date: Tue, 22 Jun 2021 14:37:48 +0500 Subject: [PATCH 7/7] Updated dependency of auth package --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bbb9b3d35a3..0b2469d3100 100644 --- a/pom.xml +++ b/pom.xml @@ -129,7 +129,7 @@ org.smartregister - hapi-fhir-opensrp-security-config + hapi-fhir-keycloak 0.0.1-SNAPSHOT