@@ -152,6 +152,7 @@ public class WebHdfsFileSystem extends FileSystem
152152 + "/v" + VERSION ;
153153 public static final String EZ_HEADER = "X-Hadoop-Accept-EZ" ;
154154 public static final String FEFINFO_HEADER = "X-Hadoop-feInfo" ;
155+ public static final String DFS_HTTP_POLICY_KEY = "dfs.http.policy" ;
155156
156157 /**
157158 * Default connection factory may be overridden in tests to use smaller
@@ -181,6 +182,7 @@ public class WebHdfsFileSystem extends FileSystem
181182
182183 private DFSOpsCountStatistics storageStatistics ;
183184 private KeyProvider testProvider ;
185+ private boolean isTLSKrb ;
184186
185187 /**
186188 * Return the protocol scheme for the FileSystem.
@@ -242,6 +244,7 @@ public synchronized void initialize(URI uri, Configuration conf
242244 .newDefaultURLConnectionFactory (connectTimeout , readTimeout , conf );
243245 }
244246
247+ this .isTLSKrb = "HTTPS_ONLY" .equals (conf .get (DFS_HTTP_POLICY_KEY ));
245248
246249 ugi = UserGroupInformation .getCurrentUser ();
247250 this .uri = URI .create (uri .getScheme () + "://" + uri .getAuthority ());
@@ -699,6 +702,11 @@ protected HttpURLConnection connect(URL url) throws IOException {
699702 //redirect hostname and port
700703 redirectHost = null ;
701704
705+ if (url .getProtocol ().equals ("http" ) &&
706+ UserGroupInformation .isSecurityEnabled () &&
707+ isTLSKrb ) {
708+ throw new IOException ("Access denied: dfs.http.policy is HTTPS_ONLY." );
709+ }
702710
703711 // resolve redirects for a DN operation unless already resolved
704712 if (op .getRedirect () && !redirected ) {
0 commit comments