diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerStatsRecorderImpl.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerStatsRecorderImpl.java index 7850babf466f2..a41e036e516c0 100644 --- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerStatsRecorderImpl.java +++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerStatsRecorderImpl.java @@ -112,8 +112,7 @@ private void init(ConsumerConfigurationData conf) { try { log.info("Starting Pulsar consumer status recorder with config: {}", w.writeValueAsString(conf)); - log.info("Pulsar client config: {}", w.withoutAttribute("authentication") - .writeValueAsString(pulsarClient.getConfiguration())); + log.info("Pulsar client config: {}", w.writeValueAsString(pulsarClient.getConfiguration())); } catch (IOException e) { log.error("Failed to dump config info", e); } diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerStatsRecorderImpl.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerStatsRecorderImpl.java index 1f1b5b2efe7c6..5a60dafb2b518 100644 --- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerStatsRecorderImpl.java +++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerStatsRecorderImpl.java @@ -104,8 +104,7 @@ private void init(ProducerConfigurationData conf) { try { log.info("Starting Pulsar producer perf with config: {}", w.writeValueAsString(conf)); - log.info("Pulsar client config: {}", - w.withoutAttribute("authentication").writeValueAsString(pulsarClient.getConfiguration())); + log.info("Pulsar client config: {}", w.writeValueAsString(pulsarClient.getConfiguration())); } catch (IOException e) { log.error("Failed to dump config info", e); } diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/conf/ClientConfigurationData.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/conf/ClientConfigurationData.java index 5214722f77f6f..7710f5c1daa4a 100644 --- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/conf/ClientConfigurationData.java +++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/conf/ClientConfigurationData.java @@ -32,6 +32,7 @@ import java.util.concurrent.TimeUnit; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.Getter; import lombok.NoArgsConstructor; import org.apache.pulsar.client.api.Authentication; import org.apache.pulsar.client.api.ProxyProtocol; @@ -58,6 +59,7 @@ public class ClientConfigurationData implements Serializable, Cloneable { value = "The implementation class of ServiceUrlProvider used to generate ServiceUrl." ) @JsonIgnore + @Getter(onMethod_ = @JsonIgnore) private transient ServiceUrlProvider serviceUrlProvider; @ApiModelProperty( @@ -254,6 +256,8 @@ public class ClientConfigurationData implements Serializable, Cloneable { value = "Password of TLS TrustStore." ) @Secret + @JsonIgnore + @Getter(onMethod_ = @JsonIgnore) private String tlsTrustStorePassword = null; @ApiModelProperty( @@ -326,8 +330,10 @@ public class ClientConfigurationData implements Serializable, Cloneable { value = "Password of SOCKS5 proxy." ) @Secret + @JsonIgnore private String socks5ProxyPassword; + @JsonIgnore public Authentication getAuthentication() { if (authentication == null) { this.authentication = AuthenticationDisabled.INSTANCE; @@ -385,6 +391,7 @@ public String getSocks5ProxyUsername() { return Objects.nonNull(socks5ProxyUsername) ? socks5ProxyUsername : System.getProperty("socks5Proxy.username"); } + @JsonIgnore public String getSocks5ProxyPassword() { return Objects.nonNull(socks5ProxyPassword) ? socks5ProxyPassword : System.getProperty("socks5Proxy.password"); } diff --git a/pulsar-client/src/test/java/org/apache/pulsar/client/impl/conf/ClientConfigurationDataTest.java b/pulsar-client/src/test/java/org/apache/pulsar/client/impl/conf/ClientConfigurationDataTest.java new file mode 100644 index 0000000000000..b5c30c9a7c6c4 --- /dev/null +++ b/pulsar-client/src/test/java/org/apache/pulsar/client/impl/conf/ClientConfigurationDataTest.java @@ -0,0 +1,57 @@ +/** + * 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.pulsar.client.impl.conf; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; +import com.fasterxml.jackson.databind.SerializationFeature; +import org.apache.pulsar.client.impl.auth.AuthenticationToken; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * Unit test {@link ClientConfigurationData}. + */ +public class ClientConfigurationDataTest { + + private final ObjectWriter w; + + { + ObjectMapper m = new ObjectMapper(); + m.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); + w = m.writer(); + } + + + @Test + public void testDoNotPrintSensitiveInfo() throws JsonProcessingException { + ClientConfigurationData clientConfigurationData = new ClientConfigurationData(); + clientConfigurationData.setTlsTrustStorePassword("xxxx"); + clientConfigurationData.setSocks5ProxyPassword("yyyy"); + clientConfigurationData.setAuthentication(new AuthenticationToken("zzzz")); + String s = w.writeValueAsString(clientConfigurationData); + Assert.assertFalse(s.contains("Password")); + Assert.assertFalse(s.contains("xxxx")); + Assert.assertFalse(s.contains("yyyy")); + Assert.assertFalse(s.contains("zzzz")); + } + +}