Class TokenAuthenticationFilter
java.lang.Object
org.springframework.web.filter.GenericFilterBean
org.springframework.web.filter.OncePerRequestFilter
ai.yda.framework.channel.rest.spring.security.TokenAuthenticationFilter
- 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
public class TokenAuthenticationFilter
extends org.springframework.web.filter.OncePerRequestFilter
Provides a Spring Security filter that processes authentication requests containing a Bearer token in the
Authorization header. The filter converts the Bearer token into an
Authentication object and attempts to
authenticate it using the TokenAuthenticationManager. If the authentication is successful, the authenticated
user is stored in the SecurityContextHolder.- Since:
- 0.1.0
- See Also:
-
Field Summary
Fields inherited from class org.springframework.web.filter.OncePerRequestFilter
ALREADY_FILTERED_SUFFIXFields inherited from class org.springframework.web.filter.GenericFilterBean
logger -
Constructor Summary
ConstructorsConstructorDescriptionTokenAuthenticationFilter(String token) Constructs a newTokenAuthenticationFilterinstance with the provided token. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanauthenticationIsRequired(org.springframework.security.core.Authentication authentication) Determines whether re-authentication is required based on the current authentication context.protected voiddoFilterInternal(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain filterChain) Processes the authentication request by extracting the Bearer token from the Authorization header, converting it to anAuthenticationobject, and attempting to authenticate it.Methods inherited from class org.springframework.web.filter.OncePerRequestFilter
doFilter, doFilterNestedErrorDispatch, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterAsyncDispatch, shouldNotFilterErrorDispatchMethods inherited from class org.springframework.web.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
-
Constructor Details
-
TokenAuthenticationFilter
Constructs a newTokenAuthenticationFilterinstance with the provided token.- Parameters:
token- the token used to authenticate incoming requests.
-
-
Method Details
-
doFilterInternal
protected void doFilterInternal(@NonNull jakarta.servlet.http.HttpServletRequest request, @NonNull jakarta.servlet.http.HttpServletResponse response, @NonNull jakarta.servlet.FilterChain filterChain) throws jakarta.servlet.ServletException, IOException Processes the authentication request by extracting the Bearer token from the Authorization header, converting it to anAuthenticationobject, and attempting to authenticate it. The request and response is then forwarded to the next filter in the chain.- Specified by:
doFilterInternalin classorg.springframework.web.filter.OncePerRequestFilter- Parameters:
request- the currentHttpServletRequest.response- the currentHttpServletResponse.filterChain- theFilterChainto proceed with the request processing.- Throws:
jakarta.servlet.ServletException- if an error occurs during the filtering process.IOException- if an I/O error occurs during the filtering process.
-
authenticationIsRequired
protected boolean authenticationIsRequired(org.springframework.security.core.Authentication authentication) Determines whether re-authentication is required based on the current authentication context.- Parameters:
authentication- the newAuthenticationrequest to be processed.- Returns:
trueif re-authentication is required andfalseotherwise.
-