io.undertow.servlet.api.DefaultServletConfig Maven / Gradle / Ivy
package io.undertow.servlet.api;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/**
* The default servlet config. By default this has quite a restrictive configuration, only allowing
* extensions in common use in the web to be served.
*
* @author Stuart Douglas
*/
public class DefaultServletConfig {
private static final String[] DEFAULT_ALLOWED_EXTENSIONS = {"js", "css", "png", "jpg", "gif", "html", "htm", "txt", "pdf"};
private static final String[] DEFAULT_DISALLOWED_EXTENSIONS = {"class", "jar", "war", "zip", "xml"};
private final boolean defaultAllowed;
private final Set allowed;
private final Set disallowed;
public DefaultServletConfig(final boolean defaultAllowed, final Set exceptions) {
this.defaultAllowed = defaultAllowed;
if(defaultAllowed) {
disallowed = Collections.unmodifiableSet(new HashSet(exceptions));
allowed = null;
} else {
allowed = Collections.unmodifiableSet(new HashSet(exceptions));
disallowed = null;
}
}
public DefaultServletConfig(final boolean defaultAllowed) {
this.defaultAllowed = defaultAllowed;
this.allowed = Collections.unmodifiableSet(new HashSet(Arrays.asList(DEFAULT_ALLOWED_EXTENSIONS)));
this.disallowed = Collections.unmodifiableSet(new HashSet(Arrays.asList(DEFAULT_DISALLOWED_EXTENSIONS)));
}
public DefaultServletConfig() {
this.defaultAllowed = false;
this.allowed = Collections.unmodifiableSet(new HashSet(Arrays.asList(DEFAULT_ALLOWED_EXTENSIONS)));
this.disallowed = Collections.unmodifiableSet(new HashSet(Arrays.asList(DEFAULT_DISALLOWED_EXTENSIONS)));
}
public boolean isDefaultAllowed() {
return defaultAllowed;
}
public Set getAllowed() {
return allowed;
}
public Set getDisallowed() {
return disallowed;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy