Class ExceptionHandlingConfigurer<H extends HttpSecurityBuilder<H>>
- java.lang.Object
-
- org.springframework.security.config.annotation.SecurityConfigurerAdapter<org.springframework.security.web.DefaultSecurityFilterChain,B>
-
- org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer<ExceptionHandlingConfigurer<H>,H>
-
- org.springframework.security.config.annotation.web.configurers.ExceptionHandlingConfigurer<H>
-
- All Implemented Interfaces:
SecurityConfigurer<org.springframework.security.web.DefaultSecurityFilterChain,H>
public final class ExceptionHandlingConfigurer<H extends HttpSecurityBuilder<H>> extends AbstractHttpConfigurer<ExceptionHandlingConfigurer<H>,H>
Adds exception handling for Spring Security related exceptions to an application. All properties have reasonable defaults, so no additional configuration is required other than applying thisSecurityConfigurer.Security Filters
The following Filters are populatedExceptionTranslationFilter
Shared Objects Created
No shared objects are created.Shared Objects Used
The following shared objects are used:- If no explicit
RequestCache, is provided aRequestCacheshared object is used to replay the request after authentication is successful AuthenticationEntryPoint- seeauthenticationEntryPoint(AuthenticationEntryPoint)
- Since:
- 3.2
-
-
Constructor Summary
Constructors Constructor Description ExceptionHandlingConfigurer()Creates a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ExceptionHandlingConfigurer<H>accessDeniedHandler(org.springframework.security.web.access.AccessDeniedHandler accessDeniedHandler)Specifies theAccessDeniedHandlerto be usedExceptionHandlingConfigurer<H>accessDeniedPage(java.lang.String accessDeniedUrl)Shortcut to specify theAccessDeniedHandlerto be used is a specific error pageExceptionHandlingConfigurer<H>authenticationEntryPoint(org.springframework.security.web.AuthenticationEntryPoint authenticationEntryPoint)Sets theAuthenticationEntryPointto be used.voidconfigure(H http)Configure theSecurityBuilderby setting the necessary properties on theSecurityBuilder.ExceptionHandlingConfigurer<H>defaultAccessDeniedHandlerFor(org.springframework.security.web.access.AccessDeniedHandler deniedHandler, org.springframework.security.web.util.matcher.RequestMatcher preferredMatcher)Sets a defaultAccessDeniedHandlerto be used which prefers being invoked for the providedRequestMatcher.ExceptionHandlingConfigurer<H>defaultAuthenticationEntryPointFor(org.springframework.security.web.AuthenticationEntryPoint entryPoint, org.springframework.security.web.util.matcher.RequestMatcher preferredMatcher)Sets a defaultAuthenticationEntryPointto be used which prefers being invoked for the providedRequestMatcher.-
Methods inherited from class org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer
disable, withObjectPostProcessor
-
Methods inherited from class org.springframework.security.config.annotation.SecurityConfigurerAdapter
addObjectPostProcessor, and, getBuilder, init, postProcess, setBuilder
-
-
-
-
Constructor Detail
-
ExceptionHandlingConfigurer
public ExceptionHandlingConfigurer()
Creates a new instance- See Also:
HttpSecurity.exceptionHandling()
-
-
Method Detail
-
accessDeniedPage
public ExceptionHandlingConfigurer<H> accessDeniedPage(java.lang.String accessDeniedUrl)
Shortcut to specify theAccessDeniedHandlerto be used is a specific error page- Parameters:
accessDeniedUrl- the URL to the access denied page (i.e. /errors/401)- Returns:
- the
ExceptionHandlingConfigurerfor further customization - See Also:
AccessDeniedHandlerImpl,accessDeniedHandler(org.springframework.security.web.access.AccessDeniedHandler)
-
accessDeniedHandler
public ExceptionHandlingConfigurer<H> accessDeniedHandler(org.springframework.security.web.access.AccessDeniedHandler accessDeniedHandler)
Specifies theAccessDeniedHandlerto be used- Parameters:
accessDeniedHandler- theAccessDeniedHandlerto be used- Returns:
- the
ExceptionHandlingConfigurerfor further customization
-
defaultAccessDeniedHandlerFor
public ExceptionHandlingConfigurer<H> defaultAccessDeniedHandlerFor(org.springframework.security.web.access.AccessDeniedHandler deniedHandler, org.springframework.security.web.util.matcher.RequestMatcher preferredMatcher)
Sets a defaultAccessDeniedHandlerto be used which prefers being invoked for the providedRequestMatcher. If only a single defaultAccessDeniedHandleris specified, it will be what is used for the defaultAccessDeniedHandler. If multiple defaultAccessDeniedHandlerinstances are configured, then aRequestMatcherDelegatingAccessDeniedHandlerwill be used.- Parameters:
deniedHandler- theAccessDeniedHandlerto usepreferredMatcher- theRequestMatcherfor this defaultAccessDeniedHandler- Returns:
- the
ExceptionHandlingConfigurerfor further customizations - Since:
- 5.1
-
authenticationEntryPoint
public ExceptionHandlingConfigurer<H> authenticationEntryPoint(org.springframework.security.web.AuthenticationEntryPoint authenticationEntryPoint)
Sets theAuthenticationEntryPointto be used.If no
authenticationEntryPoint(AuthenticationEntryPoint)is specified, thendefaultAuthenticationEntryPointFor(AuthenticationEntryPoint, RequestMatcher)will be used. The firstAuthenticationEntryPointwill be used as the default if no matches were found.If that is not provided defaults to
Http403ForbiddenEntryPoint.- Parameters:
authenticationEntryPoint- theAuthenticationEntryPointto use- Returns:
- the
ExceptionHandlingConfigurerfor further customizations
-
defaultAuthenticationEntryPointFor
public ExceptionHandlingConfigurer<H> defaultAuthenticationEntryPointFor(org.springframework.security.web.AuthenticationEntryPoint entryPoint, org.springframework.security.web.util.matcher.RequestMatcher preferredMatcher)
Sets a defaultAuthenticationEntryPointto be used which prefers being invoked for the providedRequestMatcher. If only a single defaultAuthenticationEntryPointis specified, it will be what is used for the defaultAuthenticationEntryPoint. If multiple defaultAuthenticationEntryPointinstances are configured, then aDelegatingAuthenticationEntryPointwill be used.- Parameters:
entryPoint- theAuthenticationEntryPointto usepreferredMatcher- theRequestMatcherfor this defaultAuthenticationEntryPoint- Returns:
- the
ExceptionHandlingConfigurerfor further customizations
-
configure
public void configure(H http)
Description copied from interface:SecurityConfigurerConfigure theSecurityBuilderby setting the necessary properties on theSecurityBuilder.- Specified by:
configurein interfaceSecurityConfigurer<org.springframework.security.web.DefaultSecurityFilterChain,H extends HttpSecurityBuilder<H>>- Overrides:
configurein classSecurityConfigurerAdapter<org.springframework.security.web.DefaultSecurityFilterChain,H extends HttpSecurityBuilder<H>>
-
-