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 */ 017package org.apache.camel.util; 018 019import java.util.Arrays; 020import java.util.Collections; 021import java.util.HashSet; 022import java.util.Locale; 023import java.util.Set; 024 025public final class SensitiveUtils { 026 027 private static final Set<String> SENSITIVE_KEYS = Collections.unmodifiableSet(new HashSet<>( 028 Arrays.asList( 029 // Generated by camel build tools - do NOT edit this list! 030 // SENSITIVE-KEYS: START 031 "accesskey", 032 "accesstoken", 033 "accesstokensecret", 034 "accountkey", 035 "accountsid", 036 "acltoken", 037 "apipassword", 038 "apiuser", 039 "apiusername", 040 "authkey", 041 "authorizationtoken", 042 "blobaccesskey", 043 "blobstoragesharedkeycredential", 044 "certresourcepassword", 045 "cipherkey", 046 "clientsecret", 047 "connectionstring", 048 "consumerkey", 049 "consumersecret", 050 "emailaddress", 051 "fulltokenid", 052 "httpproxypassword", 053 "keypassword", 054 "keystore", 055 "keystorepassword", 056 "login", 057 "oauthaccesstoken", 058 "oauthappid", 059 "oauthappsecret", 060 "oauthclientid", 061 "oauthclientsecret", 062 "oauthtoken", 063 "oauthtokenurl", 064 "p12filename", 065 "passcode", 066 "passphrase", 067 "password", 068 "privatekey", 069 "privatekeyfile", 070 "privatekeyname", 071 "privatekeypassword", 072 "proxyauthpassword", 073 "proxyauthusername", 074 "proxypassword", 075 "proxyuser", 076 "publickeyid", 077 "publishkey", 078 "queueownerawsaccountid", 079 "refreshtoken", 080 "sasljaasconfig", 081 "secretkey", 082 "securerandom", 083 "sharedaccesskey", 084 "sourceblobaccesskey", 085 "sslkeypassword", 086 "sslkeystore", 087 "sslkeystorepassword", 088 "sslpassword", 089 "ssltruststorepassword", 090 "subscribekey", 091 "systemid", 092 "token", 093 "user", 094 "userauthenticationcredentials", 095 "username", 096 "userpassword", 097 "verificationcode", 098 "zookeeperpassword" 099 // SENSITIVE-KEYS: END 100 ))); 101 102 private SensitiveUtils() { 103 } 104 105 /** 106 * All the sensitive keys (unmodifiable) in lower-case 107 */ 108 public static Set<String> getSensitiveKeys() { 109 return SENSITIVE_KEYS; 110 } 111 112 /** 113 * Whether the given configuration property contains a sensitive key (such as password, accesstoken, etc.) 114 * 115 * @param text the configuration property 116 * @return true if sensitive, false otherwise 117 */ 118 public static boolean containsSensitive(String text) { 119 int lastPeriod = text.lastIndexOf('.'); 120 if (lastPeriod >= 0) { 121 text = text.substring(lastPeriod + 1); 122 } 123 text = text.toLowerCase(Locale.ENGLISH); 124 text = text.replace("-", ""); 125 return SENSITIVE_KEYS.contains(text); 126 } 127 128}