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..28233564ad 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.UserInfoProvider; 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,22 +43,31 @@ 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<>(); + Map m = new HashMap<>(); m.put(key, info); payload = payload.mergeValues(Payload.CONFIGURATION, m); @@ -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); - } - } } diff --git a/server/impl/src/main/java/com/walmartlabs/concord/server/user/UserInfoProvider.java b/server/impl/src/main/java/com/walmartlabs/concord/server/user/UserInfoProvider.java index 2cc5b82921..fd2cc765bd 100644 --- a/server/impl/src/main/java/com/walmartlabs/concord/server/user/UserInfoProvider.java +++ b/server/impl/src/main/java/com/walmartlabs/concord/server/user/UserInfoProvider.java @@ -20,7 +20,6 @@ * ===== */ -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import org.immutables.value.Value; @@ -44,9 +43,15 @@ public interface UserInfoProvider { UserInfo getInfo(UUID id, String username, String userDomain); UUID create(String username, String domain, String displayName, String email, Set roles); - - @JsonInclude(JsonInclude.Include.NON_EMPTY) - interface BaseUserInfo { + + @Value.Immutable + @JsonSerialize(as = ImmutableUserInfo.class) + @JsonDeserialize(as = ImmutableUserInfo.class) + interface UserInfo { + + static ImmutableUserInfo.Builder builder() { + return ImmutableUserInfo.builder(); + } @Nullable UUID id(); @@ -69,14 +74,4 @@ interface BaseUserInfo { @Nullable Map attributes(); } - - @Value.Immutable - @JsonSerialize(as = ImmutableUserInfo.class) - @JsonDeserialize(as = ImmutableUserInfo.class) - interface UserInfo extends BaseUserInfo { - - static ImmutableUserInfo.Builder builder() { - return ImmutableUserInfo.builder(); - } - } }