This is a Spring Boot application for managing a grocery store. It includes user authentication and authorization features, allowing users to register, log in, and access different profiles based on their roles.
- User registration
- User authentication with JWT
- Role-based access control
- Secure and non-secure endpoints
- Java
- Spring Boot
- Spring Security
- JWT (JSON Web Token)
- Maven
- Java 17 or higher
- Maven 3.6.0 or higher
-
Clone the repository:
git clone https://github.com/AmirAlahmedy/Grocery.git cd grocery-store
-
Build the project:
mvn clean install
-
Run the application:
mvn spring-boot:run
GET /auth/welcome
- Public endpoint, no authentication required.POST /auth/addNewUser
- Register a new user.POST /auth/generateToken
- Authenticate and get a JWT token.GET /auth/user/userProfile
- Access user profile (requiresROLE_USER
).GET /auth/admin/adminProfile
- Access admin profile (requiresROLE_ADMIN
).
curl -X POST http://localhost:8080/auth/addNewUser -H "Content-Type: application/json" -d '{"username": "user@example.com", "password": "password"}'
curl -X POST http://localhost:8080/auth/generateToken -H "Content-Type: application/json" -d '{"username": "user@example.com", "password": "password"}'
curl -X GET http://localhost:8080/auth/user/userProfile -H "Authorization: Bearer <your-jwt-token>"
src/main/java/com/grocery/security/auth/AuthRequest.java
- Defines the authentication request.src/main/java/com/grocery/user/UserController.java
- Handles user-related endpoints.src/main/java/com/grocery/user/UserInfoService.java
- Manages user information and authentication.
I followed these tutorials to create this project: - Spring Boot + Spring Security + JWT
Contributions are welcome! Please fork the repository and submit a pull request.
This project is licensed under the MIT License. See the LICENSE
file for details.