HostRestrictingAuthorizationFilterHandler extends SimpleChannelInboundHandler<HttpRequest> { public static HostRestrictingAuthorizationFilter initializeState(Configuration conf) { String confName = HostRestrictingAuthorizationFilter.HDFS_CONFIG_PREFIX + HostRestrictingAuthorizationFilter.RESTRICTION_CONFIG; String confValue = conf.get(confName); confValue = (confValue == null ? "" : confValue); Map<String, String> confMap = ImmutableMap.of(HostRestrictingAuthorizationFilter.RESTRICTION_CONFIG , confValue); FilterConfig fc = new DatanodeHttpServer.MapBasedFilterConfig( HostRestrictingAuthorizationFilter.class.getName(), confMap); HostRestrictingAuthorizationFilter hostRestrictingAuthorizationFilter = new HostRestrictingAuthorizationFilter(); try { hostRestrictingAuthorizationFilter.init(fc); } catch (ServletException e) { throw new IllegalStateException( "Failed to initialize HostRestrictingAuthorizationFilter.", e); } return hostRestrictingAuthorizationFilter; } HostRestrictingAuthorizationFilterHandler(
      HostRestrictingAuthorizationFilter hostRestrictingAuthorizationFilter);  HostRestrictingAuthorizationFilterHandler(); static HostRestrictingAuthorizationFilter initializeState(Configuration conf); @Override void exceptionCaught(ChannelHandlerContext ctx, Throwable cause);  }
@Test public void testMultipleAcceptedGETsOneChannel() throws Exception { Configuration conf = new Configuration(); conf.set(CONFNAME, "*,*,/allowed"); HostRestrictingAuthorizationFilter filter = HostRestrictingAuthorizationFilterHandler.initializeState(conf); EmbeddedChannel channel = new CustomEmbeddedChannel("127.0.0.1", 1006, new HostRestrictingAuthorizationFilterHandler(filter)); FullHttpRequest allowedHttpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, WebHdfsFileSystem.PATH_PREFIX + "/allowed/file_one?op=OPEN"); FullHttpRequest allowedHttpRequest2 = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, WebHdfsFileSystem.PATH_PREFIX + "/allowed/file_two?op=OPEN"); FullHttpRequest allowedHttpRequest3 = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, WebHdfsFileSystem.PATH_PREFIX + "/allowed/file_three?op=OPEN"); assertTrue("Should successfully accept request", channel.writeInbound(allowedHttpRequest)); assertTrue("Should successfully accept request, second time", channel.writeInbound(allowedHttpRequest2)); assertTrue("Should successfully accept request, third time", channel.writeInbound(allowedHttpRequest3)); }
@Test public void testMultipleChannels() throws Exception { Configuration conf = new Configuration(); conf.set(CONFNAME, "*,*,/allowed"); HostRestrictingAuthorizationFilter filter = HostRestrictingAuthorizationFilterHandler.initializeState(conf); EmbeddedChannel channel1 = new CustomEmbeddedChannel("127.0.0.1", 1006, new HostRestrictingAuthorizationFilterHandler(filter)); EmbeddedChannel channel2 = new CustomEmbeddedChannel("127.0.0.2", 1006, new HostRestrictingAuthorizationFilterHandler(filter)); EmbeddedChannel channel3 = new CustomEmbeddedChannel("127.0.0.3", 1006, new HostRestrictingAuthorizationFilterHandler(filter)); FullHttpRequest allowedHttpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, WebHdfsFileSystem.PATH_PREFIX + "/allowed/file_one?op=OPEN"); FullHttpRequest allowedHttpRequest2 = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, WebHdfsFileSystem.PATH_PREFIX + "/allowed/file_two?op=OPEN"); FullHttpRequest allowedHttpRequest3 = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, WebHdfsFileSystem.PATH_PREFIX + "/allowed/file_three?op=OPEN"); assertTrue("Should successfully accept request", channel1.writeInbound(allowedHttpRequest)); assertTrue("Should successfully accept request, second time", channel2.writeInbound(allowedHttpRequest2)); channel1.close(); assertTrue("Should successfully accept request, third time", channel3.writeInbound(allowedHttpRequest3)); }