2323import java .io .DataInputStream ;
2424import java .io .DataOutput ;
2525import java .io .IOException ;
26- import java .lang .reflect .Method ;
2726import java .nio .charset .StandardCharsets ;
2827import java .security .PrivilegedExceptionAction ;
2928import java .security .Security ;
3029import java .util .ArrayList ;
3130import java .util .List ;
3231import java .util .Map ;
32+ import java .util .function .Supplier ;
3333
3434import javax .security .auth .callback .Callback ;
3535import javax .security .auth .callback .CallbackHandler ;
4242import javax .security .sasl .SaslServer ;
4343import javax .security .sasl .SaslServerFactory ;
4444
45- import com .google .common .base .Supplier ;
46- import com .google .common .base .Suppliers ;
4745import org .apache .commons .codec .binary .Base64 ;
4846import org .apache .hadoop .classification .InterfaceAudience ;
4947import 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