Skip to content

Commit c2b6ab4

Browse files
committed
Avoid using Guava.
1 parent e4e04b6 commit c2b6ab4

File tree

2 files changed

+11
-25
lines changed

2 files changed

+11
-25
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/SaslMechanismFactory.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public final class SaslMechanismFactory {
3636
static final Logger LOG = LoggerFactory.getLogger(SaslMechanismFactory.class);
3737

3838
private static final String SASL_MECHANISM_ENV = "HADOOP_SASL_MECHANISM";
39-
private static final String SASL_MECHANISM;
39+
private static volatile String SASL_MECHANISM;
4040

41-
static {
41+
private static synchronized String getSynchronously() {
4242
// env
4343
final String envValue = System.getenv(SASL_MECHANISM_ENV);
4444
LOG.debug("{} = {} (env)", SASL_MECHANISM_ENV, envValue);
@@ -61,10 +61,12 @@ public final class SaslMechanismFactory {
6161
: confValue != null ? confValue
6262
: HADOOP_SECURITY_SASL_MECHANISM_DEFAULT;
6363
LOG.debug("SASL_MECHANISM = {} (effective)", SASL_MECHANISM);
64+
return SASL_MECHANISM;
6465
}
6566

6667
public static String getMechanism() {
67-
return SASL_MECHANISM;
68+
final String value = SASL_MECHANISM;
69+
return value != null ? value : getSynchronously();
6870
}
6971

7072
public static boolean isDefaultMechanism(String mechanism) {

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/SaslRpcServer.java

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
import java.io.DataInputStream;
2424
import java.io.DataOutput;
2525
import java.io.IOException;
26-
import java.lang.reflect.Method;
2726
import java.nio.charset.StandardCharsets;
2827
import java.security.PrivilegedExceptionAction;
2928
import java.security.Security;
3029
import java.util.ArrayList;
3130
import java.util.List;
3231
import java.util.Map;
32+
import java.util.function.Supplier;
3333

3434
import javax.security.auth.callback.Callback;
3535
import javax.security.auth.callback.CallbackHandler;
@@ -42,8 +42,6 @@
4242
import javax.security.sasl.SaslServer;
4343
import javax.security.sasl.SaslServerFactory;
4444

45-
import com.google.common.base.Supplier;
46-
import com.google.common.base.Suppliers;
4745
import org.apache.commons.codec.binary.Base64;
4846
import org.apache.hadoop.classification.InterfaceAudience;
4947
import org.apache.hadoop.classification.InterfaceStability;
@@ -222,35 +220,19 @@ public static String[] splitKerberosName(String fullName) {
222220
return fullName.split("[/@]");
223221
}
224222

225-
private static String getMechanism() {
226-
// use reflection to avoid loading the class
227-
final String className = "org.apache.hadoop.security.SaslMechanismFactory";
228-
final String methodName = "getMechanism";
229-
try {
230-
final Method method = Class.forName(className).getMethod(methodName);
231-
return method.invoke(null).toString();
232-
} catch (Exception e) {
233-
throw new IllegalStateException("Failed to invoke " + methodName + " from " + className, e);
234-
}
235-
}
236-
237-
/** Memoize the mechanism value. */
238-
private static final Supplier<String> MECHANISM_SUPPLIER
239-
= Suppliers.memoize(SaslRpcServer::getMechanism);
240-
241223
/** Authentication method */
242224
@InterfaceStability.Evolving
243225
public enum AuthMethod {
244226
SIMPLE((byte) 80, ""),
245227
KERBEROS((byte) 81, "GSSAPI"),
246228
@Deprecated
247-
DIGEST((byte) 82, MECHANISM_SUPPLIER),
248-
TOKEN((byte) 82, MECHANISM_SUPPLIER),
229+
DIGEST((byte) 82, SaslMechanismFactory::getMechanism),
230+
TOKEN((byte) 82, SaslMechanismFactory::getMechanism),
249231
PLAIN((byte) 83, "PLAIN");
250232

251233
/** The code for this method. */
252234
public final byte code;
253-
private final Supplier<String> mechanismName;
235+
public final Supplier<String> mechanismName;
254236

255237
private AuthMethod(byte code, String mechanismName) {
256238
this(code, () -> mechanismName);
@@ -259,6 +241,8 @@ private AuthMethod(byte code, String mechanismName) {
259241
AuthMethod(byte code, Supplier<String> mechanismName) {
260242
this.code = code;
261243
this.mechanismName = mechanismName;
244+
LOG.debug("{} {}: code={}, mechanism=\"{}\"",
245+
getClass().getSimpleName(), name(), code, mechanismName);
262246
}
263247

264248
private static final int FIRST_CODE = values()[0].code;

0 commit comments

Comments
 (0)