You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| 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.
9
9
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.
11
11
12
12
# Table of Contents
13
13
* Features
14
14
* Technologies Used
15
15
* Project Structure
16
+
* The main packages are
17
+
* Dependencies
16
18
* How to Run
17
19
* Usage
18
-
* Testing
19
-
* Database Configuration
20
-
* Contact
20
+
* Handling Bad Credentials
21
+
* Additional Note
22
+
23
+
21
24
22
25
# Features
23
26
* 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
42
45
* The project follows the standard Spring Boot project structure with separate packages for
43
46
* controllers,
44
47
* 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.
50
53
51
54
# The main packages are:
52
55
* com.woromedia.auth.api.controller: Contains the REST API controllers.
* 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.
66
70
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.
68
73
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.
70
76
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.
72
79
73
80
* JUnit: This dependency is used for writing unit tests.
74
81
@@ -77,3 +84,109 @@ The project uses the following dependencies:
77
84
* JWT (JSON Web Tokens): This dependency provides support for generating and validating JSON Web Tokens for token-based authentication.
78
85
79
86
* 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
* 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,
* 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