001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package org.apache.camel.util;
019
020import java.util.Arrays;
021import java.util.HashSet;
022import java.util.Locale;
023import java.util.Set;
024
025public final class SensitiveUtils {
026    private static final Set<String> SENSITIVE_KEYS = new HashSet<>(
027            Arrays.asList(
028                    // Generated by camel build tools - do NOT edit this list!
029                    // SENSITIVE-KEYS: START
030                    "accesskey",
031                    "accesstoken",
032                    "accesstokensecret",
033                    "accountsid",
034                    "acltoken",
035                    "authorizationtoken",
036                    "blobaccesskey",
037                    "blobstoragesharedkeycredential",
038                    "certresourcepassword",
039                    "clientsecret",
040                    "connectionstring",
041                    "consumerkey",
042                    "consumersecret",
043                    "emailaddress",
044                    "fulltokenid",
045                    "httpproxypassword",
046                    "keypassword",
047                    "keystore",
048                    "keystorepassword",
049                    "login",
050                    "oauthaccesstoken",
051                    "oauthappid",
052                    "oauthappsecret",
053                    "oauthclientid",
054                    "oauthclientsecret",
055                    "oauthtoken",
056                    "oauthtokenurl",
057                    "p12filename",
058                    "passcode",
059                    "passphrase",
060                    "password",
061                    "privatekey",
062                    "privatekeyfile",
063                    "privatekeyname",
064                    "privatekeypassword",
065                    "proxyauthpassword",
066                    "proxyauthusername",
067                    "proxypassword",
068                    "proxyuser",
069                    "publickeyid",
070                    "queueownerawsaccountid",
071                    "refreshtoken",
072                    "sasljaasconfig",
073                    "secretkey",
074                    "securerandom",
075                    "sharedaccesskey",
076                    "sslkeypassword",
077                    "sslkeystore",
078                    "sslkeystorepassword",
079                    "sslpassword",
080                    "ssltruststorepassword",
081                    "systemid",
082                    "token",
083                    "user",
084                    "userauthenticationcredentials",
085                    "username",
086                    "userpassword",
087                    "verificationcode",
088                    "zookeeperpassword"
089            // SENSITIVE-KEYS: END
090            ));
091
092    private SensitiveUtils() {
093    }
094
095    /**
096     * Whether the given configuration property contains a sensitive a sensitive key (such as password, accesstoken,
097     * etc.)
098     *
099     * @param  text the configuration property
100     * @return      true if sensitive, false otherwise
101     */
102    public static boolean containsSensitive(String text) {
103        int lastPeriod = text.lastIndexOf('.');
104        if (lastPeriod >= 0) {
105            text = text.substring(lastPeriod + 1);
106        }
107        text = text.toLowerCase(Locale.ENGLISH);
108        text = StringHelper.replaceAll(text, "-", "");
109        return SENSITIVE_KEYS.contains(text);
110    }
111}