Package api.mpba.rastvdmy.config
Class JwtAuthenticationFilter
java.lang.Object
org.springframework.web.filter.GenericFilterBean
org.springframework.web.filter.OncePerRequestFilter
api.mpba.rastvdmy.config.JwtAuthenticationFilter
- All Implemented Interfaces:
- jakarta.servlet.Filter,- org.springframework.beans.factory.Aware,- org.springframework.beans.factory.BeanNameAware,- org.springframework.beans.factory.DisposableBean,- org.springframework.beans.factory.InitializingBean,- org.springframework.context.EnvironmentAware,- org.springframework.core.env.EnvironmentCapable,- org.springframework.web.context.ServletContextAware
@Component
public class JwtAuthenticationFilter
extends org.springframework.web.filter.OncePerRequestFilter
Filter for JWT authentication that extends 
OncePerRequestFilter.
 This filter intercepts incoming HTTP requests to validate the JWT provided in the Authorization header.
 It extracts the user email from the JWT and sets the authentication in the security context if the token is valid.
 The filter is designed to be used in conjunction with Spring Security to manage JWT-based authentication.
- 
Field SummaryFields inherited from class org.springframework.web.filter.OncePerRequestFilterALREADY_FILTERED_SUFFIXFields inherited from class org.springframework.web.filter.GenericFilterBeanlogger
- 
Constructor SummaryConstructorsConstructorDescriptionJwtAuthenticationFilter(JwtService jwtService, UserProfileService userProfileService, org.springframework.web.servlet.HandlerExceptionResolver resolver) Constructor forJwtAuthenticationFilterthat injects the necessary services.
- 
Method SummaryModifier and TypeMethodDescriptionprotected voiddoFilterInternal(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain filterChain) The main filter method that processes the incoming HTTP request and validates the JWT.Methods inherited from class org.springframework.web.filter.OncePerRequestFilterdoFilter, doFilterNestedErrorDispatch, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterAsyncDispatch, shouldNotFilterErrorDispatchMethods inherited from class org.springframework.web.filter.GenericFilterBeanaddRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
- 
Constructor Details- 
JwtAuthenticationFilterpublic JwtAuthenticationFilter(JwtService jwtService, @Lazy UserProfileService userProfileService, @Qualifier("handlerExceptionResolver") org.springframework.web.servlet.HandlerExceptionResolver resolver) Constructor forJwtAuthenticationFilterthat injects the necessary services.- Parameters:
- jwtService- The- JwtServiceused for JWT operations.
- userProfileService- The- UserProfileServicefor loading user details.
- resolver- The- HandlerExceptionResolverto handle exceptions.
 
 
- 
- 
Method Details- 
doFilterInternalprotected void doFilterInternal(@NonNull jakarta.servlet.http.HttpServletRequest request, @NonNull jakarta.servlet.http.HttpServletResponse response, @NonNull jakarta.servlet.FilterChain filterChain) The main filter method that processes the incoming HTTP request and validates the JWT. This method checks for the presence of the Authorization header, extracts the JWT, and validates it against the user's details. If the token is valid, it sets the authentication in the security context.- Specified by:
- doFilterInternalin class- org.springframework.web.filter.OncePerRequestFilter
- Parameters:
- request- The incoming HTTP request.
- response- The HTTP response to be sent.
- filterChain- The filter chain to pass the request and response to the next filter.
 
 
-