---
name: "spring-security-oauth2-resource-server"
description: "Secure Spring Boot REST APIs with stateless JWT validation and method security."
metadata:
  author: "Spring"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "configure spring security 6 jwt"
  - "spring oauth2 resource server"
  - "@preauthorize hasrole spring"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Spring Security 6 OAuth2 JWT Resource Server

Configures Spring Security 6: SecurityFilterChain bean, oauth2ResourceServer(jwt), JwtAuthenticationConverter for mapping roles to authorities, and enforcing method-level security with @PreAuthorize('hasRole("ADMIN")').

## When to Invoke
Invoke this skill whenever you need to:
- configure spring security 6 jwt
- spring oauth2 resource server
- @preauthorize hasrole spring

## Execution SOP & Rules
1. Define SecurityFilterChain bean with http.authorizeHttpRequests(...).oauth2ResourceServer(oauth2 -> oauth2.jwt(...)).
2. Configure spring.security.oauth2.resourceserver.jwt.issuer-uri in application.yml.
3. Implement custom JwtAuthenticationConverter to map nested role claims into 'ROLE_USER' format.
4. Enable method security with @EnableMethodSecurity at configuration root.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
