DavExBundleHealthCheck.java
6.08 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* 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.Reference
* 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.apache.sling.settings.SlingSettingsService
* org.osgi.framework.BundleContext
* org.osgi.service.cm.Configuration
* org.osgi.service.cm.ConfigurationAdmin
*/
package com.adobe.granite.bundles.hc.impl;
import com.adobe.granite.bundles.hc.impl.BaseBundleCheck;
import java.util.Set;
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.Reference;
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.apache.sling.settings.SlingSettingsService;
import org.osgi.framework.BundleContext;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
@Component(metatype=1, label="Adobe Granite DavEx Health Check", description="This health check checks if the DavEx bundle and SlingDavExServlet are active in the right runmodes.")
@Properties(value={@Property(name="hc.name", value={"DavEx Health Check"}, 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={"davExBundleCheck"}, propertyPrivate=1)})
@Service(value={HealthCheck.class})
public class DavExBundleHealthCheck
extends BaseBundleCheck
implements HealthCheck {
private BundleContext bundleContext;
private static final String DAVEX_BUNDLE_NAME = "org.apache.sling.jcr.davex";
private static final String DAVEX_SERVICE_NAME = "org.apache.sling.jcr.davex.impl.servlets.SlingDavExServlet";
private static final String SAMPLE = "samplecontent";
@Reference
private SlingSettingsService settings;
@Reference
private ConfigurationAdmin configurationAdmin;
public DavExBundleHealthCheck() {
super("org.apache.sling.jcr.davex", "org.apache.sling.jcr.davex.impl.servlets.SlingDavExServlet");
}
@Activate
protected void activate(BundleContext bundleContext) {
this.bundleContext = bundleContext;
}
@Deactivate
protected void deactivate() {
this.bundleContext = null;
}
public Result execute() {
Set runModes = this.settings.getRunModes();
boolean davExServletOK = false;
FormattingResultLog resultLog = new FormattingResultLog();
boolean davExBundleActive = this.isBundleActive(this.bundleContext);
if (!davExBundleActive) {
if (runModes.contains("samplecontent")) {
resultLog.warn("The Sling DavEx bundle is NOT active.", new Object[0]);
resultLog.debug("[The DavEx bundle should be available and active in the samplecontent runmode.]( )", new Object[0]);
} else {
resultLog.debug("The Sling DavEx bundle is NOT active.", new Object[0]);
}
} else if (runModes.contains("samplecontent")) {
resultLog.debug("The Sling DavEx bundle is active.", new Object[0]);
} else {
resultLog.warn("The Sling DavEx bundle is active.", new Object[0]);
resultLog.debug("[The DavEx bundle should NOT be available and active in the nosamplecontent runmode.]( )", new Object[0]);
}
Configuration[] servletCfgs = this.getServletConfigs(this.configurationAdmin);
if (runModes.contains("samplecontent")) {
if (this.isConfigurationUnbound(servletCfgs)) {
resultLog.warn("The SlingDavExServlet is NOT configured.", new Object[0]);
resultLog.warn("[The SlingDavExServlet should be configured on instances running in samplecontent mode.]( )", new Object[0]);
} else {
resultLog.debug("The SlingDavExServlet is configured.", new Object[0]);
davExServletOK = true;
}
} else if (this.isConfigurationUnbound(servletCfgs)) {
resultLog.debug("The SlingDavExServlet is NOT configured.", new Object[0]);
davExServletOK = true;
} else {
resultLog.warn("The SlingDavExServlet is configured.", new Object[0]);
resultLog.debug("[The SlingDavExServlet should NOT be configured on instances running in nosamplecontent mode.]( )", new Object[0]);
}
if (!davExServletOK) {
resultLog.warn("[Check the section about the Sling DavEx bundle and servlet in the security guidelines.](https://www.adobe.com/go/aem6_2_docs_security_webdav_en)", new Object[0]);
}
return new Result((ResultLog)resultLog);
}
protected void bindSettings(SlingSettingsService slingSettingsService) {
this.settings = slingSettingsService;
}
protected void unbindSettings(SlingSettingsService slingSettingsService) {
if (this.settings == slingSettingsService) {
this.settings = null;
}
}
protected void bindConfigurationAdmin(ConfigurationAdmin configurationAdmin) {
this.configurationAdmin = configurationAdmin;
}
protected void unbindConfigurationAdmin(ConfigurationAdmin configurationAdmin) {
if (this.configurationAdmin == configurationAdmin) {
this.configurationAdmin = null;
}
}
}