Overview
The EMS implements role-based access control (RBAC) using JPA’s Single Table Inheritance strategy. All users inherit from a baseUser entity, with role-specific attributes stored in the same table using a discriminator column.
Student
Browse and register for events
Event Organizer
Create proposals and manage events
Administrator
Approve proposals and manage the system
Single Table Inheritance
Architecture
All user types are stored in a singleusers table with a user_type discriminator column:
User.java:15-58
The
User class is abstract and cannot be instantiated directly. All users must be created as one of the three concrete subclasses.Benefits of Single Table Inheritance
Performance
Performance
- Single table queries are faster (no joins required)
- Polymorphic queries are efficient
- Simplified database schema
Flexibility
Flexibility
- Easy to add new user types
- Supports polymorphic associations
- Type-safe casting with instanceof checks
Simplicity
Simplicity
- One table to manage
- Straightforward migrations
- Easy to understand data model
User Roles
Student
Students can browse events and register for activities.Student.java:12-28
Unique student identifier (e.g., “S2024001”)
Student’s major or field of study
Current year of study (1-4)
Permissions
Browse Events
View all approved and published events
Register for Events
Register for events with capacity and conflict checking
View Registrations
View personal registration history
Cancel Registrations
Cancel registrations with 24-hour notice
Event Organizer
Organizers can create event proposals and manage approved events.EventOrganizer.java:17-37
Name of the organization (e.g., “Computer Science Club”)
Department affiliation (e.g., “Department of Computer Science”)
Lazy-loaded list of proposals created by this organizer
Permissions
Create Proposals
Submit event proposals with document uploads
View Own Proposals
View all proposals they’ve created
Manage Events
Manage approved events (view participants, post updates)
Resubmit Proposals
Resubmit rejected proposals with changes
Administrator
Administrators approve proposals and manage the system.Administrator.java:11-23
One of:
STANDARD_ADMIN, SUPER_ADMINAdmin Levels
- Standard Admin
- Super Admin
Permissions:
- Review and approve/reject proposals
- View department-specific proposals
- Monitor system activity
- Generate reports
- Cannot create SUPER_ADMIN users
- Cannot modify system-wide settings
Public registration always creates
STANDARD_ADMIN users. SUPER_ADMIN can only be created through the admin user management endpoint by an existing SUPER_ADMIN.Permission Enforcement
Method-Level Security
Permissions are enforced using Spring Security’s@PreAuthorize annotation:
ProposalController.java:31-46
The
@PreAuthorize annotation is evaluated before the method executes. If the user doesn’t have the required role, a 403 Forbidden response is returned.Multiple Roles
Some endpoints allow multiple roles:RegistrationController.java:65-76
Runtime Permission Checks
Some operations require additional runtime checks beyond role verification:RegistrationServiceImpl.java:185-194
Organizers can only view participants for events they manage. Admins can view participants for any event.
Type Casting
Safe Casting with instanceof
When working with polymorphic entities, useinstanceof checks before casting:
RegistrationServiceImpl.java:52-57
Pattern Matching (Java 17+)
Modern Java supports pattern matching for instanceof:AuthServiceImpl.java:119-128
Database Schema
users Table Structure
Primary key, auto-increment
Discriminator column: “STUDENT”, “ORGANIZER”, or “ADMIN”
Unique, not null
BCrypt hashed password, not null
Not null
Not null
Enum: “STUDENT”, “ORGANIZER”, “ADMIN”
Enum: “ACTIVE”, “SUSPENDED”, “DELETED”
Account creation timestamp
Last login timestamp (nullable)
Student-specific: unique student identifier (nullable)
Student-specific: major or field of study (nullable)
Student-specific: current year (nullable)
Organizer-specific: organization name (nullable)
Organizer-specific: department affiliation (nullable)
Admin-specific: “STANDARD_ADMIN” or “SUPER_ADMIN” (nullable)
Common Patterns
Retrieving Current User
Role-Specific Queries
Security Best Practices
Always Verify Ownership
Even if a user has the correct role, verify they own the resource they’re trying to access.
Related Documentation
Authentication
Learn about JWT-based authentication
Proposals
Understand the proposal workflow