-
Notifications
You must be signed in to change notification settings - Fork 804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass identity information into RpcMethod from Http Service #189
Conversation
@JsonGetter("params") | ||
public Object[] getParams() { | ||
return params; | ||
public JsonRpcRequest(final JsonRpcRequestBody requestBody, final Optional<User> user) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The user doesn't need to be optional as there another constructor to allow for the none case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
@JsonIgnore | ||
public int getParamLength() { | ||
return hasParams() ? params.length : 0; | ||
public Optional<User> getIdentity() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the distinction between user and identity? Perhaps this should be just getUser?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done - was written before finding the User class 👍
@@ -76,7 +77,8 @@ public void handle( | |||
LOG.debug("WS-RPC request -> {}", request.getMethod()); | |||
request.setConnectionId(id); | |||
if (AuthenticationUtils.isPermitted(authenticationService, user, method)) { | |||
future.complete(method.response(request)); | |||
final JsonRpcRequest fullRequest = new JsonRpcRequest(request, user); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the distinction between request and fullRequest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FullRequest is now "requestContext" - and contains the request, and the user
@@ -85,8 +85,8 @@ public UnsubscribeRequest mapUnsubscribeRequest(final JsonRpcRequest jsonRpcRequ | |||
} | |||
|
|||
private WebSocketRpcRequest validateRequest(final JsonRpcRequest jsonRpcRequest) { | |||
if (jsonRpcRequest instanceof WebSocketRpcRequest) { | |||
return (WebSocketRpcRequest) jsonRpcRequest; | |||
if (jsonRpcRequest.getRequestBody() instanceof WebSocketRpcRequest) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reads a bit odd. Thinking should rename WebSocketRpcRequest to WebSocketRpcRequestBody as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
@@ -62,7 +62,7 @@ public void before() { | |||
public void shouldAddConnectionToMap(final TestContext context) { | |||
final Async async = context.async(); | |||
|
|||
final JsonRpcRequest subscribeRequest = createEthSubscribeRequest(CONNECTION_ID_1); | |||
final JsonRpcRequestBody subscribeRequest = createEthSubscribeRequest(CONNECTION_ID_1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename createEthSubscribeRequest to createEthSubscribeRequestBody
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -63,7 +63,7 @@ public void shouldRemoveConnectionWithSingleSubscriptionFromMap(final TestContex | |||
final Long subscriptionId = subscriptionManager.subscribe(subscribeRequest); | |||
assertThat(subscriptionManager.getSubscriptionById(subscriptionId)).isNotNull(); | |||
|
|||
final JsonRpcRequest unsubscribeRequest = | |||
final JsonRpcRequestBody unsubscribeRequest = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to unsubscribeRequestBody
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -95,7 +95,7 @@ public void shouldRemoveSubscriptionAndKeepConnection(final TestContext context) | |||
assertThat(subscriptionManager.getSubscriptionById(subscriptionId1)).isNotNull(); | |||
assertThat(subscriptionManager.getSubscriptionById(subscriptionId2)).isNotNull(); | |||
|
|||
final JsonRpcRequest unsubscribeRequest = | |||
final JsonRpcRequestBody unsubscribeRequest = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above. rename to unsubscribeRequestBody
@@ -54,83 +55,88 @@ public void before() { | |||
|
|||
@Test | |||
public void mapRequestToUnsubscribeRequest() { | |||
final JsonRpcRequest jsonRpcRequest = | |||
final JsonRpcRequestBody jsonRpcRequest = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: these request variable names should be jsonRpcRequestBody instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if ("eth_getWork".equals(req.getMethod())) { | ||
sendNewWork(conn, req.getId()); | ||
} else if ("eth_submitWork".equals(req.getMethod())) { | ||
if ("eth_getWork".equals(req.getRequestBody().getMethod())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: extract req.getRequestBody().getMethod() to local var
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
think there's something wrong here - have changed this to use a JsonRequestBody ... the Json Deserialise was never going to work ... :/
@@ -83,9 +83,9 @@ public Stratum1Protocol(final String extranonce) { | |||
|
|||
@Override | |||
public boolean canHandle(final String initialMessage, final StratumConnection conn) { | |||
JsonRpcRequest req; | |||
JsonRpcRequestBody req; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename req to reqBody
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@JsonIgnore | ||
public boolean isNotification() { | ||
return isNotification; | ||
public JsonRpcRequestBody getRequestBody() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest keeping the requestBody
encapsulated and proving the request through to the requestBody
(i.e mediator pattern)
public Object getId(){
return requestBody.getId();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move JsonRpcRequest to JsonRpcRequestContext, making this irrelevant (I think?) - ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to suggest encapsulating the JsonRpcRequestBody
in the JsonRpcRequest
and add an identity of the JSON-RPC in the constructor (e.g. WebSockets)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll recommend renaming JsonRpcRequestBody
to JsonRpcRequest
as it is still the JSON-RPC request as defined by the specification (https://www.jsonrpc.org/specification).
Otherwise it is looking good 👍
cae7e5f
to
93cb6d2
Compare
The context includes the user data of the logged in user making the json rpc request. Signed-off-by: Trent Mohay <trent.mohay@consensys.net>
Signed-off-by: Trent Mohay <trent.mohay@consensys.net>
93cb6d2
to
551712b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switching the request to a context is a worthy change, as it'll provide the necessary structure for future extensions to request authorisation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll want to take a look at the PrivGetTransactionReceiptTest
(CI complains of a casting problem on compile)
Signed-off-by: Trent Mohay <trent.mohay@consensys.net>
…er#189) The context includes the user data of the logged in user making the json rpc request. Signed-off-by: Trent Mohay <trent.mohay@consensys.net>
…er#189) The context includes the user data of the logged in user making the json rpc request. Signed-off-by: Trent Mohay <trent.mohay@consensys.net> Signed-off-by: edwardmack <ed@edwardmack.com>
To support Privacy in a multi-tenancy operating mode, privacy-oriented requests are required to be submitted with a JWT containing the Enclave public key to be used for the operation.
This enclave key is not part of the Json RPC Body, but rather part of the header - thus the JsonRpcRequest class has been renamed JsonRpcRequestBody (and represents only the body of the request), and a new JsonRpcRequest class has been created (comprising a User, and also the a JsonRpcRequestBody).
All tests, and methods have been updated to handle the additional layer of indirection.
Signed-off-by: Trent Mohay trent.mohay@consensys.net