Przejdź do treści
Biblioteka skilli
Bezpieczeństwo · Budowanie i kod

spring-security

/spring-security

Konfiguruje, testuje i przegląda Spring Security 6 i 7: łańcuch filtrów, OAuth2 z JWT, logowanie OIDC, CSRF i CORS.

Licencja
MIT
Ostatnia zmiana repozytorium
13.11.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
9
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
2
Przestarzałość

Brak sygnałów. Repozytorium zmienione 13.11.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Konfiguruje, testuje i przegląda Spring Security 6 i 7: łańcuch filtrów, OAuth2 z JWT, logowanie OIDC, CSRF i CORS.

Oryginalny opis (EN)

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.

Jak działa

  1. Safety rules
  2. First: detect the version
  3. Core configuration
  4. Decision guide
  5. Dependencies (pin through the Boot BOM, no explicit versions)
  6. Verify
Sekcje z nagłówków SKILL.md, w oryginale · 73 linii, 537 słów
Podgląd SKILL.md
---
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>.
Pliki w paczce (9)
  • SKILL.md 5 KB
  • references/actuator-protection.md 2 KB
  • references/csrf-cors-sessions-headers.md 3 KB
  • references/method-security.md 1 KB
  • references/oauth2-resource-server-jwt.md 3 KB
  • references/oidc-login-oauth2-client.md 2 KB
  • references/password-encoding.md 1 KB
  • references/review-checklist.md 1 KB
  • references/testing-security.md 4 KB

Wersje

RepozytoriumWynikLicencja
Ta strona · github/awesome-copilot100MIT
swap-cameroon/kuro-antigravity-config100MIT
claude-dev-suite/claude-dev-suite100MIT

Migawka bazy z 13.11.2026 · wersja paczki 0f8684661cc9 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100spring-boot-security
    Wspiera Spring Security 7 w Spring Boot 4: uwierzytelnianie, autoryzacja, serwery zasobów OAuth2 i JWT, zabezpieczenia metod, CORS i CSRF, z obowiązkową migracją na Lambda DSL.
  • 100304-frameworks-spring-boot-security
    Projektuje i sprawdza bezpieczeństwo aplikacji Spring Boot: filtry, OAuth2 i JWT, CSRF, CORS, nagłówki i bezpieczne logowanie.
  • 95backend-spring-security
    Przegląda konfigurację Spring Security: łańcuchy filtrów, kodowanie haseł, CSRF i CORS, zabezpieczenia metod, sesje oraz JWT i OAuth2.
  • 100spring-boot-security
    Konfiguruje Spring Security 6+ z Lambda DSL, JWT i regułami hardeningu, także dla OAuth2.
  • 100spring-testing-security
    Testuje zabezpieczenia Spring Security: atrapy użytkowników, CSRF, reguły dostępu i komponenty uwierzytelniania.
  • 100spring-security-6
    Migruje konfigurację Spring Security 5 do Spring Security 6: usuwa WebSecurityConfigurerAdapter, zamienia @EnableGlobalMethodSecurity i antMatchers oraz przechodzi na lambda DSL.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.