- Java 8 (JDK 1.8)
- Spring Framework 2 (Spring Boot - 2.7.13)
- Json Web Token (io.jsonwebtoken - 0.11.5)
- MySQL 8 (8.0.33)
Run Spring Boot application with command:
mvn spring-boot:run
We also need to add some rows into roles table before assigning any role to User. Run following SQL insert statements:
INSERT INTO roles(name) VALUES('ROLE_USER');
INSERT INTO roles(name) VALUES('ROLE_MODERATOR');
INSERT INTO roles(name) VALUES('ROLE_ADMIN');
Example Register User: http://localhost:8080/api/auth/signup
Resquest body:
{
"username": "user",
"email": "user@gmail.com",
"password": "newPassw0rd!",
"role": ["user"]
}
Response body:
{
"message": "User registered successfully!"
}
Example Login an account: http://localhost:8080/api/auth/signin
Resquest body:
{
"username": "user",
"password": "newPassw0rd!"
}
Response body:
{
"id": 1,
"username": "user",
"email": "user@gmail.com",
"roles": [
"ROLE_USER"
]
}
Check cookies:
Example Logout the Account: http://localhost:8080/api/auth/signout
Response body:
{
"message": "You've been signed out!"
}
Example Logout the Account: http://localhost:8080/api/test/all
Response body:
Public Content.
Example Logout the Account: http://localhost:8080/api/test/user
Response body:
User Content.
Example Logout the Account: http://localhost:8080/api/test/mod
Response body:
Moderator Board.
Example Logout the Account: http://localhost:8080/api/test/admin
Response body:
Admin Board.
For further reference, please consider the following sections:
Maven dependency: jakarta.xml.bind:jakarta.xml.bind-api:2.3.2