In this section we will focus on the use a database for verifying and retrieving user names and passwords.
For this example we created a new database called SecurityDatabase using the built-in Derby database. The following steps summarize the procedure performed to create the database and tables, load some sample data and create the connection pool. Detailed instructions on how to define database connection pools are described in the Configuring database pools section.
Create database and load sample data
- In the Console Navigation menu on the left click on Database Manager.
- Enter SecurityDatabase in the Create DB: field and click Create.
- Select the SecurityDatabase database from the Use DB: pull-down menu, enter the following commands and click Run SQL.
create table users
(username varchar(15),
password varchar(15));
create table groups
(username varchar(15),
groupname varchar(15));
insert into users values('userone','p1');
insert into users values('usertwo','p2');
insert into users values('userthree','p3');
insert into groups values('userone','admin');
insert into groups values('usertwo','admin');
insert into groups values('userthree','user');
Create connection pool
- In the Console Navigation menu on the left click on Database Pools.
- Click on Using the Geronimo database pool wizard.
- Enter SecurityDatabase as the database pool name.
- Select Derby embedded from the database pool type pull-down menu and click Next.
- Verify the JDBC driver class is org.apache.derby.jdbc.EmbeddedDriver.
- From the Driver Jar scroll box select org.apache.derby/derby/10.2.2.0/jar.
- Leave blank the DB user name and password.
- Enter SecurityDatabase as the database and click Next.
- Click Test Connection.
- Click Deploy.
Add a new security realm
To create a new security realm click on Add new security realm from the Security Realms portlet.
![](database-sql-realm.data/sec_realm_1.gif)
Enter derby_security_realm in the Name of Security Realm: field and select Database (SQL) Realm from the Realm type: pull-down menu and click Next.