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:26:10 UTC
[sling-org-apache-sling-xss] 12/19: SLING-6794 : Inconsistent
handling of default configuration
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.xss-2.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-xss.git
commit e2bf950c560a386721402f8cf5c390db12f20270
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Apr 26 10:37:14 2017 +0000
SLING-6794 : Inconsistent handling of default configuration
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/xss@1792725 13f79535-47bb-0310-9956-ffa450edef68
---
.../org/apache/sling/xss/impl/XSSFilterImpl.java | 57 ++++++++++------------
1 file changed, 26 insertions(+), 31 deletions(-)
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 c50b75c..f395d01 100644
--- a/src/main/java/org/apache/sling/xss/impl/XSSFilterImpl.java
+++ b/src/main/java/org/apache/sling/xss/impl/XSSFilterImpl.java
@@ -61,7 +61,7 @@ import org.slf4j.LoggerFactory;
)
public class XSSFilterImpl implements XSSFilter, ResourceChangeListener, ExternalResourceChangeListener {
- private final Logger LOGGER = LoggerFactory.getLogger(XSSFilterImpl.class);
+ private final Logger logger = LoggerFactory.getLogger(XSSFilterImpl.class);
// Default href configuration copied from the config.xml supplied with AntiSamy
static final Attribute DEFAULT_HREF_ATTRIBUTE = new Attribute(
@@ -97,7 +97,7 @@ public class XSSFilterImpl implements XSSFilter, ResourceChangeListener, Externa
public void onChange(@Nonnull List<ResourceChange> resourceChanges) {
for (ResourceChange change : resourceChanges) {
if (change.getPath().endsWith(DEFAULT_POLICY_PATH)) {
- LOGGER.info("Detected policy file change ({}) at {}. Updating default handler.", change.getType().name(), change.getPath());
+ logger.info("Detected policy file change ({}) at {}. Updating default handler.", change.getType().name(), change.getPath());
updateDefaultHandler();
}
}
@@ -189,49 +189,44 @@ public class XSSFilterImpl implements XSSFilter, ResourceChangeListener, Externa
private synchronized void updateDefaultHandler() {
this.defaultHandler = null;
- ResourceResolver xssResourceResolver = null;
- try {
- xssResourceResolver = resourceResolverFactory.getServiceResourceResolver(null);
+ try (final ResourceResolver xssResourceResolver = resourceResolverFactory.getServiceResourceResolver(null)) {
Resource policyResource = xssResourceResolver.getResource(DEFAULT_POLICY_PATH);
if (policyResource != null) {
try (InputStream policyStream = policyResource.adaptTo(InputStream.class)) {
setDefaultHandler(new PolicyHandler(policyStream));
- LOGGER.info("Installed default policy from {}.", policyResource.getPath());
+ logger.info("Installed default policy from {}.", policyResource.getPath());
} catch (Exception e) {
Throwable[] suppressed = e.getSuppressed();
if (suppressed.length > 0) {
for (Throwable t : suppressed) {
- LOGGER.error("Unable to load policy from " + policyResource.getPath(), t);
+ logger.error("Unable to load policy from " + policyResource.getPath(), t);
}
}
- LOGGER.error("Unable to load policy from " + policyResource.getPath(), e);
+ 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.warn("Could not find a policy file at the default location {}. Attempting to use the default resource embedded in" +
- " the bundle.", DEFAULT_POLICY_PATH);
- try (InputStream policyStream = this.getClass().getClassLoader().getResourceAsStream(EMBEDDED_POLICY_PATH)) {
- setDefaultHandler(new PolicyHandler(policyStream));
- LOGGER.info("Installed default policy from the embedded {} file from the bundle.", EMBEDDED_POLICY_PATH);
- } catch (Exception e) {
- Throwable[] suppressed = e.getSuppressed();
- if (suppressed.length > 0) {
- for (Throwable t : suppressed) {
- LOGGER.error("Unable to load policy from embedded policy file.", t);
- }
+ }
+ } catch (final LoginException e) {
+ logger.error("Unable to load the default policy file.", e);
+ }
+ if (defaultHandler == null) {
+ // the content was not installed but the service is active; let's use the embedded file for the default handler
+ logger.info("Could not find a policy file at the default location {}. Attempting to use the default resource embedded in" +
+ " the bundle.", DEFAULT_POLICY_PATH);
+ try (InputStream policyStream = this.getClass().getClassLoader().getResourceAsStream(EMBEDDED_POLICY_PATH)) {
+ setDefaultHandler(new PolicyHandler(policyStream));
+ logger.info("Installed default policy from the embedded {} file from the bundle.", EMBEDDED_POLICY_PATH);
+ } catch (Exception e) {
+ Throwable[] suppressed = e.getSuppressed();
+ if (suppressed.length > 0) {
+ for (Throwable t : suppressed) {
+ logger.error("Unable to load policy from embedded policy file.", t);
}
- LOGGER.error("Unable to load policy from embedded policy file.", e);
}
+ logger.error("Unable to load policy from embedded policy file.", e);
}
- if (defaultHandler == null) {
- throw new IllegalStateException("Cannot load a default policy handler.");
- }
- } catch (LoginException e) {
- LOGGER.error("Unable to load the default policy file.", e);
- } finally {
- if (xssResourceResolver != null) {
- xssResourceResolver.close();
- }
+ }
+ if (defaultHandler == null) {
+ throw new IllegalStateException("Cannot load a default policy handler.");
}
}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.