Back to Skills

spring-boot-security-jwt

Provides JWT authentication and authorization patterns for Spring Boot 3.5.x covering token generation with JJWT, Bearer/cookie authentication, database/OAuth2 integration, and RBAC/permission-based access control using Spring Security 6.x. Use when implementing authentication or authorization in Spring Boot applications.

304stars34forksUpdated 7/11/2026

Security Assessment

Low Risk(85/100)

Detected risks:

Agent-reviewed override(Spring Boot JWT security guide: 'Token =' refers to JWT tokens (the skill's subject), 'runAs' is the Spring Security test annotation, sudo is in troubleshooting, .env is config. Defensive security-hardening guidance.)
Security Score85/100

About spring-boot-security-jwt

Stateless JWT authentication and authorization patterns for Spring Boot 3.5.x applications, built on Spring Security 6.x and the JJWT 0.12.6 library. The skill walks through the full authentication flow: adding dependencies (the security starter, OAuth2 resource server, and the three JJWT artifacts), configuring JWT properties in application.yml, implementing a JwtService that generates access and refresh tokens and validates them, and building a JwtAuthenticationFilter that extends OncePerRequestFilter to pull a token from the Authorization: Bearer header or an HttpOnly cookie and populate the SecurityContext. A SecurityFilterChain bean wires stateless session management, permitted paths, an authentication provider, and the JWT filter registered before UsernamePasswordAuthenticationFilter. Authentication endpoints for /register, /authenticate, /refresh, and /logout return access and refresh tokens, optionally as cookies. Beyond the basics it covers refresh token rotation and revocation or blacklisting for logout, Bearer versus cookie strategies, and integration with Spring Data JPA and OAuth2 providers for social login with Google or GitHub. Authorization is enforced at the method level with @EnableMethodSecurity and @PreAuthorize expressions supporting role checks (hasRole), permission checks (hasAuthority), domain-object checks (hasPermission), and Spring bean checks. Configuration guidance emphasizes security: the signing secret must be at least 256 bits and never hardcoded, cookies should be HttpOnly and secure in production, and the issuer is validated on every token. Recommended lifetimes are 15 minutes for access tokens and 7 days for refresh tokens, expressed in milliseconds. Use it when securing a REST API or SPA backend with token-based authentication, setting up RBAC or permission-based access control, or adding OAuth2 login. Reference files supply the complete JwtService, the cookie-based filter variant, CORS and logout configuration, full property listings, and Maven and Gradle dependency snippets.

FAQ

Which framework and library versions does this target?

Spring Boot 3.5.x, Spring Security 6.x, and JJWT 0.12.6 (jjwt-api at compile scope, jjwt-impl and jjwt-jackson at runtime).

Can I use cookies instead of the Authorization header?

Yes. The JwtAuthenticationFilter can read the token from the Authorization: Bearer header or an HttpOnly cookie; the cookie name and http-only/secure flags are configurable, and cookies should be HttpOnly and secure in production.

How is method-level authorization enforced?

Enable @EnableMethodSecurity and use @PreAuthorize expressions such as hasRole('ADMIN'), hasAuthority('USER_READ'), hasPermission(#id, 'Doc', 'READ'), or a Spring bean check like @myService.canAccess(#id).

What token lifetimes are recommended?

The examples use 900000 ms (15 minutes) for the access token and 604800000 ms (7 days) for the refresh token, both set via configuration properties.

How should the signing secret be handled?

The jwt.secret must be at least 256 bits and never hardcoded; supply it via an environment variable such as ${JWT_SECRET}.

All Files

20 files
assets/generate-jwt-keys.sh3.8 KB
View
references/jwt-complete-configuration.md21.7 KB
View
references/microservices-security.md20.4 KB
View
references/security-hardening.md27.6 KB
View
references/token-management.md24.0 KB
View
references/configuration.md28.7 KB
View
references/jwt-quick-reference.md12.2 KB
View
references/oauth2-integration.md23.4 KB
View
references/testing-jwt-security.md27.8 KB
View
scripts/test-jwt-setup.sh7.7 KB
View
references/authorization-patterns.md20.4 KB
View
references/examples.md27.9 KB
View
references/jwt-configuration.md16.1 KB
View
references/jwt-testing-guide.md28.4 KB
View
references/migration-spring-security-6x.md14.1 KB
View
references/performance-optimization.md20.1 KB
View
references/structure.md5.1 KB
View
references/testing.md40.5 KB
View
references/troubleshooting.md23.1 KB
View
SKILL.md15.1 KB
View

Install spring-boot-security-jwt

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill