Dependency: spring-boot-starter-security
Enable Annotation: @EnableWebSecurity
As soon as we include the dependency it:
user
) on every startupFeatures:
jjwt
dependency) creation and verification easilyThere has been major changes in the things we configure for Spring Security with release of Spring 6 (Spring Boot 3) in 2023 so be mindful of that.
After defining a SecurityFilterChain
bean with matchers for which page must display login screen, we can define the following:
UserDetailsService
(calls user repo JpaRepository)UserDetails
modelPasswordEncoder
- e.g. BcryptPasswordEncoder
AuthenticationProvider
(this ) - e.g. DaoAuthenticationProvider
(mandatory bean to define and pass service and password encoder to it)AuthenticationManager
(bean to trigger authentication)References:
We rarely use webpage form based auth. OAuth2.0 is used mostly. But standalone JWT token can be used on API Gateway using a Security Service microsevice.
Create a JWT util class that contains all methods related to JWT impl. Also create a filter class for JWT which is always called before username and password auth and checks for “Authentication” HTTP header’s presence and conditionally triggers JWT processing or do nothing (i.e. normal login screen username password auth).
UserDetails
object, specify creation time, expiration time, custom claims and sign the token with secret key.OncePerRequestFilter
, override its doFilterInternal()
method and in there write logic to extract token from HTTP request (“Authentication” header mostly).UserDetailsService
to do so and fetches its password and roles too).References:
Dependency: spring-boot-starter-batch
Enable Annotation: @EnableBatchProcessing
Terminology:
execute()
method which contains custom logic to run)JobListener
and StepListener
JobLauncher
(launches job using its run()
method)JobRepository
(stores execution stats to a database)ItemReader
ItemProcessor
ItemWriter
Dependency: spring-boot-starter-integration
Enable Annotation: @EnableIntegration
Often used with Spring Batch to decouple components within the application.
It is just messaging channels for communication between various components of a service. Not that this is often used for sending messages (e.g. events) not only to other applications but services within an application too can be decoupled.
It can be used to send messages to external systems like MQ too using Channel Adapters.
This comes from a bunch of concepts called “Enterprise Integration Patterns” from the book of the same name.
Terminology:
DirectChannel
, PublishSubscribeChannel
, etc.MessageHandler
as it handles messages)