Skip to content
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

Merged
merged 4 commits into from
Nov 20, 2019

Conversation

rain-on
Copy link
Contributor

@rain-on rain-on commented Nov 15, 2019

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

@JsonGetter("params")
public Object[] getParams() {
return params;
public JsonRpcRequest(final JsonRpcRequestBody requestBody, final Optional<User> user) {
Copy link
Contributor

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

Copy link
Contributor Author

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() {
Copy link
Contributor

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?

Copy link
Contributor Author

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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) {
Copy link
Contributor

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

Copy link
Contributor Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename createEthSubscribeRequest to createEthSubscribeRequestBody

Copy link
Contributor Author

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 =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to unsubscribeRequestBody

Copy link
Contributor Author

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 =
Copy link
Contributor

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 =
Copy link
Contributor

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

Copy link
Contributor Author

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())) {
Copy link
Contributor

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

Copy link
Contributor Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename req to reqBody

Copy link
Contributor Author

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() {
Copy link
Contributor

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();
}

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

@CjHare CjHare left a 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)

Copy link
Contributor

@CjHare CjHare left a 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 👍

shemnon and others added 2 commits November 20, 2019 09:54
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>
Copy link
Contributor

@CjHare CjHare left a 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.

Copy link
Contributor

@CjHare CjHare left a 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>
@rain-on rain-on merged commit 732cfcc into hyperledger:master Nov 20, 2019
@rain-on rain-on deleted the identity_rpc branch November 20, 2019 02:12
edwardmack pushed a commit to ChainSafe/besu that referenced this pull request Feb 4, 2020
…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>
edwardmack pushed a commit to ChainSafe/besu that referenced this pull request Feb 4, 2020
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants