You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2022/09/12 15:48:34 UTC
[jena] branch main updated: GH-1516: CORS before auth; option chainPreflight=false
This is an automated email from the ASF dual-hosted git repository.
andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git
The following commit(s) were added to refs/heads/main by this push:
new 3f270f968f GH-1516: CORS before auth; option chainPreflight=false
new 1022a46abc Merge pull request #1531 from afs/fuseki-main-cors
3f270f968f is described below
commit 3f270f968f31e3bc370b94988fef273440e3b9b8
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Mon Sep 12 09:30:28 2022 +0100
GH-1516: CORS before auth; option chainPreflight=false
---
.../org/apache/jena/fuseki/main/FusekiServer.java | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/jena-fuseki2/jena-fuseki-main/src/main/java/org/apache/jena/fuseki/main/FusekiServer.java b/jena-fuseki2/jena-fuseki-main/src/main/java/org/apache/jena/fuseki/main/FusekiServer.java
index 1377db465f..735ef4bcab 100644
--- a/jena-fuseki2/jena-fuseki-main/src/main/java/org/apache/jena/fuseki/main/FusekiServer.java
+++ b/jena-fuseki2/jena-fuseki-main/src/main/java/org/apache/jena/fuseki/main/FusekiServer.java
@@ -444,6 +444,8 @@ public class FusekiServer {
// The 7 CORS default exposed headers.
corsInitParamsDft.put(CrossOriginFilter.EXPOSED_HEADERS_PARAM,
"Cache-Control, Content-Language, Content-Length, Content-Type, Expires, Last-Modified, Pragma");
+ // Respond to preflight without passing OPTIONS down the filter chain.
+ corsInitParamsDft.put(CrossOriginFilter.CHAIN_PREFLIGHT_PARAM, "false");
}
// Builder with standard operation-action mapping.
@@ -1445,14 +1447,9 @@ public class FusekiServer {
/** Add servlets and servlet filters, including the {@link FusekiFilter} */
private void servletsAndFilters(ServletContextHandler context) {
- // First in chain. Authentication.
- if ( hasServerWideAuth() ) {
- Predicate<String> auth = serverAuth::isAllowed;
- AuthFilter authFilter = new AuthFilter(auth);
- addFilter(context, "/*", authFilter);
- }
-
- // CORS, maybe
+ // First in chain. CORS.
+ // Preflight to set to respond without passing on OPTIONS.
+ // Otherwise passes on to the next filter.
if ( corsInitParams != null ) {
Filter corsFilter = new CrossOriginFilter();
FilterHolder holder = new FilterHolder(corsFilter);
@@ -1460,6 +1457,13 @@ public class FusekiServer {
addFilterHolder(context, "/*", holder);
}
+ // Authentication.
+ if ( hasServerWideAuth() ) {
+ Predicate<String> auth = serverAuth::isAllowed;
+ AuthFilter authFilter = new AuthFilter(auth);
+ addFilter(context, "/*", authFilter);
+ }
+
beforeFilters.forEach(pair -> addFilter(context, pair.getLeft(), pair.getRight()));
// End of chain though there may be custom "afterFilters".