Skip to content

Commit

Permalink
Merge pull request #94 from srdc/fixed-token-authentication
Browse files Browse the repository at this point in the history
Implement fixed basic token authentication
  • Loading branch information
sinaci authored Sep 1, 2023
2 parents 1a57668 + 17127eb commit 31d29dd
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,10 @@ case class BearerTokenAuthorizationSettings(clientId: String,
* @param password Password for basic authentication
*/
case class BasicAuthenticationSettings(username: String, password: String) extends IFhirRepositorySecuritySettings

/**
* Security settings for FHIR API access via fixed token
*
* @param token The fixed token
*/
case class FixedTokenAuthenticationSettings(token: String) extends IFhirRepositorySecuritySettings
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.tofhir.engine.util

import akka.actor.ActorSystem
import io.onfhir.client.OnFhirNetworkClient
import io.tofhir.engine.model.{BasicAuthenticationSettings, BearerTokenAuthorizationSettings, IFhirRepositorySecuritySettings}
import io.tofhir.engine.model.{BasicAuthenticationSettings, BearerTokenAuthorizationSettings, FixedTokenAuthenticationSettings, IFhirRepositorySecuritySettings}

object FhirClientUtil {
/**
Expand All @@ -18,6 +18,7 @@ object FhirClientUtil {
case BearerTokenAuthorizationSettings(clientId, clientSecret, requiredScopes, authzServerTokenEndpoint, clientAuthenticationMethod) =>
client.withOpenIdBearerTokenAuthentication(clientId, clientSecret, requiredScopes, authzServerTokenEndpoint, clientAuthenticationMethod)
case BasicAuthenticationSettings(username, password) => client.withBasicAuthentication(username, password)
case FixedTokenAuthenticationSettings(token) => client.withFixedBasicTokenAuthentication(token)
}
.getOrElse(client)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.tofhir.engine.util

import io.tofhir.engine.config.ErrorHandlingType
import io.tofhir.engine.model.{BasicAuthenticationSettings, BearerTokenAuthorizationSettings, FhirMappingJob, FhirRepositorySinkSettings, FileSystemSinkSettings, FileSystemSource, FileSystemSourceSettings, KafkaSource, KafkaSourceSettings, LocalFhirTerminologyServiceSettings, SqlSource, SqlSourceSettings}
import io.tofhir.engine.model.{BasicAuthenticationSettings, BearerTokenAuthorizationSettings, FhirMappingJob, FhirRepositorySinkSettings, FileSystemSinkSettings, FileSystemSource, FileSystemSourceSettings, FixedTokenAuthenticationSettings, KafkaSource, KafkaSourceSettings, LocalFhirTerminologyServiceSettings, SqlSource, SqlSourceSettings}
import org.json4s.{Formats, ShortTypeHints}
import org.json4s.ext.EnumNameSerializer
import org.json4s.jackson.Serialization
Expand Down Expand Up @@ -33,6 +33,7 @@ object FhirMappingJobFormatter {
// Authorization types
classOf[BearerTokenAuthorizationSettings],
classOf[BasicAuthenticationSettings],
classOf[FixedTokenAuthenticationSettings],
//Terminology setvices
classOf[LocalFhirTerminologyServiceSettings]
))) +
Expand Down
5 changes: 4 additions & 1 deletion tofhir-server/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fhir = {
# For now, toFHIR can read definitions from a single FHIR endpoint.
definitions-fhir-endpoint = "http://localhost:8081/fhir"
fhir-endpoint-auth = {
# basic | token
# basic | token | fixed-token
# If one of the auth methods is selected, its configurations must be provided as shown below.
method = null

Expand All @@ -83,6 +83,9 @@ fhir = {
# scopes = []
# token-endpoint = "https://onauth.srdc.com.tr"
# }

# # fixed token configurations are used if the auth method is fixed-token
# fixed-token = "XXX"
}

# Path to the zip file or folder that includes the FHIR resource and data type profile definitions (FHIR StructureDefinition) to be served by toFHIR webserver so that mappings can be performed accordingly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FhirDefinitionsConfig(fhirDefinitionsConfig: Config) {
lazy val authTokenClientSecret: Option[String] = Try(fhirDefinitionsConfig.getString("fhir-endpoint-auth.token.client-secret")).toOption
lazy val authTokenScopeList: Option[Seq[String]] = Try(fhirDefinitionsConfig.getStringList("fhir-endpoint-auth.token.scopes").asScala.toSeq).toOption
lazy val authTokenEndpoint: Option[String] = Try(fhirDefinitionsConfig.getString("fhir-endpoint-auth.token.token-endpoint")).toOption

lazy val authFixedToken: Option[String] = Try(fhirDefinitionsConfig.getString("fhir-endpoint-auth.fixed-token")).toOption
/** Path to the zip file or folder that includes the FHIR resource and data type profile definitions (FHIR StructureDefinition) to be served by toFHIR webserver so that mappings can be performed accordingly. */
lazy val profilesPath: Option[String] = Try(fhirDefinitionsConfig.getString("profiles-path")).toOption

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.tofhir.server.fhir
import io.onfhir.api.{FHIR_FOUNDATION_RESOURCES, Resource}
import io.onfhir.client.OnFhirNetworkClient
import io.onfhir.config.{FSConfigReader, IFhirConfigReader}
import io.tofhir.engine.model.{BasicAuthenticationSettings, BearerTokenAuthorizationSettings}
import io.tofhir.engine.model.{BasicAuthenticationSettings, BearerTokenAuthorizationSettings, FixedTokenAuthenticationSettings}
import io.tofhir.engine.util.FhirClientUtil
import io.tofhir.engine.Execution.actorSystem
import actorSystem.dispatcher
Expand Down Expand Up @@ -43,6 +43,12 @@ class FhirEndpointResourceReader(fhirDefinitionsConfig: FhirDefinitionsConfig) e
}
FhirClientUtil.createOnFhirClient(fhirDefinitionsConfig.definitionsFHIREndpoint.get,
Some(BearerTokenAuthorizationSettings(fhirDefinitionsConfig.authTokenClientId.get, fhirDefinitionsConfig.authTokenClientSecret.get, fhirDefinitionsConfig.authTokenScopeList.get, fhirDefinitionsConfig.authTokenEndpoint.get)))
case FhirAuthMethod.FIXED_TOKEN =>
if (fhirDefinitionsConfig.authFixedToken.isEmpty) {
throw new IllegalArgumentException("For fixed token authentication, a token must be provided!")
}
FhirClientUtil.createOnFhirClient(fhirDefinitionsConfig.definitionsFHIREndpoint.get,
Some(FixedTokenAuthenticationSettings(fhirDefinitionsConfig.authFixedToken.get)))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ package object fhir {
type FhirAuthMethod = Value
final val BASIC = Value("basic")
final val BEARER_TOKEN = Value("token")
final val FIXED_TOKEN = Value("fixed-token")
}
}
5 changes: 4 additions & 1 deletion tofhir-server/src/test/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fhir = {
# For now, toFHIR can read definitions from a single FHIR endpoint.
definitions-fhir-endpoint = null
fhir-endpoint-auth = {
# basic | token
# basic | token | fixed-token
# If one of the auth methods is selected, its configurations must be provided as shown below.
method = null

Expand All @@ -79,6 +79,9 @@ fhir = {
# scopes = []
# token-endpoint = "https://onauth.srdc.com.tr"
# }

# # fixed token configurations are used if the auth method is fixed-token
# fixed-token = "XXX"
}

# Path to the zip file or folder that includes the FHIR resource and data type profile definitions (FHIR StructureDefinition) to be served by toFHIR webserver so that mappings can be performed accordingly.
Expand Down

0 comments on commit 31d29dd

Please sign in to comment.