coheigea commented on a change in pull request #681: URL: https://github.com/apache/cxf/pull/681#discussion_r453545503
########## File path: rt/features/logging/src/main/java/org/apache/cxf/ext/logging/MaskSensitiveHelper.java ########## @@ -0,0 +1,79 @@ +/** + * 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.cxf.ext.logging; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.apache.cxf.message.Message; + +public class MaskSensitiveHelper { + private static final String ELEMENT_NAME_TEMPLATE = "-ELEMENT_NAME-"; + private static final String MATCH_PATTERN_XML = "<-ELEMENT_NAME->(.*?)</-ELEMENT_NAME->"; + private static final String MATCH_PATTERN_JSON = "\"-ELEMENT_NAME-\"[ \\t]*:[ \\t]*\"(.*?)\""; + private static final String REPLACEMENT_PATTERN_XML = "<-ELEMENT_NAME->XXX</-ELEMENT_NAME->"; + private static final String REPLACEMENT_PATTERN_JSON = "\"-ELEMENT_NAME-\": \"XXX\""; + + private static final String XML_CONTENT = "xml"; + private static final String HTML_CONTENT = "html"; + private static final String JSON_CONTENT = "json"; + + final List<String> sensitiveElementNames = new ArrayList<>(); + + public void addSensitiveElementNames(final List<String> inSensitiveElementNames) { + this.sensitiveElementNames.addAll(inSensitiveElementNames); + } + + public String maskSensitiveElements( + final Message message, + final String originalLogString) { + if (sensitiveElementNames.isEmpty() || message == null) { + return originalLogString; + } Review comment: Could we also return here if originalLogString is null + remove the Optional.ofNullable in applyMasks below? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
