SlingJspScriptHandlerHealthCheck.java
5.64 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
94
95
96
97
98
99
100
101
102
103
/*
* 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 Jsp Script Handler Health Check", description="Checks if the Sling Jsp Script Handler configuration follows the security guidelines.")
@Properties(value={@Property(name="hc.name", value={"Sling Jsp 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={"slingJspScriptHandler"}, label="MBean Name", description="Name of the JMX mbean to register for this check.")})
@Service(value={HealthCheck.class})
public class SlingJspScriptHandlerHealthCheck
implements HealthCheck {
@Reference
private ConfigurationAdmin configurationAdmin;
private static final String SLING_JSP_HANDLER_PID = "org.apache.sling.scripting.jsp.JspScriptEngineFactory";
private static final String DEBUG_INFO_PROP = "jasper.classdebuginfo";
private static final String MAPPED_CONTENT_PROP = "jasper.mappedfile";
public Result execute() {
FormattingResultLog resultLog = new FormattingResultLog();
boolean success = true;
String filter = "(service.pid=org.apache.sling.scripting.jsp.JspScriptEngineFactory)";
try {
Configuration[] slingGetServletCfgs = this.configurationAdmin.listConfigurations(filter);
if (slingGetServletCfgs == null) {
resultLog.warn("The Sling JSP 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("jasper.classdebuginfo"), (boolean)false);
boolean mappedContentEnabled = PropertiesUtil.toBoolean(properties.get("jasper.mappedfile"), (boolean)false);
if (debugInfoEnabled) {
resultLog.warn("The Sling JSP Script Handler generates debug information. The system might be exposed if used as a publish environment.", new Object[0]);
} else {
resultLog.debug("The Sling JSP Script Handler does not generate debug information.", new Object[0]);
}
if (mappedContentEnabled) {
resultLog.warn("The Sling JSP Script Handler generates mapped content. The system might be exposed if used as a publish environment.", new Object[0]);
} else {
resultLog.debug("The Sling JSP Script Handler does not generate mapped content.", new Object[0]);
}
success = !debugInfoEnabled && !mappedContentEnabled;
}
}
if (success) {
resultLog.debug("[The Sling JSP Script Handler is configured according to the security guidelines.]( )", new Object[0]);
} else {
resultLog.debug("[You can change the Sling JSP Script Handler settings via the configuration manager.]({})", new Object[]{"/system/console/configMgr/org.apache.sling.scripting.jsp.JspScriptEngineFactory"});
resultLog.debug("[Check the 'OSGI Settings' section of 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 JSP Script Handler configuration.", new Object[0]);
}
catch (InvalidSyntaxException e) {
resultLog.warn("Could not access Sling JSP 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;
}
}
}