<!-- DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved. The contents of this file are subject to the terms of either the GNU General Public License Version 2 only ("GPL") or the Common Development and Distribution License("CDDL") (collectively, the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html or packager/legal/LICENSE.txt. See the License for the specific language governing permissions and limitations under the License. When distributing the software, include this License Header Notice in each file and include the License file at packager/legal/LICENSE.txt. GPL Classpath Exception: Oracle designates this particular file as subject to the "Classpath" exception as provided by Oracle in the GPL Version 2 section of the License file that accompanied this code. Modifications: If applicable, add the following below the License Header, with the fields enclosed by brackets [] replaced by your own identifying information: "Portions Copyright [year] [name of copyright owner]" Contributor(s): If you wish your version of this file to be governed by only the CDDL or only the GPL Version 2, indicate your decision by adding "[Contributor] elects to include this software in this distribution under the [CDDL or GPL Version 2] license." If you don't indicate a single choice of license, a recipient has the option to distribute your version of this file under either the CDDL, the GPL Version 2 or to extend the choice of license to its licensees as provided above. However, if you add GPL Version 2 code and therefore, elected the GPL Version 2 license, then the option applies only if the new code is made subject to such option by the copyright holder. --> <!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en"> <html> <head> <title>SAAJ Security</title> <link rel="stylesheet" type="text/css" href="style/default.css"> </head> <body bgcolor="#ffffff"> <center> <h1><font color="#000099">SAAJ Security</font> </h1> </center> <p>This document explains how to set up authentication in the SAAJ reference implementation, and how to set up HTTPS for secure message exchange.</p> <h3>Authentication</h3> <p>For basic authentication, the SAAJ reference implementation uses the <code>userInfo</code> part of the URL specification.</p> <ul> <li> Set up a user for the underlying container. Java Web Services Developer Pack users need to edit <code><<i>JWSDP_HOME</i>>/conf/tomcat-users.xml</code>.</li> <li>Add a security constraint in <code>web.xml</code>. For example: <pre> <servlet><br> <servlet-name>saaj.authenticated</servlet-name><br> <jsp-file>/echo.jsp</jsp-file><br> </servlet><br><br> <servlet-mapping><br> <servlet-name>saaj.authenticated</servlet-name><br> <url-pattern>/authecho.jsp</url-pattern><br> </servlet-mapping><br><br> <security-constraint><br> <auth-constraint><br> <role-name>saaj</role-name><br> </auth-constraint><br> </security-constraint><br><br> <login-config><br> <auth-method>BASIC</auth-method><br> </login-config><br></pre> </li> <li>The client should use the the following syntax for URLs:</li> <pre> http://USER:PASSWORD@HOST:PORT/FILE</pre> </ul> <h3>Secure Transport</h3> <p><b>Note:</b> Secure transport applies only to request/response messages (those sent using the <code>SOAPConnection.call</code> method).</p> <p>Setting up HTTPS is a bit more difficult. The critical part is setting up the server certificates, required by Java Secure Socket Extension (JSSE) in order to communicate with the server. You'll need to use the following commands:</p> <pre>keytool -genkey -alias saaj-test -dname "cn=localhost" -keyalg RSA -storepass changeit<br>keytool -export -alias saaj-test -storepass changeit -file server.cer<br>keytool -import -v -trustcacerts -alias saaj-test -file server.cer<br> -keystore $JAVA_HOME/jre/lib/security/cacerts<br> -keypass changeit -storepass changeit<br></pre> <p>The first command will generate a server certificate in your <code>$HOME/.keystore</code>. The <code>dname</code> should be localhost (if you use localhost in the URLs) or your hostname (where you run the server).</p> <p>The second command will export the certificate in a file, and the third will import the certificate into the list of certificates the client knows about.</p> <p>An alternative is to use the <code>server.cer</code> and get it signed by one of the certificate authorities; it will then work with any client, without your having to import the certificate into each client VM. Make sure you have added JSSE jars into the CLASSPATH, of course. <b></b></p> <p>The next step is getting Tomcat in the Java WSDP to work with JSSE. This is documented in the Tomcat documentation that is bundled with the Java WSDP. You may need to uncomment the "SSL Connector" portion from the <code>server.xml</code> file. Please follow the Tomcat documentation. For Setting up HTTPS with the Sun Java System Application Server refer to <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/doc/Security6.html#wp509934">http://java.sun.com/j2ee/1.4/docs/tutorial/doc/Security6.html#wp509934</a><b></b> </p> <p>Start the container and try a simple URL using HTTPS (like <code>https://host:8443/index.html</code>). The browser should ask you to accept a certificate and then display the page. If you got this to work, the server is running fine. </p> <p>From the SAAJ side, all you need to do is use URLs with HTTPS as the protocol. This will work <i>only</i> if the certificate was successfully imported into <code>$JAVA_HOME/jre/lib/security/cacerts</code>; otherwise JSSE will not allow the connection. </p> <br> </body> </html>