alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Jetty example source code file (jdbcRealm.properties)

This example Jetty source code file (jdbcRealm.properties) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Jetty tags/keywords

create, create, i'm, jdbc, jdbcuserrealm, jdbcuserrealm, mysql, mysql, replace, set, this, this, to, userrealm

The Jetty jdbcRealm.properties source code

# 
# This is a sample properties file for the org.mortbay.jetty.security.JDBCUserRealm
# implemtation of the UserRealm interface.  This allows Jetty users authentication 
# to work from a database.
#
#   +-------+      +------------+      +-------+
#   | users |      | user_roles |      | roles |
#   +-------+      +------------+      +-------+
#   | id    |     /| user_id    |\     | id    |
#   | user  -------| role_id    |------- role  |
#   | pwd   |     \|            |/     |       |
#   +-------+      +------------+      +-------+
#   
# 
# 'cachetime' is a time in seconds to cache positive database
# lookups in internal hash table. Set to 0 to disable caching.
# 
#
# For MySQL:
# create a MYSQL user called "jetty" with password "jetty"
#
# Create the tables:
# create table users 
# (
#     id integer primary key,
#     username varchar(100) not null unique key,
#     pwd varchar(20) not null
# );
# 
# create table roles
# (
#     id integer primary key,
#     role varchar(100) not null unique key
# );    
#
# create table user_roles
# (
#     user_id integer not null,
#     role_id integer not null,
#     unique key (user_id, role_id),
#     index(user_id)
# );
#
# I'm not sure unique key with a first component of user_id will be
# user by MySQL in query, so additional index wouldn't hurt.
#
# To test JDBC implementation:
#
# mysql> insert into users values (1, 'admin', 'password');
# mysql> insert into roles values (1, 'server-administrator');
# mysql> insert into roles values (2, 'content-administrator');
# mysql> insert into user_roles values (1, 1);
# mysql> insert into user_roles values (1, 2);
#
# Replace HashUserRealm in etc/admin.xml with JDBCUserRealm and
# set path to properties file.
#
jdbcdriver = org.gjt.mm.mysql.Driver
url = jdbc:mysql://localhost/jetty
username = jetty
password = jetty
usertable = users
usertablekey = id
usertableuserfield = username
usertablepasswordfield = pwd
roletable = roles
roletablekey = id
roletablerolefield = role
userroletable = user_roles
userroletableuserkey = user_id
userroletablerolekey = role_id
cachetime = 300

Other Jetty examples (source code examples)

Here is a short list of links related to this Jetty jdbcRealm.properties source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.