agentleFS
GitHubKnown publishergithub/awesome-copilot/skills/spring-security/SKILL.md

spring-security

Skill41k starsChanged 17 days agoMITView on GitHub

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.

  • Reads credentials

4 other projects use a version of this.

Adopted by

Steady: 0 new projects took it in the last 4 weeks, none the 4 weeks before.thin data

Week of Sep 13: 0 new projectsWeek of Sep 20: 0 new projectsWeek of Sep 27: 0 new projectsWeek of Oct 4: 0 new projectsWeek of Oct 11: 0 new projectsWeek of Oct 18: 0 new projectsWeek of Oct 25: 0 new projectsWeek of Nov 1: 0 new projects
Sep 2026Oct 2026Nov 2026
New projects taking a version of this file each week, over the 8 weeks our latest run read: only 0 in all, so this is a hint, not a trend.

Most recently taken up by

Who's talking about github/awesome-copilot

The biggest 5 of 86 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 86

Talked about on Bluesky, GitHub, YouTube, Hacker News and the web (86 times).

On Bluesky · 41

36 more on Bluesky

On GitHub · 34

29 more on GitHub

On YouTube · 5

On the web · 1

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 1 is distinctive, and 4 are very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Very specific:

    Never read, print, or commit secrets: .env, application-*.properties with credentials, client secrets, private keys, JWT signing keys.

    line 12
  2. Very specific:

    Never disable security (permitAll() on everything, csrf.disable() for browser apps) just to make a test or demo pass.

    line 13
  3. Very specific:

    Use multiple SecurityFilterChain beans with securityMatcher(...) and @Order when the app mixes an API and a browser UI.

    line 49
  4. Very specific:

    Add @EnableMethodSecurity and use @PreAuthorize/@PostAuthorize on services for fine-grained rules.

    line 50
  5. Distinctive:

    Run the app's tests plus security-specific tests (401 without credentials, 403 with insufficient role, 200 with the right one, CSRF …

    line 74

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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.

@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.
  • Authentication choices: OAuth2 resource server and JWT, OIDC login and OAuth2 client.
  • Session vs stateless, CSRF, CORS, headers: web protections.
  • Passwords and users: password encoding.
  • Actuator endpoints: actuator protection (see also the spring-observability skill if installed).
  • Tests: testing security.
  • Review: common mistakes checklist.

Decision guide

SituationApproach
REST API called by SPA/mobile/services with bearer tokensResource server + JWT, stateless, CSRF off (no cookie auth)
Server-rendered app or SPA with same-site cookie sessionForm login or OIDC login, sessions, CSRF on
SPA using BFF patternOIDC login in the backend, session cookie to browser, CSRF token via cookie repository
Internal service-to-serviceClient 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.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.