Package jenkins.security.csp
Class CspBuilder
java.lang.Object
jenkins.security.csp.CspBuilder
Builder for a CSP rule set.
- Since:
- TODO
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdd the given directive and values.build()Build the final CSP string.Compiles the directives into a map from key (e.g.,default-src) to values (e.g.,'self' 'unsafe-inline').Determine the current effective directives.initialize(FetchDirective fetchDirective, String... values) Adds an initial value for the specified*-srcdirective.Remove the given values from the directive, if present.
-
Constructor Details
-
CspBuilder
public CspBuilder()
-
-
Method Details
-
withDefaultContributions
-
add
Add the given directive and values. If the directive is already present, merge the values. If this is a fetch directive,#adddoes not disable inheritance from fallback directives. To disable inheritance for fetch directives, callinitialize(FetchDirective, String...)instead.The directives
Directive.REPORT_URIandDirective.REPORT_TOcannot be set manually, so will be skipped.Similarly, the value
Directive.NONEcannot be set and will be skipped. Instead, callremove(String, String...)with a single argument to reset the directive, then callinitialize(FetchDirective, String...)with just theFetchDirectiveargument to disable inheritance.- Parameters:
directive- the directive to addvalues- the values to add to the directive.nullvalues are ignored. If onlynullvalues are passed, the directive will not be added. This is different from calling this with only thedirectiveargument (i.e., an empty list of values), which will add the directive with no additional values, potentially resulting in an effectiveDirective.NONEvalue.- Returns:
- this builder
-
remove
Remove the given values from the directive, if present. If the directive does not exist, do nothing. If no values are provided, removes the entire directive.- Parameters:
directive- the directive to removevalues- the values to remove from the directive, or none if the entire directive should be removed.- Returns:
- this builder
-
initialize
Adds an initial value for the specified*-srcdirective. Unlike calls toadd(String, String...), this disables inheriting from (fetch directive) fallbacks. This can be invoked multiple times, and the merged set of values will be used.- Parameters:
fetchDirective- the directivevalues- Its initial values. If this is an empty list, will initialize asDirective.NONE.nullvalues in the list are ignored. If this is a non-empty list with onlynullvalues, this invocation has no effect.- Returns:
- this builder
-
getMergedDirectives
Determine the current effective directives. This can be used to inform potential callers ofremove(String, String...)what to remove.- Returns:
- the current effective directives
-
build
Build the final CSP string. Any directives with no values left will have the 'none' value set.- Returns:
- the CSP string
-
buildDirectives
Compiles the directives into a map from key (e.g.,default-src) to values (e.g.,'self' 'unsafe-inline').- Returns:
- a map from directive name to its value for all specified directives.
-