WebDavBundleHealthCheck.java 5.8 KB
/*
 * 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;
        }
    }
}