This is an automated email from the ASF dual-hosted git repository.

mraible pushed a commit to branch java-security-config
in repository https://gitbox.apache.org/repos/asf/roller.git

commit 481c842cb6fa6e55f30412e5366bdb1f2f62976b
Author: Matt Raible <[email protected]>
AuthorDate: Tue Nov 17 19:42:33 2026 -0700

    Match a rendering URL's site access rules against its weblog path, and 
serve Roller UI theme files without the security chain
    
    A request under /roller-ui/rendering/<servlet>/<handle>/ is now checked 
only against the most specific security.access rule for the weblog's own path, 
so with /**=member and /fam/**=family a family user can read 
/roller-ui/rendering/page/fam/... just as they can read /fam/.... A new test 
covers those overlapping rules on public and rendering URLs.
    
    /roller-ui/theme/** joins the static paths that skip the security filter 
chain, so the front-page theme images can be cached and load without a login 
when a rule covers /**.
---
 .../weblogger/ui/core/security/SecurityConfig.java | 26 +++++++---------------
 .../ui/core/security/SecurityConfigTest.java       | 25 +++++++++++++++++++--
 2 files changed, 31 insertions(+), 20 deletions(-)

diff --git 
a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/SecurityConfig.java
 
b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/SecurityConfig.java
index 74feb5836..ae8f3addf 100644
--- 
a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/SecurityConfig.java
+++ 
b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/SecurityConfig.java
@@ -133,7 +133,7 @@ public class SecurityConfig {
         // (rendering.weblogMapper.rollerProtectedUrls), so no weblog can sit
         // under a path that skips the security.access rules.
         return web -> web.ignoring().requestMatchers("/images/**", 
"/theme/**", "/webjars/**",
-                "/roller-ui/styles/**", "/roller-ui/scripts/**", 
"/roller-ui/images/**");
+                "/roller-ui/styles/**", "/roller-ui/scripts/**", 
"/roller-ui/images/**", "/roller-ui/theme/**");
     }
 
     @Bean
@@ -311,25 +311,15 @@ public class SecurityConfig {
             if (setupInProgress.getAsBoolean() && 
setupPaths.matches(context.getRequest())) {
                 return new AuthorizationDecision(true);
             }
-            for (AccessRule rule : rules) {
-                if (rule.matcher().matches(context.getRequest())) {
-                    AuthorizationResult result = 
rule.check().authorize(authentication, context);
-                    if (result == null || !result.isGranted()) {
-                        return result;
-                    }
-                    break;
-                }
-            }
             // Roller renders a weblog at 
/roller-ui/rendering/<servlet>/<handle>/...
-            // as well as at /<handle>/..., so the rules for the weblog's own
-            // path apply there too
+            // as well as at /<handle>/..., so the rules are matched against 
the
+            // weblog's own path there, and the most specific rule for that 
path
+            // applies
             String weblogPath = 
weblogPath(URL_PATH_HELPER.getPathWithinApplication(context.getRequest()));
-            if (weblogPath != null) {
-                PathContainer path = PathContainer.parsePath(weblogPath);
-                for (AccessRule rule : rules) {
-                    if (rule.pattern().matches(path)) {
-                        return rule.check().authorize(authentication, context);
-                    }
+            PathContainer path = weblogPath == null ? null : 
PathContainer.parsePath(weblogPath);
+            for (AccessRule rule : rules) {
+                if (path != null ? rule.pattern().matches(path) : 
rule.matcher().matches(context.getRequest())) {
+                    return rule.check().authorize(authentication, context);
                 }
             }
             return new AuthorizationDecision(true);
diff --git 
a/app/src/test/java/org/apache/roller/weblogger/ui/core/security/SecurityConfigTest.java
 
b/app/src/test/java/org/apache/roller/weblogger/ui/core/security/SecurityConfigTest.java
index f1a174fe6..f671c3de5 100644
--- 
a/app/src/test/java/org/apache/roller/weblogger/ui/core/security/SecurityConfigTest.java
+++ 
b/app/src/test/java/org/apache/roller/weblogger/ui/core/security/SecurityConfigTest.java
@@ -208,7 +208,7 @@ class SecurityConfigTest {
     void rollersStaticFilesSkipTheChain() throws Exception {
         FilterChainProxy chain = chain(SecurityConfig.class);
         for (String path : new String[] {"/roller-ui/styles/roller.css", 
"/roller-ui/scripts/date-fields.js",
-                "/roller-ui/images/feather.svg", "/theme/scripts/roller.js",
+                "/roller-ui/images/feather.svg", 
"/roller-ui/theme/tan/menutab-sel.gif", "/theme/scripts/roller.js",
                 "/webjars/jquery/4.0.0/jquery.min.js", 
"/images/roller-logo.png"}) {
             MockHttpServletResponse response = new MockHttpServletResponse();
             assertEquals(PASS, outcome(chain, request("GET", path, ""), 
response), path);
@@ -372,6 +372,26 @@ class SecurityConfigTest {
                 new MockHttpServletResponse()));
     }
 
+    @Test
+    void theMostSpecificRuleForTheWeblogsPathAppliesToItsRenderingPaths() 
throws Exception {
+        setProperty("security.access./**", "member");
+        setProperty("security.access./fam/**", "family");
+        FilterChainProxy chain = chain(WithUser.class);
+
+        for (String path : new String[] {"/fam/entry/x", 
"/roller-ui/rendering/page/fam/entry/x",
+                "/roller-ui/rendering/feed/fam/entries/atom"}) {
+            assertEquals(PASS, outcome(chain, request("GET", path, "family"), 
new MockHttpServletResponse()), path);
+            assertEquals("403 null", outcome(chain, request("GET", path, 
"member"), new MockHttpServletResponse()),
+                    path);
+            assertEquals(LOGIN, outcome(chain, request("GET", path, ""), new 
MockHttpServletResponse()), path);
+        }
+        for (String path : new String[] {"/myblog/entry/x", 
"/roller-ui/rendering/page/myblog/entry/x"}) {
+            assertEquals(PASS, outcome(chain, request("GET", path, "member"), 
new MockHttpServletResponse()), path);
+            assertEquals("403 null", outcome(chain, request("GET", path, 
"family"), new MockHttpServletResponse()),
+                    path);
+        }
+    }
+
     @Test
     void weblogPathsOfRenderingRequests() {
         assertEquals("/fam/entry/x", 
SecurityConfig.weblogPath("/roller-ui/rendering/page/fam/entry/x"));
@@ -424,7 +444,8 @@ class SecurityConfigTest {
 
         for (String path : new String[] {"/roller-ui/login.rol", 
"/webjars/bootstrap/5.3.8/css/bootstrap.min.css",
                 "/roller-ui/scripts/date-fields.js", 
"/roller-ui/styles/roller.css",
-                "/roller-ui/images/feather.svg", "/theme/scripts/roller.js", 
"/favicon.svg",
+                "/roller-ui/images/feather.svg", 
"/roller-ui/theme/tan/menutab-sel.gif",
+                "/theme/scripts/roller.js", "/favicon.svg",
                 "/oauth2/authorization/keycloak", "/roller-ui/logout.rol"}) {
             MockHttpServletResponse response = new MockHttpServletResponse();
             String result = outcome(chain, request("GET", path, ""), response);

Reply via email to