hadoop Verifier 源码

  • 2022-10-20
  • 浏览 (203)

haddop Verifier 代码

文件路径:/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/security/Verifier.java

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.hadoop.oncrpc.security;

import org.apache.hadoop.oncrpc.XDR;

/**
 * Base class for verifier. Currently our authentication only supports 3 types
 * of auth flavors: {@link RpcAuthInfo.AuthFlavor#AUTH_NONE}, {@link RpcAuthInfo.AuthFlavor#AUTH_SYS},
 * and {@link RpcAuthInfo.AuthFlavor#RPCSEC_GSS}. Thus for verifier we only need to handle
 * AUTH_NONE and RPCSEC_GSS
 */
public abstract class Verifier extends RpcAuthInfo {

  protected Verifier(AuthFlavor flavor) {
    super(flavor);
  }

  /**
   * Read both AuthFlavor and the verifier from the XDR.
   * @param xdr XDR message
   * @return verifier
   */
  public static Verifier readFlavorAndVerifier(XDR xdr) {
    AuthFlavor flavor = AuthFlavor.fromValue(xdr.readInt());
    final Verifier verifer;
    if (flavor == AuthFlavor.AUTH_NONE) {
      verifer = new VerifierNone();
    } else if (flavor == AuthFlavor.AUTH_SYS) {
      // Added in HADOOP-15307 based on HDFS-5085:
      // When the auth flavor is AUTH_SYS, the corresponding verifier is
      // AUTH_NONE. I.e., it is impossible to have a verifier with auth
      // flavor AUTH_SYS.
      verifer = new VerifierNone();
    } else if (flavor == AuthFlavor.RPCSEC_GSS) {
      verifer = new VerifierGSS();
    } else {
      throw new UnsupportedOperationException("Unsupported verifier flavor: "
          + flavor);
    }
    verifer.read(xdr);
    return verifer;
  }
  
  /**
   * Write AuthFlavor and the verifier to the XDR.
   * @param verifier written to XDR
   * @param xdr XDR message
   */
  public static void writeFlavorAndVerifier(Verifier verifier, XDR xdr) {
    if (verifier instanceof VerifierNone) {
      xdr.writeInt(AuthFlavor.AUTH_NONE.getValue());
    } else if (verifier instanceof VerifierGSS) {
      xdr.writeInt(AuthFlavor.RPCSEC_GSS.getValue());
    } else {
      throw new UnsupportedOperationException("Cannot recognize the verifier");
    }
    verifier.write(xdr);
  }  
}

相关信息

hadoop 源码目录

相关文章

hadoop Credentials 源码

hadoop CredentialsGSS 源码

hadoop CredentialsNone 源码

hadoop CredentialsSys 源码

hadoop RpcAuthInfo 源码

hadoop SecurityHandler 源码

hadoop SysSecurityHandler 源码

hadoop VerifierGSS 源码

hadoop VerifierNone 源码

0  赞