/** * Creates the {@link RestCsrfPreventionFilter} for the DataNode. Since the * DataNode HTTP server is not implemented in terms of the servlet API, it * takes some extra effort to obtain an instance of the filter. This method * takes care of configuration and implementing just enough of the servlet API * and related interfaces so that the DataNode can get a fully initialized * instance of the filter. * * @param conf configuration to read * @return initialized filter, or null if CSRF protection not enabled */ private static RestCsrfPreventionFilter createRestCsrfPreventionFilter( Configuration conf) { if (!conf.getBoolean(DFS_WEBHDFS_REST_CSRF_ENABLED_KEY, DFS_WEBHDFS_REST_CSRF_ENABLED_DEFAULT)) { return null; } String restCsrfClassName = RestCsrfPreventionFilter.class.getName(); Map<String, String> restCsrfParams = RestCsrfPreventionFilter .getFilterParams(conf, "dfs.webhdfs.rest-csrf."); RestCsrfPreventionFilter filter = new RestCsrfPreventionFilter(); try { filter.init(new MapBasedFilterConfig(restCsrfClassName, restCsrfParams)); } catch (ServletException e) { throw new IllegalStateException( "Failed to initialize RestCsrfPreventionFilter.", e); } return filter; }
DFS_WEBHDFS_REST_CSRF_ENABLED_DEFAULT)) { Map<String, String> restCsrfParams = RestCsrfPreventionFilter .getFilterParams(conf, "dfs.webhdfs.rest-csrf."); String restCsrfClassName = RestCsrfPreventionFilter.class.getName(); HttpServer2.defineFilter(httpServer2.getWebAppContext(),