springboot-security

Configure Spring Security for authentication, authorization, and CSRF protection.

Updated Feb 11, 2026
One-click install
npx skills add https://github.com/shygoly/sapbase --skill springboot-security-shygoly
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: springboot-security
Source: https://github.com/shygoly/sapbase/tree/main/docs/zh-CN/skills/springboot-security
Command: npx skills add https://github.com/shygoly/sapbase --skill springboot-security-shygoly

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Java Spring Boot 服务在身份验证/授权、输入验证、CSRF、密钥、标头、速率限制和依赖安全方面存在风险。本 Skill 提供一套最佳实践,帮助开发团队在代码和配置中实现强安全策略。

Core Features & Use Cases

  • 优先使用无状态 JWT 或带撤销列表的不透明令牌
  • 使用 httpOnly、Secure、SameSite=Strict 的 cookie 以保护会话
  • 启用方法安全:@EnableMethodSecurity,并通过 @PreAuthorize 等进行粒度访问控制
  • CSRF 保护,依赖项安全和密钥外部化,提升整体防护

Quick Start

配置 Spring Boot 应用以应用上述身份验证、授权、CSRF、密钥管理、头部安全、速率限制和依赖安全的最佳实践。

Frequently Asked Questions about springboot-security

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I configure JWT authentication in Spring Boot?

Configure JWT authentication in Spring Boot by prioritizing stateless JWTs or opaque tokens with revocation lists. This approach ensures robust API security by validating tokens externally and managing secure keys properly across microservices and monoliths.

How do I enable method-level authorization in Spring Security?

Enable method-level authorization in Spring Security using @EnableMethodSecurity. Apply @PreAuthorize annotations to enforce granular access control directly within your Spring Boot services, securing endpoints based on user roles and permissions across microservices and monoliths.

What is the best way to secure cookies in Spring Boot applications?

The best way to secure cookies in Spring Boot is configuring them with httpOnly, Secure, and SameSite=Strict attributes. This combination protects session tokens from cross-site scripting (XSS) and cross-site request forgery (CSRF) attacks effectively.

Does Spring Security work for both microservices and monolith architectures?

Yes, Spring Security works for both microservices and monolith architectures. You can enforce robust authentication, token validation, and CSRF protection consistently across distributed services or single monolithic Spring Boot applications using centralized configuration.

How do I externalize secret keys for Spring Boot microservices?

Externalize secret keys for Spring Boot microservices by moving them out of source code into environment variables or secure vaults. This practice prevents credential leakage and ensures proper token validation and key management across your distributed deployment.

Why do I need CSRF protection for stateless APIs?

You need CSRF protection for stateless APIs to prevent cross-site request forgery vulnerabilities. Even with token validation, applying CSRF protection alongside secure headers defends against session hijacking and ensures robust API security across microservices.