| π Articles | π€ My Profile |
πΉ Understand Spring Security basic concepts π Read here
π‘ Letβs understand how Spring Boot Security works with a database for form-based authentication.

1. Request with Credentials
2. DelegatingFilterProxy & FilterChainProxy
DelegatingFilterProxy to intercept requests.3. Filter Converts Credentials
4. AuthenticationManager
5. ProviderManager
AuthenticationManager delegates to ProviderManager.ProviderManager chooses the correct AuthenticationProvider (e.g., DaoAuthenticationProvider for username/password authentication).6. Fetch User Details
The provider calls the UserDetailsService to fetch user information.
7. Load User by Username
CustomUserDetailsService implements loadUserByUsername() to retrieve the user.8. Database Call
9. UserDetails Object
The database results are mapped to a UserDetails object, which contains:
10. Return Authenticated Object
BCryptPasswordEncoder here).11. Authentication Response
12. Filter Receives Authentication Response
UsernamePasswordAuthenticationFilter gets the authenticated object from the manager.13. Set Authenticated User into Context
SecurityContextHolder.14. Continue Filter Chain
15. Success Response
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
Object principal = auth.getPrincipal();
π₯οΈ Backend
π¨ Frontend
sec:authorize)π’οΈ Database
ποΈ Build & Dependency Management
βοΈ Utilities
@Getter, @Setter, etc.)spring-boot-security-using-database-form-based
βββ π src/
β βββ π main/
β βββ π java/
β β βββ π com/sahu/springboot/security/
β β βββ π config/
β β β βββ π CustomAuthenticationEntryPoint.java
β β β βββ π SecurityConfig.java
β β β
β β βββ π constant/
β β β βββ π AuthConstants.java
β β β
β β βββ π controller/
β β β βββ π AuthController.java
β β β βββ π HomeController.java
β β β
β β βββ π dto/
β β β βββ π UserRequest.java
β β β
β β βββ π model/
β β β βββ π Role.java
β β β βββ π User.java
β β β
β β βββ π repository/
β β β βββ π RoleRepository.java
β β β βββ π UserRepository.java
β β β
β β βββ π security/
β β β βββ π dto/
β β β β βββ π CustomUserDetails.java
β β β β
β β β βββ π util/
β β β βββ π SecurityUtil.java
β β β
β β βββ π service/
β β β βββ π impl/
β β β β βββ π CustomUserDetailsService.java
β β β β βββ π UserServiceImpl.java
β β β β
β β β βββ π UserService.java
β β β
β β βββ π SpringBootSecurityUsingDatabaseFormBasedApplication.java
β β
β βββ π resources/
β βββ π static/
β β
β βββ π templates/
β β βββ π error/
β β β βββ π 403.html
β β β
β β βββ π admin-dashboard.html
β β βββ π dashboard.html
β β βββ π login.html
β β βββ π registration.html
β β βββ π user-dashboard.html
β β
β βββ π application.yml
β
βββ π docker-compose.yml
βββ π pom.xml
You can find the complete code repository for this project on GitHub:
1οΈβ£ π³ Using Docker Compose (for MySQL container)
docker-compose up -d
β
This starts MySQL in a container (-d = detached mode).
π Verify with:
docker ps
π DB is now available at localhost:3307.
π Credentials (username, password, DB name) are in docker-compose.yml.
2οΈβ£ π» Run Directly in IntelliJ IDEA
SpringBootSecurityUsingDatabaseFormBasedApplication.java3οΈβ£ β‘ Run with Maven Command (CLI)
βΆοΈ Run app:
mvn spring-boot:run
π Run app with debug mode:
mvn spring-boot:run -Dspring-boot.run.fork=false -Dmaven.surefire.debug
π¦ Build JAR and run:
mvn clean package -DskipTests
java -jar target/spring-boot-security-using-database-form-based-0.0.1-SNAPSHOT.jar
For a detailed running and demonstration of the application walkthrough,
watch the following YouTube video: