Class KeycloakAuthenticationProcessingFilter
java.lang.Object
org.springframework.web.filter.GenericFilterBean
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
org.keycloak.adapters.springsecurity.filter.KeycloakAuthenticationProcessingFilter
- All Implemented Interfaces:
javax.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.ApplicationContextAware,org.springframework.context.ApplicationEventPublisherAware,org.springframework.context.EnvironmentAware,org.springframework.context.MessageSourceAware,org.springframework.core.env.EnvironmentCapable,org.springframework.web.context.ServletContextAware
public class KeycloakAuthenticationProcessingFilter
extends org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
implements org.springframework.context.ApplicationContextAware
Provides a Keycloak authentication processing filter.
- Version:
- $Revision: 1 $
- Author:
- Scott Rossillo
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final org.springframework.security.web.util.matcher.RequestMatcherRequest matcher that matches requests to thedefault login URIand any request with aAuthorizationheader or anadapter state cookie.Fields inherited from class org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
authenticationDetailsSource, eventPublisher, messagesFields inherited from class org.springframework.web.filter.GenericFilterBean
logger -
Constructor Summary
ConstructorsConstructorDescriptionKeycloakAuthenticationProcessingFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Creates a new Keycloak authentication processing filter with givenAuthenticationManagerand thedefault request matcher.KeycloakAuthenticationProcessingFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager, org.springframework.security.web.util.matcher.RequestMatcher requiresAuthenticationRequestMatcher) Creates a new Keycloak authentication processing filter with givenAuthenticationManagerandRequestMatcher. -
Method Summary
Modifier and TypeMethodDescriptionvoidorg.springframework.security.core.AuthenticationattemptAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) voidsetAdapterTokenStoreFactory(AdapterTokenStoreFactory adapterTokenStoreFactory) Sets the adapter token store factory to use when creating per-request adapter token stores.final voidsetAllowSessionCreation(boolean allowSessionCreation) This filter does not support explicitly enabling session creation.voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext) final voidsetContinueChainBeforeSuccessfulAuthentication(boolean continueChainBeforeSuccessfulAuthentication) This filter does not support explicitly setting a continue chain before success policyvoidsetRequestAuthenticatorFactory(RequestAuthenticatorFactory requestAuthenticatorFactory) Sets the request authenticator factory to use when creating per-request authenticators.protected voidsuccessfulAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain, org.springframework.security.core.Authentication authResult) protected voidunsuccessfulAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.security.core.AuthenticationException failed) Methods inherited from class org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
doFilter, getAllowSessionCreation, getAuthenticationManager, getFailureHandler, getRememberMeServices, getSuccessHandler, requiresAuthentication, setApplicationEventPublisher, setAuthenticationDetailsSource, setAuthenticationFailureHandler, setAuthenticationManager, setAuthenticationSuccessHandler, setFilterProcessesUrl, setMessageSource, setRememberMeServices, setRequiresAuthenticationRequestMatcher, setSessionAuthenticationStrategyMethods inherited from class org.springframework.web.filter.GenericFilterBean
addRequiredProperty, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
-
Field Details
-
AUTHORIZATION_HEADER
- See Also:
-
DEFAULT_REQUEST_MATCHER
public static final org.springframework.security.web.util.matcher.RequestMatcher DEFAULT_REQUEST_MATCHERRequest matcher that matches requests to thedefault login URIand any request with aAuthorizationheader or anadapter state cookie.
-
-
Constructor Details
-
KeycloakAuthenticationProcessingFilter
public KeycloakAuthenticationProcessingFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Creates a new Keycloak authentication processing filter with givenAuthenticationManagerand thedefault request matcher.- Parameters:
authenticationManager- theAuthenticationManagerto authenticate requests (cannot be null)- See Also:
-
KeycloakAuthenticationProcessingFilter
public KeycloakAuthenticationProcessingFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager, org.springframework.security.web.util.matcher.RequestMatcher requiresAuthenticationRequestMatcher) Creates a new Keycloak authentication processing filter with givenAuthenticationManagerandRequestMatcher.Note: the given request matcher must support matching the
Authorizationheader if bearer token authentication is to be accepted.- Parameters:
authenticationManager- theAuthenticationManagerto authenticate requests (cannot be null)requiresAuthenticationRequestMatcher- theRequestMatcherused to determine if authentication is required (cannot be null)- See Also:
-
RequestHeaderRequestMatcherOrRequestMatcher
-
-
Method Details
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Overrides:
afterPropertiesSetin classorg.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
-
attemptAuthentication
public org.springframework.security.core.Authentication attemptAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws org.springframework.security.core.AuthenticationException, IOException, javax.servlet.ServletException - Specified by:
attemptAuthenticationin classorg.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter- Throws:
org.springframework.security.core.AuthenticationExceptionIOExceptionjavax.servlet.ServletException
-
successfulAuthentication
protected void successfulAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain, org.springframework.security.core.Authentication authResult) throws IOException, javax.servlet.ServletException - Overrides:
successfulAuthenticationin classorg.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter- Throws:
IOExceptionjavax.servlet.ServletException
-
unsuccessfulAuthentication
protected void unsuccessfulAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.security.core.AuthenticationException failed) throws IOException, javax.servlet.ServletException - Overrides:
unsuccessfulAuthenticationin classorg.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter- Throws:
IOExceptionjavax.servlet.ServletException
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException - Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
setAdapterTokenStoreFactory
Sets the adapter token store factory to use when creating per-request adapter token stores.- Parameters:
adapterTokenStoreFactory- theAdapterTokenStoreFactoryto use
-
setAllowSessionCreation
public final void setAllowSessionCreation(boolean allowSessionCreation) This filter does not support explicitly enabling session creation.- Overrides:
setAllowSessionCreationin classorg.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter- Throws:
UnsupportedOperationException- this filter does not support explicitly enabling session creation.
-
setContinueChainBeforeSuccessfulAuthentication
public final void setContinueChainBeforeSuccessfulAuthentication(boolean continueChainBeforeSuccessfulAuthentication) This filter does not support explicitly setting a continue chain before success policy- Overrides:
setContinueChainBeforeSuccessfulAuthenticationin classorg.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter- Throws:
UnsupportedOperationException- this filter does not support explicitly setting a continue chain before success policy
-
setRequestAuthenticatorFactory
Sets the request authenticator factory to use when creating per-request authenticators.- Parameters:
requestAuthenticatorFactory- theRequestAuthenticatorFactoryto use
-