Skip to content
Closed
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