YARN-2511. Allowed all origins by default when CrossOriginFilter is enabled. Contributed by Jonathan Eagles.
(cherry picked from commit 51a4faf521
)
This commit is contained in:
parent
04d325afff
commit
1e40cbba7f
|
@ -155,6 +155,9 @@ Release 2.6.0 - UNRELEASED
|
||||||
YARN-2509. Enable Cross Origin Filter for timeline server only and not all
|
YARN-2509. Enable Cross Origin Filter for timeline server only and not all
|
||||||
Yarn servers (Mit Desai via jeagles)
|
Yarn servers (Mit Desai via jeagles)
|
||||||
|
|
||||||
|
YARN-2511. Allowed all origins by default when CrossOriginFilter is
|
||||||
|
enabled. (Jonathan Eagles via zjshen)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
|
|
@ -76,6 +76,7 @@ public class CrossOriginFilter implements Filter {
|
||||||
private List<String> allowedMethods = new ArrayList<String>();
|
private List<String> allowedMethods = new ArrayList<String>();
|
||||||
private List<String> allowedHeaders = new ArrayList<String>();
|
private List<String> allowedHeaders = new ArrayList<String>();
|
||||||
private List<String> allowedOrigins = new ArrayList<String>();
|
private List<String> allowedOrigins = new ArrayList<String>();
|
||||||
|
private boolean allowAllOrigins = true;
|
||||||
private String maxAge;
|
private String maxAge;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -171,7 +172,9 @@ public class CrossOriginFilter implements Filter {
|
||||||
}
|
}
|
||||||
allowedOrigins =
|
allowedOrigins =
|
||||||
Arrays.asList(allowedOriginsConfig.trim().split("\\s*,\\s*"));
|
Arrays.asList(allowedOriginsConfig.trim().split("\\s*,\\s*"));
|
||||||
|
allowAllOrigins = allowedOrigins.contains("*");
|
||||||
LOG.info("Allowed Origins: " + StringUtils.join(allowedOrigins, ','));
|
LOG.info("Allowed Origins: " + StringUtils.join(allowedOrigins, ','));
|
||||||
|
LOG.info("Allow All Origins: " + allowAllOrigins);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeMaxAge(FilterConfig filterConfig) {
|
private void initializeMaxAge(FilterConfig filterConfig) {
|
||||||
|
@ -199,8 +202,9 @@ public class CrossOriginFilter implements Filter {
|
||||||
return origin != null;
|
return origin != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isOriginAllowed(String origin) {
|
@VisibleForTesting
|
||||||
return allowedOrigins.contains(origin);
|
boolean isOriginAllowed(String origin) {
|
||||||
|
return allowAllOrigins || allowedOrigins.contains(origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean areHeadersAllowed(String accessControlRequestHeaders) {
|
private boolean areHeadersAllowed(String accessControlRequestHeaders) {
|
||||||
|
@ -213,7 +217,7 @@ public class CrossOriginFilter implements Filter {
|
||||||
|
|
||||||
private boolean isMethodAllowed(String accessControlRequestMethod) {
|
private boolean isMethodAllowed(String accessControlRequestMethod) {
|
||||||
if (accessControlRequestMethod == null) {
|
if (accessControlRequestMethod == null) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
return allowedMethods.contains(accessControlRequestMethod);
|
return allowedMethods.contains(accessControlRequestMethod);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
@ -65,6 +66,20 @@ public class TestCrossOriginFilter {
|
||||||
verify(mockChain).doFilter(mockReq, mockRes);
|
verify(mockChain).doFilter(mockReq, mockRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAllowAllOrigins() throws ServletException, IOException {
|
||||||
|
|
||||||
|
// Setup the configuration settings of the server
|
||||||
|
Map<String, String> conf = new HashMap<String, String>();
|
||||||
|
conf.put(CrossOriginFilter.ALLOWED_ORIGINS, "*");
|
||||||
|
FilterConfig filterConfig = new FilterConfigTest(conf);
|
||||||
|
|
||||||
|
// Object under test
|
||||||
|
CrossOriginFilter filter = new CrossOriginFilter();
|
||||||
|
filter.init(filterConfig);
|
||||||
|
Assert.assertTrue(filter.isOriginAllowed("example.org"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDisallowedOrigin() throws ServletException, IOException {
|
public void testDisallowedOrigin() throws ServletException, IOException {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue