Class JaasApiIntegrationFilter
- 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
A Filter which attempts to obtain a JAAS Subject and continue
the FilterChain running as that Subject.
By using this Filter in conjunction with Spring's
JaasAuthenticationProvider both Spring's SecurityContext and
a JAAS Subject can be populated simultaneously. This is useful when
integrating with code that requires a JAAS Subject to be populated.
-
Field Summary
Fields inherited from class org.springframework.web.filter.GenericFilterBean
logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voiddoFilter(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response, jakarta.servlet.FilterChain chain) Attempts to obtain and run as a JAASSubjectusingobtainSubject(ServletRequest).protected SubjectobtainSubject(jakarta.servlet.ServletRequest request) Obtains theSubjectto run as ornullif noSubjectis available.final voidsetCreateEmptySubject(boolean createEmptySubject) SetscreateEmptySubject.voidsetSecurityContextHolderStrategy(org.springframework.security.core.context.SecurityContextHolderStrategy securityContextHolderStrategy) Sets theSecurityContextHolderStrategyto use.Methods inherited from class org.springframework.web.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
-
Constructor Details
-
JaasApiIntegrationFilter
public JaasApiIntegrationFilter()
-
-
Method Details
-
doFilter
public final void doFilter(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response, jakarta.servlet.FilterChain chain) throws jakarta.servlet.ServletException, IOException Attempts to obtain and run as a JAAS
SubjectusingobtainSubject(ServletRequest).If the
Subjectisnulland createEmptySubject istrue, an empty, writeableSubjectis used. This allows for theSubjectto be populated at the time of login. If theSubjectisnull, theFilterChaincontinues with no additional processing. If theSubjectis notnull, theFilterChainis ran withSubject.doAs(Subject, PrivilegedExceptionAction)in conjunction with theSubjectobtained.- Throws:
jakarta.servlet.ServletExceptionIOException
-
obtainSubject
Obtains the
Subjectto run as ornullif noSubjectis available.The default implementation attempts to obtain the
Subjectfrom theSecurityContext'sAuthentication. If it is of typeJaasAuthenticationTokenand is authenticated, theSubjectis returned from it. Otherwise,nullis returned.- Parameters:
request- the currentServletRequest- Returns:
- the Subject to run as or
nullif noSubjectis available.
-
setCreateEmptySubject
public final void setCreateEmptySubject(boolean createEmptySubject) SetscreateEmptySubject. If the value istrue, andobtainSubject(ServletRequest)returnsnull, an empty, writeableSubjectis created instead. Otherwise noSubjectis used. The default isfalse.- Parameters:
createEmptySubject- the new value
-
setSecurityContextHolderStrategy
public void setSecurityContextHolderStrategy(org.springframework.security.core.context.SecurityContextHolderStrategy securityContextHolderStrategy) Sets theSecurityContextHolderStrategyto use. The default action is to use theSecurityContextHolderStrategystored inSecurityContextHolder.- Since:
- 5.8
-