You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2015/03/24 16:20:00 UTC
svn commit: r1668917 -
/sling/trunk/contrib/extensions/xss/src/main/java/org/apache/sling/xss/impl/XSSFilterImpl.java
Author: radu
Date: Tue Mar 24 15:19:59 2015
New Revision: 1668917
URL: http://svn.apache.org/r1668917
Log:
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
Modified:
sling/trunk/contrib/extensions/xss/src/main/java/org/apache/sling/xss/impl/XSSFilterImpl.java
Modified: sling/trunk/contrib/extensions/xss/src/main/java/org/apache/sling/xss/impl/XSSFilterImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/xss/src/main/java/org/apache/sling/xss/impl/XSSFilterImpl.java?rev=1668917&r1=1668916&r2=1668917&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/xss/src/main/java/org/apache/sling/xss/impl/XSSFilterImpl.java (original)
+++ sling/trunk/contrib/extensions/xss/src/main/java/org/apache/sling/xss/impl/XSSFilterImpl.java Tue Mar 24 15:19:59 2015
@@ -67,6 +67,7 @@ public class XSSFilterImpl implements XS
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 XS
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 XS
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 XS
}
}
+ @SuppressWarnings("unused")
public void unloadPolicy(String policyName) {
policies.remove(policyName);
}
+ @SuppressWarnings("unused")
public boolean hasPolicy(String policyName) {
return policies.containsKey(policyName);
}