ruanwenjun commented on code in PR #18585:
URL: 
https://github.com/apache/dolphinscheduler/pull/18585#discussion_r3968797196


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/SensitivePropertyUtils.java:
##########
@@ -0,0 +1,355 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.api.utils;
+
+import static 
org.apache.dolphinscheduler.common.constants.Constants.LOCAL_PARAMS;
+
+import 
org.apache.dolphinscheduler.api.dto.workflow.WorkflowDefinitionVariablesDTO;
+import 
org.apache.dolphinscheduler.api.dto.workflowInstance.WorkflowInstanceVariablesDTO;
+import org.apache.dolphinscheduler.api.enums.Status;
+import org.apache.dolphinscheduler.api.exceptions.ServiceException;
+import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import org.apache.dolphinscheduler.dao.entity.DagData;
+import org.apache.dolphinscheduler.dao.entity.TaskDefinition;
+import org.apache.dolphinscheduler.dao.entity.WorkflowDefinition;
+import org.apache.dolphinscheduler.dao.entity.WorkflowInstance;
+import org.apache.dolphinscheduler.plugin.task.api.model.Property;
+import org.apache.dolphinscheduler.plugin.task.api.utils.GlobalParameterUtils;
+import 
org.apache.dolphinscheduler.plugin.task.api.utils.PropertySensitiveUtils;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+
+import lombok.experimental.UtilityClass;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+/**
+ * API-layer helpers for sensitive {@link Property} masking and keep-original 
merge.
+ * <p>
+ * PR1 of DSIP-105: no encryption. Crypto (PasswordUtils) belongs to a 
follow-up PR.
+ * HTTP responses are masked at the outbound boundary via {@link 
#maskApiResponseData};
+ * persistence and in-process service results stay plaintext.
+ */
+@UtilityClass
+public class SensitivePropertyUtils {

Review Comment:
   This utility class looks difficult to maintain.



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/aspect/SensitivePropertyResponseAdvice.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.api.aspect;
+
+import org.apache.dolphinscheduler.api.utils.Result;
+import org.apache.dolphinscheduler.api.utils.SensitivePropertyUtils;
+
+import org.springframework.core.MethodParameter;
+import org.springframework.http.MediaType;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.server.ServerHttpRequest;
+import org.springframework.http.server.ServerHttpResponse;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+import 
org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
+
+/**
+ * HTTP outbound mask for sensitive {@code Property} values.
+ * <p>
+ * Service / persistence stay plaintext. Only {@link Result} bodies whose 
{@code data}
+ * contains workflow/task {@code Property} payloads are copied then masked; 
other
+ * {@link Result} responses are returned unchanged.
+ */
+@RestControllerAdvice(basePackages = 
"org.apache.dolphinscheduler.api.controller")
+@SuppressWarnings("unchecked")
+public class SensitivePropertyResponseAdvice implements 
ResponseBodyAdvice<Object> {
+
+    @Override
+    public boolean supports(MethodParameter returnType, Class<? extends 
HttpMessageConverter<?>> converterType) {
+        return returnType.getParameterType() != null
+                && 
Result.class.isAssignableFrom(returnType.getParameterType());
+    }
+
+    @Override
+    public Object beforeBodyWrite(Object body,
+                                  MethodParameter returnType,
+                                  MediaType selectedContentType,
+                                  Class<? extends HttpMessageConverter<?>> 
selectedConverterType,
+                                  ServerHttpRequest request,
+                                  ServerHttpResponse response) {
+        if (!(body instanceof Result)) {
+            return body;
+        }
+        Result<Object> result = (Result<Object>) body;
+        Object data = result.getData();
+        if (!SensitivePropertyUtils.containsSensitivePropertyPayload(data)) {
+            return result;
+        }
+        result.setData(SensitivePropertyUtils.maskApiResponseData(data));
+        return result;
+    }
+}

Review Comment:
   Don't use this aspect, need to mask the value at controller manual.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to