Skip to content

Commit

Permalink
[#1228] fix live response auth context and live error response forwar…
Browse files Browse the repository at this point in the history
…ding.

Signed-off-by: Yufei Cai <yufei.cai@bosch.io>
  • Loading branch information
yufei-cai committed Dec 6, 2021
1 parent d65131f commit 1a23e70
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static Props props(final Command<?> command,
@Override
public Receive createReceive() {
return ReceiveBuilder.create()
.match(ThingQueryCommandResponse.class, this::onQueryCommandResponse)
.match(CommandResponse.class, this::onCommandResponse)
.match(Acknowledgement.class, this::onAcknowledgement)
.match(Acknowledgements.class, this::onAcknowledgements)
.match(ReceiveTimeout.class, this::stopSelf)
Expand Down Expand Up @@ -115,7 +115,7 @@ private void onAcknowledgements(final Acknowledgements acks) {
acknowledgementReceiver.forward(acks, getContext());
}

private void onQueryCommandResponse(final ThingQueryCommandResponse<?> response) {
private void onCommandResponse(final CommandResponse<?> response) {
final boolean validResponse = isValidResponse(response);
logger.debug("Got <{}>, valid=<{}>", response, validResponse);
if (validResponse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ private Contextual<WithDittoHeaders> askAndBuildJsonViewWithAckForwarding(
.thenApply(getResponseCaster(signal, "before building JsonView"));
};
return ask(liveResponseForwarder, signal, askStrategy)
.thenApply(response -> filterJsonView(response, enforcer));
.thenApply(response -> filterJsonView(replaceAuthContext(response, signal), enforcer));
});
}

Expand Down Expand Up @@ -560,4 +560,12 @@ private static ThingCommand<?> adjustTimeout(final ThingCommand<?> command, fina
.build()
);
}

static ThingQueryCommandResponse<?> replaceAuthContext(final ThingQueryCommandResponse<?> response,
final WithDittoHeaders command) {
return response.setDittoHeaders(response.getDittoHeaders()
.toBuilder()
.authorizationContext(command.getDittoHeaders().getAuthorizationContext())
.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.eclipse.ditto.concierge.service.enforcement.LiveSignalEnforcement.MIN_LIVE_TIMEOUT;
import static org.eclipse.ditto.concierge.service.enforcement.LiveSignalEnforcement.THING_COMMAND_ACK_EXTRACTOR;
import static org.eclipse.ditto.concierge.service.enforcement.LiveSignalEnforcement.addEffectedReadSubjectsToThingLiveSignal;
import static org.eclipse.ditto.concierge.service.enforcement.LiveSignalEnforcement.replaceAuthContext;
import static org.eclipse.ditto.policies.api.Permission.MIN_REQUIRED_POLICY_PERMISSIONS;

import java.time.Duration;
Expand Down Expand Up @@ -350,7 +351,7 @@ private CompletionStage<ThingQueryCommandResponse<?>> doSmartChannelSelection(fi
.thenApply(getResponseCaster(liveCommand, "before building JsonView"));
};
return ask(liveResponseForwarder, liveCommand, askStrategy)
.thenApply(response -> filterJsonView(response, enforcer));
.thenApply(response -> filterJsonView(replaceAuthContext(response, command), enforcer));
}

private ThingQueryCommand<?> toLiveCommand(final ThingQueryCommand<?> command, final Enforcer enforcer) {
Expand Down

0 comments on commit 1a23e70

Please sign in to comment.