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.propertiesfile located in thesrc/main/resourcesdirectory. -
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.authenticationsystemand 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
POSTrequest to/api/v1/registerwith user details (e.g. username, password, email) in the request body. -
To generate JWT Token, make a
POSTrequest to/api/v1/login -
GET /api/v1/adminonly accessible by ADMIN user. -
To logout, make a
GETrequest to/api/v1/logout. It will logged out user and invalidate the JWT token.
To run tests, run the following command
mvn testThis command will execute all the unit tests in the project, and the test results will be displayed in the console.