10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>The</strong>re are at least two ways to enable mutual authentication over SSL:<br />

■ <strong>The</strong> preferred method is to set the method of authentication in the web.xml application<br />

deployment descriptor to CLIENT-CERT. This enforces mutual authentication by modifying<br />

the deployment descriptor of the given application. By enabling client authentication in this<br />

way, client authentication is enabled only for a specific resource controlled by the security<br />

constraint, and the check is only performed when the application requires client<br />

authentication.<br />

■ A less commonly used method is to set the clientAuth property in the certificate realm<br />

to true if you want the SSL stack to require a valid certificate chain from the client before<br />

accepting a connection. A false value (which is the default) will not require a certificate<br />

chain unless the client requests a resource protected by a security constraint that uses<br />

CLIENT-CERT authentication. When you enable client authentication by setting the<br />

clientAuth property to true, client authentication will be required for all the requests<br />

going through the specified SSL port. If you turn clientAuth on, it is on all of the time,<br />

which can severely degrade performance.<br />

When client authentication is enabled in both of these ways, client authentication will be<br />

performed twice.<br />

Creating a Client Certificate for Mutual Authentication<br />

Establishing a Secure Connection Using SSL<br />

If you have a certificate signed by a trusted Certificate Authority (CA) such as Verisign, and the<br />

Application Server cacerts.jks file already contains a certificate verified by that CA, you do<br />

not need to complete this step. You only need to install your certificate in the Application Server<br />

certificate file when your certificate is self-signed.<br />

From the directory where you want to create the client certificate, run keytool as outlined here.<br />

When you press Enter, keytool prompts you to enter the server name, organizational unit,<br />

organization, locality, state, and country code.<br />

You must enter the server name in response to keytool’s first prompt, in which it asks for first<br />

and last names. For testing purposes, this can be localhost. <strong>The</strong> host specified in the keystore<br />

must match the host identified in the javee.server.host variable specified in your<br />

tut-install/javaeetutorial5/examples/bp-project/build.properties file. If this example<br />

is to verify mutual authentication and you receive a runtime error stating that the HTTPS host<br />

name is wrong, re-create the client certificate, being sure to use the same host name that you will<br />

use when running the example. For example, if your machine name is duke, then enter duke as<br />

the certificate CN or when prompted for first and last names. When accessing the application,<br />

enter a URL that points to the same location (for example,<br />

https://duke:8181/mutualauth/hello). This is necessary because during SSL handshake, the<br />

server verifies the client certificate by comparing the certificate name and the host name from<br />

which it originates.<br />

Chapter 28 • Introduction to Security in the <strong>Java</strong> <strong>EE</strong> Platform 791

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!