Package org.faceless.publisher.type
Interface EgressFilter
public interface EgressFilter
An interface which can be used to limit access to a resource at a particular URL.
This can be set on the ReportFactory via
ReportFactory.setEgressFilter(org.faceless.publisher.type.EgressFilter)-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanstatic final EgressFilterAn EgressFilter equivalent toEgressFilter.parse("trustworthy or from-file or not file or from-api")that has the following restrictions: special URLs such as those with the schemesabout:ordata:can always be accessed URLs specified programatically (by way of an API call) can always be accessedfileandjarURLs can only ever be accessed fromfileandjarURLs otherwise all access is allowed -
Method Summary
Modifier and TypeMethodDescriptionstatic EgressFilterand(EgressFilter... filters) Return an EgressFilter built from a sequence of other EgressFilters.static EgressFiltermatchOrReplace(Pattern pattern, String replace) Return an EgressFilter the equivalent ofmatch(pattern)orreplace(pattern, replace)without having to worry about escaping.static EgressFilternot(EgressFilter a) Return an EgressFilter which "inverts" the supplied filter.static EgressFilteror(EgressFilter... filters) Return an EgressFilter built from a sequence of other EgressFilters.static EgressFilterParse an expression string describing an EgressFilter.static EgressFilterReturn an EgressFilter the equivalent ofpath(path...), without having to worry about escaping the path.This method will be supplied with the URL about to be loaded, and the URL of the document, stylesheet, other resource loading it.static EgressFilterthen(EgressFilter a, EgressFilter b) Return an EgressFilter which implements the "then" logical operation.
-
Field Details
-
DEBUG
static final boolean DEBUG -
DEFAULT
An EgressFilter equivalent toEgressFilter.parse("trustworthy or from-file or not file or from-api")that has the following restrictions:- special URLs such as those with the schemes
about:ordata:can always be accessed - URLs specified programatically (by way of an API call) can always be accessed
fileandjarURLs can only ever be accessed fromfileandjarURLs- otherwise all access is allowed
- special URLs such as those with the schemes
-
-
Method Details
-
parse
Parse an expression string describing an EgressFilter. The expression uses the terms "and", "or", "not", "then" (for the implies logical condition) and parentheses to group filters, and allows several individual filters to be named. They are:- relative - the URL has the same scheme, host and port as the from-URL
- trustworthy - the URL is potentially trustworthy (it has a scheme of data, about, or some others used internally by BFO Publisher
- file - the URL has a scheme of
file,jaror anything else that would result in file-system access - network - the URL has a scheme of
http,https,ftpor anything else that would result in -system access - lan - a subset of
networkthat matches only non-routable addresses such ashttp://127.0.0.1,http://192.168.0.1,http://server.local,http://server,http://[::1],http://[fd02::1]orhttp://169.254.0.1 - internet - a subset of
networkthat matches only routable addresses: the opposite oflan - from-file - as for
filebut tests the from-URL - from-network - as for
networkbut tests the from-URL - from-lan - as for
lanbut tests the from-URL - from-internet - as for
internetbut tests the from-URL - from-api - if the URL was supplied by an API call or from the web-service. Should normally be true
- path(arg ...) - if the URL is a scheme of
file, it's path must begin with one of the arguments (non-file URLs are always accepted) - type(arg ...) - if the URL is a scheme of
file, it's Media-Type must match one of the arguments (non-file URLs are always accepted) - scheme(arg ...) - the URL scheme must match one of the arguments
- from-scheme(arg ...) - the from-URL scheme must match one of the arguments
- match(search) - the URL must match the search argument, which is a Java-syntax regular expression
- replace(search, replace) - the URL is modified by replacing every subsequence that matches the regular expression search with the given replacement string
- default - shorthand for the
DEFAULTpolicy - fail - the URL is not accepted
trustworthy or from-file or not file or from-api
The default policy, which always allows trustworthy URLs, but only allows file access from other file URLstrustworthy or from-file or (lan and from-lan) or (not file and not lan)
Similar to the default policy, but disallows access to local URLs unless the source is also a local URLdefault and type("image/*", "font/*", "text/css")
Restricts the default policy to only allow image, font and CSS files from the local filesystemdefault and path("/www/public")
Restricts the default policy to only allow files from a certain directorydefault and not scheme("pkcs11")
Restricts the default policy to always disallow PKCS#11 URLsdefault and replace("^(http|https)://a.example.com)", "$1://b.example.com")
Rewrite any HTTP or HTTPS URLs for a.example.com to b.example.com(match("http://evil.com) then fail) or default
Always disallow references to a particular URL, but otherwise use the default policy
- Since:
- 1.4
-
and
Return an EgressFilter built from a sequence of other EgressFilters. Each is applied in turn, so if any of the filters disallows the URL it will be disallowed.- Parameters:
filters- a sequence of one or more EgressFilters- Returns:
- an EgressFilter combining the list
- Since:
- 1.4
-
or
Return an EgressFilter built from a sequence of other EgressFilters. Each is checked in turn, and the first to return a non-null value will be used as the value for this filter. returned immediately.- Parameters:
filters- a sequence of one or more EgressFilters- Returns:
- an EgressFilter combining the list
- Since:
- 1.4
-
not
Return an EgressFilter which "inverts" the supplied filter. Therewrite(url, from)method looks likereturn filter.rewrite(url, from) == null ? url : null- Parameters:
filter- the filter to invert- Returns:
- an EgressFilter inverting the list
- Since:
- 1.4
-
then
Return an EgressFilter which implements the "then" logical operation. Therewrite(url, from)method looks likereturn a.rewrite(url, from) != null ? b.rewrite(url, from) : url- Parameters:
a- the filter to test the urlb- the filter to apply to the URL if the first filter returns not-null- Returns:
- an EgressFilter implementing the described operation
- Since:
- 1.4
-
rewrite
This method will be supplied with the URL about to be loaded, and the URL of the document, stylesheet, other resource loading it. It can return the URL as it is to load it, a rewritten URL to load a new resource instead, ornullto disallow the load.- Parameters:
url- the URL being loadedfrom- the URL that is the origin of the URL being loaded - the URL of the document or stylesheet.- Returns:
- the URL to load, or
nullto disallow access
-
path
Return an EgressFilter the equivalent ofpath(path...), without having to worry about escaping the path.- Parameters:
path- a list of zero or more paths to match against- Returns:
- the EgressFilter
- Since:
- 1.5
-
matchOrReplace
Return an EgressFilter the equivalent ofmatch(pattern)orreplace(pattern, replace)without having to worry about escaping.- Parameters:
pattern- the patternreplace- if not null this the replace parameter, otherwise this is a match- Returns:
- the EgressFilter
- Since:
- 1.5
-