ReplicationTransportUsersHealthCheck.java
3.92 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
/*
* 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;
}
}
}