HADOOP-19227. ipc.Server accelerate token negotiation only for the default mechanism. (#6949)
This commit is contained in:
parent
7638b4727e
commit
9dad697dbc
@ -106,6 +106,7 @@
|
||||
import org.apache.hadoop.ipc.protobuf.RpcHeaderProtos.RPCTraceInfoProto;
|
||||
import org.apache.hadoop.net.NetUtils;
|
||||
import org.apache.hadoop.security.AccessControlException;
|
||||
import org.apache.hadoop.security.SaslConstants;
|
||||
import org.apache.hadoop.security.SaslPropertiesResolver;
|
||||
import org.apache.hadoop.security.SaslRpcServer;
|
||||
import org.apache.hadoop.security.SaslRpcServer.AuthMethod;
|
||||
@ -2604,7 +2605,8 @@ private RpcSaslProto buildSaslNegotiateResponse()
|
||||
RpcSaslProto negotiateMessage = negotiateResponse;
|
||||
// accelerate token negotiation by sending initial challenge
|
||||
// in the negotiation response
|
||||
if (enabledAuthMethods.contains(AuthMethod.TOKEN)) {
|
||||
if (enabledAuthMethods.contains(AuthMethod.TOKEN)
|
||||
&& SaslConstants.SASL_MECHANISM_DEFAULT.equals(AuthMethod.TOKEN.getMechanismName())) {
|
||||
saslServer = createSaslServer(AuthMethod.TOKEN);
|
||||
byte[] challenge = saslServer.evaluateResponse(new byte[0]);
|
||||
RpcSaslProto.Builder negotiateBuilder =
|
||||
|
@ -32,7 +32,7 @@ public class SaslConstants {
|
||||
|
||||
private static final String SASL_MECHANISM_ENV = "HADOOP_SASL_MECHANISM";
|
||||
public static final String SASL_MECHANISM;
|
||||
private static final String SASL_MECHANISM_DEFAULT = "DIGEST-MD5";
|
||||
public static final String SASL_MECHANISM_DEFAULT = "DIGEST-MD5";
|
||||
|
||||
static {
|
||||
final String mechanism = System.getenv(SASL_MECHANISM_ENV);
|
||||
|
@ -39,6 +39,7 @@
|
||||
import javax.security.auth.callback.PasswordCallback;
|
||||
import javax.security.auth.callback.UnsupportedCallbackException;
|
||||
import javax.security.auth.kerberos.KerberosPrincipal;
|
||||
import javax.security.sasl.AuthorizeCallback;
|
||||
import javax.security.sasl.RealmCallback;
|
||||
import javax.security.sasl.RealmChoiceCallback;
|
||||
import javax.security.sasl.Sasl;
|
||||
@ -681,9 +682,17 @@ public void handle(Callback[] callbacks)
|
||||
pc = (PasswordCallback) callback;
|
||||
} else if (callback instanceof RealmCallback) {
|
||||
rc = (RealmCallback) callback;
|
||||
} else if (callback instanceof AuthorizeCallback) {
|
||||
final AuthorizeCallback ac = (AuthorizeCallback) callback;
|
||||
final String authId = ac.getAuthenticationID();
|
||||
final String authzId = ac.getAuthorizationID();
|
||||
ac.setAuthorized(authId.equals(authzId));
|
||||
if (ac.isAuthorized()) {
|
||||
ac.setAuthorizedID(authzId);
|
||||
}
|
||||
} else {
|
||||
throw new UnsupportedCallbackException(callback,
|
||||
"Unrecognized SASL client callback");
|
||||
"Unrecognized SASL client callback " + callback.getClass());
|
||||
}
|
||||
}
|
||||
if (nc != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user