server.xml Tomcat's configuration files, including server.xml can be found in: $TOMCAT_HOME/conf
server.xml do not take effect until Tomcat is restarted.server.xmlserver.xml.Move into the Tomcat conf/ directory and examine the server.xml file:
$ cd $TOMCAT_HOME/conf $ less server.xml
Reference the table below to see how the server.xml elements relate to configuring TDS (mouse-over the element for a description):
tomcat-users.xml tomcat-users.xml do not take effect until Tomcat is restarted.tomcat-users.xmltomcat-users.xml.Open the $TOMCAT_HOME/conf/tomcat-users.xml file:
$ less $TOMCAT_HOME/conf/tomcat-users.xml
Reference the table below to see how the tomcat-users.xml elements relate to configuring TDS (mouse-over the element for a description):
| Tag Name | Instances | How it relates to the TDS |
|---|---|---|
<tomcat-users>Description: The tomcat-users element represents the single outermost element in tomcat-users.xml
|
1...1 | Not modified. (The only tag you get by default.) |
<role>Description: The role element defines one role or group a user can belong to.
|
1...* |
You will have at least two of these: one for the Tomcat manager application and one for the TDS. (You will need to add if you want to enable role-based authentication.)
|
<user>Description: The user element represents one valid user.
|
1...* |
You will need to create an entry for each user who needs access to the Tomcat manager application and/or the restricted areas of the TDS. (You will need to add if you want to enable user authentication.)
|
manager Applicationmanager applicationmanagerFor more information about the Tomcat manager application, see the Tomcat Manager App HOW-TO documentation.
$TOMCAT_HOME/webapps/manager directory. server.xml.manager applicationAttempt to access the Tomcat manager application in your browser: http://localhost:8080/manager/html/. You will be prompted to login via BASIC authentication, which will end in failure since we do not yet have permission to access the manager application:
Based on what we know about Tomcat configuration, which file in $TOMCAT_HOME/conf should we edit to grant ourselves access to the manager application?
manager applicationtomcat-users.xml to add role and user elements.Using your favorite editor, open $TOMCAT_HOME/conf/tomcat-users.xml:
$ vi tomcat-users.xml
Between the <tomcat-users> tags, add a role element and specify the rolename attribute as manager:
<tomcat-users>
<role rolename="manager"/>
</tomcat-users>
Now add a new user by adding a user element. Create a username and password for the new user and specify manager as one of the roles (in this example we are creating a user called 'admin' with a corresponding password of 'secret'):
<tomcat-users>
<role rolename="manager"/>
<user name="admin" password="secret" roles="manager"/>
</tomcat-users>
manager application.Changes to tomcat-users.xml do not take effect until Tomcat is restarted.
Attempt to access the manager application again (http://localhost:8080/manager/html/), this time logging in using the name and password specified in tomcat-users.xml:
To gain access to restricted parts of the TDS, you will perform the same steps you used to grant yourself access to the manager application.
Voilà! You should have access to the manager application.
tomcat-users.xml to make sure it is well-formed and without error.tomcat-users.xml?$TOMCAT_HOME/logs/catalina.out. manager application$TOMCAT_HOME/conf/tomcat-users.xml to grant yourself access to the Tomcat manager application.manager applicationmanager application to undeploy the TDS.Find the TDS in the list of web application on the Applications page. Stop and then Undeploy the TDS:

List the contents of $TOMCAT_HOME/webapps/ to verify that both thredds.war and the unpacked thredds/ directory have been removed:
$ cd $TOMCAT_HOME/webapps $ ls -l total 10284 drwxr-xr-x 11 thredds workshop 4096 2009-05-13 17:15 docs drwxr-xr-x 5 thredds workshop 4096 2009-05-13 17:15 examples drwxr-xr-x 5 thredds workshop 4096 2009-05-13 17:15 host-manager drwxr-xr-x 5 thredds workshop 4096 2009-05-13 17:15 manager drwxr-xr-x 3 thredds workshop 4096 2009-05-13 17:15 ROOT
manager application.Upload the TDS WAR file using the Deploy section of the manager application:
Confirm the deployment went as planned by accessing the TDS using your browser: http://localhost:8080/thredds/
manager applicationmanager application.manager applicationPermGen infoFor a really good description of the issue, see this series of three articles:
The dreaded java.lang.OutOfMemoryError: PermGen space failure error:
manager application, your WAR file is unpacked and parts of the class file definition are loaded into PermGen space, like string constants.manager application that never completes a task, and the java.lang.OutOfMemoryError: PermGen space failure error being displayed in $TOMCAT_HOME/logs/catalina.out -XX:MaxPermSize switch to $JAVA_OPTS to increase the amount of memory allocated for the permanent generation, However this is only postponed the inevitable, as even an increased memory in permanent generation will eventually fill up. When this happens, you will need to stop/start Tomcat at this point. For this reason, you may want to restart Tomcat whenever you redeploy TDS or another webapp.For added incentive to use encrypted passwords, read about the man-in-the-middle attack.
tomcat-users.xml. server.xml.Open $TOMCAT_HOME/conf/server.xml with your favorite editor:
$ vi server.xml
Locate the UserDatabaseRealm (right above the Host element) and comment it out:
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<!--
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
-->
<!-- Define the default virtual host
Note: XML Schema validation will not work with Xerces 2.2.
-->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
Now add the flowing MemoryRealm information inside the Host element:
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<!--
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
-->
<!-- Define the default virtual host
Note: XML Schema validation will not work with Xerces 2.2.
-->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Realm className="org.apache.catalina.realm.MemoryRealm"
digest="SHA" />
Tomcat provides a script ($TOMCAT_HOME/bin/digest.sh) that will encrypt a password string according to the algorithm specified. Use this script as follows with the password you made for yourself previously:
$ /home/thredds/apache-tomcat-6.0.20/bin/digest.sh -a SHA secret secret:e5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4
tomcat-users.xml.Replace your clear-text password in tomcat-users.xml with the encrypted version:
<tomcat-users>
<role rolename="manager"/>
<user name="admin" password="e5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4" roles="manager"/>
</tomcat-users>
Since we are using BASIC authentication, you will need to clear any authenticated sessions in your browser to test whether digested passwords have been enabled.
Restart Tomcat and verify digest passwords have been successfully enabled by logging into the Tomcat manager application using your password in clear text: http://localhost:8080/manager/html/
tomcat-users.xml and server.xml to make sure it is well-formed and without error.tomcat-users.xml and server.xml ?$TOMCAT_HOME/logs/catalina.out. For more information on how SSL works, Wikipedia details the steps involved during an SSL transaction.
https instead of http.Other than the compelling security reasons, you will want to enable SSL to take advantage of the TDS remote management tool which (out-of-the-box) requires SSL in order to access: http://localhost:8080/thredds/admin/debug
$TOMCAT_HOME/conf/keystore.Run the $JAVA_HOME/bin/keytool command:
$ cd /home/thredds/jdk1.6.0_15/bin $ ./keytool -genkey -alias tomcat -keyalg RSA -keystore /home/thredds/apache-tomcat-6.0.20/conf/keystore
Meaning of the keytool options:
| Command | Purpose |
|---|---|
$JAVA_HOME/bin/keytool
|
Java provides a tool, called keytool, that generates a self-signed certificate and puts in a keystore file.
|
-genkey
|
The -genkey option specifies that a key pair (private key and public key) needs to be created. This key pair will be enclosed in the self-signed certificate.
|
-alias tomcat
|
The -alias tomcat option creates an entry in the keystore file identified by the alias "tomcat" (which Tomcat will use to find your entry).
|
-keyalg RSA
|
The -keyalg RSA option specifies the algorithm (in this case is RSA) to be used for the creation the key pair.
|
-keystore $TOMCAT_HOME/conf/keystore
|
-keystore $TOMCAT_HOME/conf/keystore is location of where want to put our keystore. Otherwise, the default keystore is $user_home/.keystore.
|
Create the self-signed certificate identity. While you are filling out the identity fields for your certificate, keep in mind:
first and last name, or CN, should be the host namekeystore password (the first password you are prompted to enter) is always changeitkey password) and keystore password need to be the same (changeit). Enter keystore password: changeit Re-enter new password: changeit What is your first and last name? [Unknown]: localhost What is the name of your organizational unit? [Unknown]: THREDDS What is the name of your organization? [Unknown]: Unidata What is the name of your City or Locality? [Unknown]: Boulder What is the name of your State or Province? [Unknown]: Colorado What is the two-letter country code for this unit? [Unknown]: US Is CN=localhost, OU=THREDDS, O=Unidata, L=Boulder, ST=Colorado, C=US correct? [no]: y Enter key password for(RETURN if same as keystore password):
Verify the new keystore file has been generated in $TOMCAT_HOME/conf:
$ cd /home/thredds/apache-tomcat-6.0.20/conf thredds@workshop03 conf]$ ls -l total 100 drwxr-xr-x 3 thredds workshop 4096 2009-08-03 16:08 Catalina -rw------- 1 thredds workshop 8690 2009-05-13 17:15 catalina.policy -rw------- 1 thredds workshop 3665 2009-05-13 17:15 catalina.properties -rw------- 1 thredds workshop 1396 2009-05-13 17:15 context.xml -rw-r--r-- 1 thredds workshop 1360 2009-08-03 16:42 keystore -rw------- 1 thredds workshop 3257 2009-05-13 17:15 logging.properties -rw------- 1 thredds workshop 6576 2009-08-03 16:36 server.xml -rw------- 1 thredds workshop 1231 2009-08-03 16:37 tomcat-users.xml -rw------- 1 thredds workshop 50757 2009-05-13 17:15 web.xml
Based on what we know about Tomcat configuration, which file in $TOMCAT_HOME/conf should we edit to to enable SSL?
Open $TOMCAT_HOME/conf/server.xml with your favorite editor:
$ vi server.xml
Locate the Java HTTP/1.1 Connector listening on port 8080 and verify it is redirecting SSL traffic to port 8443:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
Find and uncomment the SSL HTTP/1.1 Connector listening on port 8443 to activate this connector:
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
Add a keystoreFile attribute to the SSL HTTP/1.1 Connector to tell Tomcat where to find the keystore:
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" keystoreFile="/home/thredds/apache-tomcat-6.0.20/conf/keystore" />
Finally, verify the AprLifecycleListener is uncommented (found near the top of the file):
<!--APR library loader. Documentation at /docs/apr.html --> <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
Restart Tomcat:
$ $TOMCAT_HOME/bin/shutdown.sh $ $TOMCAT_HOME/bin/startup.sh
Verify Tomcat is listening on port 8443 by running the netstat command:
$ netstat -an | grep tcp
man netstatRun man netstat in your terminal window to learn more about this command.
netstat (short for network statistics) is available on Unix, Unix-like, and Windows NT-based operating systems. It is a command-line tool that displays:
Look for the following in the output:
tcp 0 0 127.0.0.1:8443 0.0.0.0:* LISTEN
server.xml to make sure it is well-formed and without error.key password) and keystore password should be the same (changeit). If they differ, Tomcat cannot open the keystore and you will get this error: java.io.IOException: Cannot recover key.server.xml?keystore file in server.xml?$TOMCAT_HOME/conf/tomcat-users.xml to add a new role with the rolename attribute of tdsConfig, and add this role to your list of roles:
<tomcat-users>
<role rolename="manager"/>
<role rolename="tdsConfig"/>
<user name="admin" password="e5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4" roles="manager,tdsConfig"/>
</tomcat-users>
How did Tomcat know to use SSL for the TDS remote management tool?
Where, in any of the configuration changes you made to $TOMCAT_HOME/conf/server.xml or $TOMCAT_HOME/conf/tomcat-users.xml, did you explicitly specify that TDS remote management tool must be accessed via SSL?
/WEB-INF/web.xmlweb.xml.WEB-INF directory of the web application: <application name>/WEB-INF/web.xml. Navigate to the unpacked thredds directory in $TOMCAT_HOME/webapps, and view the file:
$ cd /home/thredds/apache-tomcat-6.0.20/webapps/thredds $ less WEB-INF/web.xml
/admin/debug).Near the bottom of the deployment descriptor you will find this entry:
<!-- This allows "remote configuration":
/thredds/admin/debug gives access to various debug and status info.
/thredds/admin/content/ -> "{tomcat_home}/content/thredds/"
/thredds/admin/root/ -> "{tomcat_home}/webapps/thredds/" DISABLED
/thredds/admin/dataDir/path -> "{dataRoot(path)}/webapps/thredds/" DISABLED
-->
<security-constraint>
<web-resource-collection>
<web-resource-name>sensitive read access</web-resource-name>
<url-pattern>/admin/*</url-pattern>
<http-method>GET</http-method>
<!-- http-method>PUT</http-method -->
</web-resource-collection>
<auth-constraint>
<role-name>tdsConfig</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
For more information on how to configure security requirements for a web application in a deployment descriptor, see: Defining Security Requirements for Web Applications.
<user-data-constraint> establishes a requirement that the constrained requests be received over a protected transport layer connection. This guarantees how the data will be transported between client and server. <transport-guarantee> choices for type of transport guarantee include NONE, INTEGRAL, and CONFIDENTIAL: CONFIDENTIAL when the application requires that data be transmitted so as to prevent other entities from observing the contents of the transmission. (E.g., via SSL.)INTEGRAL when the application requires that the data be sent between client and server in such a way that it cannot be changed in transit. NONE to indicate that the container must accept the constrained requests on any connection, including an unprotected one.manager applicationmanager application.Using your favorite editor, open the deployment descriptor for the Tomcat manager application:
$ vi /home/thredds/apache-tomcat-6.0.20/webapps/manager/WEB-INF/web.xml
Locate the <security-constraint> element (near the bottom of the file):
<!-- Define a Security Constraint on this Application -->
<security-constraint>
<web-resource-collection>
<web-resource-name>HTMLManger and Manager command</web-resource-name>
<url-pattern>/jmxproxy/*</url-pattern>
<url-pattern>/html/*</url-pattern>
<url-pattern>/list</url-pattern>
<url-pattern>/expire</url-pattern>
<url-pattern>/sessions</url-pattern>
<url-pattern>/start</url-pattern>
<url-pattern>/stop</url-pattern>
<url-pattern>/install</url-pattern>
<url-pattern>/remove</url-pattern>
<url-pattern>/deploy</url-pattern>
<url-pattern>/undeploy</url-pattern>
<url-pattern>/reload</url-pattern>
<url-pattern>/save</url-pattern>
<url-pattern>/serverinfo</url-pattern>
<url-pattern>/status/*</url-pattern>
<url-pattern>/roles</url-pattern>
<url-pattern>/resources</url-pattern>
</web-resource-collection>
<auth-constraint>
<!-- NOTE: This role is not present in the default users file -->
<role-name>manager</role-name>
</auth-constraint>
</security-constraint>
The comment in the <auth-constraint> element is no longer correct:
<!-- NOTE: This role is not present in the default users file -->
(Since we've already added the role of manager to the tomcat-users.xml file, we might as well remove the comment.)
Add a <user-data-constraint> with a <transport-guarantee> of CONFIDENTIAL to enable port-forwarding to port 8443:
<!-- Define a Security Constraint on this Application -->
<security-constraint>
<web-resource-collection>
<web-resource-name>HTMLManger and Manager command</web-resource-name>
<url-pattern>/jmxproxy/*</url-pattern>
<url-pattern>/html/*</url-pattern>
<url-pattern>/list</url-pattern>
<url-pattern>/expire</url-pattern>
<url-pattern>/sessions</url-pattern>
<url-pattern>/start</url-pattern>
<url-pattern>/stop</url-pattern>
<url-pattern>/install</url-pattern>
<url-pattern>/remove</url-pattern>
<url-pattern>/deploy</url-pattern>
<url-pattern>/undeploy</url-pattern>
<url-pattern>/reload</url-pattern>
<url-pattern>/save</url-pattern>
<url-pattern>/serverinfo</url-pattern>
<url-pattern>/status/*</url-pattern>
<url-pattern>/roles</url-pattern>
<url-pattern>/resources</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>manager</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
manager application.Restart Tomcat and verify SSL has been enabled for the Tomcat manager application: http://localhost:8080/manager/html/
web.xml to make sure it is well-formed and without error.<transport-guarantee> of CONFIDENTIAL? web.xml?manager application.manager application. We have compiled a list of a few additional step you should take to help secure Tomcat and your TDS server. This is not a complete laundry list of security fixes! Please use it as a starting point when securing your server.
This document is maintained by Unidata. Send comments to THREDDS support.