The spring-boot-starter-security dependency adds Spring Security to a Spring Boot application and applies secure defaults immediately. Once it is on the classpath, every HTTP endpoint requires authentication, a generated user and password are created, CSRF protection and security headers are switched on, and you can replace any default with your own SecurityFilterChain bean.
It is the standard way to get authentication, authorization and protection against common web attacks without writing the plumbing yourself.
The starter includes spring-security-config, spring-security-web and spring-aop, plus the core Spring Boot starter. It does not include OAuth2, SAML or testing support, which have their own artifacts such as spring-boot-starter-oauth2-resource-server, spring-boot-starter-oauth2-client and spring-security-test.
With no other configuration, Spring Boot auto-configures the following for a servlet web application:
user is created with a random password printed to the log at startup (look for Using generated security password).X-Content-Type-Options and Cache-Control are added, and session fixation protection is on.You can change the default user with properties, which is useful only for local development:
To customise the rules, declare a SecurityFilterChain bean. Once you do, Boot's default chain backs off. The WebSecurityConfigurerAdapter class was removed in Spring Security 6, so the component-based style below is the only supported approach.
The lambda DSL shown here is the current style. authorizeHttpRequests replaced the older authorizeRequests. For a stateless REST API that uses tokens instead of browser sessions, you would typically disable form login, set the session policy to stateless and add an OAuth2 resource server or a JWT filter. Only disable CSRF when the API is truly stateless and does not rely on cookies.
Authentication needs a source of users. Provide a UserDetailsService bean that loads users from your database, or use the in-memory and JDBC implementations for simple cases:
Never store plain-text passwords. The delegating encoder hashes with bcrypt by default and stores an identifier prefix, so you can migrate to stronger algorithms later. Spring Security also provides Argon2PasswordEncoder and SCryptPasswordEncoder.
@EnableMethodSecurity activates annotations that guard service methods, not only URLs:
Use @PreAuthorize and @PostAuthorize for expressions, and keep URL rules as a coarse first layer.
Add spring-security-test as a test dependency. Then @WithMockUser(roles = "ADMIN") runs a test as an authenticated user, and SecurityMockMvcRequestPostProcessors.csrf() adds a valid CSRF token to MockMvc requests.
That is the default: all endpoints are protected. Add a SecurityFilterChain that permits the paths you want to be public.
It is logged at startup by UserDetailsServiceAutoConfiguration. It changes on every run unless you set spring.security.user.password.
WebSecurityConfigurerAdapter still available?No. It was deprecated in Spring Security 5.7 and removed in version 6. Use a SecurityFilterChain bean.
Not by itself. Add the OAuth2 resource server or client starters for those features.
spring-boot-starter-security gives a Spring Boot application secure defaults with a single dependency: authentication on every endpoint, CSRF protection, security headers and a generated user. Replace the defaults with a SecurityFilterChain bean, a UserDetailsService and a strong PasswordEncoder, and add method security and the dedicated OAuth2 starters as your needs grow.