diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/FastSaslClientFactory.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/FastSaslClientFactory.java index d5259d338feb2..843ae62f37a17 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/FastSaslClientFactory.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/FastSaslClientFactory.java @@ -29,6 +29,9 @@ import javax.security.sasl.SaslClientFactory; import javax.security.sasl.SaslException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import org.apache.hadoop.classification.InterfaceAudience; /** @@ -36,19 +39,29 @@ */ @InterfaceAudience.LimitedPrivate({ "HDFS", "MapReduce" }) public class FastSaslClientFactory implements SaslClientFactory { + + public static final Logger LOG = LoggerFactory.getLogger(FastSaslClientFactory.class); + private final Map> factoryCache = new HashMap>(); public FastSaslClientFactory(Map props) { final Enumeration factories = Sasl.getSaslClientFactories(); + if (props == null) { + props = new HashMap<>(); + } while (factories.hasMoreElements()) { SaslClientFactory factory = factories.nextElement(); - for (String mech : factory.getMechanismNames(props)) { - if (!factoryCache.containsKey(mech)) { - factoryCache.put(mech, new ArrayList()); + try{ + for (String mech : factory.getMechanismNames(props)) { + if (!factoryCache.containsKey(mech)) { + factoryCache.put(mech, new ArrayList()); + } + factoryCache.get(mech).add(factory); } - factoryCache.get(mech).add(factory); + } catch (Exception e) { + LOG.warn("Exception occurred while initialising {} factory. Exception details: {}\n", factory, e.getMessage(), e); } } }