mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-12 21:33:30 +00:00
Add By-RequestMatcher Exception Handling
Issue gh-5185
This commit is contained in:
parent
98a2ca3bbc
commit
34b40deb38
@ -46,7 +46,9 @@ import org.springframework.security.core.authority.mapping.SimpleAttributes2Gran
|
|||||||
import org.springframework.security.core.authority.mapping.SimpleMappableAttributesRetriever;
|
import org.springframework.security.core.authority.mapping.SimpleMappableAttributesRetriever;
|
||||||
import org.springframework.security.web.access.AccessDeniedHandlerImpl;
|
import org.springframework.security.web.access.AccessDeniedHandlerImpl;
|
||||||
import org.springframework.security.web.access.ExceptionTranslationFilter;
|
import org.springframework.security.web.access.ExceptionTranslationFilter;
|
||||||
|
import org.springframework.security.web.access.RequestMatcherDelegatingAccessDeniedHandler;
|
||||||
import org.springframework.security.web.authentication.AnonymousAuthenticationFilter;
|
import org.springframework.security.web.authentication.AnonymousAuthenticationFilter;
|
||||||
|
import org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint;
|
||||||
import org.springframework.security.web.authentication.Http403ForbiddenEntryPoint;
|
import org.springframework.security.web.authentication.Http403ForbiddenEntryPoint;
|
||||||
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
|
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
|
||||||
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider;
|
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider;
|
||||||
@ -165,6 +167,8 @@ final class AuthenticationConfigBuilder {
|
|||||||
private BeanDefinition authorizationCodeGrantFilter;
|
private BeanDefinition authorizationCodeGrantFilter;
|
||||||
private BeanReference authorizationCodeAuthenticationProviderRef;
|
private BeanReference authorizationCodeAuthenticationProviderRef;
|
||||||
|
|
||||||
|
private final Map<BeanDefinition, BeanMetadataElement> defaultDeniedHandlerMappings = new ManagedMap<>();
|
||||||
|
private final Map<BeanDefinition, BeanMetadataElement> defaultEntryPointMappings = new ManagedMap<>();
|
||||||
private final List<BeanDefinition> csrfIgnoreRequestMatchers = new ManagedList<>();
|
private final List<BeanDefinition> csrfIgnoreRequestMatchers = new ManagedList<>();
|
||||||
|
|
||||||
AuthenticationConfigBuilder(Element element, boolean forceAutoConfig,
|
AuthenticationConfigBuilder(Element element, boolean forceAutoConfig,
|
||||||
@ -806,6 +810,7 @@ final class AuthenticationConfigBuilder {
|
|||||||
|
|
||||||
}
|
}
|
||||||
accessDeniedHandler.addPropertyValue("errorPage", errorPage);
|
accessDeniedHandler.addPropertyValue("errorPage", errorPage);
|
||||||
|
return accessDeniedHandler.getBeanDefinition();
|
||||||
}
|
}
|
||||||
else if (StringUtils.hasText(ref)) {
|
else if (StringUtils.hasText(ref)) {
|
||||||
return new RuntimeBeanReference(ref);
|
return new RuntimeBeanReference(ref);
|
||||||
@ -813,6 +818,19 @@ final class AuthenticationConfigBuilder {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.defaultDeniedHandlerMappings.isEmpty()) {
|
||||||
|
return accessDeniedHandler.getBeanDefinition();
|
||||||
|
}
|
||||||
|
if (this.defaultDeniedHandlerMappings.size() == 1) {
|
||||||
|
return this.defaultDeniedHandlerMappings.values().iterator().next();
|
||||||
|
}
|
||||||
|
|
||||||
|
accessDeniedHandler = BeanDefinitionBuilder
|
||||||
|
.rootBeanDefinition(RequestMatcherDelegatingAccessDeniedHandler.class);
|
||||||
|
accessDeniedHandler.addConstructorArgValue(this.defaultDeniedHandlerMappings);
|
||||||
|
accessDeniedHandler.addConstructorArgValue
|
||||||
|
(BeanDefinitionBuilder.rootBeanDefinition(AccessDeniedHandlerImpl.class));
|
||||||
|
|
||||||
return accessDeniedHandler.getBeanDefinition();
|
return accessDeniedHandler.getBeanDefinition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -825,6 +843,16 @@ final class AuthenticationConfigBuilder {
|
|||||||
return new RuntimeBeanReference(customEntryPoint);
|
return new RuntimeBeanReference(customEntryPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!defaultEntryPointMappings.isEmpty()) {
|
||||||
|
if (defaultEntryPointMappings.size() == 1) {
|
||||||
|
return defaultEntryPointMappings.values().iterator().next();
|
||||||
|
}
|
||||||
|
BeanDefinitionBuilder delegatingEntryPoint = BeanDefinitionBuilder
|
||||||
|
.rootBeanDefinition(DelegatingAuthenticationEntryPoint.class);
|
||||||
|
delegatingEntryPoint.addConstructorArgValue(defaultEntryPointMappings);
|
||||||
|
return delegatingEntryPoint.getBeanDefinition();
|
||||||
|
}
|
||||||
|
|
||||||
Element basicAuthElt = DomUtils.getChildElementByTagName(httpElt,
|
Element basicAuthElt = DomUtils.getChildElementByTagName(httpElt,
|
||||||
Elements.BASIC_AUTH);
|
Elements.BASIC_AUTH);
|
||||||
Element formLoginElt = DomUtils.getChildElementByTagName(httpElt,
|
Element formLoginElt = DomUtils.getChildElementByTagName(httpElt,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user