Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mohamad-shosha/spring-jpa-mvc-security
This project integrates Spring MVC, JPA, and Hibernate for managing Instructor, Address, and Course entities. It uses Liquibase for database management and Postman for API testing. Key features include creating, reading, updating, and deleting entities, along with security to ensure authentication, authorization measures for safe data handling.
https://github.com/mohamad-shosha/spring-jpa-mvc-security
bootstrap css database error-handling hibernate html5 java jpa-entities liquibase maven mysql spring-boot spring-data-jpa spring-mvc spring-security thymeleaf
Last synced: 6 days ago
JSON representation
This project integrates Spring MVC, JPA, and Hibernate for managing Instructor, Address, and Course entities. It uses Liquibase for database management and Postman for API testing. Key features include creating, reading, updating, and deleting entities, along with security to ensure authentication, authorization measures for safe data handling.
- Host: GitHub
- URL: https://github.com/mohamad-shosha/spring-jpa-mvc-security
- Owner: Mohamad-shosha
- Created: 2024-10-10T15:44:38.000Z (27 days ago)
- Default Branch: main
- Last Pushed: 2024-10-27T13:05:20.000Z (10 days ago)
- Last Synced: 2024-10-27T14:38:13.752Z (10 days ago)
- Topics: bootstrap, css, database, error-handling, hibernate, html5, java, jpa-entities, liquibase, maven, mysql, spring-boot, spring-data-jpa, spring-mvc, spring-security, thymeleaf
- Language: HTML
- Homepage: https://drive.google.com/drive/folders/1Z7WG3Q52P4SGVnE3FR706UXGT05RHmjF
- Size: 154 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ Spring-MVC-JPA-Security
This project showcases the powerful integration of **Spring MVC** with **Java Persistence API (JPA)**, utilizing **Hibernate** for efficient Object-Relational Mapping (ORM).
### ๐ Key Features:
- **Seamless Backend Integration**: Effortlessly manage and query data with a robust backend framework.
- **Core Entities**:
- **Instructor**: Manage instructor details and associated courses.
- **Address**: Handle address information for instructors and courses.
- **Course**: Organize and maintain course offerings and their related entities.- **Database Schema Management**: Leverage **Liquibase** to manage database versioning and migrations, ensuring smooth transitions during updates.
- **API Testing**: Utilize **Postman** as a client for testing API endpoints, making it easy to verify and validate the functionality of your application.
With this setup, you can efficiently build and maintain a robust application tailored to your data management needs!
## ๐ Table of Contents
- [Features](#features)
- [Prerequisites](#prerequisites)
- [Getting Started](#getting-started)
- [Security](#security)
- [Technologies](#technologies)
- [Demo](#demo)
- [Docker](#docker)
- [Resources](#resources)## ๐ Features
This project boasts a range of powerful features that streamline your application development and enhance user experience:
### ๐ Key Functionalities
- **CRUD Operations**: Effortlessly perform *Create, Read, Update, and Delete* operations for Instructor, Address, and Course entities.
- **MVC Architecture**: Utilize a clean and organized *Model-View-Controller* architecture for clear separation of concerns.- **Spring Boot Integration**: Benefit from *Spring Boot* for rapid backend development with automatic configuration and dependency management.
- **Efficient ORM**: Leverage *JPA & Hibernate* for smooth Object-Relational Mapping and database interactions.
- **Dynamic Web Pages**: Render interactive and dynamic web pages with *Thymeleaf*.
- **Database Management**: Manage database schema versioning and migrations seamlessly with *Liquibase*.
- **API Testing Made Easy**: Use *Postman* for quick and efficient testing of your API endpoints.
---
### ๐ Explore the Features
#### 1. **Create**
- Easily add new Instructor, Address, or Course entities through a user-friendly web form.#### 2. **Read**
- Retrieve and display data for Instructor, Address, or Course entities in a well-structured format.#### 3. **Update**
- Modify existing entities with an intuitive interface for effortless changes.#### 4. **Delete**
- Remove entities with a single click, simplifying data management.---
With these features, your application will be robust, user-friendly, and maintainable!
Remove entities with a single click.
---
## ๐ Prerequisites
Before you begin, ensure you have the following:
- *Java Development Kit (JDK)* installed (preferably JDK 11 or later).
- *Maven* installed for dependency management.
- Your favorite IDE (e.g., IntelliJ IDEA, Eclipse) for code editing.
- *Postman* for API testing.---
## โจ Getting Started
Follow these steps to set up your Spring Boot project quickly and efficiently:
### ๐ Step 1: Create a Spring Boot Project
Begin by generating a new Spring Boot project using [Spring Initializr](https://start.spring.io/) with the following settings:
- **Project**: Maven Project
- **Language**: Java
- **Spring Boot**: Latest stable version
- **Packaging**: Jar
- **Dependencies**:
- Spring Web
- Spring Data JPA
- Thymeleaf
- Liquibase
- MySQL DriverClick **"Generate"** to download the project zip file.
---
### ๐ฅ Step 2: Extract and Import into IDE
1. Extract the downloaded zip file.
2. Import the project into your preferred IDE (e.g., IntelliJ IDEA, Eclipse).---
### โ๏ธ Step 3: Configure Database and Liquibase
- **Database Configuration**: Update your `application.properties` or `application.yml` file with your database connection details.
- **Liquibase Configuration**: Configure Liquibase in your `application.properties` and add your changelog files in `src/main/resources/db/changelog`.
```application.properties
spring.liquibase.change-log=db/changelog/db_master_changelog.xml
```---
### ๐๏ธ Step 4: Define Entities
Create entity classes for **Instructor**, **Address**, and **Course** in your project.
---
### ๐ Step 5: Create Repository Interfaces
Define repository interfaces for each entity to enable CRUD operations.
---
### ๐ Step 6: Implement Service Layer
Develop a service layer to manage business logic and facilitate interaction with repositories.
---
### ๐ฅ๏ธ Step 7: Implement Controllers
Create MVC controllers to manage HTTP requests and return appropriate views.
---
### ๐จ Step 8: Create Thymeleaf Views
Design Thymeleaf templates for displaying forms and results.
---
### ๐งช Step 9: Test Using Postman
Utilize Postman to test your API endpoints by sending requests to create, read, update, and delete entities.
---
### โถ๏ธ Step 10: Run Your Application
Run your Spring Boot application. The server will start at [http://localhost:8082](http://localhost:8082).
---
## ๐ Technologies
- **Spring Boot**: For building the backend application.
- **Spring MVC**: For handling web requests and rendering views.
- **JPA & Hibernate**: For ORM and database interactions.
- **Thymeleaf**: For server-side templating.
- **Liquibase**: For database schema management and migrations.
- **MySQL**: As the database.
- **Postman**: For API testing.---
## ๐ Security
Ensuring the security of your application is crucial. Here are some recommendations and practices to secure your Spring MVC application:
### 1. **Use Spring Security**
Integrate Spring Security to handle authentication and authorization. This framework provides comprehensive security features, including:
- **Authentication**: Secure your endpoints by requiring users to log in.
- **Authorization**: Control access to various resources based on user roles.**Setup Example**:
Add Spring Security dependency in your `pom.xml`:
```xmlorg.springframework.boot
spring-boot-starter-security```
### 2. **Secure Sensitive Information**- **Environment Variables**: Store sensitive data (like database passwords) in environment variables instead of hardcoding them in your `application.properties` file. For example:
```application.properties
database.url=jdbc:mysql://localhost:3307/mydb
database.username=root
database.password=shosh404@@spring.datasource.url=${database.url}
spring.datasource.username=${database.username}
spring.datasource.password=${database.password}
```Step 1: Add Spring Security Dependency.๐ก๏ธ
In your pom.xml (for Maven) or build.gradle (for Gradle), add the Spring Security dependency
Step 2: Handle User Authentication.๐
This App uses in-memory authentication ,this step provide username,password and role For a production application.
Step 3: Secure Endpoints
By specify which endpoints require authentication and authorization by configuring HttpSecurity.
Step 4: Define User Roles.๐๏ธ
Define roles that represent different levels of access in your application , For example that apply on my app, you might have roles like ROLE_EMPLOYEE , ROLE_MANAGER and ROLE_ADMIN.
You can assign roles to users during user authentication.## ๐ฅ Demo
Get a firsthand look at the project in action! See how the features come together and experience the functionality of the application.
๐ [**Watch the Demo Video Here**](https://drive.google.com/drive/folders/1Z7WG3Q52P4SGVnE3FR706UXGT05RHmjF)
---
## ๐ณ Docker
To push your Docker image to Docker Hub, use the following command:
```bash
docker push your-docker-repo/spring-mvc-app:latest
```## ๐ Resources
- [Spring Boot Documentation](https://spring.io/projects/spring-boot) - Official documentation for Spring Boot.
- [Spring MVC Documentation](https://docs.spring.io/spring-framework/docs/current/reference/html/web.html#mvc) - Comprehensive guide to Spring MVC framework.
- [JPA and Hibernate Guide](https://docs.jboss.org/hibernate/orm/current/userguide/html_single/) - Detailed documentation for using JPA with Hibernate.
- [Liquibase Documentation](https://www.liquibase.org/documentation/index.html) - Resources for managing database schema with Liquibase.
- [Postman Documentation](https://learning.postman.com/) - Official documentation for using Postman to test APIs.
- [Thymeleaf Documentation](https://www.thymeleaf.org/documentation.html) - Guide to using Thymeleaf for server-side rendering.
- [Docker Documentation](https://docs.docker.com/get-started/) - Getting started with Docker for containerization.