Skip to content
Back to skills

Spring Boot Security

ASecurity

Spring Security 7 implementation for Spring Boot 4. Use when configuring authentication, authorization, OAuth2/JWT resource servers, method security, or CORS/CSRF. Covers the mandatory Lambda DSL migration, SecurityFilterChain patterns, @PreAuthorize, and password encoding. For testing secured endpoints, see spring-boot-testing skill.

  • 21 stars
  • 0 votes
  • 0 copies
  • 23 views
  • Added February 8, 2026
securitygojavakotlinspringtestingapisecurity

Works with

  • api

Security analysis

A100/100

Pro scans all 6 files and shows the line behind each finding

Scanned February 10, 2026

npx -y skills add joaquimscosta/arkhe-claude-plugins --skill spring-boot-security --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Spring Boot Security?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Spring Boot Security
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/joaquimscosta-spring-boot-security/badge)](https://www.skillsdirectory.com/skills/joaquimscosta-spring-boot-security)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: spring-boot-security
description: Spring Security 7 implementation for Spring Boot 4. Use when configuring authentication, authorization, OAuth2/JWT resource servers, method security, or CORS/CSRF. Covers the mandatory Lambda DSL migration, SecurityFilterChain patterns, @PreAuthorize, and password encoding. For testing secured endpoints, see spring-boot-testing skill.
---

# Spring Security 7 for Spring Boot 4

Implements authentication and authorization with Spring Security 7's mandatory Lambda DSL.

## Critical Breaking Changes

| Removed API | Replacement | Status |
|-------------|-------------|--------|
| `and()` method | Lambda DSL closures | **Required** |
| `authorizeRequests()` | `authorizeHttpRequests()` | **Required** |
| `antMatchers()` | `requestMatchers()` | **Required** |
| `WebSecurityConfigurerAdapter` | `SecurityFilterChain` bean | **Required** |
| `@EnableGlobalMethodSecurity` | `@EnableMethodSecurity` | **Required** |

## Core Workflow

1. **Create SecurityFilterChain bean** → Configure with Lambda DSL
2. **Define authorization rules** → `authorizeHttpRequests()` with `requestMatchers()`
3. **Configure authentication** → Form login, HTTP Basic, or OAuth2
4. **Add method security** → `@EnableMethodSecurity` + `@PreAuthorize`
5. **Handle CORS/CSRF** → Configure for REST APIs

## Quick Patterns

See [EXAMPLES.md](EXAMPLES.md) for complete working examples including:
- **REST API Security** with JWT/OAuth2 (Java + Kotlin)
- **Form Login with Session Security** and CSRF
- **Method Security** with @PreAuthorize and SpEL
- **CORS Configuration** for cross-origin APIs
- **Password Encoder** (Argon2 for Security 7)

## Spring Boot 4 Specifics

- **Lambda DSL** is mandatory (no `and()` chaining)
- **Argon2** password encoder: `Argon2PasswordEncoder.defaultsForSpring7()`
- **CSRF for SPAs**: `CookieCsrfTokenRepository.withHttpOnlyFalse()`
- **@EnableMethodSecurity** replaces `@EnableGlobalMethodSecurity`

## Detailed References

- **Examples**: See [EXAMPLES.md](EXAMPLES.md) for complete working code examples
- **Troubleshooting**: See [TROUBLESHOOTING.md](TROUBLESHOOTING.md) for common issues and Boot 4 migration
- **Security Configuration**: See [references/SECURITY-CONFIG.md](references/SECURITY-CONFIG.md) for complete SecurityFilterChain patterns
- **Authentication**: See [references/AUTHENTICATION.md](references/AUTHENTICATION.md) for UserDetailsService, password encoding
- **JWT/OAuth2**: See [references/JWT-OAUTH2.md](references/JWT-OAUTH2.md) for resource server, token validation

## Anti-Pattern Checklist

| Anti-Pattern | Fix |
|--------------|-----|
| Using `and()` chaining | Use Lambda DSL closures |
| `antMatchers()` | Replace with `requestMatchers()` |
| `authorizeRequests()` | Replace with `authorizeHttpRequests()` |
| CSRF disabled without JWT | Keep CSRF for session-based auth |
| Hardcoded credentials | Use environment variables or Secret Manager |
| `permitAll()` on sensitive endpoints | Audit all permit rules |
| Missing `authenticated()` default | End with `.anyRequest().authenticated()` |

## Critical Reminders

1. **Lambda DSL is mandatory** — No more `and()` chaining in Security 7
2. **Order matters** — More specific `requestMatchers` before general ones
3. **CSRF for sessions** — Only disable for stateless JWT APIs
4. **Method security needs enabling** — Add `@EnableMethodSecurity`
5. **Test security configuration** — Use `@WithMockUser` and JWT test support (see `spring-boot-testing`)

Files in this skill

  • EXAMPLES.md5.6 KB
  • SKILL.md3.4 KB
  • TROUBLESHOOTING.md6.1 KB
  • references/authentication.md11.6 KB
  • references/jwt-oauth2.md14.3 KB
  • references/security-config.md11.7 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in security →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.