Skip to content

VaradM-17/my-blog-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“– Blog Application

A full-featured Blog Application built with Spring Boot, Spring Security, and JWT.
It supports user authentication, role-based access (ADMIN & USER), posts, comments, and pagination.


πŸ“‚ Project Structure

blog-app/
│── src/main/java/com/security/blog/
β”‚   β”œβ”€β”€ config/          # Security configurations
β”‚   β”œβ”€β”€ controller/      # REST controllers
β”‚   β”œβ”€β”€ dto/             # Data Transfer Objects (LoginDto, RegisterDto, etc.)
β”‚   β”œβ”€β”€ entity/          # Entities (Post, Comment, User)
β”‚   β”œβ”€β”€ exception/       # Custom exceptions & handlers
β”‚   β”œβ”€β”€ repository/      # Spring Data JPA repositories
β”‚   β”œβ”€β”€ security/        # JWT classes (Filter, TokenProvider, EntryPoint)
β”‚   β”œβ”€β”€ service/         # Business logic layer
β”‚   └── BlogAppApplication # Main Spring Boot application
β”‚
└── src/main/resources/
    β”œβ”€β”€ application.properties # Database & JWT configurations

βš™οΈ Installation & Setup

  1. Clone the repository

    git clone https://github.com/VaradM-17/my-blog-app.git
    cd my-blog-app/blog-app
  2. Configure Database
    Open src/main/resources/application.properties and update it with your DB credentials:

    spring.datasource.url=jdbc:mysql://localhost:3306/blog_app
    spring.datasource.username=root
    spring.datasource.password=yourpassword
    spring.jpa.hibernate.ddl-auto=update
    
    # JWT properties
    app.jwt-secret=your_jwt_secret_key
    app.jwt-expiration-milliseconds=604800000
  3. Build & Run the application

    mvn spring-boot:run

πŸš€ Features

  • πŸ” Authentication & Authorization using Spring Security + JWT
  • πŸ‘₯ Role-based access (ADMIN, USER)
  • πŸ“ Posts & Comments (One-to-Many relationship)
  • πŸ“‘ Pagination & Sorting for posts
  • πŸ“¦ DTOs for clean API requests/responses
  • ⚠️ Exception handling
  • πŸ—„οΈ MySQL Database with JPA & Hibernate

πŸ”‘ API Endpoints

πŸ” Authentication

Endpoint Method Access Description
/api/auth/register POST Public Register a new user
/api/auth/login POST Public Login and receive JWT token

πŸ“ Posts

Endpoint Method Access Description
/api/posts POST ADMIN Create a new post
/api/posts GET USER, ADMIN Get all posts (with pagination & sorting)
/api/posts/{id} GET USER, ADMIN Get a post by ID
/api/posts/{id} PUT ADMIN Update a post
/api/posts/{id} DELETE ADMIN Delete a post

πŸ’¬ Comments

Endpoint Method Access Description
/api/posts/{postId}/comments POST USER, ADMIN Add a comment to a post
/api/posts/{postId}/comments GET USER, ADMIN Get all comments for a post
/api/comments/{id} DELETE USER, ADMIN Delete a comment

πŸ”’ JWT Security Flow

  1. User registers or logs in β†’ receives a JWT token
  2. Client sends JWT in the Authorization header:
    Authorization: Bearer <your_token>
  3. Every request is checked by JwtAuthenticationFilter
  4. If the token is valid β†’ request continues
  5. If invalid β†’ JwtAuthenticationEntryPoint returns Unauthorized (401)

About

A complete Blog Application backend using Spring Boot, Spring Security, and JWT. Includes role-based authentication & authorization, pagination, sorting, and REST APIs for posts, comments, and user management.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages