A simple Spring Boot MVC application demonstrating basic web security implementation using Spring Security, Thymeleaf, and authentication mechanisms.
spring-security-demonstration.mp4
- Basic authentication system
- Protected and public routes
- Login/Logout functionality
- User authentication with in-memory user management
- Thymeleaf integration for dynamic views

- Spring Boot
- Spring Security
- Thymeleaf
- Tailwind CSS Feather Icons (for styling)
src/
├── main/
│ ├── java/
│ │ └── com/example/securing_web/
│ │ ├── WebSecurityConfig.java # Security configuration
│ │ ├── MvcConfig.java # MVC Configuration
│ │ └── SecuringWebApplication.java # Main application class
│ └── resources/
│ ├── templates/
│ │ ├── home.html # Public home page
│ │ ├── hello.html # Protected page
│ │ └── login.html # Login page
│ └── application.properties
@Configuration
@EnableWebSecurity
public class WebSecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests((requests) ->
requests
.requestMatchers("/", "/home").permitAll()
.anyRequest().authenticated()
)
.formLogin((form) ->
form
.loginPage("/login")
.permitAll()
)
.logout((logout) ->
logout.permitAll()
);
return http.build();
}
@Bean
public UserDetailsService userDetailsService() {
UserDetails user = User.withDefaultPasswordEncoder()
.username("user")
.password("password")
.roles("USER")
.build();
return new InMemoryUserDetailsManager(user);
}
}
- Public routes ("/", "/home") are accessible WITHOUT login
- All other routes require authentication
- Custom login page at "/login"
- In-memory user authentication (user/password)
- Route protection
- Authentication
- Login/Logout mechanisms
- User role management
- Clone the repository
git clone https://github.com/ProgrammerPratik/java-spring-security
cd java-spring-security
- Ensure Java version 23 and Maven are installed (this specific project uses java 23)
- Run
mvnw spring-boot:run
OR you can use any IDE like intellij to build and run project - Access at
http://localhost:8080
- Username:
superman
- Password:
password
- Understand Spring Security basics
- Implement authentication in Spring Boot
- Create protected and public routes
- Use Thymeleaf for dynamic views
MIT License