CRUD REST API to practice Spring Security basics.
- Clone this repository:
https://github.com/matheusbloize/java-spring-simple-security.git
- Create your PostgreSQL database
- Create .env and add environment variables (example)
- Build project:
./mvnw clean package
- Run app:
java -jar target/simple-security-food-order-system-0.0.1-SNAPSHOT.jar
- Run SQL Boilerplate to create a user
INSERT INTO tb_user VALUES (gen_random_uuid(), 'John Doe', '$2a$12$mjv.QSjzmq9lPX7yFu.XmeCnc/H8LF9RGSf/aD61pCm1sPPgIE1cS');
INSERT INTO tb_role VALUES (gen_random_uuid(), 'ROLE_USER');
INSERT INTO tb_role VALUES (gen_random_uuid(), 'ROLE_ADMIN');
INSERT INTO tb_users_roles (user_id, role_id)
SELECT u.id, r.id
FROM tb_user u
JOIN tb_role r ON r.name = 'ROLE_ADMIN'
WHERE u.name = 'John Doe';
Access with the user created:
- Name: John Doe
- Password: password
API:
- Orders: localhost:8080/orders
Swagger UI: localhost:8080/swagger-ui/index.html
GET /orders ADMIN only
POST /orders USER only
GET /orders/{id} ADMIN and USER (his orders)
PUT /orders/{id} ADMIN and USER (his orders)
DELETE /orders/{id} ADMIN and USER (his orders)
