+ * Annotates object properties that contain sensitive content and must not be serialized when returned publicly or to + * arbitrary users (e.g. via a REST endpoint of the service). + *
+ *+ * Note that the serializer {@link SensitiveDataSerializer} must be registered in the Jackson ObjectMapper for this + * annotation to be respected. + *
+ * + * @see SensitiveDataSerializer + * @see SensitiveDataBeanSerializerModifier + */ +@Target({ ElementType.FIELD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface SensitiveData { +} diff --git a/java/common/org.eclipse.theia.cloud.common/src/main/java/org/eclipse/theia/cloud/common/serialization/SensitiveDataBeanSerializerModifier.java b/java/common/org.eclipse.theia.cloud.common/src/main/java/org/eclipse/theia/cloud/common/serialization/SensitiveDataBeanSerializerModifier.java new file mode 100644 index 00000000..8f766e7b --- /dev/null +++ b/java/common/org.eclipse.theia.cloud.common/src/main/java/org/eclipse/theia/cloud/common/serialization/SensitiveDataBeanSerializerModifier.java @@ -0,0 +1,34 @@ +package org.eclipse.theia.cloud.common.serialization; + +import com.fasterxml.jackson.databind.BeanDescription; +import com.fasterxml.jackson.databind.SerializationConfig; +import com.fasterxml.jackson.databind.ser.BeanSerializerModifier; +import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; + +import java.util.List; + +/** + *+ * A Jackson {@link BeanSerializerModifier} that modifies the serialization of sensitive data. It assigns the + * {@link SensitiveDataSerializer} to fields annotated with {@link SensitiveData}. The serializer is assigned for + * regular and null value serialization to prevent leaking information. + *
+ *+ * To use this serializer modifier, it must be registered with Jackson's + * {@link com.fasterxml.jackson.databind.ObjectMapper ObjectMapper}. + *
+ */ +public class SensitiveDataBeanSerializerModifier extends BeanSerializerModifier { + @Override + public List