Skip to content

Commit 21cf0f4

Browse files
authored
Update README.md
1 parent 3d3dfce commit 21cf0f4

File tree

1 file changed

+128
-15
lines changed

1 file changed

+128
-15
lines changed

README.md

Lines changed: 128 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@
55
![authentication_system users](https://github.com/SDEParag/Java-backend-Spring-boot-MySQL-login-logout-Authentication-System/assets/137553676/a8424f77-9bbd-4ab7-9dc1-ca586708622d)
66

77
# Java-backend-Spring-boot-MySQL-login-logout-Authentication-System
8-
| Java backend | Simple authentication system using Spring Security, JWT, MySQL, and authenticate users with the login and logout functionalities.
8+
* | Java backend | Simple authentication system using Spring Security, JWT, MySQL, and authenticate users with the login and logout functionalities.
99

10-
This is a Spring Boot-based authentication system developed for the Woro-media assignment. It provides user registration, login, role-based access control, and logout functionalities.
10+
* This is a Spring Boot-based authentication system. It provides user registration, login, role-based access control, and logout functionalities.
1111

1212
# Table of Contents
1313
* Features
1414
* Technologies Used
1515
* Project Structure
16+
* The main packages are
17+
* Dependencies
1618
* How to Run
1719
* Usage
18-
* Testing
19-
* Database Configuration
20-
* Contact
20+
* Handling Bad Credentials
21+
* Additional Note
22+
23+
2124

2225
# Features
2326
* User registration with username, email, and password
@@ -42,33 +45,37 @@ This is a Spring Boot-based authentication system developed for the Woro-media a
4245
* The project follows the standard Spring Boot project structure with separate packages for
4346
* controllers,
4447
* services,
45-
* repositories,
46-
* entities,
47-
* payloads, and
48-
* utils,
49-
* security configuration.
48+
* repositories,
49+
* entities,
50+
* payloads, and
51+
* utils,
52+
* security configuration.
5053

5154
# The main packages are:
5255
* com.woromedia.auth.api.controller: Contains the REST API controllers.
5356
* com.woromedia.auth.api.entity: Contains JPA entity classes.
5457
* com.woromedia.auth.api.payload: Contains payload classes for request and response.
5558
* com.woromedia.auth.api.repository: Contains JPA repositories.
5659
* com.woromedia.auth.api.security: Contains security-related classes like JWT token provider,
57-
custom user details service, and authentication filter.
60+
custom user details service, and authentication filter.
5861
* com.woromedia.auth.api.service: Contains service interfaces and their implementations.
5962
* com.woromedia.auth.api.utils: Contains utility classes.
6063

6164
# Dependencies
6265

6366
The project uses the following dependencies:
6467

65-
* Spring Boot Starter Web: This dependency enables the development of web applications using Spring Boot. It provides essential components for building RESTful APIs.
68+
* Spring Boot Starter Web: This dependency enables the development of web applications using Spring Boot.
69+
It provides essential components for building RESTful APIs.
6670

67-
* Spring Boot Starter Data JPA: This dependency enables JPA (Java Persistence API) support in the application. It simplifies the interaction with the database.
71+
* Spring Boot Starter Data JPA: This dependency enables JPA (Java Persistence API) support
72+
in the application. It simplifies the interaction with the database.
6873

69-
* Spring Boot Starter Security: This dependency provides security support for Spring Boot applications. It allows you to secure your API endpoints and handle authentication and authorization.
74+
* Spring Boot Starter Security: This dependency provides security support for Spring Boot
75+
applications. It allows you to secure your API endpoints and handle authentication and authorization.
7076

71-
* Spring Boot Starter Validation: This dependency enables validation support for the request payloads. It allows you to enforce constraints on the incoming request data.
77+
* Spring Boot Starter Validation: This dependency enables validation support
78+
for the request payloads. It allows you to enforce constraints on the incoming request data.
7279

7380
* JUnit: This dependency is used for writing unit tests.
7481

@@ -77,3 +84,109 @@ The project uses the following dependencies:
7784
* JWT (JSON Web Tokens): This dependency provides support for generating and validating JSON Web Tokens for token-based authentication.
7885

7986
* MySQL Connector/J: This dependency provides the MySQL JDBC driver to connect the application with the MySQL database.
87+
88+
# How to Run
89+
Follow the steps below to run the application:
90+
91+
* Clone the repository to your local machine.
92+
* Make sure you have Java 8 and MySQL installed and running.
93+
* Set up the database by configuring the application.properties file with the correct database URL, username, and password.
94+
* (my mysql database is authentication_system , so create only database with any name as per your requirement)
95+
* Run the application using Intellij IDE.
96+
97+
* This is my application.properties
98+
* #Database Configuration
99+
spring.datasource.url=jdbc:mysql://localhost:3306/authentication_system <-------Add your database name only
100+
spring.datasource.username=root <-------Add your database username
101+
spring.datasource.password=2022 <-------Add your database password
102+
103+
* #Enable SQL query logging
104+
spring.jpa.show-sql=true
105+
106+
* #Hibernate DDL auto
107+
spring.jpa.hibernate.ddl-auto=update
108+
109+
* #Hibernate properties
110+
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
111+
112+
* #App Properties
113+
app.jwt-secret=JWTSecretKey
114+
app.jwt-expiration-milliseconds=604800000
115+
116+
117+
118+
119+
# Usage
120+
You can interact with the API endpoints using Postman or any other API testing tool.I am using Postman
121+
122+
* Handling API Endpoints with Different Responses
123+
124+
* 1 User Registration Endpoint:
125+
126+
URL:
127+
* Method POST: http://localhost:8080/api/auth/register
128+
Select --> Body --> raw --> JSON
129+
Request Body:
130+
131+
* JSON Structure
132+
{
133+
"username": "woromedia_1",
134+
"password": "password123",
135+
"email": "woromedia_1@example.com"
136+
}
137+
click on ---> Send
138+
* Response: HTTP 200 OK with "User registered successfully" message.
139+
140+
* Bad Credentials: If the provided username or email is already taken,
141+
the endpoint returns HTTP 400 Bad Request with an appropriate error message.
142+
143+
* 2 User Login Endpoint:
144+
URL:
145+
* Method POST: http://localhost:8080/api/auth/login
146+
Select --> Body --> raw --> JSON
147+
Request Body:
148+
* JSON Structure
149+
{
150+
"usernameOrEmail": "woromediaintern_1",
151+
"password": "password123"
152+
}
153+
154+
* Response: HTTP 200 OK with a JWT token in the response body.
155+
156+
* JWT token (On successful login):
157+
{
158+
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJqb2huX2RvZSIsInJvbGUiOiJST0x
159+
FX1VTRVIiLCJpYXQiOjE2MjgxOTQ1OTUsImV4cCI6MTYyODE5ODM5NX0.kiZb0N6dO03t
160+
9pPmFgWkGTr5F76vE7w_z-ZrkaCLy2c"
161+
}
162+
163+
* Bad Credentials: If the provided username or email and password combination is invalid, the endpoint returns HTTP 401 Unauthorized with an error message.
164+
165+
* 3 Admin Panel Endpoint:
166+
167+
URL:
168+
* Method GET : http://localhost:8080/api/auth/admin
169+
* Select --> Authorization --> Bearer token --> copy login token paste in Token like below,
170+
Token: [ eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJqb2huX2RvZSIsInJvbGUiOiJST0x
171+
FX1VTRVIiLCJpYXQiOjE2MjgxOTQ1OTUsImV4cCI6MTYyODE5ODM5NX0.kiZb0N6dO03t9pPmFgWkGTr5F76vE7w_z-ZrkaCLy2c ]
172+
173+
Click on Send
174+
* Response: HTTP 200 OK with "Admin Panel" message.
175+
176+
* Authorization Error: If a user without the "ROLE_ADMIN" role tries to access
177+
this endpoint, the application returns HTTP 403 Forbidden with an error message.
178+
179+
180+
* User Logout Endpoint:
181+
182+
URL:
183+
* Method POST /api/auth/logout
184+
* Response: HTTP 200 OK with "Logged out successfully" message
185+
186+
# Handling Bad Credentials
187+
* If the provided username or email during registration is already taken, the application returns HTTP 400 Bad Request with an appropriate error message.
188+
189+
* If the provided username or email and password combination during login is invalid, the application returns HTTP 401 Unauthorized with an error message.
190+
191+
# Additional Note
192+
Remember to configure the application.properties file with the correct database connection details and secret key for JWT token generation.

0 commit comments

Comments
 (0)