diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index af0b5d9559e..5bf6f308347 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -188,6 +188,9 @@ Release 2.6.0 - UNRELEASED YARN-2229. Changed the integer field of ContainerId to be long type. (Tsuyoshi OZAWA via jianhe) + YARN-2547. Cross Origin Filter throws UnsupportedOperationException upon + destroy (Mit Desai via jeagles) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/timeline/webapp/CrossOriginFilter.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/timeline/webapp/CrossOriginFilter.java index 5a0703d4047..cceee5422db 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/timeline/webapp/CrossOriginFilter.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/timeline/webapp/CrossOriginFilter.java @@ -150,8 +150,8 @@ public class CrossOriginFilter implements Filter { if (allowedMethodsConfig == null) { allowedMethodsConfig = ALLOWED_METHODS_DEFAULT; } - allowedMethods = - Arrays.asList(allowedMethodsConfig.trim().split("\\s*,\\s*")); + allowedMethods.addAll( + Arrays.asList(allowedMethodsConfig.trim().split("\\s*,\\s*"))); LOG.info("Allowed Methods: " + getAllowedMethodsHeader()); } @@ -161,8 +161,8 @@ public class CrossOriginFilter implements Filter { if (allowedHeadersConfig == null) { allowedHeadersConfig = ALLOWED_HEADERS_DEFAULT; } - allowedHeaders = - Arrays.asList(allowedHeadersConfig.trim().split("\\s*,\\s*")); + allowedHeaders.addAll( + Arrays.asList(allowedHeadersConfig.trim().split("\\s*,\\s*"))); LOG.info("Allowed Headers: " + getAllowedHeadersHeader()); } @@ -172,8 +172,8 @@ public class CrossOriginFilter implements Filter { if (allowedOriginsConfig == null) { allowedOriginsConfig = ALLOWED_ORIGINS_DEFAULT; } - allowedOrigins = - Arrays.asList(allowedOriginsConfig.trim().split("\\s*,\\s*")); + allowedOrigins.addAll( + Arrays.asList(allowedOriginsConfig.trim().split("\\s*,\\s*"))); allowAllOrigins = allowedOrigins.contains("*"); LOG.info("Allowed Origins: " + StringUtils.join(allowedOrigins, ',')); LOG.info("Allow All Origins: " + allowAllOrigins); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/timeline/webapp/TestCrossOriginFilter.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/timeline/webapp/TestCrossOriginFilter.java index ccc9bbfde56..e0990f97c2b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/timeline/webapp/TestCrossOriginFilter.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/timeline/webapp/TestCrossOriginFilter.java @@ -217,6 +217,55 @@ public class TestCrossOriginFilter { verify(mockChain).doFilter(mockReq, mockRes); } + @Test + public void testCrossOriginFilterAfterRestart() throws ServletException { + + // Setup the configuration settings of the server + Map conf = new HashMap(); + conf.put(CrossOriginFilter.ALLOWED_ORIGINS, "example.com"); + conf.put(CrossOriginFilter.ALLOWED_HEADERS, "X-Requested-With,Accept"); + conf.put(CrossOriginFilter.ALLOWED_METHODS, "GET,POST"); + FilterConfig filterConfig = new FilterConfigTest(conf); + + // Object under test + CrossOriginFilter filter = new CrossOriginFilter(); + filter.init(filterConfig); + + //verify filter values + Assert.assertTrue("Allowed headers do not match", + filter.getAllowedHeadersHeader() + .compareTo("X-Requested-With,Accept") == 0); + Assert.assertTrue("Allowed methods do not match", + filter.getAllowedMethodsHeader() + .compareTo("GET,POST") == 0); + Assert.assertTrue(filter.isOriginAllowed("example.com")); + + //destroy filter values and clear conf + filter.destroy(); + conf.clear(); + + // Setup the configuration settings of the server + conf.put(CrossOriginFilter.ALLOWED_ORIGINS, "newexample.com"); + conf.put(CrossOriginFilter.ALLOWED_HEADERS, "Content-Type,Origin"); + conf.put(CrossOriginFilter.ALLOWED_METHODS, "GET,HEAD"); + filterConfig = new FilterConfigTest(conf); + + //initialize filter + filter.init(filterConfig); + + //verify filter values + Assert.assertTrue("Allowed headers do not match", + filter.getAllowedHeadersHeader() + .compareTo("Content-Type,Origin") == 0); + Assert.assertTrue("Allowed methods do not match", + filter.getAllowedMethodsHeader() + .compareTo("GET,HEAD") == 0); + Assert.assertTrue(filter.isOriginAllowed("newexample.com")); + + //destroy filter values + filter.destroy(); + } + private static class FilterConfigTest implements FilterConfig { final Map map;