14 December 2012

Tomcat JDBCRealm

JDBCRealm

Introduction

JDBCRealm is an implementation of the Tomcat Realm interface that looks up users in a relational database accessed via a JDBC driver. There is substantial configuration flexibility that lets you adapt to existing table and column names, as long as your database structure conforms to the following requirements:
  • There must be a table, referenced below as the users table, that contains one row for every valid user that this Realm should recognize.
  • The users table must contain at least two columns (it may contain more if your existing applications required it):
    • Username to be recognized by Tomcat when the user logs in.
    • Password to be recognized by Tomcat when the user logs in. This value may in cleartext or digested - see below for more information.
  • There must be a table, referenced below as the user roles table, that contains one row for every valid role that is assigned to a particular user. It is legal for a user to have zero, one, or more than one valid role.
  • The user roles table must contain at least two columns (it may contain more if your existing applications required it):
    • Username to be recognized by Tomcat (same value as is specified in the users table).
    • Role name of a valid role associated with this user.

Quick Start

To set up Tomcat to use JDBCRealm, you will need to follow these steps:
  1. If you have not yet done so, create tables and columns in your database that conform to the requirements described above.
  2. Configure a database username and password for use by Tomcat, that has at least read only access to the tables described above. (Tomcat will never attempt to write to these tables.)
  3. Place a copy of the JDBC driver you will be using inside the $CATALINA_HOME/lib directory. Note that only JAR files are recognized!
  4. Set up a <Realm> element, as described below, in your $CATALINA_BASE/conf/server.xml file.
  5. Restart Tomcat if it is already running.

Realm Element Attributes

To configure JDBCRealm, you will create a <Realm> element and nest it in your$CATALINA_BASE/conf/server.xml file, as described above. The attributes for the JDBCRealm are defined in the Realm configuration documentation.

Example

An example SQL script to create the needed tables might look something like this (adapt the syntax as required for your particular database):
create table users (
  user_name         varchar(15) not null primary key,
  user_pass         varchar(15) not null
);

create table user_roles (
  user_name         varchar(15) not null,
  role_name         varchar(15) not null,
  primary key (user_name, role_name)
);
Example Realm elements are included (commented out) in the default $CATALINA_BASE/conf/server.xmlfile. Here's an example for using a MySQL database called "authority", configured with the tables described above, and accessed with username "dbuser" and password "dbpass":
<Realm className="org.apache.catalina.realm.JDBCRealm"
      driverName="com.mysql.jdbc.Driver"
   connectionURL="jdbc:mysql://localhost/authority?user=dbuser&amp;password=dbpass"
       userTable="users" userNameCol="user_name" userCredCol="user_pass"
   userRoleTable="user_roles" roleNameCol="role_name"/>

Additional Notes

JDBCRealm operates according to the following rules:
  • When a user attempts to access a protected resource for the first time, Tomcat will call theauthenticate() method of this Realm. Thus, any changes you have made to the database directly (new users, changed passwords or roles, etc.) will be immediately reflected.
  • Once a user has been authenticated, the user (and his or her associated roles) are cached within Tomcat for the duration of the user's login. (For FORM-based authentication, that means until the session times out or is invalidated; for BASIC authentication, that means until the user closes their browser). The cached user is not saved and restored across sessions serialisations. Any changes to the database information for an already authenticated user will not be reflected until the next time that user logs on again.
  • Administering the information in the users and user roles table is the responsibility of your own applications. Tomcat does not provide any built-in capabilities to maintain users and roles.

10 comments:

ninest123 Ninest said...

ninest123 08.13
coach outlet store online, jordan shoes, replica watches, christian louboutin uk, michael kors outlet online, gucci handbags, burberry handbags, burberry outlet, nike air max, coach purses, ray ban sunglasses, michael kors outlet online, coach outlet, tiffany jewelry, michael kors outlet, kate spade outlet, kate spade, polo outlet, prada outlet, michael kors outlet, tory burch outlet, tiffany and co, true religion outlet, longchamp outlet, michael kors outlet online, christian louboutin shoes, oakley sunglasses wholesale, ray ban sunglasses, christian louboutin outlet, oakley sunglasses, longchamp outlet, nike outlet, nike free, coach outlet, prada handbags, longchamp outlet, christian louboutin, chanel handbags, michael kors outlet store, polo ralph lauren outlet online, oakley sunglasses, nike air max

ninest123 Ninest said...

polo ralph lauren, nike free uk, nike tn, burberry pas cher, timberland pas cher, polo lacoste, mulberry uk, michael kors outlet, nike air force, jordan pas cher, true religion outlet, ray ban pas cher, nike free run, lululemon canada, guess pas cher, sac longchamp pas cher, michael kors pas cher, true religion jeans, nike air max, hollister uk, abercrombie and fitch uk, ralph lauren uk, louboutin pas cher, nike air max uk, hogan outlet, north face, hollister pas cher, new balance, air max, north face uk, oakley pas cher, ray ban uk, sac hermes, true religion outlet, vans pas cher, nike blazer pas cher, sac vanessa bruno, nike air max uk, michael kors, converse pas cher, nike roshe, longchamp pas cher

ninest123 Ninest said...

ferragamo shoes, beats by dre, timberland boots, mont blanc pens, bottega veneta, nike air max, reebok outlet, nike trainers uk, giuseppe zanotti outlet, vans outlet, insanity workout, chi flat iron, herve leger, nike roshe run, ghd hair, new balance shoes, iphone 6 cases, mac cosmetics, celine handbags, jimmy choo outlet, hollister clothing, valentino shoes, nike roshe run uk, asics running shoes, mcm handbags, north face outlet, nfl jerseys, wedding dresses, longchamp uk, hermes belt, p90x workout, oakley, soccer shoes, nike huaraches, north face outlet, abercrombie and fitch, instyler, babyliss, hollister, lululemon, baseball bats, soccer jerseys

ninest123 Ninest said...

lancel, ralph lauren, juicy couture outlet, louboutin, ray ban, toms shoes, replica watches, swarovski, thomas sabo, ugg pas cher, coach outlet, ugg boots, links of london, hollister, uggs outlet, karen millen uk, pandora jewelry, uggs on sale, nike air max, converse, montre pas cher, pandora uk, supra shoes, ugg,ugg australia,ugg italia, juicy couture outlet, wedding dresses, pandora charms, hollister, uggs outlet, converse outlet, vans, ugg boots, ugg uk, swarovski crystal, marc jacobs, ugg, ugg,uggs,uggs canada, gucci
ninest123 08.13

Eric Yao said...

Kate Spade Outlet Tory Burch Outlet
Michael Kors Outlet Ralph Lauren Outlet Gucci Factory Outlet Gucci Outlet Gucci Handbags Cheap Ray Ban Sunglasses North Face Jackets Prada Outlet Burberry Outlet Hollister Clothing Ferragamo Shoes Tiffany Jewelry Tiffany Outlet NFL Jerseys Cheap Jordans Oakley Outlet North Face Outlet Burberry Outlet Ray Ban Sunglasses
Chan Luu Sale Toms Outlet Burberry Outlet Oakley Sunglasses Toms Shoes Sale Beats By Dr Dre Coach Outlet Christian Louboutin Shoes Oakley Sunglasses Valentino Shoes
Oakley Eyeglasses Michael Kors Outlet Coach Factory Outlet Coach Outlet Online Coach Purses Kate Spade Outlet Toms Shoes North Face Outlet Coach Outlet Gucci Belt

艾丰 said...

jianbin0620
louboutin pas cher
beats by dr dre
air max 90
michael kors outlet
coach outlet
christian louboutin outlet
adidas outlet store
oakley sunglasses wholesale
cheap ray ban sunglasses
ray ban sunglasses
mulberry handbags
ray-ban sunglasses
ralph lauren femme
dior sunglasses
coach outlet online
cheap soccer jerseys
mulberry handbags sale
tory burch shoes
mont blanc outlet
coach outlet store
tory burch outlet
lacoste shirts
louis vuitton bags
ferragamo shoes
michael kors outlet clearance
fitflops sale
prada sunglasses for women
michael kors handbags
jordan pas cher
longchamp outlet online
omega watches

kate said...

Michael Kors Outlet Coach Outlet Red Bottoms Kevin Durant Shoes New Balance Outlet Adidas Outlet Coach Outlet Online Stephen Curry Jersey Vans Outlet Ralph Lauren Outlet
Ugg Boots Sale UGGS For Women Skechers Go Walk Adidas Yeezy Boost Adidas Yeezy Adidas NMD Coach Outlet North Face Outlet Ralph Lauren Outlet Puma SneakersPolo Outlet
Under Armour Outlet Under Armour Hoodies Herve Leger MCM Belt Nike Air Max Louboutin Heels Jordan Retro 11 Converse Outlet Nike Roshe Run UGGS Outlet North Face Outlet
Adidas Originals Ray Ban Lebron James Shoes Sac Longchamp Air Max Pas Cher Chaussures Louboutin Keds Shoes Asics Shoes Coach Outlet Salomon Shoes True Religion Outlet

Liu Liu said...

Josh Gordon's Nike Free Run Cleveland Browns comeback has hit another roadblock. The wide receiver announced Thursday that he is entering an in-patient rehabilitation facility in an effort to "gain full control of my life." nfl jerseys store Gordon is eligible to play in the Browns' Week 5 contest against the New England Patriots as part Nike Air Max 2015 Shoes of the wholesale nfl jerseys terms of his NFL reinstatement for a substance abuse violation. Nike Air Max 90 Gordon's decision to enter rehab, however, puts his comeback on hold indefinitely. "After careful thought and deep consideration I've decided that I need to step away from cheap nfl jerseys pursuing my return to the Browns and my football career to enter an in-patient rehabilitation facility," Gordon wrote. "This is the right decision for me and one that I hope will enable me to gain full control of my life and continue on a path to reach my full potential as a person. Nike Roshe Run I appreciate the support of the NFL, NFLPA, the Browns, NFL Jerseys my teammates, my agent and the community through this extremely challenging process."

eric yao said...

Coach Outlet http://www.coachoutletfactory-stores.us.com

Kate Spade Outlet http://www.katespadefactoryoutlet.in.net

ED Hardy Outlet http://www.edhardypopsale.com

Coach Outlet Store Online http://www.coachstoreonline.in.net

Kate Spade Outlet http://www.katespadeoutletstore.in.net

Cheap Jordans http://www.cheapjordansretro.us.com

Coach Purses http://www.coachpurses.eu.com

Coach Outlet http://www.coachoutlet2016.us.com

Tory Burch Shoes http://www.toryburchoutlets.us.com

Longchamp Outlet http://www.longchampoutlet.in.net

Michael Kors Handbags http://www.innnov8.com

Coach Outlet http://www.innnovate.com

Red Bottom Shoes http://www.redbottomshoes.us.org

Moncler Jackets http://www.monclerdownjackets.us.com

Kate Spade Outlet http://www.katespadeoutletstore.us.com

Moncler Outlet http://www.moncleroutletonline.in.net

Coach Factory http://www.maganates.com

Coach Factory Outlet http://www.coachfactorysoutlet.in.net

Kate Spade Outlet http://www.katespadesoutlet.us.com

Ray Ban Outlet http://www.raybanoutletstore.in.net

Christian Louboutin Shoes http://www.christianlouboutinshoes2016.in.net

North Face Outlet http://www.northfaceoutlets.us.org

Coach Factory Outlet http://www.coachoutletstore.name

Kate Spade Outlet http://www.katespadeoutletonline.name

Coach Outlet http://www.coach-outlets.us.org

Nike Roshe Run http://www.tanie-nikerosherun.pl

Buty Nike Air Max http://www.airmaxsprzedazdla.pl

Nike Air Max http://www.nikeairmax.us.org

Red Bottom Shoes http://www.redbottomshoe.in.net

Christian Louboutin Outlet http://www.christianlouboutinoutlet.us.org

Balenciaga Outlet http://www.balenciaga-outlet.us.com

Balenciaga Handbags http://www.balenciaga-handbags.us.com

Kate Spade Outlet http://www.katespadefactoryoutlet.in.net

Toms Shoes http://www.tomshoesoutlet.us.com

Hermes Belt http://www.hermes-belts.us.com

Prada Outlet http://www.pradafactoryoutlet.com

Louis Vuitton Outlet http://www.louisvuittonsoutlet.us.com

North Face Outlet Store http://www.northfaceoutletstore.in.net

North Face Jackets http://www.north-face.in.net

North Face http://www.north-faceoutlets.us.com

Louis Vuitton Outlet http://www.louisvuitton-outlets.us.org

Timberland Boots http://www.timberland-outlets.us.com

Cheap Timberland Boots http://www.timberlandoutlet.us.com

Tory Burch Outlet http://www.toryburch-outlets.us.com

Ralph Lauren Outlet http://www.ralphlaurenstoreoutlet.us.com

Gucci Shoes http://www.guccifactoryoutlet.name

Gucci Outlet http://www.guccioutletinc.us.com

North Face Jackets http://www.northfacefactoryoutlet.us.com

Prada Outlet http://www.pradaoutlets.in.net

Hollister Clothing http://www.hollister-clothing.us.com

Ferragamo Shoes http://www.ferragamoshoes.us.org

Tiffany Outlet http://www.tiffany-outlets.us.com

Tiffany Outlet http://www.tiffanyco-outlet.us.com

NFL Jerseys http://www.nfljerseys.name

Toms Outlet http://www.outlettoms.us.com

Cheap Jordans http://www.cheapjordans.eu.com

North Face Outlet http://www.thenorthfaceoutlet.us.org

Prada Handbags http://www.pradaoutlet.us.org

Chan Luu http://www.chanluu.us.com

Toms Outlet http://www.tomsoutletstores.us.com

Kate Spade Outlet http://www.katespadeoutletofficial.us.com

Beats By Dr Dre http://www.beatsbydrdre.us.org

Coach Outlet http://www.coachstoreoutlet.us.org

Christian Louboutin Shoes http://www.christianlouboutinshoe.eu.com

Valentino Shoes http://www.valentinoshoes.eu.com

Michael Kors Outlet http://www.michaelkorsoutlet.us.org

Coach Factory Outlet http://www.coachfactoryoutlet.us.org

Coach Outlet Online http://www.coachoutletonlinestore.us.org

Coach Purses http://www.coachpurse.us.com

raybanoutlet001 said...

tiffany and co outlet
yeezy boost 350 v2
yeezy boost
michael jordan shoes
adidas neo
fitflops
timberland online shop
kobe bryant shoes
http://www.uggoutlet.uk
hogan outlet online