
Welcome to this course ! Let me explain what is the agenda of this course
Build a Spring Boot web application and secure backend APIs with Spring Security, exploring start.spring.io setup, Java versions, Maven, dev tools, and essential IDE workflows.
Create a simple spring boot rest API by renaming the main class to EasyBankBackendApplication, adding WelcomeController with a /welcome get endpoint, and configure logging patterns and port 8080.
Add the spring security starter, then configure static credentials in application properties to secure a spring boot web app; define spring.security.user.name and spring.security.user.password for login.
Learn why security matters for web applications, explore encryption, hashing, and base64 encoding, understand different securities, and see how spring security helps, with memes illustrating common pitfalls.
In this video, we will discuss on what is security and why it is important for any web application
Explore how servlets and filters shape the Spring security internal flow, learn how servlet containers convert http requests and how filters intercept and enforce authentication for rest and mvc paths.
This video will explain how Spring Security process a income request internally every time and the architecture associated to it
This lecture demonstrates Spring Security internal flow with a Spring Boot app, showing how the authorization filter blocks unauthenticated access and redirects to a generated login page.
Explore how Spring Security processes a login through the internal filter chain, including username/password extraction, authentication with the provider manager, dao authentication, and updating the security context.
Discover the default Spring Security sequence flow: client, filters, UsernamePasswordAuthenticationFilter, ProviderManager, DaoAuthenticationProvider, InMemoryUserDetailsManager, PasswordEncoder, and the security context enabling the rest API.
In this video, we will see how spring security framework works in the case of multiple requests after authentication where it will not ask for credentials again and again.
Explore the EasyBank UI architecture with a separate Angular front end and Spring Boot backend, and learn how public and secured REST APIs power login and dashboard access.
Build and rename the EasyBank backend APIs with Spring Security, creating controllers for account, balance, cards, loans, contact, and notices, and securing endpoints while planning public versus secure configurations.
Examine the default spring security configuration and its http security filter chain. Learn to customize with a security filter chain bean, including form login, http basic, and oauth2 login.
Learn to balance api security by using requestMatchers with authenticated() and permitAll() for apis like myAccount, myBalance, myLoans, and myCards, while notices, contact, and /error remain accessible.
Learn how to disable formLogin and httpBasic in a Spring Boot web app, switch to lambda-based configuration, and understand the role of BasicAuthenticationFilter and UsernamePasswordAuthenticationFilter when securing REST APIs.
Learn to test secured APIs with Postman using http basic authentication, including setting up collections, pre-request scripts, and environment variables, and observing the basic authentication flow with JSESSIONID cookies.
Learn to configure multiple in-memory users in a Spring Boot security app using InMemoryUserDetailsManager and UserDetailsService, including user and admin credentials, authorities, and no password encoder for quick demos.
Configure password encoding with PasswordEncoderFactories to delegate to bcrypt by default, explore prefixes like {noop} for plain text, and see how InMemoryUserDetailsManager uses PasswordEncoder for secure login.
Explore how Spring Security 6.3 uses a compromisedPasswordChecker bean with HaveIBeenPawnedRestApiPasswordChecker to block simple passwords like 12345 and 54321, enforcing strong passwords in production.
Explore how Spring Security models end users with UserDetails and manages them via UserDetailsService and UserDetailsManager, including loadUserByUsername, createUser, updateUser, deleteUser, changePassword, and userExists, with InMemoryUserDetailsManager, JdbcUserDetailsManager, and LdapUserDetailsManager implementations.
Explains the separation between user details and authentication in Spring security, showing how UserDetails becomes an Authentication token via DaoAuthenticationProvider. Highlights loadUserByUsername and eraseCredentials in the login flow.
Review enhancements to the spring boot app: add security dependency and configure users in properties. Use in-memory authentication with multiple users via InMemoryUserDetailsManager and prepare for database-backed authentication.
Learn to set up a MySQL database with Docker for the Spring Security 6 course, including running a container, port 3306 mapping, and connecting to the eazybank database.
Explore the JdbcUserDetailsManager and JdbcDaoImpl to learn how Spring Security stores users and authorities in a database. Learn about users and authorities schemas, and the createUser and updateUser sql workflows.
Add jdbc, mysql, and spring data jpa dependencies, configure a mysql datasource in application.properties, and replace in-memory with JdbcUserDetailsManager connected to the DataSource.
Create a custom authentication table named customer with an auto-increment id, email as username, PWD for passwords, and a role, then update Spring Security to use it.
Create a JPA entity and repository for the customer table using Spring Data JPA, including @Entity, @Id, @GeneratedValue, and a findByEmail method; leverage Lombok for getters and setters.
Implement a custom UserDetailsService to load user details from a bespoke table during authentication with the DaoAuthenticationProvider, using a repository to find by email and map to UserDetails.
Build a rest api for user registration with a custom user details service, hashed passwords via password encoder, and database persistence, tested with Postman, while disabling csrf for creation endpoints.
Learn how passwords are hashed with a bcrypt PasswordEncoder in Spring Security, using a delegating PasswordEncoder, and why plain text storage is dangerous.
Explore encoding, decoding, encryption, and hashing. Understand why encoding is unsuitable for password management while discussing data masking and privacy.
Explain why encryption is not suitable for password management. Compare symmetric and asymmetric encryption, and outline data in transit and data at rest with key management.
Demonstrate encryption and decryption with openssl aes-256-cbc, using secret key 12345 and pbkdf2, illustrating plain.txt to encrypted.txt and decrypt.txt, plus base64 encoding and a note on hashing.
Explore hashing as a one-way, deterministic process that converts input into a fixed-size digest for secure password storage and data integrity, with SHA-256 examples and OpenSSL demonstrations.
Explore hashing drawbacks for password management, including identical hashes for identical inputs and the speed of attacks. See how brute force, dictionary, and rainbow table attacks threaten security.
Learn how salts and slow hashing algorithms like bcrypt, scrypt, and Argon2 protect passwords from rainbow attacks, dictionary attacks, and brute-force attacks, with per-user salts and strong password rules.
Understand how password encoders add random salt and slow hashing to secure passwords. Learn about bcrypt, scrypt, argon2, and pbkdf2, and how encode, matches, and upgradeEncoding manage credentials.
Compare password encoder implementations, from deprecated NoOp and StandardPassword to robust BCrypt, SCrypt, Argon2, and PBKDF2, highlighting salt, iterations, versions, and delegation patterns.
Demonstrate registration and login flows using bcrypt password encoding within Spring Security, showcasing the DelegatingPasswordEncoder handling salts and hashing without code changes.
Explore why and when to create a custom AuthenticationProvider in Spring Security, beyond the default DaoAuthenticationProvider, to support multiple authentication styles and bespoke validation.
Understand the AuthenticationProvider interface with authenticate() and supports(), how it loads user details and validates credentials with PasswordEncoder, and how ProviderManager routes to tokens like UsernamePasswordAuthenticationToken.
Implement a custom authentication provider in a Spring Security app by creating a new authentication provider, implementing supports and authenticate, and leveraging a user details service and a password encoder.
Leverage Spring Boot profiles to conditionally load security configurations and authentication rules across production and lower environments, including conditional login behavior for testers and developers.
Learn to configure environment-specific properties in Spring Boot with profiles and multiple property files, activate prod via spring.profiles.active or environment variables, and apply external overrides for logs and credentials.
Activate prod and non-prod security configurations with @Profile based beans like EazyBankProdUsernameAuthenticationProvider and EazyBankUsernamePwdAuthenticationProvider, enforcing password validation in prod and bypassing it otherwise.
enforce https only traffic in a Spring Boot application with Spring Security by using prod profile configurations and requires channel, while enabling http in non production environments for local testing.
Explore how Spring Security handles authentication and access denial through exception translation, authenticate with 401 via authentication entry points and 403 via access denied handlers; learn to customize responses.
Define a custom authentication entry point for http basic to handle 401 errors in microservices, adding a bespoke header ezaybank-error-reason and a customizable json response.
Configure authentication entry points in Spring Security using httpBasic and global exceptionHandling with a CustomBasicAuthenticationEntryPoint; learn why formLogin bypasses global entry points and when to apply global configuration.
Implement a custom access denied handler in Spring Security 6 by creating CustomAccessDeniedHandler, overriding handle() to return 403 with an ezbank-denied-reason header, and configure it globally.
Configure spring security session timeouts in spring boot, override the default 30 minutes with server.servlet.session.timeout, and use an invalid session url with permitAll to redirect users during timeout.
Control concurrent sessions in Spring Security by configuring maximumSessions and maximumSessionsPreventsLogin, demonstrating one or multiple sessions, session expiry, and optional expiredURL handling.
Explore session hijacking and session fixation, and learn how Spring Security protects sessions by default with changeSessionId and how to configure session fixation strategies.
Listen to how Spring Security publishes authentication events, including AuthenticationSuccessEvent and AuthenticationFailureEvent, and implement event listeners with @EventListener to log, email, or audit login outcomes.
Learn how spring security publishes authentication success and failure events via the provider manager and the default event publisher, and how to listen with event listeners to log login outcomes.
Master formLogin() customization in Spring Security to define a custom login page and post authentication flow, as demonstrated in the EazySchool MVC app.
Configure form login in spring security 6 mvc apps, including disabling csrf and permitting static assets. Route to a custom login page to secure the dashboard and avoid redirect loops.
Configure form login for mvc or monolithic apps, set dashboard as the post-login landing page, display the current user’s username and authorities, and customize login parameters using usernameParameter and passwordParameter.
Configure form login in MVC apps with defaultSuccessUrl and failureUrl, then implement custom authentication success and failure handlers to redirect to dashboard or show login errors.
Configure logout behavior in Spring Security with http.logout(), show 'you have been successfully logged out' via the logout success URL, and clear session, authentication, and delete J Session ID cookie.
Learn how to integrate Spring Security with Thymeleaf to conditionally render header navigation. Use the Thymeleaf security dialect to check isAuthenticated and isAnonymous, and retrieve authentication and principal details.
Explains how authentication details with principal, credentials, and authorities are stored in the security context. Shows how SecurityContextHolder uses threadlocal strategies, including inheritable and global modes.
Learn how to load the current authenticated user in Spring Security using SecurityContextHolder or a method parameter, and access name and authorities in controllers or services.
Setting up the EazyBank UI project
Explore the Angular UI architecture, including components, models, and services, and learn how the login and dashboard flows call backend Spring Boot APIs.
Explore how an Angular frontend calls backend APIs via observables, implements login, session storage, and route guards, and uses an HTTP interceptor to attach credentials for Spring Security.
Create a new db schema for the EazyBank backend by building and populating tables: customer, accounts, account_transactions, loans, cards, notice_details, and contact_messages, with key relationships and test data.
Update backend to reflect the latest db schema with entity models and repositories, including findByCustomerId and jpql queries for notices, and implement cache control for responses.
Start the Spring Boot backend, verify the register API with Postman, and fix id generation by using GenerationType.IDENTITY to ensure the new user is created successfully.
Diagnose a CORS error when the Angular UI calls the Notices API. See how Postman tests succeed, and how JsonIgnore hides createDt and updateDt to streamline the response.
Cross-origin resource sharing (CORS) fundamentals, how browsers block cross-origin requests by default, and how to configure allowed origins for secure browser communication.
Explore cross-origin communication fixes for the ui and backend, using @CrossOrigin with specified origins and then spring security cors configuration to handle preflight requests and headers.
Configure cors in Spring Security to allow specific origins, methods, credentials, and headers using a cors configuration source and cors filter; verify via pre-flight requests and response headers.
Explore how Spring Security's default CSRF protection guards web apps from CSRF attacks and why disabling it briefly permits POST requests, causing 403 errors until a CSRF solution is applied.
Understand cross-site request forgery (CSRF), where a hacker uses a malicious site and an embedded form to make a Netflix request using your cookies, without your consent.
Explore CSRF defense using a unique per-session CSRF token (XSRF), delivered as a cookie and verified in the header or payload to distinguish legitimate requests from malicious ones.
Learn how Spring Security represents and generates CSRF tokens with CsrfToken and CookieCsrfTokenRepository, storing in cookies via a custom CSRF cookie filter exposing XSRF-TOKEN and X-XSRF-TOKEN.
Configure the backend to generate a CSRF token at login and expose it as a cookie read by CSRF filter via CsrfTokenRequestAttributeHandler. Validate requests with the X-XSRF-TOKEN header and jsessionId.
Read and store the CSRF token from the backend's XSRF-TOKEN cookie into session storage, then attach it as X-XSRF-TOKEN in all requests via an interceptor.
Ignore csrf protection for public apis like contact and register with ignoringRequestMatchers(), and implement token handling with csrfTokenRequestAttributeHandler() and CookieCsrfTokenRepository.
Clarify authentication vs authorization with a real-world airport analogy. Then explain how spring security implements authorization using roles, authorities, and privileges, and the 401/403 distinctions.
Explain how Spring Security stores authorities with GrantedAuthority and SimpleGrantedAuthority, and how UserDetails and Authentication carry these authorities through unmodifiable collections and UsernamePasswordAuthenticationToken.
Create a new authorities table linked to the customer, store multiple roles per user, seed authorities, and adjust Spring Security to enforce access by those authorities.
Load authorities from the new table by creating an Authority entity linked to Customer, map with many-to-one and join column, and convert to SimpleGrantedAuthority for security.
configure authorities inside the spring security configuration by replacing authenticated with hasAuthority and hasAnyAuthority on APIs, and illustrate using the access method for complex rules.
Understand the difference between authorities and roles in Spring Security, and see how roles group privileges for coarse-grained access while authorities enable fine-grained control, with custom prefixes via GrantedAuthorityDefaults.
Define and assign user roles for role-based authorization in a Spring Security web app, and use hasRole/hasAnyRole without ROLE_ prefix in ProjectSecurityConfig.
Learn to listen for authorization denied events in Spring Security, handle 403 on client and backend, log details, and consult official docs on authorization granted events.
Explore the inbuilt Spring Security filters that intercept every request, perform authentication and authorization, and operate in a configurable filter chain before dispatching to the DispatcherServlet.
Discover how to create and inject custom filters into the Spring Security filter chain. Explore three approaches: Filter interface, GenericFilterBean, and OncePerRequestFilter, and configure placement with addFilterAfter, addFilterBefore, or addFilterAt.
Create a custom request validation filter and insert it before the BasicAuthenticationFilter using addFilterBefore. Validate the authorization header, decode credentials, block emails containing test, and continue the filter chain.
Create and configure a custom post-authentication filter, AuthoritiesLoggingAfterFilter, using addFilterAfter() to log the authenticated user and authorities after the BasicAuthenticationFilter.
Configure a custom filter with addFilterAt(), placing it at the same position as BasicAuthenticationFilter. Note that addFilterAt() does not replace the existing filter and its order is non-deterministic.
'Spring Security Zero to Master' course will help in understanding the Spring Security Architecture, important packages, interfaces, classes inside it which handles authentication and authorization requests in the web applications. It also covers most common security related topics like CORs, CSRF, JWT, OAUTH2, password management, method level security, user, roles & authorities management inside web applications.
Below are the important topics that this course covers,
Spring Security framework details and it features
How to adapt security for a Java web application using Spring Security
Password Management in Spring Security with PasswordEncoders
Deep dive about encoding, encryption and hashing
What is CSRF, CORS and how to address them
What is Authentication and Authorization. How they are different from each other.
Filters in Spring Security and how to write own custom filters
Deep dive about JWT (JSON Web Tokens) and the role of them inside Authentication & Authorization
Deep dive about OAUTH2 and various grant type flows inside OAUTH2.
Deep dive about OpenID Connect & how it is related to OAUTH2
Applying authorization rules using roles, authorities inside a web application using Spring Security
Method level security in web/non-web applications
Social Login integrations into web applications
Set up of Authorization Server using KeyCloak, Spring Authorization Server
The pre-requisite for the course is basic knowledge of Java, Spring, SpringBoot and interest to learn.