This project is a simple authentication system. It demonstrate how to secure your APIs with spring security with JWT.
├── src/
| ├── main/
| | ├── java/
| | | └── com.assignment.authenticationsystem/
| | | ├── config/
| | | ├── controllers/
| | | ├── dto/
| | | ├── exception/
| | | ├── models/
| | | ├── repository/
| | | ├── security/
| | | └── services/
| | | ├── token/
| | └── resources/
| | ├── static/
| | |── templates/
| | └── application.properties/
├── test/
├── pom.xml
└── README.md
- Java 17
- Maven
- MySQL
- Postman or Talend API Tester
- Java Development Kit (JDK) 17 or higher: You can download the JDK from Oracle
Clone the repository using Git
- Run the following commands in your Terminal
git clone https://github.com/hemantDwivedi/authentication-system.git
cd authentication-system
-
Create a new database named
'authentication_system'
in your MYSQL. -
Open project folder in IntelliJ IDEA and wait till to download all neccessary dependencies.
-
Open the
application.properties
file located in thesrc/main/resources
directory. -
Update the database connection properties (e.g.,
spring.datasource.url, spring.datasource.username, spring.datasource.password
) to match your database configuration. -
Right Click on AuthenticationSystemApplication.java located in the
src/main/java/com.assignment.authenticationsystem
and run the applcation.
Once the application is running, you can test APIs in your Postman or with chrome extention Talend API Tester.
-
To create a new user, make a
POST
request to/api/v1/register
with user details (e.g. username, password, email) in the request body. -
To generate JWT Token, make a
POST
request to/api/v1/login
-
GET /api/v1/admin
only accessible by ADMIN user. -
To logout, make a
GET
request to/api/v1/logout
. It will logged out user and invalidate the JWT token.
To run tests, run the following command
mvn test
This command will execute all the unit tests in the project, and the test results will be displayed in the console.