Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HADOOP-19308: FastSaslClientFactory failing to initialise due to NPE #7112

Open
wants to merge 1 commit into
base: branch-3.4.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,39 @@
import javax.security.sasl.SaslClientFactory;
import javax.security.sasl.SaslException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.hadoop.classification.InterfaceAudience;

/**
* Class for dealing with caching SASL client factories.
*/
@InterfaceAudience.LimitedPrivate({ "HDFS", "MapReduce" })
public class FastSaslClientFactory implements SaslClientFactory {

public static final Logger LOG = LoggerFactory.getLogger(FastSaslClientFactory.class);

private final Map<String, List<SaslClientFactory>> factoryCache =
new HashMap<String, List<SaslClientFactory>>();

public FastSaslClientFactory(Map<String, ?> props) {
final Enumeration<SaslClientFactory> 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<SaslClientFactory>());
try{
for (String mech : factory.getMechanismNames(props)) {
if (!factoryCache.containsKey(mech)) {
factoryCache.put(mech, new ArrayList<SaslClientFactory>());
}
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);
}
}
}
Expand Down