diff --git a/server/impl/src/main/java/com/walmartlabs/concord/server/process/pipelines/processors/CurrentUserInfoProcessor.java b/server/impl/src/main/java/com/walmartlabs/concord/server/process/pipelines/processors/CurrentUserInfoProcessor.java index eb72538506..d87a7f508e 100644 --- a/server/impl/src/main/java/com/walmartlabs/concord/server/process/pipelines/processors/CurrentUserInfoProcessor.java +++ b/server/impl/src/main/java/com/walmartlabs/concord/server/process/pipelines/processors/CurrentUserInfoProcessor.java @@ -20,6 +20,7 @@ * ===== */ +import com.fasterxml.jackson.databind.ObjectMapper; import com.walmartlabs.concord.sdk.Constants; import com.walmartlabs.concord.server.process.pipelines.processors.signing.Signing; import com.walmartlabs.concord.server.user.UserManager; @@ -31,7 +32,7 @@ public class CurrentUserInfoProcessor extends UserInfoProcessor { @Inject - public CurrentUserInfoProcessor(UserManager userManager, Signing signing) { - super(Constants.Request.CURRENT_USER_KEY, userManager, signing); + public CurrentUserInfoProcessor(UserManager userManager, Signing signing, ObjectMapper objectMapper) { + super(Constants.Request.CURRENT_USER_KEY, userManager, signing, objectMapper); } } diff --git a/server/impl/src/main/java/com/walmartlabs/concord/server/process/pipelines/processors/InitiatorUserInfoProcessor.java b/server/impl/src/main/java/com/walmartlabs/concord/server/process/pipelines/processors/InitiatorUserInfoProcessor.java index 43183311f4..9522e546cd 100644 --- a/server/impl/src/main/java/com/walmartlabs/concord/server/process/pipelines/processors/InitiatorUserInfoProcessor.java +++ b/server/impl/src/main/java/com/walmartlabs/concord/server/process/pipelines/processors/InitiatorUserInfoProcessor.java @@ -20,6 +20,7 @@ * ===== */ +import com.fasterxml.jackson.databind.ObjectMapper; import com.walmartlabs.concord.sdk.Constants; import com.walmartlabs.concord.server.process.pipelines.processors.signing.Signing; import com.walmartlabs.concord.server.user.UserManager; @@ -31,7 +32,7 @@ public class InitiatorUserInfoProcessor extends UserInfoProcessor { @Inject - public InitiatorUserInfoProcessor(UserManager userManager, Signing signing) { - super(Constants.Request.INITIATOR_KEY, userManager, signing); + public InitiatorUserInfoProcessor(UserManager userManager, Signing signing, ObjectMapper objectMapper) { + super(Constants.Request.INITIATOR_KEY, userManager, signing, objectMapper); } } diff --git a/server/impl/src/main/java/com/walmartlabs/concord/server/process/pipelines/processors/UserInfoProcessor.java b/server/impl/src/main/java/com/walmartlabs/concord/server/process/pipelines/processors/UserInfoProcessor.java index 5169a3487a..3bf2303f69 100644 --- a/server/impl/src/main/java/com/walmartlabs/concord/server/process/pipelines/processors/UserInfoProcessor.java +++ b/server/impl/src/main/java/com/walmartlabs/concord/server/process/pipelines/processors/UserInfoProcessor.java @@ -20,17 +20,20 @@ * ===== */ -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.databind.node.TextNode; import com.walmartlabs.concord.server.process.Payload; import com.walmartlabs.concord.server.process.pipelines.processors.signing.Signing; import com.walmartlabs.concord.server.sdk.ConcordApplicationException; import com.walmartlabs.concord.server.user.UserInfoProvider.BaseUserInfo; import com.walmartlabs.concord.server.user.UserManager; -import org.immutables.value.Value; import java.util.HashMap; import java.util.Map; +import java.util.Optional; + +import static java.util.Objects.requireNonNull; /** * Collects and stores the current user's data. @@ -40,19 +43,28 @@ public abstract class UserInfoProcessor implements PayloadProcessor { private final String key; private final UserManager userManager; private final Signing signing; + private final ObjectMapper objectMapper; + + public UserInfoProcessor(String key, + UserManager userManager, + Signing signing, + ObjectMapper objectMapper) { - public UserInfoProcessor(String key, UserManager userManager, Signing signing) { - this.key = key; - this.userManager = userManager; - this.signing = signing; + this.key = requireNonNull(key); + this.userManager = requireNonNull(userManager); + this.signing = requireNonNull(signing); + this.objectMapper = requireNonNull(objectMapper); } @Override public Payload process(Chain chain, Payload payload) { - BaseUserInfo info = userManager.getCurrentUserInfo(); + var info = userManager.getCurrentUserInfo(); + var result = objectMapper.convertValue(info, ObjectNode.class); if (signing.isEnabled()) { - info = sign(info); + Optional.ofNullable(info.username()) + .map(this::sign) + .ifPresent(signature -> result.set("usernameSignature", signature)); } Map m = new HashMap<>(); @@ -63,28 +75,11 @@ public Payload process(Chain chain, Payload payload) { return chain.process(payload); } - private BaseUserInfo sign(BaseUserInfo i) { - if (i == null || i.username() == null) { - return i; - } - + private TextNode sign(String username) { try { - String s = signing.sign(i.username()); - return SignedUserInfo.from(i).usernameSignature(s).build(); + return TextNode.valueOf(signing.sign(username)); } catch (Exception e) { throw new ConcordApplicationException("Error while singing process data: " + e.getMessage(), e); } } - - @Value.Immutable - @JsonSerialize(as = ImmutableSignedUserInfo.class) - @JsonDeserialize(as = ImmutableSignedUserInfo.class) - public interface SignedUserInfo extends BaseUserInfo { - - String usernameSignature(); - - public static ImmutableSignedUserInfo.Builder from(BaseUserInfo i) { - return ImmutableSignedUserInfo.builder().from(i); - } - } }