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.
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
-
Clone the repository
git clone https://github.com/VaradM-17/my-blog-app.git cd my-blog-app/blog-app -
Configure Database
Opensrc/main/resources/application.propertiesand 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
-
Build & Run the application
mvn spring-boot:run
- π 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
| Endpoint | Method | Access | Description |
|---|---|---|---|
/api/auth/register |
POST | Public | Register a new user |
/api/auth/login |
POST | Public | Login and receive JWT token |
| 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 |
| 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 |
- User registers or logs in β receives a JWT token
- Client sends JWT in the
Authorizationheader:Authorization: Bearer <your_token> - Every request is checked by
JwtAuthenticationFilter - If the token is valid β request continues
- If invalid β
JwtAuthenticationEntryPointreturns Unauthorized (401)