0Pricing
Spring Security 6 & JWT Authentication · Lezione

Comprendere la catena di filtri di Spring Security

Esamini il funzionamento interno di Spring Security 6 per capire come la catena di filtri servlet elabora ogni richiesta e quale ruolo svolge l'autenticazione.

Comprendere la catena di filtri di Spring Security è una lezione Spring Security 6 & JWT Authentication gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Spring Security 6 & JWT Authentication, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Spring Security 6 & JWT Authentication include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

How Requests Get Secured

So how does every request actually get checked? The security filter chain — a series of servlet filters Spring slots in before your controllers.

What Is a Servlet Filter?

A servlet Filter intercepts HTTP requests and responses before they reach your code. Spring Security is built almost entirely from these filters.

The DelegatingFilterProxy

The real servlet filter, DelegatingFilterProxy, hands each request to a Spring-managed bean — bridging the servlet world and the Spring context.

The FilterChainProxy

Behind that proxy sits FilterChainProxy, which holds one or more SecurityFilterChain instances and routes each request to the one that matches.

Key Filters in Order

Filters run in a fixed order: SecurityContextHolderFilter loads context, the auth filter handles login, and AuthorizationFilter enforces access rules.

Defining a SecurityFilterChain Bean

In Spring Security 6 you configure everything by declaring a SecurityFilterChain bean — the modern replacement for WebSecurityConfigurerAdapter. See below.

@Bean
SecurityFilterChain chain(HttpSecurity http) throws Exception {
    http.authorizeHttpRequests(a -> a.anyRequest().authenticated())
        .formLogin(Customizer.withDefaults());
    return http.build();
}

Where the SecurityContext Lives

After login, the Authentication is stored in the SecurityContext and stays reachable via SecurityContextHolder for the rest of the request.

Authentication auth = SecurityContextHolder.getContext().getAuthentication();

Permitting Some Paths

Let public paths through while securing the rest — all on the same chain. The code uses permitAll() for /public and authenticated() for everything else.

http.authorizeHttpRequests(a -> a
    .requestMatchers('/public/**').permitAll()
    .anyRequest().authenticated());

Multiple Filter Chains

Register several SecurityFilterChain beans with securityMatcher so API and web paths get different rules. The first matching chain wins.

http.securityMatcher('/api/**');

Adding a Custom Filter

Slot your own filter at a precise position with addFilterBefore — the foundation for the JWT processing you'll build later in this course.

http.addFilterBefore(myFilter, UsernamePasswordAuthenticationFilter.class);

Why This Matters

Knowing the chain explains why ordering matters, where auth versus authz happens, and exactly where a custom JWT filter has to plug in.

Quick Check

In Spring Security 6, how do you define your security configuration?

Recap

Recap: requests flow DelegatingFilterProxy to FilterChainProxy to SecurityFilterChain; filters run in order, auth then authz, and addFilterBefore inserts custom ones.

Domande Frequenti

La lezione «Comprendere la catena di filtri di Spring Security» è gratuita?

Sì — il testo completo di «Comprendere la catena di filtri di Spring Security» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Spring Security 6 & JWT Authentication, passa a CoddyKit PRO. Il corso Spring Security 6 & JWT Authentication include 4 lezioni in totale.

Cosa imparerò in «Comprendere la catena di filtri di Spring Security»?

Esamini il funzionamento interno di Spring Security 6 per capire come la catena di filtri servlet elabora ogni richiesta e quale ruolo svolge l'autenticazione. Eserciti Spring Security 6 & JWT Authentication con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Spring Security 6 & JWT Authentication?

Non è richiesta alcuna esperienza precedente. Spring Security 6 & JWT Authentication su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.

Quanto tempo richiede la lezione «Comprendere la catena di filtri di Spring Security»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Spring Security 6 & JWT Authentication?

Sì. Ogni lezione Spring Security 6 & JWT Authentication include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Introduzione a Spring Security 6
  2. Configurazione del progetto e dipendenze
  3. Autenticazione degli utenti in memoria
  4. Comprendere la catena di filtri di Spring Security
← Torna a Spring Security 6 & JWT Authentication