Tomcatxx
Indice
- 1 TOMCAT - Appunti di gestione/configurazione
TOMCAT - Appunti di gestione/configurazione
Configurazione tramite file parametri JNDI
<Environment description="Cartella file di configurazione ..."
name="url/com.netsitech.myapp.urlConfig"
type="java.lang.String"
value="file:///C:/Programmi/Sitech/myapp/config"/>
o in caso di architettura *nix
<Environment description="Cartella file di configurazione ..."
name="url/com.netsitech.myapp.urlConfig"
type="java.lang.String"
value="file:///etc/myapp/config"/>
Esempio di configurazione per l'autenticazione LDAP
La sezione di configurazione seguente, ma messa all'interno del tag <Engine> del file server.xml.
<!-- Autenticazione Ldap Sitech -->
<Realm className="org.apache.catalina.realm.JNDIRealm"
debug="99"
connectionName="account-per-bind"
connectionPassword="password-account-per-bind"
connectionURL="ldap://ldap.server.dominio:389"
referrals="follow"
userBase="DC=2ndlevel-domain,DC=domain,DC=toplevel"
userSearch="(sAMAccountName={0})"
userSubtree="true"
userRoleName="memberOf" />
E' importante ricordare che, nel caso particolare di ActiveDirectory, in corrispondenza della voce memberOf, verranno elencati solo i gruppi secondari per l'utente. Come conseguenza di questo comportamento, è importante che il gruppo principale di assegnazione di ogni account, sia diverso da quello utilizzato per verificare le crednziali di autenticazione.
Nel caso di faccia uso del canale protetto (LDAPS), è importante che nel keystore della JVM su cui viene eseguito TOMCAT sia inserito il certificato del server LDAPS.
La configurazione per ottenere l'autenticazione va completata con alcune righe nel descrittore (file web.xml) della web application.
In particolare vanno aggiunte le seguenti righe:
<security-constraint>
<web-resource-collection>
<web-resource-name>Accesso all'area protetta del sito</web-resource-name>
<url-pattern>/areaprotetta/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<!-- NOTE: This role is not present in the default users file -->
<role-name>CN=Utenti area protetta,OU=unita-organizzativa,DC=2ndevel-domain,DC=domain,DC=topleve</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Descrizione del realm</realm-name>
</login-config>
<!-- Security roles referenced by this web application -->
<security-role>
<description>
Ruolo richiesto per l'accesso all'area protetta del sito
</description>
<role-name>CN=Utenti area protetta,OU=ufficio sviluppo,DC=2ndevel-domain,DC=domain,DC=topleve</role-name>
</security-role>
Le righe sopra esposte, fanno si che il sito pubblico in questione, contenga una cartella protetta individuata dal prefisso /areaprotetta all'interno della quale, ogni file (/*) è soggetto al controllo di autenticazione.
Saranno ammessi a quest'area tutti gli utenti per i quali esiste una definizione in AD (ldap) che preveda l'appartenenza al gruppo di protezione Utenti area protetta, dell'unità organizzativa ufficio sviluppo appartenente al dominio 2ndlevel.domain.toplevel.
Configurazione per TOMCAT Manager
Nel caso del tomcat manager, il file web.xml da modificare è quello che si trova nella cartella WEB-INF della cartella che contiene l'applicazione di gestione (tomcat-manager).
root@c23f7be68b0a:# cat /usr/local/tomcat/webapps/manager/WEB-INF/web.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3 Licensed to the Apache Software Foundation (ASF) under one or more
4 contributor license agreements. See the NOTICE file distributed with
5 this work for additional information regarding copyright ownership.
6 The ASF licenses this file to You under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with
8 the License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 -->
18 <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
19 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
21 http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
22 version="4.0"
23 metadata-complete="true">
24
25 <display-name>Tomcat Manager Application</display-name>
26 <description>
27 A scriptable management web application for the Tomcat Web Server;
28 Manager lets you view, load/unload/etc particular web applications.
29 </description>
30
31 <request-character-encoding>UTF-8</request-character-encoding>
32
33 <servlet>
34 <servlet-name>Manager</servlet-name>
35 <servlet-class>org.apache.catalina.manager.ManagerServlet</servlet-class>
36 <init-param>
37 <param-name>debug</param-name>
38 <param-value>2</param-value>
39 </init-param>
40 </servlet>
41 <servlet>
42 <servlet-name>HTMLManager</servlet-name>
43 <servlet-class>org.apache.catalina.manager.HTMLManagerServlet</servlet-class>
44 <init-param>
45 <param-name>debug</param-name>
46 <param-value>2</param-value>
47 </init-param>
48 <!-- Uncomment this to show proxy sessions from the Backup manager or a
49 StoreManager in the sessions list for an application
50 <init-param>
51 <param-name>showProxySessions</param-name>
52 <param-value>true</param-value>
53 </init-param>
54 -->
55 <multipart-config>
56 <!-- 50MB max -->
57 <max-file-size>104857600</max-file-size>
58 <max-request-size>104857600</max-request-size>
59 <file-size-threshold>0</file-size-threshold>
60 </multipart-config>
61 </servlet>
62 <servlet>
63 <servlet-name>Status</servlet-name>
64 <servlet-class>org.apache.catalina.manager.StatusManagerServlet</servlet-class>
65 <init-param>
66 <param-name>debug</param-name>
67 <param-value>0</param-value>
68 </init-param>
69 </servlet>
70
71 <servlet>
72 <servlet-name>JMXProxy</servlet-name>
73 <servlet-class>org.apache.catalina.manager.JMXProxyServlet</servlet-class>
74 </servlet>
75
76 <!-- Define the Manager Servlet Mapping -->
77 <servlet-mapping>
78 <servlet-name>Manager</servlet-name>
79 <url-pattern>/text/*</url-pattern>
80 </servlet-mapping>
81 <servlet-mapping>
82 <servlet-name>Status</servlet-name>
83 <url-pattern>/status/*</url-pattern>
84 </servlet-mapping>
85 <servlet-mapping>
86 <servlet-name>JMXProxy</servlet-name>
87 <url-pattern>/jmxproxy/*</url-pattern>
88 </servlet-mapping>
89 <servlet-mapping>
90 <servlet-name>HTMLManager</servlet-name>
91 <url-pattern>/html/*</url-pattern>
92 </servlet-mapping>
93
94 <filter>
95 <filter-name>CSRF</filter-name>
96 <filter-class>org.apache.catalina.filters.CsrfPreventionFilter</filter-class>
97 <init-param>
98 <param-name>entryPoints</param-name>
99 <param-value>/html,/html/,/html/list,/index.jsp</param-value>
100 </init-param>
101 </filter>
102
103 <!-- Configured to set X-FRAME-OPTIONS. Disable HSTS in case it interferes -->
104 <!-- with an existing setting. Keep X-Content-Type-Options and -->
105 <!-- X-XSS-Protection as they are page specific. -->
106 <filter>
107 <filter-name>HTTP header security filter</filter-name>
108 <filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
109 <init-param>
110 <param-name>hstsEnabled</param-name>
111 <param-value>false</param-value>
112 </init-param>
113 </filter>
114
115 <filter-mapping>
116 <filter-name>CSRF</filter-name>
117 <servlet-name>HTMLManager</servlet-name>
118 </filter-mapping>
119
120 <filter-mapping>
121 <filter-name>HTTP header security filter</filter-name>
122 <url-pattern>/*</url-pattern>
123 </filter-mapping>
124
125 <!-- Define a Security Constraint on this Application -->
126 <!-- NOTE: None of these roles are present in the default users file -->
127 <security-constraint>
128 <web-resource-collection>
129 <web-resource-name>HTML Manager interface (for humans)</web-resource-name>
130 <url-pattern>/html/*</url-pattern>
131 </web-resource-collection>
132 <auth-constraint>
133 <role-name>manager-gui</role-name>
134 <role-name>CN=Test Deployer,OU=Groups,OU=SITECH,DC=sede,DC=netsitech,DC=com</role-name>
135 </auth-constraint>
136 </security-constraint>
137 <security-constraint>
138 <web-resource-collection>
139 <web-resource-name>Text Manager interface (for scripts)</web-resource-name>
140 <url-pattern>/text/*</url-pattern>
141 </web-resource-collection>
142 <auth-constraint>
143 <role-name>manager-script</role-name>
144 <role-name>CN=Test Deployer,OU=Groups,OU=SITECH,DC=sede,DC=netsitech,DC=com</role-name>
145 </auth-constraint>
146 </security-constraint>
147 <security-constraint>
148 <web-resource-collection>
149 <web-resource-name>JMX Proxy interface</web-resource-name>
150 <url-pattern>/jmxproxy/*</url-pattern>
151 </web-resource-collection>
152 <auth-constraint>
153 <role-name>manager-jmx</role-name>
154 <role-name>CN=Test Deployer,OU=Groups,OU=SITECH,DC=sede,DC=netsitech,DC=com</role-name>
155 </auth-constraint>
156 </security-constraint>
157 <security-constraint>
158 <web-resource-collection>
159 <web-resource-name>Status interface</web-resource-name>
160 <url-pattern>/status/*</url-pattern>
161 </web-resource-collection>
162 <auth-constraint>
163 <role-name>manager-gui</role-name>
164 <role-name>manager-script</role-name>
165 <role-name>manager-jmx</role-name>
166 <role-name>manager-status</role-name>
167 <role-name>CN=Test Deployer,OU=Groups,OU=SITECH,DC=sede,DC=netsitech,DC=com</role-name>
168 </auth-constraint>
169 </security-constraint>
170
171 <!-- Define the Login Configuration for this Application -->
172 <login-config>
173 <auth-method>BASIC</auth-method>
174 <realm-name>Tomcat Manager Application</realm-name>
175 </login-config>
176
177 <!-- Security roles referenced by this web application -->
178 <security-role>
179 <description>
180 The role that is required to access the HTML Manager pages
181 </description>
182 <role-name>manager-gui</role-name>
183 </security-role>
184 <security-role>
185 <description>
186 The role that is required to access the text Manager pages
187 </description>
188 <role-name>manager-script</role-name>
189 </security-role>
190 <security-role>
191 <description>
192 The role that is required to access the HTML JMX Proxy
193 </description>
194 <role-name>manager-jmx</role-name>
195 </security-role>
196 <security-role>
197 <description>
198 The role that is required to access to the Manager Status pages
199 </description>
200 <role-name>manager-status</role-name>
201 </security-role>
202 <security-role>
203 <description>
204 The role that is required to log in to the Manager Application
205 </description>
206 <role-name>CN=Test Deployer,OU=Groups,OU=SITECH,DC=sede,DC=netsitech,DC=com</role-name>
207 </security-role>
208
209 <error-page>
210 <error-code>401</error-code>
211 <location>/WEB-INF/jsp/401.jsp</location>
212 </error-page>
213 <error-page>
214 <error-code>403</error-code>
215 <location>/WEB-INF/jsp/403.jsp</location>
216 </error-page>
217 <error-page>
218 <error-code>404</error-code>
219 <location>/WEB-INF/jsp/404.jsp</location>
220 </error-page>
221
222 </web-app>
Nello specifico le righe interessate dalla modifica sono:
- Riga 134
- Riga 144
- Riga 154
- Riga 167
nelle quali vengono associati i percorsi ldap che descrivono chi potrà accedere alle risorse espresse nella clausole:
<web-resource-name> <url-pattern>
La configurazione si completa con la riga 206.
Accesso remoto
Aggiornare il file context.xml nella CATALINA_HOME,
CATALINA_HOME/webapps/manager/META-INF/context.xml
nel seguente modo:
1 <Context antiResourceLocking="false" privileged="true" >
2 <!--
3 <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
4 -->
5 </Context>
Errore durante la convalida di un certificato (ad esempio per autenticazione LDAPS)
Nel caso di presente l'errore:
javax.net.ssl.SSLHandshakeException: No subject alternative DNS name matching ......
oppure:
java.security.cert.CertificateException: No subject alternative DNS name matching .....
ed in ogni caso nell'eccezione sollevata comparisse come causa: No subject alternative DNS name matching ....., la soluzione è nell'includere la seguente definizione nel file di impostazione delle variabili di ambiente utilizzata all'avvio di TOMCAT:
CATALINA_OPTS="-Dcom.sun.jndi.ldap.object.disableEndpointIdentification=true"
Solitamente il file in cui includere questa definizione è:
setenv.sh
la cui collocazione fisica sul file system dipende dalla versione e tipologia di JVM/distribuzione di TOMCAT utilizzata.
Di seguito due casi diversi:
/var/lib/tomcat9/bin/setenv.sh
e
/usr/share/tomcat9/bin/setenv.sh
Abilitare/Disabilitare il Directory Listing
Accedere al file web.xml presente nella cartella di configurazione dell'installazione Tomcat e impostare il valore del parametro listings al valore true o false.
Proteggere una cartella
Per proteggere una cartella è necessario creare un security-descriptor nel file web.xml.
Ecco un esempio di security descriptor
<!-- Define a Security Constraint on this Application -->
<security-constraint>
<web-resource-collection>
<web-resource-name>Descrizione della cartella da proteggere</web-resource-name>
<url-pattern>/cartella-da-proteggere/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>reserved</role-name>
</auth-constraint>
</security-constraint>
<!-- Define the Login Configuration for this Application -->
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Messaggio che vogliamo che compaia nella dialog di logon</realm-name>
</login-config>
<!-- Security roles referenced by this web application -->
<security-role>
<description>Ruolo necessario per accedere alla cartella protetta</description>
<role-name>reserved</role-name>
</security-role>
Questo va bene nel caso in cui la cartella da proteggere appartenga ad un contesto (Context) già definito.
Nel caso invece in cui si possa definire un contesto specifico per la cartella da proteggere, si può procedere come segue:
- Creare il nuovo Context
<Context path="/cartella-da-proteggere" docBase="${catalina.home}/folder-da-proteggere" privileged="true" allowLinking="true" >
<!-- Definizione facoltativa solo se è necessario restringere l'accesso ad un certo numero di IP -->
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="172.16.0.*, 10.*" deny="10.172.16.*"/>
</Context>
- Posizionarsi nella cartella identificata da ${catalina.home}/folder-da-proteggere
- Creare una cartella di nome WEB-INF
- Creare all'interno di questa un file web.xml il cui contenuto è il seguente:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID"
version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Nome-Contesto</display-name>
<description>Breve descrizione del contesto</description>
<!-- Define a Security Constraint on this Application -->
<security-constraint>
<web-resource-collection>
<web-resource-name>Descrizione del contesto da proteggere</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>reserved</role-name>
</auth-constraint>
</security-constraint>
<!-- Define the Login Configuration for this Application -->
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Messaggio che vogliamo che compaia nella dialog di logon</realm-name>
</login-config>
<!-- Security roles referenced by this web application -->
<security-role>
<description>Ruolo necessario per accedere al contesto protetto</description>
<role-name>reserved</role-name>
</security-role>
</web-app>