WebDavBundleHealthCheck.java
5.8 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
/*
* 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 WebDav Access Health Check", description="This health check checks if the WebDav bundle and SimpleWebDavServlet are active in the right runmodes.")
@Properties(value={@Property(name="hc.name", value={"WebDAV 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={"webDavAccess"}, propertyPrivate=1)})
@Service(value={HealthCheck.class})
public class WebDavBundleHealthCheck
extends BaseBundleCheck
implements HealthCheck {
private BundleContext bundleContext;
private static final String WEBDAV_BUNDLE_NAME = "org.apache.sling.jcr.webdav";
private static final String WEBDAV_SERVICE_NAME = "org.apache.sling.jcr.webdav.impl.servlets.SimpleWebDavServlet";
private static final String PUBLISH = "publish";
private static final String SAMPLE = "samplecontent";
@Reference
private SlingSettingsService settings;
@Reference
private ConfigurationAdmin configurationAdmin;
public WebDavBundleHealthCheck() {
super("org.apache.sling.jcr.webdav", "org.apache.sling.jcr.webdav.impl.servlets.SimpleWebDavServlet");
}
@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 webDavServletOK = false;
FormattingResultLog resultLog = new FormattingResultLog();
boolean webDavBundleFound = this.isBundleActive(this.bundleContext);
if (webDavBundleFound) {
resultLog.debug("The Sling WebDav bundle is active.", new Object[0]);
} else {
resultLog.warn("The Sling WebDav bundle is NOT active.", new Object[0]);
resultLog.warn("[The WebDav bundle should be available and active in all runmodes.]( )", new Object[0]);
}
Configuration[] servletCfgs = this.getServletConfigs(this.configurationAdmin);
if (runModes.contains("publish") && !runModes.contains("samplecontent")) {
if (this.isConfigurationUnbound(servletCfgs)) {
resultLog.debug("The SimpleWebDavServlet is NOT configured.", new Object[0]);
webDavServletOK = true;
} else {
resultLog.warn("The SimpleWebDavServlet is configured.", new Object[0]);
resultLog.debug("[On instances started in publish + nosampleconent runmodes the SimpleWebDavServlet should NOT be configured.]( )", new Object[0]);
}
} else if (this.isConfigurationUnbound(servletCfgs)) {
resultLog.warn("The SimpleWebDavServlet is NOT configured. ", new Object[0]);
resultLog.debug("[On instances started in author or publish + sampleconent runmodes the SimpleWebDavServlet should be configured.]( )", new Object[0]);
} else {
resultLog.debug("The SimpleWebDavServlet is configured.", new Object[0]);
webDavServletOK = true;
}
if (!webDavBundleFound || !webDavServletOK) {
resultLog.warn("[Check the section about the Sling WebDAV 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;
}
}
}