Skip to content
Tutorials Center
My learning

Topics

Spring Security Tutorial

Learn Spring Security step by step: 39 lessons in 9 chapters with examples, quizzes, diagrams and projects.

Start learning →

of lessons completed

Getting Started

  1. 1 Introduction to Spring Security What Spring Security is, what problems it solves, how authentication differs from authorization, and how this course teaches it with runnable Java stand-ins.
  2. 2 Your First Secured Spring Application Add the Spring Security starter to a Boot app, see the generated password and login page, and learn exactly what the framework does before you configure anything.
  3. 3 Core Concepts: Authentication, SecurityContext and Authorities Learn the types every Spring Security feature builds on: Authentication, GrantedAuthority, SecurityContext, SecurityContextHolder, and how the context travels between threads.
  4. 4 Boot Auto-Configuration and Security Defaults Understand how Spring Boot configures Spring Security for you, which beans it creates, when it backs off, and which properties and defaults you can change.

Filter Chain and Configuration

  1. 5 The Spring Security Filter Chain, Step by Step Follow a request through DelegatingFilterProxy, FilterChainProxy and the ordered security filters, and learn to read the filter list from the debug log.
  2. 6 The SecurityFilterChain Bean and the Lambda DSL Write modern Spring Security configuration with a SecurityFilterChain bean, HttpSecurity and lambda customizers, and migrate old WebSecurityConfigurerAdapter code.
  3. 7 Request Matchers and Authorization Rules Master authorizeHttpRequests, requestMatchers, path patterns, HTTP methods and first-match-wins rule ordering, and avoid the rule mistakes that leave URLs open.
  4. 8 Multiple SecurityFilterChains in One Application Use several SecurityFilterChain beans with securityMatcher and @Order to give an API token security and a web UI session login in the same Spring Boot application.
  5. 9 Writing Custom Security Filters Write your own servlet filter for Spring Security, place it with addFilterBefore and addFilterAfter, and learn how an API-key filter fits into the chain.
  6. 10 Exception Handling: Entry Points and Access Denied Understand ExceptionTranslationFilter, the difference between 401 and 403, and write a custom AuthenticationEntryPoint and AccessDeniedHandler returning JSON.

Authentication Mechanisms

  1. 11 Form Login and Logout in Spring Security Configure formLogin with a custom page, success and failure handlers, understand the session cookie flow, and set up a safe POST-based logout.
  2. 12 HTTP Basic and Stateless Authentication Learn how HTTP Basic works, configure it in Spring Security, make an API stateless with SessionCreationPolicy.STATELESS, and know when Basic is and is not safe.
  3. 13 UserDetailsService, UserDetails and Password Encoders Load users with UserDetailsService, model accounts with UserDetails, hash passwords with DelegatingPasswordEncoder and upgrade old hashes without forcing resets.
  4. 14 AuthenticationManager, ProviderManager and Custom Providers See how ProviderManager asks each AuthenticationProvider in turn, how supports() selects one, and how to write a custom provider for one-time codes or API keys.
  5. 15 JDBC User Stores and Custom Schemas Store users in a database with JdbcUserDetailsManager, learn its default schema, then write your own queries for a custom users table with authorities and lockout fields.
  6. 16 Remember-Me, Session Management and Fixation Understand remember-me cookies (hash-based and persistent token), session fixation protection, concurrent session limits and timeouts, and how to choose safe defaults.

Authorization and Method Security

  1. 17 Roles, Authorities and Role Hierarchies Learn the difference between roles and authorities, the ROLE_ prefix rule, how hasRole and hasAuthority work, and how to model permissions and role hierarchies cleanly.
  2. 18 Method Security with @PreAuthorize and @PostAuthorize Protect service methods with @EnableMethodSecurity, @PreAuthorize, @PostAuthorize and @PreFilter, and understand why it works through proxies and what self-invocation breaks.
  3. 19 SpEL Security Expressions and PermissionEvaluator Write security expressions with SpEL, use method arguments, returnObject and bean references, and implement a PermissionEvaluator for hasPermission checks on domain objects.
  4. 20 The AuthorizationManager API and Custom Rules Learn how AuthorizationManager powers URL and method security, write a custom manager for IP, time or tenant rules, and combine managers with AND, OR and deny-by-default.

JWT and OAuth2 Resource Server

  1. 21 JWT Structure: Header, Payload and Signature Learn how a JSON Web Token is built: header, claims payload and signature, Base64URL encoding, registered claims and why a JWT is signed but not secret.
  2. 22 Signing and Validating JWTs Sign and verify JWTs the safe way: HMAC versus RSA keys, constant-time comparison, expiry and clock skew, and why the alg none and algorithm confusion attacks work.
  3. 23 OAuth2 Resource Server Configuration Configure a Spring Security JWT resource server: oauth2ResourceServer, JwtDecoder, issuer and audience validation, scopes to authorities, and 401 versus 403.
  4. 24 Refresh Tokens, Rotation and Revocation Design short-lived access tokens with refresh tokens: rotation, reuse detection, a jti denylist for logout, and where to store tokens safely in browsers and apps.

OAuth2 Login and OIDC

  1. 25 OAuth2 Roles and Grant Types Explained Understand OAuth2: the four roles, the authorization code flow step by step, state and redirect URI checks, and which grant type fits web apps, SPAs and services.
  2. 26 PKCE Explained: Proof Key for Code Exchange Learn PKCE for OAuth2: code verifier, S256 code challenge, the attack it prevents, how Spring Security enables it, and a runnable Java demonstration.
  3. 27 OIDC Login and ID Tokens in Spring Security Add Log in with Google or Keycloak using oauth2Login: client registration properties, the OIDC ID token, nonce, claim validation and a runnable validator in Java.
  4. 28 Custom User Mapping and Authorities for OAuth2 Login Map OAuth2 and OIDC logins to your own users: OAuth2UserService, OidcUserService, GrantedAuthoritiesMapper, auto-provisioning and role claims, with runnable stand-ins.

CSRF, CORS and Headers

  1. 29 CSRF Protection in Spring Security Understand cross-site request forgery and how Spring Security stops it: synchronizer tokens, SameSite cookies, SPA setups, BREACH masking and when to disable CSRF.
  2. 30 CORS Configuration with Spring Security Understand CORS and configure it correctly in Spring Security: same-origin policy, preflight requests, allowed origins, credentials, Vary header and common mistakes.
  3. 31 Security Headers and Session Protection Configure Spring Security response headers (HSTS, CSP, frame options, nosniff), cookie flags and session fixation protection, with runnable Java stand-ins.

Testing and Hardening

  1. 32 Testing Secured Endpoints in Spring Security Test Spring Security rules with MockMvc: @WithMockUser, jwt() and csrf() request post-processors, 401 and 403 checks, a test matrix and a runnable Java test harness.
  2. 33 Password Storage, Hashing and Migration Store passwords safely: salted slow hashes, DelegatingPasswordEncoder with id prefixes, bcrypt and Argon2 choices, upgrading old hashes at login and a runnable PBKDF2 demo.
  3. 34 Login Throttling and Rate Limiting Stop password guessing and credential stuffing: failed-attempt counters, account lockout trade-offs, per-IP limits, token buckets, uniform error messages and a runnable stand-in.
  4. 35 Security Audit Events and Logging Record who did what: authentication and authorization events, structured audit logs, what never to log, masking secrets and a runnable event-bus stand-in for Spring Security.
  5. 36 Production Hardening Checklist for Spring Security Harden a Spring Security app before launch: HTTPS and HSTS, secrets, actuator exposure, error messages, default deny, dependency updates and a runnable configuration audit.

Projects and Practice

  1. 37 Project: A Secure Notes API with Token Auth Build a notes API step by step: signed tokens, stateless filter, scopes, per-owner access checks and tests. Full Spring Security code is read-only, a runnable Java stand-in shows the logic.
  2. 38 Project: A Role-Based Admin Console with Sessions Plan a server-rendered admin console: form login, roles and a role hierarchy, session fixation protection, CSRF tokens and audit trail, with a runnable Java stand-in of the rules.
  3. 39 Practice: Reviewing Spring Security Code Sharpen your eye with Spring Security review exercises: rule ordering, path matching bugs, missing ownership checks, weak tokens and unsafe CORS, each with a runnable demonstration.