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 "accountkey", 034 "accountsid", 035 "acltoken", 036 "authorizationtoken", 037 "blobaccesskey", 038 "blobstoragesharedkeycredential", 039 "certresourcepassword", 040 "clientsecret", 041 "connectionstring", 042 "consumerkey", 043 "consumersecret", 044 "emailaddress", 045 "fulltokenid", 046 "httpproxypassword", 047 "keypassword", 048 "keystore", 049 "keystorepassword", 050 "login", 051 "oauthaccesstoken", 052 "oauthappid", 053 "oauthappsecret", 054 "oauthclientid", 055 "oauthclientsecret", 056 "oauthtoken", 057 "oauthtokenurl", 058 "p12filename", 059 "passcode", 060 "passphrase", 061 "password", 062 "privatekey", 063 "privatekeyfile", 064 "privatekeyname", 065 "privatekeypassword", 066 "proxyauthpassword", 067 "proxyauthusername", 068 "proxypassword", 069 "proxyuser", 070 "publickeyid", 071 "queueownerawsaccountid", 072 "refreshtoken", 073 "sasljaasconfig", 074 "secretkey", 075 "securerandom", 076 "sharedaccesskey", 077 "sslkeypassword", 078 "sslkeystore", 079 "sslkeystorepassword", 080 "sslpassword", 081 "ssltruststorepassword", 082 "systemid", 083 "token", 084 "user", 085 "userauthenticationcredentials", 086 "username", 087 "userpassword", 088 "verificationcode", 089 "zookeeperpassword" 090 // SENSITIVE-KEYS: END 091 )); 092 093 private SensitiveUtils() { 094 } 095 096 /** 097 * Whether the given configuration property contains a sensitive a sensitive key (such as password, accesstoken, 098 * etc.) 099 * 100 * @param text the configuration property 101 * @return true if sensitive, false otherwise 102 */ 103 public static boolean containsSensitive(String text) { 104 int lastPeriod = text.lastIndexOf('.'); 105 if (lastPeriod >= 0) { 106 text = text.substring(lastPeriod + 1); 107 } 108 text = text.toLowerCase(Locale.ENGLISH); 109 text = StringHelper.replaceAll(text, "-", ""); 110 return SENSITIVE_KEYS.contains(text); 111 } 112}