-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathletsencrypt-tomcat.xsl
More file actions
151 lines (139 loc) · 7.23 KB
/
letsencrypt-tomcat.xsl
File metadata and controls
151 lines (139 loc) · 7.23 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:param name="Connector.http"/>
<xsl:param name="Connector.scheme.http"/>
<xsl:param name="Connector.port.http"/>
<xsl:param name="Connector.proxyName.http"/>
<xsl:param name="Connector.proxyPort.http"/>
<xsl:param name="Connector.redirectPort.http"/>
<xsl:param name="Connector.connectionTimeout.http"/>
<xsl:param name="Connector.compression.http"/>
<xsl:param name="Connector.https"/>
<xsl:param name="Connector.scheme.https"/>
<xsl:param name="Connector.port.https"/>
<xsl:param name="Connector.maxThreads.https"/>
<xsl:param name="Connector.clientAuth.https"/>
<xsl:param name="Connector.proxyName.https"/>
<xsl:param name="Connector.proxyPort.https"/>
<xsl:param name="Connector.keystoreFile.https"/>
<xsl:param name="Connector.keystorePass.https"/>
<xsl:param name="Connector.keyAlias.https"/>
<xsl:param name="Connector.keyPass.https"/>
<xsl:param name="Connector.compression.https"/>
<xsl:param name="RemoteIpValve" select="'false'"/>
<xsl:param name="RemoteIpValve.protocolHeader" select="'X-Forwarded-Proto'"/>
<xsl:param name="RemoteIpValve.portHeader" select="'X-Forwarded-Port'"/>
<xsl:param name="RemoteIpValve.remoteIpHeader" select="'X-Forwarded-For'"/>
<xsl:param name="RemoteIpValve.hostHeader" select="'X-Forwarded-Host'"/>
<xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'"/>
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- redirect HTTP to HTTPS-->
<!-- @redirectPort requires security-constraint in web.xml: https://tomcat.apache.org/tomcat-8.0-doc/config/http.html -->
<xsl:template match="Connector[@protocol = 'HTTP/1.1']">
<!-- xsltproc does not support boolean parameters -->
<xsl:if test="translate($Connector.http, $lowercase, $uppercase) = 'TRUE'">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:if test="$Connector.scheme.http">
<xsl:attribute name="scheme">
<xsl:value-of select="$Connector.scheme.http"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$Connector.port.http">
<xsl:attribute name="port">
<xsl:value-of select="$Connector.port.http"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$Connector.proxyName.http">
<xsl:attribute name="proxyName">
<xsl:value-of select="$Connector.proxyName.http"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$Connector.proxyPort.http">
<xsl:attribute name="proxyPort">
<xsl:value-of select="$Connector.proxyPort.http"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$Connector.redirectPort.http">
<xsl:attribute name="redirectPort">
<xsl:value-of select="$Connector.redirectPort.http"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$Connector.connectionTimeout.http">
<xsl:attribute name="connectionTimeout">
<xsl:value-of select="$Connector.connectionTimeout.http"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$Connector.compression.http">
<xsl:attribute name="compression">
<xsl:value-of select="$Connector.compression.http"/>
</xsl:attribute>
</xsl:if>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:if>
</xsl:template>
<xsl:template match="Server/Service/Engine">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<!-- add RemoteIpValve if requested and not already present -->
<xsl:if test="translate($RemoteIpValve, $lowercase, $uppercase) = 'TRUE' and not(Valve[@className='org.apache.catalina.valves.RemoteIpValve'])">
<Valve className="org.apache.catalina.valves.RemoteIpValve">
<xsl:attribute name="protocolHeader">
<xsl:value-of select="$RemoteIpValve.protocolHeader"/>
</xsl:attribute>
<xsl:attribute name="portHeader">
<xsl:value-of select="$RemoteIpValve.portHeader"/>
</xsl:attribute>
<xsl:attribute name="remoteIpHeader">
<xsl:value-of select="$RemoteIpValve.remoteIpHeader"/>
</xsl:attribute>
<xsl:attribute name="hostHeader">
<xsl:value-of select="$RemoteIpValve.hostHeader"/>
</xsl:attribute>
</Valve>
</xsl:if>
<xsl:apply-templates select="node()"/>
</xsl:copy>
<!-- add HTTPS connector after Engine if not already present -->
<xsl:if test="not(../Connector[@protocol = 'org.apache.coyote.http11.Http11NioProtocol']) and translate($Connector.https, $lowercase, $uppercase) = 'TRUE'">
<Connector port="{$Connector.port.https}" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="{$Connector.maxThreads.https}" SSLEnabled="true" secure="true"
keystoreFile="{$Connector.keystoreFile.https}" keystorePass="{$Connector.keystorePass.https}"
keyAlias="{$Connector.keyAlias.https}" keyPass="{$Connector.keyPass.https}"
sslProtocol="TLS">
<xsl:if test="$Connector.scheme.https">
<xsl:attribute name="scheme">
<xsl:value-of select="$Connector.scheme.https"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$Connector.proxyName.https">
<xsl:attribute name="proxyName">
<xsl:value-of select="$Connector.proxyName.https"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$Connector.proxyPort.https">
<xsl:attribute name="proxyPort">
<xsl:value-of select="$Connector.proxyPort.https"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$Connector.clientAuth.https">
<xsl:attribute name="clientAuth">
<xsl:value-of select="$Connector.clientAuth.https"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$Connector.compression.https">
<xsl:attribute name="compression">
<xsl:value-of select="$Connector.compression.https"/>
</xsl:attribute>
</xsl:if>
</Connector>
</xsl:if>
</xsl:template>
</xsl:stylesheet>