Plumb in plugin whitelist additions to AMQP implementation. (#1415)

This commit is contained in:
Rick Parker 2017-09-05 08:35:26 +01:00 committed by GitHub
parent 30687592c2
commit ead4d09011
2 changed files with 23 additions and 5 deletions

View File

@ -1,20 +1,35 @@
package net.corda.nodeapi.internal.serialization package net.corda.nodeapi.internal.serialization
import net.corda.core.serialization.ClassWhitelist import net.corda.core.node.CordaPluginRegistry
import net.corda.core.serialization.SerializationContext import net.corda.core.serialization.*
import net.corda.core.serialization.SerializationDefaults
import net.corda.core.serialization.SerializedBytes
import net.corda.core.utilities.ByteSequence import net.corda.core.utilities.ByteSequence
import net.corda.nodeapi.internal.serialization.amqp.AmqpHeaderV1_0 import net.corda.nodeapi.internal.serialization.amqp.AmqpHeaderV1_0
import net.corda.nodeapi.internal.serialization.amqp.DeserializationInput import net.corda.nodeapi.internal.serialization.amqp.DeserializationInput
import net.corda.nodeapi.internal.serialization.amqp.SerializationOutput import net.corda.nodeapi.internal.serialization.amqp.SerializationOutput
import net.corda.nodeapi.internal.serialization.amqp.SerializerFactory import net.corda.nodeapi.internal.serialization.amqp.SerializerFactory
import java.util.*
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
val AMQP_ENABLED get() = SerializationDefaults.P2P_CONTEXT.preferredSerializationVersion == AmqpHeaderV1_0 val AMQP_ENABLED get() = SerializationDefaults.P2P_CONTEXT.preferredSerializationVersion == AmqpHeaderV1_0
class AMQPSerializationCustomization(val factory: SerializerFactory) : SerializationCustomization {
override fun addToWhitelist(vararg types: Class<*>) {
factory.addToWhitelist(*types)
}
}
fun SerializerFactory.addToWhitelist(vararg types: Class<*>) {
for (type in types) {
(this.whitelist as? MutableClassWhitelist)?.add(type)
}
}
abstract class AbstractAMQPSerializationScheme : SerializationScheme { abstract class AbstractAMQPSerializationScheme : SerializationScheme {
internal companion object { internal companion object {
private val pluginRegistries: List<CordaPluginRegistry> by lazy {
ServiceLoader.load(CordaPluginRegistry::class.java, this.javaClass.classLoader).toList()
}
fun registerCustomSerializers(factory: SerializerFactory) { fun registerCustomSerializers(factory: SerializerFactory) {
factory.apply { factory.apply {
register(net.corda.nodeapi.internal.serialization.amqp.custom.PublicKeySerializer) register(net.corda.nodeapi.internal.serialization.amqp.custom.PublicKeySerializer)
@ -40,6 +55,8 @@ abstract class AbstractAMQPSerializationScheme : SerializationScheme {
register(net.corda.nodeapi.internal.serialization.amqp.custom.X509CertificateHolderSerializer) register(net.corda.nodeapi.internal.serialization.amqp.custom.X509CertificateHolderSerializer)
register(net.corda.nodeapi.internal.serialization.amqp.custom.PartyAndCertificateSerializer(factory)) register(net.corda.nodeapi.internal.serialization.amqp.custom.PartyAndCertificateSerializer(factory))
} }
val customizer = AMQPSerializationCustomization(factory)
pluginRegistries.forEach { it.customizeSerialization(customizer) }
} }
} }

View File

@ -64,7 +64,8 @@ class DefaultWhitelist : CordaPluginRegistry() {
LocalDate::class.java, LocalDate::class.java,
Period::class.java, Period::class.java,
BitSet::class.java, BitSet::class.java,
OnErrorNotImplementedException::class.java) OnErrorNotImplementedException::class.java,
StackTraceElement::class.java)
} }
return true return true
} }