github/awesome-copilot / skills/spring-security
spring-security
UnverifiedConfigure, test and review Spring Security 6/7 in Spring Boot 3/4 apps: SecurityFilterChain lambda DSL, method security, OAuth2 resource server with JWT, OIDC login, CSRF/CORS, password encoding, headers, actuator protection, and MockMvc security tests. Use when adding or auditing authentication and authorization.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 5.2 KB |
| references/actuator-protection.md | markdown | 2.0 KB |
| references/csrf-cors-sessions-headers.md | markdown | 3.4 KB |
| references/method-security.md | markdown | 1.4 KB |
| references/oauth2-resource-server-jwt.md | markdown | 2.9 KB |
| references/oidc-login-oauth2-client.md | markdown | 2.0 KB |
| references/password-encoding.md | markdown | 650 B |
| references/review-checklist.md | markdown | 729 B |
| references/testing-security.md | markdown | 3.8 KB |
references/method-security.md
View on GitHub# Method security
Enable with `@EnableMethodSecurity` on a `@Configuration` class (replaces `@EnableGlobalMethodSecurity`). `@PreAuthorize`, `@PostAuthorize`, `@PreFilter`, `@PostFilter` are on by default; `@Secured` and JSR-250 need `securedEnabled = true` / `jsr250Enabled = true`.
```java
@Service
class DocumentService {
@PreAuthorize("hasRole('ADMIN') or #owner == authentication.name")
List<Document> findByOwner(String owner) { ... }
@PreAuthorize("hasAuthority('SCOPE_documents.write')")
void save(Document d) { ... }
@PostAuthorize("returnObject.owner == authentication.name")
Document load(Long id) { ... }
}
```
Guidance:
- `hasRole('ADMIN')` checks authority `ROLE_ADMIN`; `hasAuthority('SCOPE_x')` checks the exact string. JWT scopes become `SCOPE_` authorities by default.
- Put annotations on service-layer methods (or controllers), never on private methods or on self-invoked calls: they rely on proxies and are bypassed.
- Prefer a custom bean for complex rules: `@PreAuthorize("@documentAuth.canEdit(#id, authentication)")`.
- Meta-annotations keep rules readable: `@Target(METHOD) @Retention(RUNTIME) @PreAuthorize("hasRole('ADMIN')") @interface IsAdmin {}`.
- Method security complements, not replaces, URL rules: keep a deny-by-default filter chain.
- Test with `@WithMockUser` (see [testing](testing-security.md)); a missing proxy shows up as a test passing with no authentication.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 464k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 464k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 464k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 192k | Updated | Claude CodeCodex | Verified | Install |