From 50195c46aa35033590c474390b9882bb8e44525e Mon Sep 17 00:00:00 2001 From: c3Vu <71494005+c3Vu@users.noreply.github.com> Date: Wed, 28 Jun 2023 14:10:51 +0800 Subject: [PATCH] [Improvement-11913] Mask password when creating/editing alert instances (#14415) * [Improvement-11913] Mask password when creating/editing alert instances --- .../dingtalk/DingTalkAlertChannelFactory.java | 4 +- .../alert/email/EmailAlertChannelFactory.java | 6 +- .../alert/email/EmailAlertChannelTest.java | 4 +- .../feishu/FeiShuAlertChannelFactory.java | 4 +- .../telegram/TelegramAlertChannelFactory.java | 4 +- .../spi/params/PasswordParam.java | 87 ------------------- .../spi/params/PluginParamsTransferTest.java | 13 ++- 7 files changed, 19 insertions(+), 103 deletions(-) delete mode 100644 dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/params/PasswordParam.java diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactory.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactory.java index 95dd2042a2..4bf8b59d64 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactory.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkAlertChannelFactory.java @@ -25,7 +25,6 @@ import static org.apache.dolphinscheduler.common.constants.Constants.STRING_YES; import org.apache.dolphinscheduler.alert.api.AlertChannel; import org.apache.dolphinscheduler.alert.api.AlertChannelFactory; import org.apache.dolphinscheduler.alert.api.AlertInputTips; -import org.apache.dolphinscheduler.spi.params.PasswordParam; import org.apache.dolphinscheduler.spi.params.base.DataType; import org.apache.dolphinscheduler.spi.params.base.ParamsOptions; import org.apache.dolphinscheduler.spi.params.base.PluginParams; @@ -136,9 +135,10 @@ public final class DingTalkAlertChannelFactory implements AlertChannelFactory { .setRequired(false) .build()) .build(); - PasswordParam passwordParam = PasswordParam + InputParam passwordParam = InputParam .newBuilder(DingTalkParamsConstants.NAME_DING_TALK_PASSWORD, DingTalkParamsConstants.DING_TALK_PASSWORD) .setPlaceholder(AlertInputTips.PASSWORD.getMsg()) + .setType("password") .build(); return Arrays.asList(webHookParam, keywordParam, secretParam, msgTypeParam, atMobilesParam, atUserIdsParam, diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactory.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactory.java index 638aff3b6e..b82860b1ad 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactory.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelFactory.java @@ -27,7 +27,6 @@ import org.apache.dolphinscheduler.alert.api.AlertChannelFactory; import org.apache.dolphinscheduler.alert.api.AlertConstants; import org.apache.dolphinscheduler.alert.api.AlertInputTips; import org.apache.dolphinscheduler.alert.api.ShowType; -import org.apache.dolphinscheduler.spi.params.PasswordParam; import org.apache.dolphinscheduler.spi.params.base.DataType; import org.apache.dolphinscheduler.spi.params.base.ParamsOptions; import org.apache.dolphinscheduler.spi.params.base.PluginParams; @@ -97,9 +96,10 @@ public final class EmailAlertChannelFactory implements AlertChannelFactory { .setPlaceholder(AlertInputTips.USERNAME.getMsg()) .build(); - PasswordParam mailPassword = - PasswordParam.newBuilder(MailParamsConstants.NAME_MAIL_PASSWD, MailParamsConstants.MAIL_PASSWD) + InputParam mailPassword = + InputParam.newBuilder(MailParamsConstants.NAME_MAIL_PASSWD, MailParamsConstants.MAIL_PASSWD) .setPlaceholder(AlertInputTips.PASSWORD.getMsg()) + .setType("password") .build(); RadioParam enableTls = RadioParam diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelTest.java index 3c14f3adec..9df19154aa 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelTest.java @@ -23,7 +23,6 @@ import org.apache.dolphinscheduler.alert.api.AlertInfo; import org.apache.dolphinscheduler.alert.api.AlertResult; import org.apache.dolphinscheduler.alert.api.ShowType; import org.apache.dolphinscheduler.common.utils.JSONUtils; -import org.apache.dolphinscheduler.spi.params.PasswordParam; import org.apache.dolphinscheduler.spi.params.PluginParamsTransfer; import org.apache.dolphinscheduler.spi.params.base.ParamsOptions; import org.apache.dolphinscheduler.spi.params.base.PluginParams; @@ -107,9 +106,8 @@ public class EmailAlertChannelTest { .setValue("dolphinscheduler@126.com") .build(); - PasswordParam mailPassword = PasswordParam.newBuilder(MailParamsConstants.NAME_MAIL_PASSWD, "passwd") + InputParam mailPassword = InputParam.newBuilder(MailParamsConstants.NAME_MAIL_PASSWD, "passwd") .setPlaceholder("if enable use authentication, you need input password") - .setValue("escheduler123") .build(); RadioParam enableTls = diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannelFactory.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannelFactory.java index d6e888f499..016cfa9a70 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannelFactory.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuAlertChannelFactory.java @@ -25,7 +25,6 @@ import static org.apache.dolphinscheduler.common.constants.Constants.STRING_YES; import org.apache.dolphinscheduler.alert.api.AlertChannel; import org.apache.dolphinscheduler.alert.api.AlertChannelFactory; import org.apache.dolphinscheduler.alert.api.AlertInputTips; -import org.apache.dolphinscheduler.spi.params.PasswordParam; import org.apache.dolphinscheduler.spi.params.base.DataType; import org.apache.dolphinscheduler.spi.params.base.ParamsOptions; import org.apache.dolphinscheduler.spi.params.base.PluginParams; @@ -85,9 +84,10 @@ public final class FeiShuAlertChannelFactory implements AlertChannelFactory { .addValidate(Validate.newBuilder() .setRequired(false).build()) .build(); - PasswordParam passwordParam = PasswordParam + InputParam passwordParam = InputParam .newBuilder(FeiShuParamsConstants.NAME_FEI_SHU_PASSWORD, FeiShuParamsConstants.FEI_SHU_PASSWORD) .setPlaceholder(AlertInputTips.PASSWORD.getMsg()) + .setType("password") .build(); return Arrays.asList(webHookParam, isEnableProxy, proxyParam, portParam, userParam, passwordParam); diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-telegram/src/main/java/org/apache/dolphinscheduler/plugin/alert/telegram/TelegramAlertChannelFactory.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-telegram/src/main/java/org/apache/dolphinscheduler/plugin/alert/telegram/TelegramAlertChannelFactory.java index 8dcf36dd89..284ecee8fa 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-telegram/src/main/java/org/apache/dolphinscheduler/plugin/alert/telegram/TelegramAlertChannelFactory.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-telegram/src/main/java/org/apache/dolphinscheduler/plugin/alert/telegram/TelegramAlertChannelFactory.java @@ -25,7 +25,6 @@ import static org.apache.dolphinscheduler.common.constants.Constants.STRING_YES; import org.apache.dolphinscheduler.alert.api.AlertChannel; import org.apache.dolphinscheduler.alert.api.AlertChannelFactory; import org.apache.dolphinscheduler.alert.api.AlertInputTips; -import org.apache.dolphinscheduler.spi.params.PasswordParam; import org.apache.dolphinscheduler.spi.params.base.DataType; import org.apache.dolphinscheduler.spi.params.base.ParamsOptions; import org.apache.dolphinscheduler.spi.params.base.PluginParams; @@ -131,12 +130,13 @@ public final class TelegramAlertChannelFactory implements AlertChannelFactory { .build()) .build(); - PasswordParam passwordParam = PasswordParam + InputParam passwordParam = InputParam .newBuilder(TelegramParamsConstants.NAME_TELEGRAM_PASSWORD, TelegramParamsConstants.TELEGRAM_PASSWORD) .addValidate(Validate.newBuilder() .setRequired(false) .build()) .setPlaceholder("if enable use authentication, you need input password") + .setType("password") .build(); return Arrays.asList(webHookParam, botTokenParam, chatIdParam, parseMode, isEnableProxy, proxyParam, portParam, diff --git a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/params/PasswordParam.java b/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/params/PasswordParam.java deleted file mode 100644 index 5516470504..0000000000 --- a/dolphinscheduler-spi/src/main/java/org/apache/dolphinscheduler/spi/params/PasswordParam.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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.spi.params; - -import org.apache.dolphinscheduler.spi.params.base.FormType; -import org.apache.dolphinscheduler.spi.params.base.ParamsProps; -import org.apache.dolphinscheduler.spi.params.base.PluginParams; -import org.apache.dolphinscheduler.spi.params.base.Validate; - -import java.util.ArrayList; -import java.util.List; - -/** - * password param - */ -public class PasswordParam extends PluginParams { - - private PasswordParam(Builder builder) { - super(builder); - } - - public static Builder newBuilder(String name, String title) { - return new Builder(name, title); - } - - public static class Builder extends PluginParams.Builder { - - public Builder(String name, String title) { - super(name, FormType.INPUT, title); - ParamsProps paramsProps = new ParamsProps(); - this.props = paramsProps; - } - - public Builder setPlaceholder(String placeholder) { - this.props.setPlaceholder(placeholder); - return this; - } - - public Builder addValidate(Validate validate) { - if (this.validateList == null) { - this.validateList = new ArrayList<>(); - } - this.validateList.add(validate); - return this; - } - - public Builder setName(String name) { - this.name = name; - return this; - } - - public Builder setTitle(String title) { - this.title = title; - return this; - } - - public Builder setValue(Object value) { - this.value = value; - return this; - } - - public Builder setValidateList(List validateList) { - this.validateList = validateList; - return this; - } - - @Override - public PasswordParam build() { - return new PasswordParam(this); - } - } -} diff --git a/dolphinscheduler-spi/src/test/java/org/apache/dolphinscheduler/spi/params/PluginParamsTransferTest.java b/dolphinscheduler-spi/src/test/java/org/apache/dolphinscheduler/spi/params/PluginParamsTransferTest.java index 72fae3d56d..d058943d49 100644 --- a/dolphinscheduler-spi/src/test/java/org/apache/dolphinscheduler/spi/params/PluginParamsTransferTest.java +++ b/dolphinscheduler-spi/src/test/java/org/apache/dolphinscheduler/spi/params/PluginParamsTransferTest.java @@ -86,8 +86,9 @@ public class PluginParamsTransferTest { .setPlaceholder("if enable use authentication, you need input user") .build(); - PasswordParam mailPassword = new PasswordParam.Builder("field8", "field8") + InputParam mailPassword = new InputParam.Builder("field8", "field8") .setPlaceholder("if enable use authentication, you need input password") + .setType("password") .build(); RadioParam enableTls = new RadioParam.Builder("field9", "field9") @@ -160,9 +161,13 @@ public class PluginParamsTransferTest { + "\"validateEvent\":null,\"showPassword\":null,\"placeholder\":\"if enable use authentication, " + "you need input user\",\"size\":\"small\"},\"field\":\"field7\",\"name\":\"field7\"," + "\"type\":\"input\",\"title\":\"field7\",\"value\":null,\"validate\":null,\"emit\":null}," - + "{\"field\":\"field8\",\"name\":\"field8\",\"props\":{\"disabled\":null,\"placeholder\":" - + "\"if enable use authentication, you need input password\",\"size\":\"small\"},\"type\":" - + "\"input\",\"title\":\"field8\",\"value\":null,\"validate\":null,\"emit\":null},{\"props\":" + + "{\"props\":{\"disabled\":null,\"type\":\"password\",\"maxlength\":null,\"minlength\":null,\"" + + "clearable\":null,\"prefixIcon\":null,\"suffixIcon\":null,\"rows\":null,\"autosize\":null," + + "\"autocomplete\":null,\"name\":null,\"readonly\":null,\"max\":null,\"min\":null,\"step\":null," + + "\"resize\":null,\"autofocus\":null,\"form\":null,\"label\":null,\"tabindex\":null,\"validateEvent\":null," + + "\"showPassword\":null,\"placeholder\":\"if enable use authentication, you need input password\"," + + "\"size\":\"small\"},\"field\":\"field8\",\"name\":\"field8\",\"type\":\"input\",\"title\":\"field8\"," + + "\"value\":null,\"validate\":null,\"emit\":null},{\"props\":" + "null,\"field\":\"field9\",\"name\":\"field9\",\"type\":\"radio\",\"title\":\"field9\"," + "\"value\":false,\"validate\":[{\"required\":true,\"message\":null,\"type\":\"string\"," + "\"trigger\":\"blur\",\"min\":null,\"max\":null}],\"emit\":null,\"options\":[{\"label\":"