Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6321341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:07:56+00:00 2026-05-24T16:07:56+00:00

I have a problem with security in Java EE. I have an application that

  • 0

I have a problem with security in Java EE.
I have an application that supposed to be a kind of e-shop. I have three entities:
User class that is not mapped into database, and two inherited classes – Client and Administrator, that are mapped into different tables:

@MappedSuperclass
@Inheritance(strategy= InheritanceType.TABLE_PER_CLASS)
public class User implements Serializable {...}

@Entity
public class Client extends User {...}

@Entity
public class Administrator extends User {...}

Now I need to provide security for Client and Administrator resources. I use FORM authentication with jdbcRealm and standart login page:


    <form  action="j_security_check" method="POST">
        <input type="text" name="j_username"/>
        <input type="password" name="j_password"/>
        <input type="submit" value="Login"/>
    </form>

But the problem is that jdbcRealm refers only to one table. And it’s not allowed to set two jdbcRealms in web.xml. So how can I provide authentication for both Client and Administrator without changing database structure? Is it possible to use few jdbcRealms in a single application?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:07:57+00:00Added an answer on May 24, 2026 at 4:07 pm

    You can use a combined realm to combine two JDBC realms:

    In the $CATALINA_BASE/conf/server.xml

    <Realm className="org.apache.catalina.realm.CombinedRealm" >
        <Realm className="org.apache.catalina.realm.JDBCRealm"
               driverName="org.gjt.mm.mysql.Driver"
               connectionURL="jdbc:mysql://localhost/db?user=dbuser&amp;password=dbpass"
               userTable="client" 
               userNameCol="user_name" userCredCol="user_pass"
               userRoleTable="user_roles" roleNameCol="role_name"/>
        <Realm className="org.apache.catalina.realm.JDBCRealm"
               driverName="org.gjt.mm.mysql.Driver"
               connectionURL="jdbc:mysql://localhost/db?user=dbuser&amp;password=dbpass"
               userTable="administrator" 
               userNameCol="user_name" userCredCol="user_pass"
               userRoleTable="user_roles" roleNameCol="role_name"/>
    </Realm>
    

    However, in this instance it may be better to set up a datasource and use the DataSourceRealm to access the tables.

    <Realm className="org.apache.catalina.realm.CombinedRealm" >
         <Realm className="org.apache.catalina.realm.DataSourceRealm"
                dataSourceName="jdbc/authority"
                userTable="clients" userNameCol="user_name" userCredCol="user_pass"
                userRoleTable="user_roles" roleNameCol="role_name"/>
         <Realm className="org.apache.catalina.realm.DataSourceRealm"
                dataSourceName="jdbc/authority"
                userTable="administrators" userNameCol="user_name" userCredCol="user_pass"
                userRoleTable="user_roles" roleNameCol="role_name"/>
    </Realm>
    

    That way you only need to set up connection string in the datasource rather than having the duplication in the realm.

    N.B. Personally, I would question whether it is a good idea to have a different ADMINISTRATOR and USER table, as what would happen if you’ve got a username that is both a client and an administrator, so you’d have to ensure that this doesn’t happen, which is much easier by having a constraint on just one table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a Java application that stores RSA public keys and allows a user
I have a java web application that use spring security for log in users,
I have a problem modernizing a Java WebStart application under Java 6 u 13
I have written simple application with container-managed security. The problem is when I log
Signed Java Applets have the same security clearance as a normal Java application running
We have a JSF web application that uses Acegi security. We also have a
I have read everywhere that unsigned Java applets are not allowed to make network
i have a problem is shown below; groovy.lang.MissingMethodException: No signature of method: static org.springframework.security.oauth.User.withTransaction()
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with fancybox. I want to write a function that will run

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.