JDBCRealm

Can you explain JDBCRealm?

JDBC Realm

A realm is a collection of pages, images and applications (collectively known as "resources") that is protected by a login or authentication method. JDBC Realm involves storing the credentials of user like username and passwords inside a database. Then Tomcat is configured to use this database and the JDBC realm option inside the configuration files will need to be enabled.

The following steps are used for JDBC Realm:

1. Create Database

2. Create Tables
Like user table containing usernames and passwords and roles table containing usernames and assigned roles.

3. Configure Tomcat
The server.xml file is configured in Tomcat.
<Realm className="org.apache.catalina.realm.JDBCRealm" debug="0"

driverName="jdbc:odbc:JdbcOdbcDriver"

connectionURL="jdbc:sql:localhost/8080:/opt/fsql/db/realmdb.fdb"

connectionName="sysdba" connectionPassword="password"

userTable="users" userNameCol="user_name" userCredCol="user_pwd"

userRoleTable="roles" roleNameCol="role_name" />

4. Edit the web.xml file to require Authentication
<security-constraint>

<web-resource-collection>

<url-pattern>/*</url-pattern>

<http-method>POST</http-method>

</web-resource-collection>

<auth-constraint>

<description>These roles are allowed access</description>

<role-name>tomcat</role-name>

</auth-constraint>

</security-constraint>

<login-config>

<auth-method>FORM</auth-method>

<realm-name>MyFirst Protected Area</realm-name>

<form-login-config>

<form-login-page>/login.html</form-login-page>

<form-error-page>/Error.html</form-error-page>

</form-login-config>

</login-config>

<security-role>

<description>Only 'tomcat' role is allowed to access this web application</description>

<role-name>tomcat</role-name>

</security-role>
37 Java Interview Questions and Answers for Freshers
Java interview questions and answers for freshers - What are the basic features of java?, How java becomes object oriented?, How java becomes robust?, How a Java program compiles?........
25 Basic Java Interview Questions and Answers
Basic Java interview questions - What is reflection?What is JVM?Explain different layout manager in Java.What is the difference between Stream classes and Reader writer classes?......
34 Advanced Java Interview Questions - Senior Level Java Interview
Advanced java interview questions - Can we compare String using equality operator (==) operator?What is intern() method in Java?When is class garbage collected?What is the difference between a Choice and a List?.......
Post your comment