Wiki source code of Configuration Tomcat
Last modified by Christian SENET on 2016/01/26 17:34
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
| |
1.1 | 1 | Gestion des rôles JEE. |
| 2 | |||
| 3 | L'application propose quelques outils d'aide. Ceux ci sont accessibles sous [[http://host[:port]/mywebapp/>>url:http://host/mywebapp/index.jsp?login=myuser&password=mypassword]]console | ||
| 4 | |||
| 5 | la ressource /console est protégée par un rôle JEE. | ||
| 6 | |||
| 7 | |||
| 8 | Ajout du rôle dans tomcat-user.xml | ||
| 9 | |||
| 10 | |||
| 11 | {{code language="xml" language="xml"}} | ||
| 12 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 13 | ... | ||
| 14 | <role rolename="wagon-administrator"/> | ||
| 15 | ... | ||
| 16 | <user username="admin" password="secret" roles="wagon-administrator"/> | ||
| 17 | </tomcat-users> | ||
| 18 | {{/code}} | ||
| 19 | |||
| 20 | |||
| 21 | |||
| 22 | Sécurisation des mots de passe dans tomcat : modifier Realm dans server.xml | ||
| 23 | |||
| 24 | |||
| 25 | {{code language="xml" language="xml"}} | ||
| 26 | <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase" digest="sha-512" /> | ||
| 27 | {{/code}} | ||
| 28 | |||
| 29 | |||
| 30 | Ensuite il faut générer le mot de passe depuis TOMCAT_HOME\bin\digest.bat (ou .sh) | ||
| 31 | digest.bat -a sha-512 myverysecretpassword | ||
| 32 | [[myverysecretpassword:b607e0c2a25e30495304307e058924512bf13705d56e18e568ba5297543d9b30$1$a679223cb>>url:http://myverysecretpasswordb607e0c2a25e30495304307e058924512bf13705d56e18e568ba5297543d9b30$1$a679223cb]] | ||
| 33 | et il faut copier le mot de passe encodé après le : dans la valeur password du tomcat-users.xml | ||
| 34 | |||
| 35 | |||
| 36 | Configuration du connector dans server.xml | ||
| 37 | |||
| 38 | |||
| 39 | {{code language="xml" language="xml"}} | ||
| 40 | <Connector compressableMimeType="text/html,text/xml,text/css,text/plain,application/json,application/javascript" compression="force" connectionTimeout="20000" port="80" protocol="HTTP/1.1" redirectPort="8443" maxPostSize="4194304" URIEncoding="UTF-8"/> | ||
| 41 | {{/code}} | ||
| 42 | |||
| 43 | * remarque : les directives **compressableMimeType** et **compression** ne sont nécessaire qu'en l'absence d'un frontal web, généralement en charge de la compression de flux | ||
| 44 | |||
| 45 | |||
| 46 | |||
| 47 | Configuration du connector derrière un reverse proxy. Cette configuration n'est possible que si votre reverse proxy supporte les websockets | ||
| 48 | |||
| 49 | |||
| 50 | {{code language="xml" language="xml"}} | ||
| 51 | <!-- Connecteur en reverse-proxy pour une connection http --> | ||
| 52 | <Connector acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" enableLookups="false" maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" port="81" protocol="HTTP/1.1" redirectPort="8443" useBodyEncodingForURI="true" scheme="http" proxyName="www.domain.com" proxyPort="80"/> | ||
| 53 | |||
| 54 | <!-- Connecteur en reverse-proxy pour une connection https --> | ||
| 55 | <Connector acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" enableLookups="false" maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" port="82" protocol="HTTP/1.1" redirectPort="8443" useBodyEncodingForURI="true" scheme="https" proxyName="www.domain.com" proxyPort="443"/> | ||
| 56 | {{/code}} | ||
| 57 | |||
| 58 | |||
| 59 | |||
| 60 | Augmentation de la taille du buffer texte des websockets. modification du fichier $TOMCAT_HOME/conf/web.xml, ajout de | ||
| 61 | |||
| 62 | |||
| 63 | {{code language="xml" language="xml"}} | ||
| 64 | <context-param> | ||
| 65 | <param-name>org.apache.tomcat.websocket.textBufferSize</param-name> | ||
| 66 | <param-value>65536</param-value> | ||
| 67 | </context-param> | ||
| 68 | |||
| 69 | {{/code}} | ||
| 70 | |||
| 71 | |||
| 72 | Définition des expirations de ressource en cas d'absence d'un frontal web en charge de cette opération modification du fichier $TOMCAT_HOME/conf/web.xml, ajout de | ||
| 73 | |||
| 74 | |||
| 75 | {{code language="xml" language="xml"}} | ||
| 76 | <filter> | ||
| 77 | <filter-name>ExpiresFilter</filter-name> | ||
| 78 | <filter-class>org.apache.catalina.filters.ExpiresFilter</filter-class> | ||
| 79 | <init-param> | ||
| 80 | <param-name>ExpiresByType image</param-name> | ||
| 81 | <param-value>access plus 10 days</param-value> | ||
| 82 | </init-param> | ||
| 83 | <init-param> | ||
| 84 | <param-name>ExpiresByType text/css</param-name> | ||
| 85 | <param-value>access plus 10 days</param-value> | ||
| 86 | </init-param> | ||
| 87 | <init-param> | ||
| 88 | <param-name>ExpiresByType application/javascript</param-name> | ||
| 89 | <param-value>access plus 10 days</param-value> | ||
| 90 | </init-param> | ||
| 91 | </filter> | ||
| 92 | <filter-mapping> | ||
| 93 | <filter-name>ExpiresFilter</filter-name> | ||
| 94 | <url-pattern>/*</url-pattern> | ||
| 95 | <dispatcher>REQUEST</dispatcher> | ||
| 96 | </filter-mapping> | ||
| 97 | |||
| 98 | {{/code}} | ||
| 99 | |||
| 100 | |||
| 101 | L'ensemble des données sont fournies à titre d'exemple, il convient bien évidemment de les adapter à votre contexte. | ||
| 102 | |||
| 103 | ((( | ||
| 104 | = Configuration d'une extension JMX = | ||
| 105 | ))) | ||
| 106 | ((( | ||
| 107 | == Configuration d'une extension JMX non sécurisée dans Tomcat. == | ||
| 108 | ))) | ||
| 109 | |||
| 110 | Modification du ficher catalina.sh ou catalina.bat | ||
| 111 | |||
| 112 | |||
| 113 | {{code language="none"}} | ||
| 114 | Linux : | ||
| 115 | |||
| 116 | # for JMX monitoring | ||
| 117 | JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote=true" | ||
| 118 | JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=1111" | ||
| 119 | JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false" | ||
| 120 | JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=false" | ||
| 121 | |||
| 122 | Microsoft Windows : | ||
| 123 | |||
| 124 | rem for JMX monitoring | ||
| 125 | set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote=true | ||
| 126 | set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.port=1111 | ||
| 127 | set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.ssl=false | ||
| 128 | set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.authenticate=false | ||
| 129 | {{/code}} | ||
| 130 | |||
| 131 | ((( | ||
| 132 | == Configuration de JMX avec l'authentification de client sans SSL. == | ||
| 133 | ))) | ||
| 134 | |||
| 135 | Création dans le répertoire conf du fichier (% style="color: rgb(0,0,0);" %)jmxremote.access. exemple(%%) | ||
| 136 | |||
| 137 | |||
| 138 | {{code language="none"}} | ||
| 139 | monitorRoleUser readonly | ||
| 140 | controlRoleUser readwrite | ||
| 141 | {{/code}} | ||
| 142 | |||
| 143 | |||
| 144 | |||
| 145 | (% style="color: rgb(0,0,0);" %)Création dans le répertoire conf du fichier (% style="color: rgb(0,0,0);" %)jmxremote.password. exemple(%%)(%%) | ||
| 146 | |||
| 147 | |||
| 148 | {{code language="none"}} | ||
| 149 | monitorRoleUser password1 | ||
| 150 | controlRoleUser password2 | ||
| 151 | {{/code}} | ||
| 152 | |||
| 153 | |||
| 154 | (% style="color: rgb(0,0,0);" %)Important :(%%)(% style="color: rgb(0,0,0);" %) Etant donné que des mots de passe en texte en clair sont stockés dans le fichier (%%)jmxremote.password(% style="color: rgb(0,0,0);" %), ce fichier doit être lisible par le propriétaire uniquement. Sinon, le programme se ferme avec une erreur.(%%) | ||
| 155 | |||
| 156 | |||
| 157 | {{code language="none"}} | ||
| 158 | Linux : | ||
| 159 | |||
| 160 | chmod 600 jmxremote.password | ||
| 161 | |||
| 162 | Windows in administrator mode : | ||
| 163 | icacls jmxremote.password /setowner myuser | ||
| 164 | icacls jmxremote.password /inheritance:r | ||
| 165 | icacls jmxremote.password /grant:r myuser:(r,w) | ||
| 166 | {{/code}} | ||
| 167 | |||
| 168 | |||
| 169 | |||
| 170 | Modification du ficher catalina.sh ou catalina.bat | ||
| 171 | |||
| 172 | |||
| 173 | {{code language="none"}} | ||
| 174 | Linux : | ||
| 175 | |||
| 176 | # for JMX monitoring | ||
| 177 | JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote=true" | ||
| 178 | JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=1111" | ||
| 179 | JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false" | ||
| 180 | JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=true" | ||
| 181 | JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.access.file=../conf/jmxremote.access" | ||
| 182 | JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.password.file=../conf/jmxremote.password" | ||
| 183 | |||
| 184 | Microsoft Windows : | ||
| 185 | |||
| 186 | rem for JMX monitoring | ||
| 187 | set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote=true | ||
| 188 | set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.port=1111 | ||
| 189 | set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.ssl=false | ||
| 190 | set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.authenticate=true | ||
| 191 | set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.access.file=..\conf\jmxremote.access | ||
| 192 | set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.password.file=..\conf\jmxremote.password | ||
| 193 | {{/code}} | ||
| 194 | |||
| 195 |