Configuring SSL and Authorized Users
This chapter discusses configuring security for your web service and web service client using the WSIT security mechanisms. Some of these mechanisms require some configuration outside of NetBeans IDE. Depending upon which security mechanism you plan to use, some of the following tasks will need to be completed:
- If you are using the GlassFish container and message security, you must update the GlassFish keystore and truststore by importing v3 certificates. The procedure for updating the certificates is described in Updating GlassFish Certificates.
- If you are using a security mechanism that requires a user to enter a user name and password, create authorized users for your container. Steps for creating an authorized user for the GlassFish container are described in Adding Users to GlassFish.
- To use a mechanism that uses secure transport (SSL), you must configure the system to point to the client and server keystore and truststore files. Steps for doing this are described in Configuring SSL For Your Applications.
Configuring SSL For Your Applications
This section describes adding the steps to configure your application for SSL. These steps will need to be accomplished for any application that uses one of the mechanisms:
The following steps are generic to any application, but have example configurations that will work with the tutorial examples, in particular, Example: SAML Authorization over SSL (SA) and Example: Transport Security (SSL).
To configure SSL for your application, follow these steps:
- Select one of the mechanisms that require SSL. These include Transport Security (SSL), Message Authentication over SSL, and SAML Authorization over SSL.
- Server Configuration
- GlassFish is already configured for SSL. No further SSL configuration is necessary if you are using Transport Security. However, if you are using one of the Message Security mechanisms with SSL, you must update the GlassFish certificates as described in Updating GlassFish Certificates.
- Configure a user on GlassFish as described in Adding Users to GlassFish.
- Client Configuration
For configuring your system for SSL in order to work through the examples in this tutorial, the same keystore and truststore files are used for both the client and the service. This obviates the needs to set system properties to point to the client stores, as both GlassFish and NetBeans are aware of these certificates and point to them by default.
In general, for the client side of SSL you will not be using the same certificates for the client and the service. In that case, you need to define the client certificate stores by setting the system properties
-Djavax.net.ssl.trustStore
,-Djavax.net.ssl.keyStore
,-Djavax.net.ssl.trustStorePassword
, and-Djavax.net.ssl.keyStorePassword
in the application client container.You can specify the environment variables for keystore and truststore by setting the environment variable
VMARGS
through the shell environment or inside an Ant script, or by passing them in when you start NetBeans IDE from the command line. For example, in the latter case:
<
NETBEANS_HOME
>/bin/netbeans.exe
-J-Djavax.net.ssl.trustStore=
<AS_HOME
>/domains/domain1/config/cacerts.jks
-J-Djavax.net.ssl.keyStore=
<AS_HOME
>/domains/domain1/config/keystore.jks
-J-Djavax.net.ssl.trustStorePassword=changeit
-J-Djavax.net.ssl.keyStorePassword=changeitUse the hard-coded path to the keystore and truststore files, not variables.
For the SSL mechanism, The browser will prompt you to accept the server alias
s1as
.- On the client side, for the Transport Security (SSL) mechanism, you must either use the fully-qualified hostname in the URL for the service WSDL when you are creating the web sercie client, or else you must follow the steps in Transport Security (SSL) Workaround.
- Service Configuration
To require the service to use the HTTPS protocol, you have to specify the security requirements in the service's application deployment descriptor. This file is
ejb-jar.xml
for a web service that is implemented as an EJB endpoint, andweb.xml
for a web service implemented as a servlet. To specify the security information, follow these steps:
- From your web service application expand Web Pages
WEB-INF.
- Double-click
web.xml
(orejb-jar.xml
) to open it in the editor.- Select the Security tab.
- On the Security Constraints line, click Add Security Constraint.
- Under Web Resource Collection, click Add.
- Enter a Name for the Resource (for example,
CalcWebResource
), and enter the URL Pattern to be protected (for example,/*
). Select which HTTP Methods to protect, for example, POST. Click OK to close this dialog.- Check the Enable User Data Constraint box. Select CONFIDENTIAL for the Transport Guarantee to specify that the application uses SSL because the application requires that data be transmitted so as to prevent other entities from observing the contents of the transmission.
- The IDE looks like this:
![]()
Figure 6-4 Deployment Descriptor page
- Click the XML tab to display the additions to
web.xml
. The security constraint looks like this:<security-constraint> <display-name>Constraint1</display-name> <web-resource-collection> <web-resource-name> CalcWebResource </web-resource-name> <description/> <url-pattern>/*</url-pattern> <http-method>POST</http-method> </web-resource-collection> <user-data-constraint> <description/> <transport-guarantee> CONFIDENTIAL </transport-guarantee> </user-data-constraint> </security-constraint>- When you run this project (right-click, select Run Project), the browser will ask you to accept the server certificate of
s1as
. Accept this certificate. The WSDL displays in the browser.- Creating a Client
When creating your client application, use the fully-qualified hostname to specify the secure WSDL location (use
https://<
fully_qualified_hostname>:8181
/CalculatorApplication/CalculatorWSService?wsdl
, for example, in place ofhttp://localhost:8080/CalculatorApplication/CalculatorWSService?wsdl
).In some cases, you might get an error dialog telling you that the URL
https://<
fully_qualified_hostname
>:8181/CalculatorApplication/CalculatorWSService?wsdl
couldn't be downloaded. However, this is the correct URL, and it does load when you run the service. So, when this error occurs, repeat the steps that create the Web Service Client using the secure WSDL. The second time, the web service reference is created and you can continue creating the client.Adding Users to GlassFish
The following topics are covered:
Adding Users to GlassFish Using Admin Console
To add users to GlassFish using the Admin Console, follow these steps:
- Start GlassFish if you haven't already done so.
- Start the Admin Console if you haven't already done so. You can start the Admin Console by starting a web browser and entering the URL
http://localhost:4848/asadmin
. If you changed the default Admin port during installation, enter the correct port number in place of4848
.- To log in to the Admin Console, enter the user name and password of a user in the
admin-realm
who belongs to theasadmin
group. The name and password entered during installation will work, as will any users added to this realm and group subsequent to installation.- Expand the Configuration node in the Admin Console tree.
- Expand the Security node in the Admin Console tree.
- Expand the Realms node. Select the
file
realm.- Click the Manage Users button.
- Click New to add a new user to the realm.
- Enter the correct information into the User ID, Password, and Group(s) fields. The example applications reference a user with the following attributes:
- Click OK to add this user to the list of users in the realm.
- Click Logout when you have completed this task.
Adding Users to GlassFish From Command Line
To add users to GlassFish from the command line, make sure GlassFish is running, then enter the following command:
Enter
changeit
for the password when prompted.