All Examples  This Package  Security Examples

package examples.security.rdbmsrealm

Class Index

Exception Index

about this example

The RDBMSRealm example demonstrates how to implement a custom realm in WebLogic Server. RDBMSRealm stores Users, Groups, and ACLs in a relational database.

how to use this example

To run the RDBMSRealm example, you:

  1. Create tables for users, groups, and ACLs in a database
  2. Edit the rdbmsrealm.properties file, which provides RDBMSRealm with information about your database
  3. Compile the realm
  4. Edit the weblogic.properties file to enable RDBMSRealm

Creating the RDBMSRealm database tables

RDBMSRealm uses three database tables: aclentries, groupmembers, and users. The DDL statements that create the realm, and some test data, are in the file rdbmsrealm.ddl. You can use the utils.Schema to execute the SQL commands in this file.

First, edit rdbmsrealm.ddl in this directory and make any changes required for your DBMS. Be sure not to change the table or column names. (If you must change anything, you must make the corresponding changes in the rdbmsrealm.properties file.) You can also replace the test data with your data.

Set the property getGroupNewStatement to true if you have recursive groups (groups are members of other groups) in your database, unless your JDBC driver allows you to have multiple results sets on the same PreparedStatement.

To use utils.Schema, you need a JDBC driver for your database. See WebLogic Utilities for help using utils.Schema.

If you want to use the Cloudscape demo database included with WebLogic Server for RDBMSRealm, you must add cloudscape.jar to your classpath and you must set cloudscape.system.home on the java command line. On Windows NT, for example, you can use these commands to execute the DDL file with utils.Schema. Be sure to enter the last command all on one line.

  $ cd c:\weblogic
  $ setEnv
  $ set CLASSPATH=%CLASSPATH%;c:\weblogic\eval\cloudscape\lib\cloudscape.jar
  $ java -Dcloudscape.system.home=c:\weblogic\eval\cloudscape\data
         utils.Schema jdbc:cloudscape:demo COM.cloudscape.core.JDBCDriver -verbose
         rdbmsrealm.ddl

Edit the rdbmsrealm.properties file

The rdbmsrealm.properties file contains two sections. In the first section, you set properties for your JDBC driver and the database where you created the RDBMSRealm tables.

The Cloudscape JDBC driver is selected by default. If you want to use a different database, comment out the Cloudscape properties and uncomment the properties for the driver you want to use. Edit the properties so that they correct for your database.

The second section of the rdbsmrealm.properties file contains properties that contain the text of SQL queries that RDBMSRealm executes. RDBMSRealm uses JDBC PreparedStatements, and these queries contain question marks where values are substituted when the query is executed. You should only have to change these properties if you changed the schema in the rdbmsrealm.ddl file.

Compile the realm

Run the build.cmd (Windows NT) or build.sh (UNIX) script to build RDBMSRealm. The script compiles the Java classes and copies the rdbmsrealm.properties file to the WebLogic Server installation directory.

Edit the weblogic.properties file

Enable RDBMSRealm by editing your weblogic.properties file. Add the following property:

  weblogic.security.realmClass=examples.security.rdbmsrealm.RDBMSRealm

Restart WebLogic Server.

there's more...

To learn about how RDBMSRealm is implemented or how to create your own custom realm, read Using WebLogic Realms and ACLs.

RDBMSRealm uses the caching realm to cache lookups in WebLogic Server. All calls into RDBMSRealm are passed through the caching realm. However, the cache is disabled by default--no realm objects are cached until you enable caching by setting properties in the weblogic.properties file. Caching has significant performance advantages, limiting trips to the database, so you will probably want to enable this feature. Read Using the caching realm to learn how to enable and tune the cache.