Basic Tutorial
Queries
Spring Security is a powerful and customizable framework used to secure Java applications. It provides authentication, authorization, and protection against common security threats.
Spring Security is a framework that provides:
Key Features
Secure endpoints with minimal configuration
Support for various authentication methods (DB, LDAP, OAuth2, JWT)
Method-level security (@PreAuthorize
, @PostAuthorize
)
Built-in password hashing (BCrypt, PBKDF2)
Spring Boot simplifies security by auto-configuring it when you add the dependency.
Once the application is running, test the endpoints:
When you add spring-boot-starter-security
, Spring Boot:
Default Login Credentials Check the generated password in logs:
Once the application is running, test the endpoints:
Set Basic Auth Username and Password
SecurityAutoConfiguration
Spring Boot auto-configures security through SecurityAutoConfiguration
, which:
How does it work? Spring Boot detects spring-boot-starter-security
and applies the default security settings.
🔹 To customize security, you must override the default security configuration.
If you want to disable security (not recommended in production):
SecurityAutoConfiguration
Add this to your application.properties
file:
Or exclude it in the main class:
A better approach is to override the default security settings using SecurityFilterChain
will explain later topics.
✅ This will disable the default security but allows you to implement custom authentication.