JDBC Realm Authentication Sample Application

JDBC Realm Authentication Sample Application


The Java Database Connectivity (JDBC) realm sample code demonstrates how to develop a custom authentication realm for Sun Java System Web Server.

This sample application document contains the following sections:


Overview

 The JDBC Realm Authentication sample demonstrates how to develop a custom authentication realm and use it with any authentication web application. A custom authentication realm can be plugged into Sun Java System Web Server to perform user authentication for Java web applications hosted by the Sun Java System Web Server web container. This sample realm implementation performs authentication against a database (using JDBC), however, you can modify it to authenticate against any backend you need by developing the appropriate logic and compiling your own custom realm. Refer to the javadoc comments in JDBCRealm and JDBCLoginModule for further guidance on custom realm development.

Before you begin to compile and deploy the code, complete the following prerequisites.

Note - Make sure the necessary parameters for running the samples are specified in the install_root/samples/java/webapps/common.properties.

  1. For information about creating and maintaining the database, refer to the database documentation.
    For information about using the PointBase database with Sun Java System Web Server, refer to How to run sample applications with Pointbase.
    For information about using the Oracle database with Sun Java System Web Server, refer to How to run sample applications with Oracle.


  2. If you want to run the sample on an Oracle database, you must use the following script to create the user_tbl table with data:
    install_root
    /samples/java/webapps/security/jdbcrealm/src/sql/dbscript-ora.sql

    If you want to run the sample on a PointBase database, you must use the following script to create the user_tbl table with data:
    install_root
    /samples/java/webapps/security/jdbcrealm/src/sql/dbscript-pb.sql

  3. Add the following line to the login.conf file in install_root/admin-server/config-store/config_directory/config/login.conf:

    jdbcRealm { samples.security.jdbcrealm.JDBCLoginModule required debug=false; };


Compiling and Assembling the Application


To compile and assemble the sample application, complete the following steps:

  1. Execute ant under install_root/samples/java/webapps/security/jdbcrealm/src.
    This creates jdbcrealm.jar under the install_root/samples/java/webapps/security/jdbcrealm/src/WEB-INF/lib directory.

  1. Set the necessary values for the properties in the install_root/samples/java/webapps/security/jdbcrealm/src/jdbcrealm.build.properties file.

    NOTE - The values for db.driver.name and db.url properties for a PointBase server database are:
    db.driver.name=com.pointbase.jdbc.jdbcUniversalDriver and
    db.url=jdbc:pointbase:server://host_name/database_name
    For an Oracle database:
    db.driver.name=oracle.jdbc.driver.OracleDriver and
    db.url=jdbc:oracle:thin:@host_name:port:sid

  2. Execute ant create_auth_realm to create the jdbc auth realm.

  3. You can use any authentication web application. For example, you can use the basic authentication sample.. Ensure that the basic authentication sample is deployed and running normally.

  4. (Optional.) Clean the web application project area.

    # ant clean


Running the Sample Application



You can run the basic authentication application through the following URL:

http://Sun_Java_System_Web_Server_hostname:port//webapps-security-basic

Log in as j2ee using the password secret.

The following message displays: "Welcome to our BASIC secure zone!"


Deleting the auth_realm


Execute ant delete_auth_realm to delete the jdbc auth realm and default-auth-realm-name.


Troubleshooting




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