sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject [sling-org-apache-sling-xss] 02/04: SLING-4542 - The XSSFilterImpl cannot always be successfully activated
Date Tue, 07 Nov 2017 10:25:49 GMT
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.xss-1.0.2
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-xss.git

commit 293a000041b48faef620f4f968719cbee9fc8822
Author: Radu Cotescu <radu@apache.org>
AuthorDate: Tue Mar 24 15:19:59 2015 +0000

    SLING-4542 - The XSSFilterImpl cannot always be successfully activated
    
    * use the default policy file from the bundle until a policy file is installed in the
repository
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/xss@1668917
13f79535-47bb-0310-9956-ffa450edef68
---
 .../org/apache/sling/xss/impl/XSSFilterImpl.java    | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/main/java/org/apache/sling/xss/impl/XSSFilterImpl.java b/src/main/java/org/apache/sling/xss/impl/XSSFilterImpl.java
index d7c6bb0..2779dba 100644
--- a/src/main/java/org/apache/sling/xss/impl/XSSFilterImpl.java
+++ b/src/main/java/org/apache/sling/xss/impl/XSSFilterImpl.java
@@ -67,6 +67,7 @@ public class XSSFilterImpl implements XSSFilter, EventHandler {
     public void handleEvent(final Event event) {
         final String path = (String) event.getProperty(SlingConstants.PROPERTY_PATH);
         if (path.endsWith("/" + DEFAULT_POLICY_PATH)) {
+            LOGGER.debug("Detected policy file change at {}. Updating default handler.",
path);
             updateDefaultHandler();
         }
     }
@@ -110,6 +111,21 @@ public class XSSFilterImpl implements XSSFilter, EventHandler {
                         LOGGER.error("Unable to load policy from " + policyResource.getPath(),
e);
                     }
                 }
+            } else {
+                // the content was not installed but the service is active; let's use the
embedded file for the default handler
+                LOGGER.debug("Could not find a policy file at the default location {}. Attempting
to use the default resource embedded in" +
+                        " the bundle.", DEFAULT_POLICY_PATH);
+                InputStream policyStream = this.getClass().getClassLoader().getResourceAsStream("SLING-INF/content/config.xml");
+                if (policyStream != null) {
+                    try {
+                        if (defaultHandler == null) {
+                            defaultHandler = new PolicyHandler(policyStream);
+                            policyStream.close();
+                        }
+                    } catch (Exception e) {
+                        LOGGER.error("Unable to load policy from embedded policy file.",
e);
+                    }
+                }
             }
             if (defaultHandler == null) {
                 throw new IllegalStateException("Cannot load a default policy handler.");
@@ -167,14 +183,17 @@ public class XSSFilterImpl implements XSSFilter, EventHandler {
         return ctx.filter(handler, src);
     }
 
+    @SuppressWarnings("unused")
     public void setDefaultPolicy(InputStream policyStream) throws Exception {
         defaultHandler = new PolicyHandler(policyStream);
     }
 
+    @SuppressWarnings("unused")
     public void resetDefaultPolicy() {
         updateDefaultHandler();
     }
 
+    @SuppressWarnings("unused")
     public void loadPolicy(String policyName, InputStream policyStream) throws Exception
{
         if (policies.size() < DEFAULT_POLICY_CACHE_SIZE) {
             PolicyHandler policyHandler = new PolicyHandler(policyStream);
@@ -182,10 +201,12 @@ public class XSSFilterImpl implements XSSFilter, EventHandler {
         }
     }
 
+    @SuppressWarnings("unused")
     public void unloadPolicy(String policyName) {
         policies.remove(policyName);
     }
 
+    @SuppressWarnings("unused")
     public boolean hasPolicy(String policyName) {
         return policies.containsKey(policyName);
     }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <commits@sling.apache.org>.

Mime
View raw message