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     */
018    package org.apache.hadoop.hdfs.protocol.datatransfer;
019    
020    import java.net.InetAddress;
021    
022    import org.apache.hadoop.conf.Configurable;
023    import org.apache.hadoop.conf.Configuration;
024    import org.apache.hadoop.hdfs.DFSConfigKeys;
025    import 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     */
036    public 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       * @param conf
043       * @return TrustedChannelResolver
044       */
045      public static TrustedChannelResolver getInstance(Configuration conf) {
046        Class<? extends TrustedChannelResolver> clazz =
047          conf.getClass(
048              DFSConfigKeys.DFS_TRUSTEDCHANNEL_RESOLVER_CLASS,
049              TrustedChannelResolver.class, TrustedChannelResolver.class);
050        return ReflectionUtils.newInstance(clazz, conf);
051      }
052    
053      @Override
054      public void setConf(Configuration conf) {
055        this.conf = conf;
056      }
057    
058      @Override
059      public Configuration getConf() {
060        return conf;
061      }
062    
063      /**
064       * Return boolean value indicating whether a channel is trusted or not
065       * from a client's perspective.
066       * @return true if the channel is trusted and false otherwise.
067       */
068      public boolean isTrusted() {
069        return false;
070      }
071    
072    
073      /**
074       * Identify boolean value indicating whether a channel is trusted or not.
075       * @param peerAddress address of the peer
076       * @return true if the channel is trusted and false otherwise.
077       */
078      public boolean isTrusted(InetAddress peerAddress) {
079        return false;
080      }
081    }