Skip to main content
skill CX Codex official · GitHub

spring-security — GitHub Copilot skill: setup and install

A GitHub Copilot skill for configuring, testing, and reviewing Spring Security. It activates when adding or auditing authentication and authorization in a Spring Boot app.

MIT ★ 41,430 updated 2026-10-23

Install into GitHub Copilot · GitHub CLI All methods and platforms ↓
gh skill install github/awesome-copilot skills/spring-security
Open on GitHub

What spring-security does

The skill covers SecurityFilterChain rules, method-level access controls, JWT resource servers, and OIDC login. It also guides checks for CSRF, CORS, password encoding, actuator endpoints, and MockMvc security tests.

First identify the Spring Boot and Spring Security versions, then determine whether the app uses servlet MVC or WebFlux and whether it relies on browser sessions or a stateless API. Boot 3.x pairs with Spring Security 6.x; Boot 4.x pairs with 7.x. Guidance differs between these versions, and some APIs deprecated in 6.x are removed in 7.x.

What it helps with

  • configure access rules with SecurityFilterChain
  • add method-level authorization
  • choose a security approach for an API or browser app
  • test 401, 403, and 200 responses
  • spot exposed endpoints and security configuration mistakes

Example prompts for the agent

  • Set up SecurityFilterChain for my API with JWT and role checks.
  • Review Spring Security in this Spring Boot 4 app and find exposed endpoints.
  • Add MockMvc security tests for 401, 403, and 200 responses.

How to install spring-security

1GitHub CLI

gh skill install github/awesome-copilot skills/spring-security

2Manually: put the files in place

.github/skills/spring-security/SKILL.md

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about spring-security

How do I install spring-security in GitHub Copilot?

Run gh skill install github/awesome-copilot skills/spring-security. The skill file is installed at .github/skills/spring-security/SKILL.md.

What does spring-security do?

It helps configure and review authentication and authorization in Spring Boot apps, including filter-chain rules and security tests.

Which Spring Security versions does spring-security cover?

It covers Spring Security 6.x with Spring Boot 3.x and 7.x with Boot 4.x. Some APIs deprecated in 6.x have been removed in 7.x.

Source text

SKILL.md · MIT
---
name: spring-security
description: 'Configure, 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.'
---

# Spring Security

Practical guidance for Spring Security 6.x (Spring Boot 3.x) and 7.x (Spring Boot 4.x). Details per topic are in `references/`.

## Safety rules

- Never read, print, or commit secrets: `.env`, `application-*.properties` with credentials, client secrets, private keys, JWT signing keys. Reference them via environment variables or a secret manager.
- Never disable security (`permitAll()` on everything, `csrf.disable()` for browser apps) just to make a test or demo pass.

## First: detect the version

1. Find the Boot version (`pom.xml` parent/BOM, `build.gradle(.kts)`, `libs.versions.toml`) and run `./mvnw dependency:tree -Dincludes=org.springframework.security` or `./gradlew dependencies --configuration runtimeClasspath` to see the Spring Security version.
2. Boot 3.x -> Security 6.x; Boot 4.x -> Security 7.x. Do not mix guidance: in 7.x, APIs deprecated in 6.x are removed (for example `and()` chaining, `authorizeRequests`, `AntPathRequestMatcher`/`MvcRequestMatcher` style matchers; use the lambda DSL and `requestMatchers(...)`). Check the "What's New" and migration pages on docs.spring.io/spring-security when upgrading.
3. Identify the app type: servlet MVC (`SecurityFilterChain`) or WebFlux (`SecurityWebFilterChain`, `@EnableWebFluxSecurity`); browser app with sessions, or stateless API.

## Core configuration

Declare a `SecurityFilterChain` bean. `WebSecurityConfigurerAdapter` no longer exists.

```java
@Configuration
@EnableWebSecurity
@EnableMethodSecurity
class SecurityConfig {

    @Bean
    SecurityFilterChain api(HttpSecurity http) throws Exception {
        http
            .authorizeHttpRequests(auth -> auth
                .requestMatchers("/actuator/health/**", "/public/**").permitAll()
                .requestMatchers("/admin/**").hasRole("ADMIN")
                .anyRequest().authenticated())
            .oauth2ResourceServer(oauth2 -> oauth2.jwt(Customizer.withDefaults()))
            .sessionManagement(s -> s.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
            .csrf(csrf -> csrf.disable()); // only for stateless token APIs without cookies
        return http.build();
    }
}
```

Rules of thumb:

- Rules are evaluated in order; put specific matchers first and end with `anyRequest().authenticated()` (deny by default).
- Use multiple `SecurityFilterChain` beans with `securityMatcher(...)` and `@Order` when the app mixes an API and a browser UI.
- Add `@EnableMethodSecurity` and use `@PreAuthorize`/`@PostAuthorize` on services for fine-grained rules; see [method security](references/method-security.md).
- Authentication choices: [OAuth2 resource server and JWT](references/oauth2-resource-server-jwt.md), [OIDC login and OAuth2 client](references/oidc-login-oauth2-client.md).
- Session vs stateless, CSRF, CORS, headers: [web protections](references/csrf-cors-sessions-headers.md).
- Passwords and users: [password encoding](references/password-encoding.md).
- Actuator endpoints: [actuator protection](references/actuator-protection.md) (see also the `spring-observability` skill if installed).
- Tests: [testing security](references/testing-security.md).
- Review: [common mistakes checklist](references/review-checklist.md).

## Decision guide

| Situation | Approach |
|---|---|
| REST API called by SPA/mobile/services with bearer tokens | Resource server + JWT, stateless, CSRF off (no cookie auth) |
| Server-rendered app or SPA with same-site cookie session | Form login or OIDC login, sessions, CSRF on |
| SPA using BFF pattern | OIDC login in the backend, session cookie to browser, CSRF token via cookie repository |
| Internal service-to-service | Client credentials grant, resource server on the receiving side |

## Dependencies (pin through the Boot BOM, no explicit versions)

- `spring-boot-starter-security`, plus `spring-boot-starter-oauth2-resource-server` or `spring-boot-starter-oauth2-client` on Boot 3.x. Boot 4.x names: `spring-boot-starter-security-oauth2-resource-server` / `spring-boot-starter-security-oauth2-client` (the old names remain as deprecated aliases).
- Tests: add `spring-security-test` (test scope) on Boot 3.x; on Boot 4.x use `spring-boot-starter-security-test` (plus `spring-boot-starter-security-oauth2-resource-server-test` / `-client-test` when those starters are used) together with modular test starters such as `spring-boot-starter-webmvc-test`.

## Verify

Run the app's tests plus security-specific tests (401 without credentials, 403 with insufficient role, 200 with the right one, CSRF rejection on state-changing browser requests). Confirm no endpoint was accidentally left open by listing the mappings and checking each against the filter chain.

See also (prefer over this skill for the version in use): Spring Security reference <https://docs.spring.io/spring-security/reference/index.html> and migration chapter <https://docs.spring.io/spring-security/reference/migration/index.html>.

© github · MIT · github/awesome-copilot

Similar skills

All skills for Security →

From the same set993

The whole set →
pr-address-feedback The pr-address-feedback skill steps through pull request review comments one by one, groups repeated patterns, and builds a resolution plan before editing files. Useful for triaging review feedback. CX Codex +1 2installs java-testcontainers java-testcontainers helps write Java integration tests using Testcontainers 2.x and JUnit Jupiter with Docker dependencies. Useful when adding container tests or migrating from version 1.x. CX Codex +1 1installs java-debugging java-debugging — a skill that walks the agent through finding a Java bug: reproduce, narrow down, test one hypothesis, attach a debugger. Useful once logs stop explaining anything. CX Codex +1 1installs supabase-rls-policies supabase-rls-policies — a skill for GitHub Copilot that designs, audits, and tests Supabase Row Level Security policies. Runs when drafting migrations, changing exposed tables, or verifying tenant isolation. CX Codex +1 ★ 41,430repo stars spring-observability spring-observability — a GitHub Copilot skill that sets up and audits observability in Spring Boot 3 and 4 services. Runs when adding Micrometer metrics, OpenTelemetry tracing, and structured logging around Actuator. CX Codex +1 ★ 41,430repo stars spring-boot-4-migration The spring-boot-4-migration GitHub Copilot skill guides Spring Boot 3.x projects through a move to 4.0. It also handles migration-related build or test failures and reviews an existing upgrade. CX Codex +1 ★ 41,430repo stars skill-distribution-audit skill-distribution-audit — a GitHub Copilot skill that validates skill collections before release. Reconciles source repositories against distribution manifests and actual discovery output. CX Codex +1 ★ 41,430repo stars scout-issue The scout-issue GitHub Copilot skill finds open GitHub issues that fit a developer’s contribution goals. It asks about skills, experience, available time, and contribution type before ranking candidates. CX Codex +1 ★ 41,430repo stars

Project sponsors

Companies that keep this analytics open