mirror of
https://github.com/corda/corda.git
synced 2025-06-20 08:03:53 +00:00
Corda 3513 rpc flow without permission (#5828)
* CORDA-3513: Don't try to reconnect for PermissionExceptions * CORDA-3513: Don't try to reconnect for PermissionExceptions * CORDA-3513: Add test for not reconnecting for PermissionExceptions * CORDA-3513: Update exception message and test
This commit is contained in:
committed by
Matthew Nesbit
parent
5df5d01f14
commit
e0eac8fa0d
@ -303,9 +303,7 @@ class ReconnectingCordaRPCOps private constructor(
|
|||||||
* A negative number for [maxNumberOfAttempts] means an unlimited number of retries will be performed.
|
* A negative number for [maxNumberOfAttempts] means an unlimited number of retries will be performed.
|
||||||
*/
|
*/
|
||||||
private fun doInvoke(method: Method, args: Array<out Any>?, maxNumberOfAttempts: Int): Any? {
|
private fun doInvoke(method: Method, args: Array<out Any>?, maxNumberOfAttempts: Int): Any? {
|
||||||
if (reconnectingRPCConnection.isClosed()) {
|
checkIfClosed()
|
||||||
throw RPCException("Cannot execute RPC command after client has shut down.")
|
|
||||||
}
|
|
||||||
var remainingAttempts = maxNumberOfAttempts
|
var remainingAttempts = maxNumberOfAttempts
|
||||||
var lastException: Throwable? = null
|
var lastException: Throwable? = null
|
||||||
while (remainingAttempts != 0) {
|
while (remainingAttempts != 0) {
|
||||||
@ -331,6 +329,9 @@ class ReconnectingCordaRPCOps private constructor(
|
|||||||
Thread.sleep(1000) // TODO - explain why this sleep is necessary
|
Thread.sleep(1000) // TODO - explain why this sleep is necessary
|
||||||
checkIfIsStartFlow(method, e)
|
checkIfIsStartFlow(method, e)
|
||||||
}
|
}
|
||||||
|
is PermissionException -> {
|
||||||
|
throw RPCException("User does not have permission to perform operation ${method.name}.", e)
|
||||||
|
}
|
||||||
else -> {
|
else -> {
|
||||||
log.warn("Failed to perform operation ${method.name}. Unknown error. Retrying....", e)
|
log.warn("Failed to perform operation ${method.name}. Unknown error. Retrying....", e)
|
||||||
reconnectingRPCConnection.reconnectOnError(e)
|
reconnectingRPCConnection.reconnectOnError(e)
|
||||||
@ -345,6 +346,12 @@ class ReconnectingCordaRPCOps private constructor(
|
|||||||
throw MaxRpcRetryException(maxNumberOfAttempts, lastException)
|
throw MaxRpcRetryException(maxNumberOfAttempts, lastException)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun checkIfClosed() {
|
||||||
|
if (reconnectingRPCConnection.isClosed()) {
|
||||||
|
throw RPCException("Cannot execute RPC command after client has shut down.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun invoke(proxy: Any, method: Method, args: Array<out Any>?): Any? {
|
override fun invoke(proxy: Any, method: Method, args: Array<out Any>?): Any? {
|
||||||
return when (method.returnType) {
|
return when (method.returnType) {
|
||||||
DataFeed::class.java -> {
|
DataFeed::class.java -> {
|
||||||
|
@ -184,6 +184,23 @@ class FlowRetryTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Permission exceptions are not retried and propagate`() {
|
||||||
|
val user = User("mark", "dadada", setOf())
|
||||||
|
driver(DriverParameters(isDebug = true, startNodesInProcess = isQuasarAgentSpecified())) {
|
||||||
|
|
||||||
|
val nodeAHandle = startNode(providedName = ALICE_NAME, rpcUsers = listOf(user)).getOrThrow()
|
||||||
|
|
||||||
|
CordaRPCClient(nodeAHandle.rpcAddress).start(user.username, user.password).use {
|
||||||
|
assertThatExceptionOfType(CordaRuntimeException::class.java).isThrownBy {
|
||||||
|
it.proxy.startFlow(::AsyncRetryFlow).returnValue.getOrThrow()
|
||||||
|
}.withMessageStartingWith("User not authorized to perform RPC call")
|
||||||
|
// This stays at -1 since the flow never even got called
|
||||||
|
assertEquals(-1, GeneralExternalFailureFlow.retryCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isQuasarAgentSpecified(): Boolean {
|
fun isQuasarAgentSpecified(): Boolean {
|
||||||
|
Reference in New Issue
Block a user