CrxdeSupportBundleHealthCheck.java
4.28 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
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Deactivate
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.PropertyUnbounded
* org.apache.felix.scr.annotations.Service
* org.apache.sling.hc.api.HealthCheck
* org.apache.sling.hc.api.Result
* org.apache.sling.hc.api.ResultLog
* org.apache.sling.hc.util.FormattingResultLog
* org.osgi.framework.Bundle
* org.osgi.framework.BundleContext
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.granite.bundles.hc.impl;
import java.util.Dictionary;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.PropertyUnbounded;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.hc.api.HealthCheck;
import org.apache.sling.hc.api.Result;
import org.apache.sling.hc.api.ResultLog;
import org.apache.sling.hc.util.FormattingResultLog;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=1, label="Adobe Granite CRXDE Support Bundle Health Check", description="This health check checks if the crxde-support bundle is active.")
@Properties(value={@Property(name="hc.name", value={"CRXDE Support"}, propertyPrivate=1), @Property(name="hc.tags", unbounded=PropertyUnbounded.ARRAY, value={"bundles", "security", "production"}, label="Tags", description="Tags for this check to be used by composite health checks."), @Property(name="hc.mbean.name", value={"crxdeSupportBundle"}, propertyPrivate=1)})
@Service(value={HealthCheck.class})
public class CrxdeSupportBundleHealthCheck
implements HealthCheck {
Logger log;
private BundleContext bundleContext;
private static final String[] CRXDE_PACKAGE_NAMES = new String[]{"com.day.crx.crxde-support", "com.adobe.granite.crx-explorer", "com.adobe.granite.crxde-lite"};
public CrxdeSupportBundleHealthCheck() {
this.log = LoggerFactory.getLogger(this.getClass());
}
@Activate
protected void activate(BundleContext bundleContext) {
this.bundleContext = bundleContext;
}
@Deactivate
protected void deactivate() {
this.bundleContext = null;
}
public Result execute() {
Bundle[] bundles;
boolean found = false;
FormattingResultLog resultLog = new FormattingResultLog();
for (Bundle bundle : bundles = this.bundleContext.getBundles()) {
String symbolicName;
Dictionary headers = bundle.getHeaders();
if (headers == null || (symbolicName = (String)headers.get("Bundle-SymbolicName")) == null || !this.isCrxDeBundle(symbolicName)) continue;
if (bundle.getState() == 32 || bundle.getState() == 8 && CrxdeSupportBundleHealthCheck.isLazyActivatian(bundle)) {
found = true;
resultLog.warn("The {} bundle is active.", new Object[]{symbolicName});
continue;
}
resultLog.debug("The {} bundle is not active.", new Object[]{symbolicName});
}
resultLog.debug("[The CRX Development Bundles should be disabled on production systems.]( )", new Object[0]);
if (found) {
resultLog.warn("[You can disable the CRX Development Bundles in the administration console.]({})", new Object[]{"/system/console/bundles"});
resultLog.warn("[See Disable CRXDE Support in the security guidelines.](https://www.adobe.com/go/aem6_2_docs_security_crxde_en)", new Object[0]);
}
return new Result((ResultLog)resultLog);
}
private static boolean isLazyActivatian(Bundle b) {
return "lazy".equals(b.getHeaders().get("Bundle-ActivationPolicy"));
}
private boolean isCrxDeBundle(String bundleName) {
for (int i = 0; i < CRXDE_PACKAGE_NAMES.length; ++i) {
if (!CRXDE_PACKAGE_NAMES[i].equals(bundleName)) continue;
return true;
}
return false;
}
}