HADOOP-15418. Hadoop KMSAuthenticationFilter needs to use getPropsByPrefix instead of iterator to avoid ConcurrentModificationException. Contributed by lqjack and Suma Shivaprasad

(cherry picked from commit cd2158456d)
This commit is contained in:
Wei-Chiu Chuang 2018-10-18 17:25:57 -07:00
parent ca18ae3bc1
commit ab3fb28d47
2 changed files with 63 additions and 8 deletions

View File

@ -17,6 +17,7 @@
*/ */
package org.apache.hadoop.crypto.key.kms.server; package org.apache.hadoop.crypto.key.kms.server;
import com.google.common.annotations.VisibleForTesting;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.crypto.key.kms.KMSDelegationToken; import org.apache.hadoop.crypto.key.kms.KMSDelegationToken;
@ -54,16 +55,22 @@ public class KMSAuthenticationFilter
@Override @Override
protected Properties getConfiguration(String configPrefix, protected Properties getConfiguration(String configPrefix,
FilterConfig filterConfig) { FilterConfig filterConfig) {
Properties props = new Properties();
Configuration conf = KMSWebApp.getConfiguration(); Configuration conf = KMSWebApp.getConfiguration();
for (Map.Entry<String, String> entry : conf) { return getKMSConfiguration(conf);
String name = entry.getKey();
if (name.startsWith(CONFIG_PREFIX)) {
String value = conf.get(name);
name = name.substring(CONFIG_PREFIX.length());
props.setProperty(name, value);
} }
@VisibleForTesting
Properties getKMSConfiguration(Configuration conf) {
Properties props = new Properties();
Map<String, String> propsWithPrefixMap = conf.getPropsWithPrefix(
CONFIG_PREFIX);
for (Map.Entry<String, String> entry : propsWithPrefixMap.entrySet()) {
props.setProperty(entry.getKey(), entry.getValue());
} }
String authType = props.getProperty(AUTH_TYPE); String authType = props.getProperty(AUTH_TYPE);
if (authType.equals(PseudoAuthenticationHandler.TYPE)) { if (authType.equals(PseudoAuthenticationHandler.TYPE)) {
props.setProperty(AUTH_TYPE, props.setProperty(AUTH_TYPE,

View File

@ -0,0 +1,48 @@
/**
* 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.hadoop.crypto.key.kms.server;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.crypto.key.kms.KMSDelegationToken;
import org.apache.hadoop.security.token.delegation.web
.DelegationTokenAuthenticationHandler;
import org.apache.hadoop.security.token.delegation.web
.PseudoDelegationTokenAuthenticationHandler;
import org.junit.Test;
import java.util.Properties;
import static org.junit.Assert.assertEquals;
/**
* Test KMS Authentication Filter.
*/
public class TestKMSAuthenticationFilter {
@Test public void testConfiguration() throws Exception {
Configuration conf = new Configuration();
conf.set("hadoop.kms.authentication.type", "simple");
Properties prop = new KMSAuthenticationFilter().getKMSConfiguration(conf);
assertEquals(prop.getProperty(KMSAuthenticationFilter.AUTH_TYPE),
PseudoDelegationTokenAuthenticationHandler.class.getName());
assertEquals(
prop.getProperty(DelegationTokenAuthenticationHandler.TOKEN_KIND),
KMSDelegationToken.TOKEN_KIND_STR);
}
}