DavExBundleHealthCheck.java 6.08 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 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;
        }
    }
}