Basic Authentication Sample Application

  Samples Index




Basic Authentication Sample Application


This document describes how to utilize the Basic Authentication sample application in conjunction with the Application Server. The basic authentication sample demonstrates the use of the file-based authentication realm.

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 Application Server introduces you to the 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.


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 this step:


  1. Compile and Assemble Web Application. For example:

    Execute asant under <install_dir>/samples/webapps/apps/security/basic-auth/

    The default target core will be executed to rebuild the WAR file.

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


Optional Step

  • Clean the web application project area. For example:

    Execute asant clean

    This will remove the sample application assemble and build directories.



    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 the 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 Admin GUI to import and deploy the sample application.


    Command Line-based Deployment

    Since a complete WAR 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 web-basic-auth.war 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 web-basic-auth.war 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_dir>/samples/webapps/apps/security/basic-auth


    2. Run asant using deploy task. For example:

      %asant deploy


    Note You must run asant undeploy before redeploying this sample. This will ensure that all modules are undeployed and the resources are disabled.  The application is undelpoyed, however to remove resources you should run "asant keydel" .  Warning: Do not execute this "asant keydel" step if form--auth security sample is running.





    Using the asadmin command


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

      <install_dir>/samples/webapps/apps/security/basic-auth


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

      asadmin deploy --user <user-name> --password <password> --host <hostname> --port <admin-port> web-basic-auth.war

    The deployment process involves the following operations:

    • Authenticates against the local application server's administrative server

    • The WAR file is transferred to the administrative server

    • The administrative server begins the registration process:

      • Parses the WAR file

      • Explodes the bits into repository

      • Registers the J2EE application "web-basic-auth" by updating domain.xml

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


    GUI Based Deployment

    Since a pre-built Web Application Archive (.war) file for the sample application is included with the application server, you can use the Admin GUI to quickly read in the .war file and deploy it to the application server.

    1. Start the admin server if it is not already started. Here are the commands for each platform:
      1. Unix - Execute the <install_dir>/bin/asadmin start-domain domain1 command.
      2. Windows - Click "Start->Programs->Sun Microsystems->J2EE 1.4 SDK->Start Default Server"  command.
    2. Open the .war file.
      1. Start Admin GUI, by entering URL  http://localhost:<admin.port>/asadmin   in browser. See replacing "localhost" and <admin.port> note here to determine correct values to use for your environment
      2. You are prompted to supply the user name and password of the application server. Enter correct values for your installed application server for "User Name:"  and "Password:" input fields, then click on the "Login" button.
      3. In the left-hand frame, click Applications-->Web Applications  icon in the tree.
      4. In the right-hand frame, click on the "Deploy..."  button.
      5. Choose the file to be deployed by clicking on the "Browse..."  button, and navigate to select component to deploy (web-basic-auth.war).
      6. In the browse dialog, click on the "OK"  button.
      7. In the right-hand frame, click on the "Next"  button.
      8. In the right-hand frame, click on the "OK"  button. (Optionally fill in remaining values for application to be deployed)
      9. In the left hand pane, you will see the newly deployed module's icon in the tree. In the right hand pane you will also see the component listed as deployed.

    Verifying Deployment

    As an optional step, you can use the 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 --user <user-name> --password <password> 

      You will see web-basic-auth listed.


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

      Applications-->Enterprise Applications.


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

      You will see web-basic-auth listed.



    Running the Sample Application

    You can run the application through the following URL: http://<hostname>:<port>/web-basic-auth/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, context-root and servlet alias names in this sample are all "web-basic-auth", 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 name (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-dir>/domains/<domain_name>/logs/server.log to learn what exactly went wrong.



  • Copyright © 2004 Sun Microsystems, Inc. All rights reserved.

    Last Updated March 6, 2004