ReplicationTransportUsersHealthCheck.java 3.92 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.replication.AgentConfig
 *  com.day.cq.replication.ConfigManager
 *  org.apache.felix.scr.annotations.Component
 *  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
 */
package com.adobe.granite.replication.hc.impl;

import com.day.cq.replication.AgentConfig;
import com.day.cq.replication.ConfigManager;
import java.util.Map;
import java.util.Set;
import org.apache.felix.scr.annotations.Component;
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;

@Component(metatype=1, label="Adobe Granite Replication & Transport Users Health Check", description="This health check checks the replication and transport users.")
@Properties(value={@Property(name="hc.name", value={"Replication and Transport Users"}, label="Name", description="Name of the health check."), @Property(name="hc.tags", unbounded=PropertyUnbounded.ARRAY, value={"security", "replication", "cq"}, label="Tags", description="Tags for the health check."), @Property(name="hc.mbean.name", value={"replicationTransportUsers"}, label="MBean Name", description="Name of the JMX mbean to register for this check.")})
@Service(value={HealthCheck.class})
public class ReplicationTransportUsersHealthCheck
implements HealthCheck {
    @Reference
    ConfigManager configManager;
    private static final String ADMIN_USER = "admin";

    public Result execute() {
        boolean success = true;
        FormattingResultLog resultLog = new FormattingResultLog();
        Map agentConfigs = this.configManager.getConfigurations();
        if (agentConfigs == null) {
            resultLog.warn("Could not get replication agent configurations.", new Object[0]);
            return new Result((ResultLog)resultLog);
        }
        Set agentConfigNames = agentConfigs.keySet();
        for (String agentConfigName : agentConfigNames) {
            AgentConfig agentConfig = (AgentConfig)agentConfigs.get(agentConfigName);
            String transportUserName = agentConfig.getTransportUser();
            if (!"admin".equals(transportUserName)) continue;
            resultLog.warn("Transport user is {} for replication agent [{}].", new Object[]{"admin", agentConfig.getName()});
            success = false;
        }
        resultLog.info("[You can change the transport user by editing the agent settings in the Replication page.](/etc/replication.html)", new Object[0]);
        if (success) {
            resultLog.debug("None of the replication agents are using {} as a transport user.", new Object[]{"admin"});
        } else {
            resultLog.warn("[Replication agents should not use the default '{}' as a transport user.]( )", new Object[]{"admin"});
            resultLog.debug("[Check the 'Configure Replication and Transport Users' section of the security guideline.](https://www.adobe.com/go/aem6_2_docs_security_replication_en)", new Object[0]);
        }
        return new Result((ResultLog)resultLog);
    }

    protected void bindConfigManager(ConfigManager configManager) {
        this.configManager = configManager;
    }

    protected void unbindConfigManager(ConfigManager configManager) {
        if (this.configManager == configManager) {
            this.configManager = null;
        }
    }
}