Spring Security with currency converter api for Online Shop Web Application
Assessment created by Safwan kher(https://github.com/safwan-kher).
First part of README is by me for application instruction and result description. Second part is the original README by Safwan kher for the project requirements and concepts to implement.
README by Chizuru Yamauchi
On terminal, sudo -u postgres psql -> CREATE DATABASE database_name; -> \c database_name -> \q
Application Properties: Configure the PostgreSQL database connection in the application.properties
file(and put the file name in .gitignore to secure the sensitive information.)
There is no user so far in the database and we have to sign up first.
After filling the sign-up form and click 'Sign Up', the user get the verification email
The user will get verification Email: Click the url to verify the email.
After clicking the link, the user will be verified('enabled' becomes 'true' from 'false' on database) and the user can log in with the username and password.
on database after verification:
on the web application:
Newly log in with a new username and a new password as a user(role).
Email Testing: Test passed.
Home as a user :logged in as a user (username = 'naruto') *Updated
Click 'Browser Products' and the user(naruto) can see product lists :(Jump to Product List and see all the products)
*Because naruto logged in as a role_user now, there is no feature of 'Add New Product'
Home as an admin
Click 'Admin Home' and jump to Admin Home Page and see all the option admin could do
Click Product List and see all the products. It is empty now because there is no product yet. But since the user logged in as an admin, the admin can add a new product with 'Add New Product' button.
Click Add Product and add a new product
Click 'Save' the product then the product list will show the product
Click 'View' to see the product detail
Click 'Convert Price' to go to the convert currency page to convert the price with product id number to different currencies
On actual URL, you can see the converted price
Click 'Edit' to edit the product
Assign role to the user as admin
After assigning the role, you can see the modification on the database
The user ('user_id 6' = demoChizuru) is now assigned as an admin(and also still as a user) on database. 'role_id 5' = ROLE_ADMIN)'
demoChizuru can go to 'Admin Home' and do the admin tasks
Click 'Manage Users' and see the user list
Click 'View' to see the user detail
demoChizuru can still go to 'User Home' and can view as a normal user(*Updated)
demoChizuru can view her own profile
When you want to log out click logout, and you will be logged out, then you can log in again as a user or admin.
README and instruction by Safwan kher.
In this assignment, you will build an online shop application using Java Spring Boot, Spring Security, JPA, Hibernate, and Thymeleaf. The application will allow users to sign up, log in, browse products, add products to their cart, and convert prices between different currencies using the ExchangeRate API.
User Management:
ROLE_USER
, ROLE_ADMIN
).ROLE_ADMIN
to other users.Product Management:
Currency Conversion:
Security:
BCryptPasswordEncoder
.Database:
User Interface:
Spring Boot:
Spring Security:
JPA and Hibernate:
Thymeleaf:
Controllers:
Service Layer:
RESTful API Integration:
RestTemplate
to make HTTP requests to the ExchangeRate API.Bidirectional Relationships:
Error Handling:
Create a new Spring Boot project with the following dependencies:
Configure the application.properties
file with the necessary settings:
# Server Configuration
server.port=8080
# Database Configuration
spring.datasource.url=jdbc:postgresql://localhost:5432/onlineshop
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.datasource.driver-class-name=org.postgresql.Driver
# JPA/Hibernate properties
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
# Email Configuration
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username[email protected]
spring.mail.password=your_email_password
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
# ExchangeRate-API Key
exchangerate.api.key=your_api_key
Entities:
User
and Role
entities with a many-to-many relationship.VerificationToken
entity for email verification.Repositories:
UserRepository
, RoleRepository
, and VerificationTokenRepository
.Services:
UserService
to handle user-related operations.Controllers:
UserController
to handle user-related requests (signup, login, assign admin role, verify email).Security Configuration:
SecurityConfig
to configure authentication and authorization.Entities:
Product
entity with fields like id
, name
, description
, price
, and currency
.Repositories:
ProductRepository
.Services:
ProductService
to handle product-related operations.Controllers:
ProductController
to handle product-related requests (add, update, delete, view products).Service:
CurrencyConverterService
to interact with the ExchangeRate API.Controller:
CurrencyConverterController
to handle currency conversion requests.Templates:
currency-converter.html
to allow users to convert product prices between different currencies.Templates:
login.html
, signup.html
, home.html
, admin-home.html
, product-list.html
, product-form.html
, and currency-converter.html
using Thymeleaf.Dynamic Content:
Sign Up and Log In:
Product Management:
Currency Conversion:
Security:
Submit the following:
Spring Boot:
Spring Security:
JPA and Hibernate:
Thymeleaf:
Controllers:
Service Layer:
RESTful API Integration:
Bidirectional Relationships:
User
can have multiple Roles
, and a Role
can have multiple Users
.Error Handling:
By completing this assignment, you will gain hands-on experience with these concepts and learn how to build a secure, user-friendly online shop application with currency conversion capabilities.