From c7487a869685dec0147e0b676ba58f85d9d2443e Mon Sep 17 00:00:00 2001 From: szymonsztuka Date: Tue, 9 Jan 2018 18:25:54 +0000 Subject: [PATCH] Enable deserialisation for certain package from Oracle database drivers. (#298) * Oracle database drivers ojdbc7.jar and ojdbc8.jar use deserialisation which is disabled by the default in Corda. Added an Oracle package to serialFilter when the node uses Oracle database. --- .../persistence/HibernateConfiguration.kt | 5 ++++- .../kotlin/net/corda/node/internal/NodeStartup.kt | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/persistence/HibernateConfiguration.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/persistence/HibernateConfiguration.kt index da84b91749..336f5298e2 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/persistence/HibernateConfiguration.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/persistence/HibernateConfiguration.kt @@ -173,4 +173,7 @@ class HibernateConfiguration( return "corda-wrapper-binary" } } -} \ No newline at end of file +} + +/** Allow Oracle database drivers ojdbc7.jar and ojdbc8.jar to deserialize classes from oracle.sql.converter package. */ +fun oracleJdbcDriverSerialFilter(clazz: Class<*>) : Boolean = clazz.name.startsWith("oracle.sql.converter.") diff --git a/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt b/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt index a1dde93b70..aaf202a751 100644 --- a/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt +++ b/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt @@ -13,6 +13,7 @@ import net.corda.node.shell.InteractiveShell import net.corda.node.utilities.registration.HTTPNetworkRegistrationService import net.corda.node.utilities.registration.NetworkRegistrationHelper import net.corda.nodeapi.internal.addShutdownHook +import net.corda.nodeapi.internal.persistence.oracleJdbcDriverSerialFilter import org.fusesource.jansi.Ansi import org.fusesource.jansi.AnsiConsole import org.slf4j.bridge.SLF4JBridgeHandler @@ -201,7 +202,19 @@ open class NodeStartup(val args: Array) { open protected fun loadConfigFile(cmdlineOptions: CmdLineOptions): NodeConfiguration = cmdlineOptions.loadConfig() open protected fun banJavaSerialisation(conf: NodeConfiguration) { - SerialFilter.install(if (conf.notary?.bftSMaRt != null) ::bftSMaRtSerialFilter else ::defaultSerialFilter) + val isOracleDbDriver = conf.dataSourceProperties.getProperty("dataSource.url", "").startsWith("jdbc:oracle:") + val filter = + if (conf.notary?.bftSMaRt != null && isOracleDbDriver) { + val bftAndOracleSerialFilter: (Class<*>) -> Boolean = { clazz -> bftSMaRtSerialFilter(clazz) || oracleJdbcDriverSerialFilter(clazz) } + bftAndOracleSerialFilter + } else if (conf.notary?.bftSMaRt != null) { + ::bftSMaRtSerialFilter + } else if (isOracleDbDriver) { + ::oracleJdbcDriverSerialFilter + } else { + ::defaultSerialFilter + } + SerialFilter.install(filter) } open protected fun getVersionInfo(): VersionInfo {