| 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
- Compiling and Assembling the Application
- Running the Sample Application
- Deleting the auth_realm
- Troubleshooting
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.
- 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.
- 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- 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:
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.
- 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
Execute ant create_auth_realm to create the jdbc auth realm.
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.
(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!"Execute ant delete_auth_realm to delete the jdbc auth realm and default-auth-realm-name.
- If you run the sample application more than once, make sure that you close all instances of the browser so that the session information is not stored. Otherwise, the system will not prompt you for the user name and password. Make sure that you also close your email sessions so that all stored session information is destroyed.
- If you encounter problems when running the application, review the log files at instance_root/logs/errors to determine what went wrong.
Copyright © 2007 Sun Microsystems, Inc. All rights reserved.