mirror of
https://github.com/corda/corda.git
synced 2025-06-23 17:53:31 +00:00
Validate protocol type and args via whitelist ahead of class loading. Also, push this work into another method on the Factory.
This commit is contained in:
@ -49,6 +49,22 @@ class ProtocolLogicRefFactory(private val protocolWhitelist: Map<String, Set<Str
|
||||
require(protocolWhitelist[className]!!.contains(argClassName)) { "Args to ${className} must have types on the args whitelist: $argClassName" }
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a [ProtocolLogicRef] for the Kotlin primary constructor of a named [ProtocolLogic]
|
||||
*/
|
||||
fun createKotlin(protocolLogicClassName: String, args: Map<String,Any?>, attachments: List<SecureHash> = emptyList()): ProtocolLogicRef {
|
||||
val context = AppContext(attachments)
|
||||
validateProtocolClassName(protocolLogicClassName, context)
|
||||
for(arg in args.values.filterNotNull()) {
|
||||
validateArgClassName(protocolLogicClassName, arg.javaClass.name, context)
|
||||
}
|
||||
val clazz = Class.forName(protocolLogicClassName)
|
||||
require(ProtocolLogic::class.java.isAssignableFrom(clazz)) { "$protocolLogicClassName is not a ProtocolLogic" }
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val logic = clazz as Class<ProtocolLogic<ProtocolLogic<*>>>
|
||||
return createKotlin(logic, args)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a [ProtocolLogicRef] for the Kotlin primary constructor or Java constructor and the given args.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user