Activator.java
3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceResolverFactory
* org.apache.sling.api.resource.ResourceUtil
* org.osgi.framework.Bundle
* org.osgi.framework.BundleActivator
* org.osgi.framework.BundleContext
* org.osgi.framework.BundleEvent
* org.osgi.framework.ServiceReference
* org.osgi.util.tracker.BundleTracker
* org.osgi.util.tracker.BundleTrackerCustomizer
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.granite.xss.impl;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
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.ResourceUtil;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.BundleTracker;
import org.osgi.util.tracker.BundleTrackerCustomizer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Activator
implements BundleActivator {
private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
private static final String SLING_XSS_BUNDLE = "org.apache.sling.xss";
private static final String SLING_ESAPI_POLICIES = "/libs/sling/xss/config.xml";
private BundleTracker bundleTracker;
public void start(final BundleContext bundleContext) throws Exception {
this.bundleTracker = new BundleTracker(bundleContext, 32, null){
public Object addingBundle(Bundle bundle, BundleEvent event) {
if ("org.apache.sling.xss".equals(bundle.getSymbolicName())) {
try {
ResourceResolverFactory rrf;
bundle.uninstall();
LOGGER.warn("Uninstalled the {} bundle due to its potential conflicts with com.day.cq.cq-xssprotection which embeds it.", (Object)"org.apache.sling.xss");
ServiceReference rrfSR = bundleContext.getServiceReference(ResourceResolverFactory.class);
if (rrfSR != null && (rrf = (ResourceResolverFactory)bundleContext.getService(rrfSR)) != null) {
ResourceResolver adminResolver = rrf.getAdministrativeResourceResolver(null);
Resource parent = adminResolver.getResource(ResourceUtil.getParent((String)"/libs/sling/xss/config.xml"));
if (parent != null && parent.getChild("config.xml") == null) {
Resource config = adminResolver.create(parent, ResourceUtil.getName((String)"/libs/sling/xss/config.xml"), (Map)new HashMap<String, Object>(){});
adminResolver.create(config, "jcr:content", (Map)new HashMap<String, Object>(){});
}
adminResolver.commit();
adminResolver.close();
bundleContext.ungetService(rrfSR);
}
}
catch (Exception e) {
LOGGER.error("Unable to uninstall bundle org.apache.sling.xss. Please remove the bundle manually due to its potential conflicts with com.day.cq.cq-xssprotection.", (Throwable)e);
}
}
return super.addingBundle(bundle, event);
}
};
this.bundleTracker.open();
}
public void stop(BundleContext bundleContext) throws Exception {
if (this.bundleTracker != null) {
this.bundleTracker.close();
}
}
}