*/
public CORSConfiguration(final Properties props)
throws CORSConfigurationException {
try {
PropertyRetriever pr = new PropertyRetriever(props);
// Parse the allow generic HTTP requests option
allowGenericHttpRequests = pr.getOptBoolean("cors.allowGenericHttpRequests", true);
// Parse the allowed origins list
String originSpec = pr.getOptString("cors.allowOrigin", "*").trim();
allowedOrigins = new HashSet<ValidatedOrigin>();
if (originSpec.equals("*")) {
allowAnyOrigin = true;
} else {
allowAnyOrigin = false;
String[] urls = parseWords(originSpec);
for (String url: urls) {
try {
allowedOrigins.add(new Origin(url).validate());
} catch (OriginException e) {
throw new PropertyParseException("Bad origin URL in property cors.allowOrigin: " + url);
}
}
}
// Parse the allow origin suffix matching option
allowSubdomains = pr.getOptBoolean("cors.allowSubdomains", false);
// Parse the supported methods list
String methodSpec = pr.getOptString("cors.supportedMethods", "GET, POST, HEAD, OPTIONS").trim().toUpperCase();
String[] methodNames = parseWords(methodSpec);
supportedMethods = new HashSet<HTTPMethod>();
for (String methodName: methodNames) {
try {
supportedMethods.add(HTTPMethod.valueOf(methodName));
} catch (IllegalArgumentException e) {
throw new PropertyParseException("Bad HTTP method name in property cors.allowMethods: " + methodName);
}
}
// Parse the supported headers list
String headerSpec;
// Empty value has special meaning of "no supported headers"
try {
headerSpec = pr.getString("cors.supportedHeaders");
} catch (PropertyParseException e) {
headerSpec = "*";
}
if (headerSpec.equals("*")) {
supportAnyHeader = true;
supportedHeaders = Collections.unmodifiableSet(new HashSet<HeaderFieldName>());
} else {
supportAnyHeader = false;
String[] headers = parseWords(headerSpec);
supportedHeaders = new HashSet<HeaderFieldName>();
for (String header: headers) {
try {
supportedHeaders.add(new HeaderFieldName(header));
} catch (IllegalArgumentException e) {
throw new PropertyParseException("Bad header field name in property cors.supportedHeaders: " + header);
}
}
}
// Parse the exposed headers list
exposedHeaders = new HashSet<HeaderFieldName>();
for (String header: parseWords(pr.getOptString("cors.exposedHeaders", ""))) {
try {
exposedHeaders.add(new HeaderFieldName(header));
} catch (IllegalArgumentException e) {
throw new PropertyParseException("Bad header field name in property cors.exposedHeaders: " + header);
}
}
// Parse the allow credentials option
supportsCredentials = pr.getOptBoolean("cors.supportsCredentials", true);
// Parse the max cache age of preflight requests
maxAge = pr.getOptInt("cors.maxAge", -1);
} catch (PropertyParseException e) {
// Simply reformat as a more specific exception class