From 5f1590d97f2031693444551e7b6099b5ae00a1e3 Mon Sep 17 00:00:00 2001 From: Michal Kit Date: Thu, 25 Jan 2018 15:41:59 +0000 Subject: [PATCH] Cherry picked commit from the release DEV preview branch. This is the fix for the database config not being honoured by doorman (#408) --- docs/source/running-doorman.rst | 2 +- network-management/doorman.conf | 5 +++++ .../networkmanage/doorman/DoormanParameters.kt | 3 ++- .../com/r3/corda/networkmanage/doorman/Main.kt | 16 +++++----------- .../doorman/DoormanParametersTest.kt | 10 ++++------ 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/docs/source/running-doorman.rst b/docs/source/running-doorman.rst index 8bf93f2594..5915c23965 100644 --- a/docs/source/running-doorman.rst +++ b/docs/source/running-doorman.rst @@ -35,7 +35,7 @@ Allowed parameters are: :approveAll: Whether to approve all request (defaults to false), this is for debug only. -:databaseProperties: database properties +:database: database properties. The same (including its default value) as for node configuration (see :doc:`corda-configuration-file`). :dataSourceProperties: datasource properties diff --git a/network-management/doorman.conf b/network-management/doorman.conf index ed58ea2d6f..f4a8b8d18f 100644 --- a/network-management/doorman.conf +++ b/network-management/doorman.conf @@ -12,6 +12,11 @@ dataSourceProperties { "dataSource.user" = sa "dataSource.password" = "" } + +database { + runMigration = true +} + h2port = 0 # Comment out this section if running without doorman service diff --git a/network-management/src/main/kotlin/com/r3/corda/networkmanage/doorman/DoormanParameters.kt b/network-management/src/main/kotlin/com/r3/corda/networkmanage/doorman/DoormanParameters.kt index 0ee3264c50..83cb4a715f 100644 --- a/network-management/src/main/kotlin/com/r3/corda/networkmanage/doorman/DoormanParameters.kt +++ b/network-management/src/main/kotlin/com/r3/corda/networkmanage/doorman/DoormanParameters.kt @@ -7,6 +7,7 @@ import net.corda.core.internal.div import net.corda.core.internal.isRegularFile import net.corda.core.utilities.seconds import net.corda.nodeapi.internal.config.parseAs +import net.corda.nodeapi.internal.persistence.DatabaseConfig import java.nio.file.Path import java.nio.file.Paths import java.util.* @@ -15,7 +16,7 @@ data class NetworkManagementServerParameters(// TODO: Move local signing to sign val host: String, val port: Int, val dataSourceProperties: Properties, - val databaseProperties: Properties? = null, + val database: DatabaseConfig = DatabaseConfig(), val mode: Mode, val doormanConfig: DoormanConfig?, diff --git a/network-management/src/main/kotlin/com/r3/corda/networkmanage/doorman/Main.kt b/network-management/src/main/kotlin/com/r3/corda/networkmanage/doorman/Main.kt index 3b57cf7f0b..ec191b997b 100644 --- a/network-management/src/main/kotlin/com/r3/corda/networkmanage/doorman/Main.kt +++ b/network-management/src/main/kotlin/com/r3/corda/networkmanage/doorman/Main.kt @@ -8,26 +8,20 @@ import com.r3.corda.networkmanage.common.utils.CertPathAndKey import com.r3.corda.networkmanage.common.utils.ShowHelpException import com.r3.corda.networkmanage.doorman.signer.LocalSigner import com.r3.corda.networkmanage.hsm.configuration.Parameters.Companion.DEFAULT_CSR_CERTIFICATE_NAME -import net.corda.core.crypto.Crypto -import net.corda.core.crypto.SignatureScheme -import net.corda.core.identity.CordaX500Name -import net.corda.core.internal.createDirectories -import net.corda.core.internal.div import net.corda.core.serialization.internal.SerializationEnvironmentImpl import net.corda.core.serialization.internal.nodeSerializationEnv import net.corda.core.utilities.NetworkHostAndPort -import net.corda.nodeapi.internal.crypto.* +import net.corda.nodeapi.internal.crypto.getCertificateAndKeyPair +import net.corda.nodeapi.internal.crypto.getSupportedKey +import net.corda.nodeapi.internal.crypto.loadOrCreateKeyStore import net.corda.nodeapi.internal.network.NetworkParameters import net.corda.nodeapi.internal.serialization.AMQP_P2P_CONTEXT import net.corda.nodeapi.internal.serialization.SerializationFactoryImpl import net.corda.nodeapi.internal.serialization.amqp.AMQPClientSerializationScheme import org.bouncycastle.pkcs.PKCS10CertificationRequest -import java.nio.file.Path import java.security.cert.X509Certificate import java.time.Instant -import javax.security.auth.x500.X500Principal import kotlin.concurrent.thread -import kotlin.system.exitProcess data class NetworkMapStartParams(val signer: LocalSigner?, val updateNetworkParameters: NetworkParameters?, val config: NetworkMapConfig) @@ -84,7 +78,7 @@ fun main(args: Array) { caPrivateKeyPassword) Mode.DOORMAN -> { initialiseSerialization() - val database = configureDatabase(dataSourceProperties) + val persistence = configureDatabase(dataSourceProperties, database) // TODO: move signing to signing server. val csrAndNetworkMap = processKeyStore(this) @@ -103,7 +97,7 @@ fun main(args: Array) { NetworkMapStartParams(csrAndNetworkMap?.second, networkParameters, it) } - networkManagementServer.start(NetworkHostAndPort(host, port), database, csrAndNetworkMap?.first, doormanConfig, networkMapStartParams) + networkManagementServer.start(NetworkHostAndPort(host, port), persistence, csrAndNetworkMap?.first, doormanConfig, networkMapStartParams) Runtime.getRuntime().addShutdownHook(thread(start = false) { networkManagementServer.close() diff --git a/network-management/src/test/kotlin/com/r3/corda/networkmanage/doorman/DoormanParametersTest.kt b/network-management/src/test/kotlin/com/r3/corda/networkmanage/doorman/DoormanParametersTest.kt index 473097caa3..be633fa879 100644 --- a/network-management/src/test/kotlin/com/r3/corda/networkmanage/doorman/DoormanParametersTest.kt +++ b/network-management/src/test/kotlin/com/r3/corda/networkmanage/doorman/DoormanParametersTest.kt @@ -10,6 +10,7 @@ import java.lang.reflect.InvocationTargetException import kotlin.test.assertEquals import kotlin.test.assertFailsWith import kotlin.test.assertNull +import kotlin.test.assertTrue class DoormanParametersTest { private val validOverrideNetworkConfigPath = File("network-parameters.conf").absolutePath @@ -48,12 +49,9 @@ class DoormanParametersTest { } @Test - fun `should parse jira config correctly`() { - val parameter = parseParameters(*validArgs).doormanConfig!! - assertEquals("https://doorman-jira-host.com/", parameter.jiraConfig?.address) - assertEquals("TD", parameter.jiraConfig?.projectCode) - assertEquals("username", parameter.jiraConfig?.username) - assertEquals("password", parameter.jiraConfig?.password) + fun `should parse database config correctly`() { + val parameter = parseParameters(*validArgs).database + assertTrue(parameter.runMigration) } @Test