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 6385343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:53:14+00:00 2026-05-25T02:53:14+00:00

I would like to build a simple ORM/database permission system where I have users,

  • 0

I would like to build a simple ORM/database permission system where I have users, groups and rights:

  • Each user can be a member of multiple groups, every group can have multiple users as members.
  • Each relationship between user and group has an additional piece of information: rights.

The idea is that each user can have different rights in each group.

How should my entities look like so I can query things

  • from the “group view” like “retrieve all members of this group”
  • and the “user view” like “retrieve all groups this user is a member in”
  • as well as “given this user and this group, which rights does the user have”?

I’m using Java 6 with JPA2 annotations and EclipseLink.

  • 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-25T02:53:15+00:00Added an answer on May 25, 2026 at 2:53 am

    I think you might want to look at implementations already provided by the application server community. Typically speaking, what you’ve described is a definition of form based authentication.

    http://tomcat.apache.org/tomcat-5.5-doc/config/realm.html

    Basically speaking, the relationship is:

        User
          + Role[]
    

    Once configured this allows frameworks such as JSF (but you’ll notice I’m accessing the Tomcat session here) to query for a specific role. The code below is taken from a basic form-based authentication scheme I have on a small web-app, and it is in dire need of refactoring, I’ve just had higher priorities

    public boolean isUserInRole(Roles role)
      {
        return FacesContext.getCurrentInstance().getExternalContext().isUserInRole(role.getRoleValue()); 
      }
    

    In this case Roles is a (poorly named) enum type that is stored in my “Role” Entity:

    @Entity
    @Table(name = "role", uniqueConstraints = @UniqueConstraint(columnNames = { "user_user", "role" }))
    public class Role implements Serializable
    {
        private static final long serialVersionUID = 1L;
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private Long id;
        @ManyToOne(targetEntity = User.class, fetch = FetchType.LAZY)
        private User user;
        private String role;
    
        public Long getId()
        {
            return id;
        }
    
        public void setId(Long id)
        {
            this.id = id;
        }
    
        public User getUser()
        {
            return user;
        }
    
        public void setUser(User user)
        {
            this.user = user;
        }
    
        public String getRole()
        {
            return role;
        }
    
        public void setRole(String role)
        {
            this.role = role;
        }
    }
    

    This ends up creating the tables (as I specified the fields) so I can provide an SQL query to the configuration and create a realm. There’s a lot of good documentation on this if you Google “j_security_check”.

    As to a group? A group sounds like a collection of roles to me–so it isn’t a stretch to modify the query to a third table, or simply provide an enum.

    (after reading this, the only clarification is that my roles are stored in an enum which contains the string value of the role, so roles.getValue() returns a string like “administrators”.

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

Sidebar

Related Questions

I would like to build a simple menu for each list element clicked on
I would like to build a simple animation for a school project. I want
I'm using Prototype here and would like to build a simple toggler that toggles
I would like to build turret, that can rotate in all axis. So the
I would like to build a simple standalone solitaire game in ruby. Are there
I building a simple, 7 page, database driven, website, and I would like to
I would like to build a few simple countdown timers in a UITableview. I
I would like to build a code library in IronPython and have another C#
I have a wxWidgets application and would like to add a way for users
I am trying to build simple application, just for knowledge. I would like to

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.