You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 10:25:36 UTC
[sling-org-apache-sling-xss] 02/06: SLING-6007 : XSSFilterImpl
should move to new ResourceChangeListener API . Apply slightly modified
patch from abdul hameed pathan
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.16
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-xss.git
commit 732f2ee049d6fed561c9b3550f14d16a3d7220ff
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Thu Sep 22 13:45:41 2016 +0000
SLING-6007 : XSSFilterImpl should move to new ResourceChangeListener API . Apply slightly modified patch from abdul hameed pathan
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/xss@1761969 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 17 ++++-------
.../org/apache/sling/xss/impl/XSSFilterImpl.java | 33 ++++++++++++----------
2 files changed, 24 insertions(+), 26 deletions(-)
diff --git a/pom.xml b/pom.xml
index 88ee33c..0e62572 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>26</version>
+ <version>28</version>
<relativePath />
</parent>
@@ -236,17 +236,13 @@
<dependency>
<groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
+ <artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.compendium</artifactId>
+ <artifactId>osgi.core</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
@@ -255,7 +251,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.api</artifactId>
- <version>2.2.0</version>
+ <version>2.11.0</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -277,14 +273,13 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
- <version>1.8.4</version>
- <type>jar</type>
+ <version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
- <version>1.5.5</version>
+ <version>1.6.5</version>
<scope>test</scope>
</dependency>
<dependency>
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 23926ec..cfb71d0 100644
--- a/src/main/java/org/apache/sling/xss/impl/XSSFilterImpl.java
+++ b/src/main/java/org/apache/sling/xss/impl/XSSFilterImpl.java
@@ -19,25 +19,26 @@ package org.apache.sling.xss.impl;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;
+import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
-import org.apache.sling.api.SlingConstants;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
+import org.apache.sling.api.resource.observation.ExternalResourceChangeListener;
+import org.apache.sling.api.resource.observation.ResourceChange;
+import org.apache.sling.api.resource.observation.ResourceChangeListener;
import org.apache.sling.xss.ProtectionContext;
import org.apache.sling.xss.XSSFilter;
-import org.osgi.service.event.Event;
-import org.osgi.service.event.EventConstants;
-import org.osgi.service.event.EventHandler;
import org.owasp.validator.html.model.Attribute;
import org.owasp.validator.html.model.Tag;
import org.slf4j.Logger;
@@ -48,9 +49,12 @@ import org.slf4j.LoggerFactory;
* <a href="http://code.google.com/p/owaspantisamy/">http://code.google.com/p/owaspantisamy/</a>.
*/
@Component(immediate = true)
-@Service(value = {EventHandler.class, XSSFilter.class})
-@Property(name = EventConstants.EVENT_TOPIC, value = {"org/apache/sling/api/resource/Resource/*"})
-public class XSSFilterImpl implements XSSFilter, EventHandler {
+@Service(value = {ResourceChangeListener.class, XSSFilter.class})
+@Properties({
+ @Property(name = ResourceChangeListener.CHANGES, value = {"ADDED","CHANGED", "REMOVED"}),
+ @Property(name = ResourceChangeListener.PATHS, value = {"glob:/**/sling/xss/config.xml", "glob:/sling/xss/config.xml"})
+})
+public class XSSFilterImpl implements XSSFilter, ResourceChangeListener, ExternalResourceChangeListener {
private static final Logger LOGGER = LoggerFactory.getLogger(XSSFilterImpl.class);
@@ -81,13 +85,13 @@ public class XSSFilterImpl implements XSSFilter, EventHandler {
private ResourceResolverFactory resourceResolverFactory = null;
@Override
- 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();
- }
- }
+ public void onChange(List<ResourceChange> resourceChanges) {
+ for(ResourceChange change : resourceChanges){
+ LOGGER.debug("Detected policy file change at {}. Updating default handler.", change.getPath());
+ updateDefaultHandler();
+ }
+
+ }
@Override
public boolean check(final ProtectionContext context, final String src) {
@@ -249,5 +253,4 @@ public class XSSFilterImpl implements XSSFilter, EventHandler {
}
return isValid;
}
-
}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.