Sun ONE logo     
Basic Authentication Sample Application



Basic Authentication Sample Application


This document describes how to utilize the Basic Authentication sample application in conjunction with Sun ONE Application Server version 7.

This sample application document contains the following sections:



Overview

The Basic Authentication sample application is a collection of simple applications that demonstrate the usage of the Java Servlet and Java Server Pages (JSP) specification. Assembling this application and deploying it to the Sun ONE Application Server introduces you to the Sun ONE Application Server Administration Tool.

The following instructions describe how to manually deploy the application. You may want to experiment by modifying and redeploying the sample.


Precompilation Tasks

Before you begin to compile and deploy the code, there are some housekeeping tasks that need to be done.

You will need to add usernames in the keyfile. The procedure is as follows:

  1. Login as administrator through the admin GUI and perform the following steps.

  2. Expand the server instance (server1).

  3. Expand Security.

  4. Expand Realm.

  5. Open File.

  6. Click Manage Users.

  7. Click New and enter required information.

    Click Ok.

    ( Create users j2ee, ias, alpha, beta, gamma with password set to secret and groups as staff and eng ).

  8. Apply changes and restart the instance.

  9. Verify that the entry is added in the <install-root>/domains/domain1/server1/config/keyfile



Note Restart the appserver once you update the keyfile.



To add users from command line, the syntax is as follows:

asadmin create-file-user --user <admin_user> --password <admin_password> --host localhost --port <port> --instance <serverinstance> --userpassword <user_password> --groups <user_groups:user_groups> <username>

After all the users are added from command line, make sure you run the reconfig command. For example:

asadmin reconfig



Compiling and Assembling the Sample Application

This section contains instructions to build and assemble the Basic Authentication sample application using a Command Line Interface (CLI).

To rebuild the entire application from scratch, follow these steps:

  1. Compile and Assemble Web Application. For example:

    Execute asant under <install_root>/samples/webapps/security/basic-auth/src/

    The default target core will be executed to rebuild the WAR and EAR files.

  2. Deploy the application.

    Once you have re-created the sample application from scratch proceed to Deploying the Sample Application.

  3. Clean the web application project area. For example:

    Execute asant clean

    This will remove the sample application assemble and build directories.

You are now ready to use this ear file for deployment.



Deploying the Sample Application



In this section, you will learn how to deploy the Basic Authentication sample application.

Select one of the following approaches to deploying the application:

  • Command Line-based Deployment describes how to manually register the application in Sun ONE Application Server using a Command Line Interface (CLI). This is the fastest means of deploying the sample application.

  • GUI-based Deployment describes how to use the Sun ONE Application Server Deployment Tool to import and deploy the sample application.


Command Line-based Deployment

Since a complete EAR file is supplied, the fastest means of setting up the application is to use the command line utilities as described in this section.

The pre-built WebBasicApp.ear file is an Enterprise Archive file that contains the XML deployment descriptor files, application class files, JSPs, and other content required by the application.

Deploying the pre-built WebBasicApp.ear file is simple. Deploy either by Using the asant script or by Using the asadmin command.


Using the asant script

  1. Go to the src directory of the sample. For example:

    <install_root>/samples/webapps/security/basic-auth/src

  2. Run asant using deploy task. For example:

    %asant deploy


Using the asadmin command

  1. Go to the root of the sample directory. For example:

    <install_root>/samples/webapps/security/basic-auth

  2. Execute asadmin to deploy application to the local application server instance. For example:

    asadmin deploy -u <user-name> -w <password> -H <hostname> -p <admin server port> --instance <instance name> WebBasicApp.ear

The deployment process involves the following operations:

  • Authenticates against the local application server's administrative server

  • The EAR file is transferred to the administrative server

  • The administrative server begins the registration process:

    • Parses the EAR file and embedded WAR file

    • Explodes the bits into repository

    • Registers the J2EE application "WebBasicAuth" by updating server.xml

If you would like to verify the registration of the application, you may proceed to Verifying Deployment. Otherwise, proceed to Running the Sample Application.


GUI-based Deployment

Since a pre-built Enterprise Archive (EAR) file for the sample application is included with the application server, you can use the Sun ONE Application Server Administration Tool to quickly read in the .ear file and deploy it to the application server.

To deploy the EAR file, follow these steps:

  1. Open the pre-existing sample EAR file.

  2. Start the admin server if not already started. For example, in UNIX, execute the following: <s1as_install_dir>/domains/domain1/admin-server/startserv

  3. Open the EAR file.

    1. Navigate to the browser based admin server page [http://<server-host>:<admin-port>/index.html].

    2. Enter your <username> and <password> to access the admin server.

    3. Click on App Server Instances>server1>Applications>Enterprise Apps

    4. In the right hand pane, click on Deploy to deploy an application.

      Choose the file (from disk) to be deployed (WebBasicApp.ear) and Click OK.

    5. You will be asked for the application name. Enter WebBasicApp and Click OK.

      If the deployment goes through fine, you will see the original pane with ClientCertApp application as deployed. In the startup dialog, select Browse for more applications to find the WebBasicApp.ear file.


Verifying Deployment

As an optional step, you can use the Sun ONE Application Server Administration Tool to verify that the application has been registered. Otherwise, proceed directly to Running the Sample Application.

To verify the registration of the application, follow these steps:

  1. Execute the command asadmin list-components to look at applications deployed with a server instance. For example:

    asadmin list-components -u <username> -w <password> -H <host> -p <admin-port> <server instance name>

    You will see WebBasicAuth listed.

  2. Alternately, you may navigate the Admin tool GUI to the following:

    App Server Instances>server1>Applications.

  3. On the left frame, Click on Enterprise Apps to display list of applications deployed on server.

    You will see WebBasicAuth listed.



Running the Sample Application

You can run the application through the following URL: http://<hostname>:<port>/basic/index.jsp

Log on as "j2ee" with password "secret".



Troubleshooting



  • Close all the browser instances before you try relogging in again; if you are using Netscape, you have to close the email session also. Otherwise it will pick up the session information from the previous logins and grant you access.

  • While appending data to the keyfile, make sure that the usernames entered are unique. For example, the j2ee username is shared by both the Pet Store and the Security application. Having two entires in the keyfile with the same username and different passwords will not allow either application to run.

  • Although the war, ear, context-root and servlet alias names in this sample are all "WebBasicApp", it is not necessary that it be so. The application will work as expected if the names of each of these attributes is unique. Rebuild the app after changing the context-root (in application.xml), the servlet alias (in web.xml) and the war and ear names (in the asant build.xml), redeploy and test the sample to confirm this.

  • If you encounter problems when running the application, review the log files at <install-root>/domains/domain1/<server-instance>/logs/server.log to learn what exactly went wrong.



Copyright © 2002 Sun Microsystems, Inc. All rights reserved.

Last Updated August 20, 2002