This project demonstrates the implementation of the latest Spring Security mechanism using JWT (JSON Web Token) for authentication, email validation with tokens, and logout functionality.
- User Registration with Email Validation: Users register with their email, and receive a validation token to activate their account.
- JWT Authentication: Secure login using JWT for token-based authentication.
- Logout Functionality: Token invalidation to ensure secure logout.
- Role-based Authorization: Secure endpoints based on user roles.
- Java 17 or higher
- Maven
- SMTP server configuration for email validation
git clone https://github.com/abdelmottalib/Spring-boot-Jwt-Email-Authentication
cd Spring-boot-Jwt-Email-Authentication
Update the src/main/resources/application.yml
file with your database and email server configurations.
security:
jwt:
secret-key: Your secret Key
expiration: Your intended expiration
This runs postgres and maildev continers
docker-compose up -d
mvn spring-boot:run
The application will start on http://localhost:8088.
- Register:
POST api/v1/auth/register
- Authenticate:
POST api/v1/auth/authenticate
- Activate Account:
GET api/v1/auth/activate-account
- Logout:
POST api/v1/auth/logout
- movies:
POST api/v1/movies
#Test endpoint to test if the endpoint is working
src/
└── main/
├── java/
│ └── com/
│ └── konami/
│ ├── auth/ # Authentication and Authorization
│ ├── role/ # User Roles
│ ├── email/ # Email validation configuration
│ ├── handler/ # Global exception handler
│ ├── security/ # Spring security configuration and jwt filter
│ ├── movies/ # Test Endpoint
│ ├── config/ # Security and application configuration
│ └── user/ # User management
├── resources/
│ ├── application.yml
│ ├── application-dev.yml
└── test/
- Fork the repository
- Create a feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -m 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request