@ConditionalOnWebApplication(type=SERVLET) @ConditionalOnClass(name="org.springframework.security.web.access.AccessDeniedHandler") public class ServletSecurityErrorsAutoConfiguration extends Object
AccessDeniedHandler and another
AuthenticationEntryPoint when the traditional Spring Security is detected. Using these
two handlers will make sure that our exception handling mechanism would properly catch and handle
all security related exceptions.
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
private final AccessDeniedHandler accessDeniedHandler;
private final AuthenticationEntryPoint authenticationEntryPoint;
public SecurityConfig(AccessDeniedHandler accessDeniedHandler, AuthenticationEntryPoint authenticationEntryPoint) {
this.accessDeniedHandler = accessDeniedHandler;
this.authenticationEntryPoint = authenticationEntryPoint;
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.exceptionHandling()
.accessDeniedHandler(accessDeniedHandler)
.authenticationEntryPoint(authenticationEntryPoint);
}
}
| Constructor and Description |
|---|
ServletSecurityErrorsAutoConfiguration() |
| Modifier and Type | Method and Description |
|---|---|
org.springframework.security.web.access.AccessDeniedHandler |
accessDeniedHandler()
Registers a handler to handle to access denied exceptions.
|
org.springframework.security.web.AuthenticationEntryPoint |
authenticationEntryPoint()
Registers a handler to handle all authentication exceptions.
|
public ServletSecurityErrorsAutoConfiguration()
@Bean @ConditionalOnClass(name="org.springframework.security.web.access.AccessDeniedHandler") public org.springframework.security.web.access.AccessDeniedHandler accessDeniedHandler()
@Bean @ConditionalOnClass(name="org.springframework.security.web.AuthenticationEntryPoint") public org.springframework.security.web.AuthenticationEntryPoint authenticationEntryPoint()
Copyright © 2019. All rights reserved.