SlingJavaScriptHandlerHealthCheck.java
4.9 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* 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.commons.osgi.PropertiesUtil
* 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.osgi.framework.InvalidSyntaxException
* org.osgi.service.cm.Configuration
* org.osgi.service.cm.ConfigurationAdmin
*/
package com.adobe.granite.bundles.hc.impl;
import java.io.IOException;
import java.util.Dictionary;
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.commons.osgi.PropertiesUtil;
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.osgi.framework.InvalidSyntaxException;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
@Component(metatype=1, label="Apache Sling Java Script Handler Health Check", description="Checks if the Sling Java Script Handler configuration follows the security guidelines.")
@Properties(value={@Property(name="hc.name", value={"Sling Java Script Handler"}, label="Name", description="Name of the health check."), @Property(name="hc.tags", unbounded=PropertyUnbounded.ARRAY, value={"sling", "security", "production"}, label="Tags", description="Tags for the health check."), @Property(name="hc.mbean.name", value={"slingJavaScriptHandler"}, label="MBean Name", description="Name of the JMX mbean to register for this check.")})
@Service(value={HealthCheck.class})
public class SlingJavaScriptHandlerHealthCheck
implements HealthCheck {
@Reference
private ConfigurationAdmin configurationAdmin;
private static final String SLING_JAVA_HANDLER_PID = "org.apache.sling.scripting.java.impl.JavaScriptEngineFactory";
private static final String DEBUG_INFO_PROP = "java.classdebuginfo";
public Result execute() {
FormattingResultLog resultLog = new FormattingResultLog();
boolean success = true;
String filter = "(service.pid=org.apache.sling.scripting.java.impl.JavaScriptEngineFactory)";
try {
Configuration[] slingGetServletCfgs = this.configurationAdmin.listConfigurations(filter);
if (slingGetServletCfgs == null) {
resultLog.warn("The Sling Java Script Handler uses the default configuration. The system might be exposed if used as a publish environment.", new Object[0]);
success = false;
} else {
for (Configuration config : slingGetServletCfgs) {
Dictionary properties = config.getProperties();
boolean debugInfoEnabled = PropertiesUtil.toBoolean(properties.get("java.classdebuginfo"), (boolean)false);
if (!debugInfoEnabled) continue;
resultLog.warn("The Sling Java Script Handler generates debug information. The system might be exposed if used as a publish environment.", new Object[0]);
success = false;
}
}
if (success) {
resultLog.debug("The Sling Java Script Handler does not generate debug information.", new Object[0]);
} else {
resultLog.debug("[You can stop the Sling Java Script Handler from generating debug information by unchecking 'Generate Debug Info' in its configuration.]({})", new Object[]{"/system/console/configMgr/org.apache.sling.scripting.java.impl.JavaScriptEngineFactory"});
resultLog.debug("[Check OSGI Settings in the security guidelines.](https://www.adobe.com/go/aem6_2_docs_security_osgi_en)", new Object[0]);
}
}
catch (IOException e) {
resultLog.warn("Could not access Sling Java Script Handler configuration.", new Object[0]);
}
catch (InvalidSyntaxException e) {
resultLog.warn("Could not access Sling Java Script Handler configuration.", new Object[0]);
}
return new Result((ResultLog)resultLog);
}
protected void bindConfigurationAdmin(ConfigurationAdmin configurationAdmin) {
this.configurationAdmin = configurationAdmin;
}
protected void unbindConfigurationAdmin(ConfigurationAdmin configurationAdmin) {
if (this.configurationAdmin == configurationAdmin) {
this.configurationAdmin = null;
}
}
}