-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathletsencrypt-tomcat.xsl
127 lines (117 loc) · 5.35 KB
/
letsencrypt-tomcat.xsl
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
<?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="http"/>
<xsl:param name="http.scheme"/>
<xsl:param name="http.port"/>
<xsl:param name="http.proxyName"/>
<xsl:param name="http.proxyPort"/>
<xsl:param name="http.redirectPort"/>
<xsl:param name="http.connectionTimeout"/>
<xsl:param name="http.compression"/>
<xsl:param name="https"/>
<xsl:param name="https.scheme"/>
<xsl:param name="https.port"/>
<xsl:param name="https.maxThreads"/>
<xsl:param name="https.clientAuth"/>
<xsl:param name="https.proxyName"/>
<xsl:param name="https.proxyPort"/>
<xsl:param name="https.keystoreFile"/>
<xsl:param name="https.keystorePass"/>
<xsl:param name="https.keyAlias"/>
<xsl:param name="https.keyPass"/>
<xsl:param name="https.compression"/>
<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($http, $lowercase, $uppercase) = 'TRUE'">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:if test="$http.scheme">
<xsl:attribute name="scheme">
<xsl:value-of select="$http.scheme"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$http.port">
<xsl:attribute name="port">
<xsl:value-of select="$http.port"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$http.proxyName">
<xsl:attribute name="proxyName">
<xsl:value-of select="$http.proxyName"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$http.proxyPort">
<xsl:attribute name="proxyPort">
<xsl:value-of select="$http.proxyPort"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$http.redirectPort">
<xsl:attribute name="redirectPort">
<xsl:value-of select="$http.redirectPort"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$http.connectionTimeout">
<xsl:attribute name="connectionTimeout">
<xsl:value-of select="$http.connectionTimeout"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$http.compression">
<xsl:attribute name="compression">
<xsl:value-of select="$http.compression"/>
</xsl:attribute>
</xsl:if>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:if>
</xsl:template>
<!-- enable HTTPS if it's not already enabled -->
<xsl:template match="Service[not(Connector/@protocol = 'org.apache.coyote.http11.Http11NioProtocol')]/*[last()]">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
<!-- xsltproc does not support boolean parameters -->
<xsl:if test="translate($https, $lowercase, $uppercase) = 'TRUE'">
<Connector port="{$https.port}" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="{$https.maxThreads}" SSLEnabled="true" secure="true"
keystoreFile="{$https.keystoreFile}" keystorePass="{$https.keystorePass}"
keyAlias="{$https.keyAlias}" keyPass="{$https.keyPass}"
sslProtocol="TLS">
<xsl:if test="$https.scheme">
<xsl:attribute name="scheme">
<xsl:value-of select="$https.scheme"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$https.proxyName">
<xsl:attribute name="proxyName">
<xsl:value-of select="$https.proxyName"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$https.proxyPort">
<xsl:attribute name="proxyPort">
<xsl:value-of select="$https.proxyPort"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$https.clientAuth">
<xsl:attribute name="clientAuth">
<xsl:value-of select="$https.clientAuth"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$https.compression">
<xsl:attribute name="compression">
<xsl:value-of select="$https.compression"/>
</xsl:attribute>
</xsl:if>
</Connector>
</xsl:if>
</xsl:template>
</xsl:stylesheet>