001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hdfs.protocol.datatransfer; 019 020import java.net.InetAddress; 021 022import org.apache.hadoop.conf.Configurable; 023import org.apache.hadoop.conf.Configuration; 024import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys; 025import org.apache.hadoop.util.ReflectionUtils; 026 027/** 028 * Class used to indicate whether a channel is trusted or not. 029 * The default implementation is to return false indicating that 030 * the channel is not trusted. 031 * This class can be overridden to provide custom logic to determine 032 * whether a channel is trusted or not. 033 * The custom class can be specified via configuration. 034 * 035 */ 036public class TrustedChannelResolver implements Configurable { 037 Configuration conf; 038 039 /** 040 * Returns an instance of TrustedChannelResolver. 041 * Looks up the configuration to see if there is custom class specified. 042 * @return TrustedChannelResolver 043 */ 044 public static TrustedChannelResolver getInstance(Configuration conf) { 045 Class<? extends TrustedChannelResolver> clazz = 046 conf.getClass( 047 HdfsClientConfigKeys.DFS_TRUSTEDCHANNEL_RESOLVER_CLASS, 048 TrustedChannelResolver.class, TrustedChannelResolver.class); 049 return ReflectionUtils.newInstance(clazz, conf); 050 } 051 052 @Override 053 public void setConf(Configuration conf) { 054 this.conf = conf; 055 } 056 057 @Override 058 public Configuration getConf() { 059 return conf; 060 } 061 062 /** 063 * Return boolean value indicating whether a channel is trusted or not 064 * from a client's perspective. 065 * @return true if the channel is trusted and false otherwise. 066 */ 067 public boolean isTrusted() { 068 return false; 069 } 070 071 072 /** 073 * Identify boolean value indicating whether a channel is trusted or not. 074 * @param peerAddress address of the peer 075 * @return true if the channel is trusted and false otherwise. 076 */ 077 public boolean isTrusted(InetAddress peerAddress) { 078 return false; 079 } 080}