From aa096d56c1b08733532f72729971b4750a5a36fe Mon Sep 17 00:00:00 2001
From: Simone Bordet
A typical configuration could be: + *
A typical configuration could be:
** <web-app ...> * ... @@ -93,7 +90,7 @@ import org.eclipse.jetty.util.log.Logger; * </filter-mapping> * ... * </web-app> - *+ * */ public class CrossOriginFilter implements Filter { @@ -195,8 +192,8 @@ public class CrossOriginFilter implements Filter exposedHeaders.addAll(Arrays.asList(exposedHeadersConfig.split(","))); String chainPreflightConfig = config.getInitParameter(OLD_CHAIN_PREFLIGHT_PARAM); - if (chainPreflightConfig!=null) // TODO remove this - LOG.warn("DEPRECATED CONFIGURATION: Use "+CHAIN_PREFLIGHT_PARAM+ " instead of "+OLD_CHAIN_PREFLIGHT_PARAM); + if (chainPreflightConfig != null) + LOG.warn("DEPRECATED CONFIGURATION: Use " + CHAIN_PREFLIGHT_PARAM + " instead of " + OLD_CHAIN_PREFLIGHT_PARAM); else chainPreflightConfig = config.getInitParameter(CHAIN_PREFLIGHT_PARAM); if (chainPreflightConfig == null) @@ -206,13 +203,13 @@ public class CrossOriginFilter implements Filter if (LOG.isDebugEnabled()) { LOG.debug("Cross-origin filter configuration: " + - ALLOWED_ORIGINS_PARAM + " = " + allowedOriginsConfig + ", " + - ALLOWED_METHODS_PARAM + " = " + allowedMethodsConfig + ", " + - ALLOWED_HEADERS_PARAM + " = " + allowedHeadersConfig + ", " + - PREFLIGHT_MAX_AGE_PARAM + " = " + preflightMaxAgeConfig + ", " + - ALLOW_CREDENTIALS_PARAM + " = " + allowedCredentialsConfig + "," + - EXPOSED_HEADERS_PARAM + " = " + exposedHeadersConfig + "," + - CHAIN_PREFLIGHT_PARAM + " = " + chainPreflightConfig + ALLOWED_ORIGINS_PARAM + " = " + allowedOriginsConfig + ", " + + ALLOWED_METHODS_PARAM + " = " + allowedMethodsConfig + ", " + + ALLOWED_HEADERS_PARAM + " = " + allowedHeadersConfig + ", " + + PREFLIGHT_MAX_AGE_PARAM + " = " + preflightMaxAgeConfig + ", " + + ALLOW_CREDENTIALS_PARAM + " = " + allowedCredentialsConfig + "," + + EXPOSED_HEADERS_PARAM + " = " + exposedHeadersConfig + "," + + CHAIN_PREFLIGHT_PARAM + " = " + chainPreflightConfig ); } } @@ -297,7 +294,7 @@ public class CrossOriginFilter implements Filter { if (allowedOrigin.contains("*")) { - Matcher matcher = createMatcher(origin,allowedOrigin); + Matcher matcher = createMatcher(origin, allowedOrigin); if (matcher.matches()) return true; } @@ -319,8 +316,8 @@ public class CrossOriginFilter implements Filter private String parseAllowedWildcardOriginToRegex(String allowedOrigin) { - String regex = allowedOrigin.replace(".","\\."); - return regex.replace("*",".*"); // we want to be greedy here to match multiple subdomains, thus we use .* + String regex = allowedOrigin.replace(".", "\\."); + return regex.replace("*", ".*"); // we want to be greedy here to match multiple subdomains, thus we use .* } private boolean isSimpleRequest(HttpServletRequest request) @@ -362,7 +359,7 @@ public class CrossOriginFilter implements Filter private void handlePreflightResponse(HttpServletRequest request, HttpServletResponse response, String origin) { boolean methodAllowed = isMethodAllowed(request); - + if (!methodAllowed) return; List