![]() |
JDBC Realm Authentication Sample Application |
JDBC Realm Authentication Sample Application
This document describes how to utilize the JDBC Realm Authentication sample application in conjunction with Sun Java (tm) System Application Server version 7.This sample application document contains the following sections:
Overview
Compiling and Assembling the Sample Application
Deploying the Sample Application
Overview
The JDBC Realm Authentication sample application is a collection of simple applications that demonstrate the basic security mechanism in the Sun Java (tm) System Application Server. Assembling this application and deploying it to the Sun Java (tm) System Application Server introduces you to the Sun Java (tm) System 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.
Startup the PointBase database server.
Make sure the PUBLIC.user_tbl exists and there are users in the PUBLIC.user_tbl.
- Go to the <install_root>/pointbase/server directory and run the StartServer.sh script.
- The default admin username and password are security/security.
Add the following line to the login.conf in the <install_root>/domains/domain1/server1/config/login.conf:
Connect to the adminserver and select the instance of the appserver where you want the jdbcsecurity app deployed.
- jdbcRealm { samples.security.jdbcrealm.JDBCLoginModule required debug=false; };
From the left hand side column select Security --> Realms
Click on Security on the Left Hand Side Column.
Cick on jdbc on the left hand column under App Server Instances --> server1 --> Security --> Realms --> jdbc
- You should see 4 tabs on the Right Hand side.
- Select the Default Realm as jdbc.
name = dbusername
value=security
name = dbpasswd
value=security
name = userpasswdcol
value=passwd
name = usergroupcol
value=groups
name = jaas-context
value=jdbcRealm
To connect to pointbase database add:
Or, to connect to oracle database add
name = usernamecol
value=userid
name = usertable
value=user_tbl
name = dbdrivername
value=oracle.jdbc.driver.OracleDriver
name = dburl
value=jdbc:oracle:thin:@<server>:<port>:<SID>
If you want to run the sample on Oracle database, create the user/password as security/security using the scripts mentioned in this document. Once the username is created you have manually create the user_tbl and insert the data in the table using sqlplus. To do this, use the following script: <install_root>/samples/security/realms/rdbms/src/sql/dbscript-ora.sql.
Compiling and Assembling the Sample Application
This section contains instructions to build and assemble the sample application using a Command Line Interface (CLI).To rebuild the entire application from scratch, follow these steps:
Compile and Assemble the JDBC and Web Application. For example:
You are now ready to use this ear file for deployment.
Execute asant under <install_root>/samples/security/realms/rdbms/src/
Add the jdbcsecurity.jar file to the classpath. To do this, follow these steps:
- <install_root>/samples/webapps/security/basic-auth/src/
Login in as admin and select the server instance.
Deploy the application.On the right hand side of the screen select the JVM Settings tab and click on the Path Settings link.
In the Classpath Suffix , add entire path to the jdbcsecurity.jar file.
- For example: <install_root>/samples/security/realms/rdbms/jdbcsecurity.jar
Clean the web application project area. For example:
- Once you have re-created the sample application from scratch proceed to Deploying the Sample Application.
- 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 JDBC Realm 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 Java (tm) System 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 Java (tm) System Application Server Deployment Tool to import and deploy the sample application.
Command Line-based Deployment
The fastest means of setting up the application is to use the command line utilities as described in this section.The WebBasicApp.ear file is an Enterprise Archive file that contains Web Archive (WAR) file of the application. Within the WAR file resides the XML deployment descriptor files, application class files, JSPs and other content required by the application.
Deploying the WebBasicApp.ear file is simple. Deploy either by Using the asant script or by Using the asadmin command.
Go to the src directory of the sample. For example:
Run asant using deploy task. For example:
- install_root>/samples/webapps/security/basic-auth/src
- %asant deploy
Go to the root of the sample directory. For example:
The deployment process involves the following operations:
Execute asadmin to deploy application to the local application server instance. For example:
- <install_root>/samples/webapps/security/basic-auth
- asadmin deploy -u <user-name> -w <password> -H <hostname> -p <admin server port> --instance <instance name> WebBasicApp.ear
Authenticates against the local application server's administrative server
If you would like to verify the registration of the application, you may proceed to Verifying Deployment. Otherwise, proceed to Running the Sample Application.The EAR file is transferred to the administrative server
The administrative server begins the registration process:
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 Java (tm) System 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:
Open the pre-existing sample EAR file.
If the deployment goes through fine, you will see the original pane with WebBasicAuth application as deployed. In the startup dialog, select Browse for more applications to find the WebBasicApp.ear file.Start the admin server if not already started. For example, in UNIX, execute the following: <sjsas_install_dir>/domains/domain1/admin-server/startserv
Navigate to the browser based admin server page [http://<server-host>:<admin-port>/index.html].
Enter your <username> and <password> to access the admin server.
Click on App Server Instances>server1>Applications>Enterprise Apps
In the right hand pane, click on Deploy to deploy an application.
You will be asked for the application name.
- Choose the file (from disk) to be deployed (fortune.ear) and Click OK.
- Enter WebBasicApp and Click OK.
Generating Javadocs
To better understand sample application source code, you may refer to the related javadocs. To generate javadocs run one of the following commands:After javadocs have been generated, you can access them at <install_dir>/samples/security/realms/rdbms/javadocs/index.html
Verifying Deployment
As an optional step, you can use the Sun Java (tm) System 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:
Execute the command asadmin list-components to look at applications deployed with a server instance. For example:
Alternately, you may navigate the Admin tool GUI to the following:
- asadmin list-components -u <username> -w <password> -H <host> -p <admin-port> <server instance name>
- You will see WebBasicAuth listed.
On the left frame, Click on Enterprise Apps to display list of applications deployed on server.
- App Server Instances>server1>Applications.
- You will see WebBasicAuth listed.
Running the Sample Application
You can run the application through the following URL: http://<hostname>:<port>/basic/index.jspLog on as "j2ee" with password "secret".
If you run the sample app more than once make sure you close all the instances of the browser so that the session information is not stored. Otherwise, it will not prompt you for the usename and password. Make sure you close your email sessions as well, so that all stored session information is destroyed.
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 Ant 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 22, 2002