|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
- * Copyright 2002-2024 the original author or authors.
|
|
|
+ * Copyright 2002-2025 the original author or authors.
|
|
|
*
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
* you may not use this file except in compliance with the License.
|
|
@@ -82,6 +82,7 @@ import org.springframework.security.web.session.ForceEagerSessionCreationFilter;
|
|
|
import org.springframework.security.web.session.SessionManagementFilter;
|
|
|
import org.springframework.security.web.session.SimpleRedirectInvalidSessionStrategy;
|
|
|
import org.springframework.security.web.session.SimpleRedirectSessionInformationExpiredStrategy;
|
|
|
+import org.springframework.security.web.transport.HttpsRedirectFilter;
|
|
|
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
|
|
import org.springframework.util.Assert;
|
|
|
import org.springframework.util.ClassUtils;
|
|
@@ -176,6 +177,8 @@ class HttpConfigurationBuilder {
|
|
|
|
|
|
private BeanDefinition cpf;
|
|
|
|
|
|
+ private BeanDefinition httpsRedirectFilter;
|
|
|
+
|
|
|
private BeanDefinition securityContextPersistenceFilter;
|
|
|
|
|
|
private BeanDefinition forceEagerSessionCreationFilter;
|
|
@@ -252,6 +255,7 @@ class HttpConfigurationBuilder {
|
|
|
createServletApiFilter(authenticationManager);
|
|
|
createJaasApiFilter();
|
|
|
createChannelProcessingFilter();
|
|
|
+ createHttpsRedirectFilter();
|
|
|
createFilterSecurity(authenticationManager);
|
|
|
createAddHeadersFilter();
|
|
|
createCorsFilter();
|
|
@@ -656,6 +660,19 @@ class HttpConfigurationBuilder {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void createHttpsRedirectFilter() {
|
|
|
+ String ref = this.httpElt
|
|
|
+ .getAttribute(HttpSecurityBeanDefinitionParser.ATT_REDIRECT_TO_HTTPS_REQUEST_MATCHER_REF);
|
|
|
+ if (!StringUtils.hasText(ref)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ RootBeanDefinition channelFilter = new RootBeanDefinition(HttpsRedirectFilter.class);
|
|
|
+ channelFilter.getPropertyValues().addPropertyValue("requestMatcher", new RuntimeBeanReference(ref));
|
|
|
+ channelFilter.getPropertyValues().addPropertyValue("portMapper", this.portMapper);
|
|
|
+ this.httpsRedirectFilter = channelFilter;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Deprecated
|
|
|
private void createChannelProcessingFilter() {
|
|
|
ManagedMap<BeanMetadataElement, BeanDefinition> channelRequestMap = parseInterceptUrlsForChannelSecurity();
|
|
|
if (channelRequestMap.isEmpty()) {
|
|
@@ -691,7 +708,9 @@ class HttpConfigurationBuilder {
|
|
|
* Parses the intercept-url elements to obtain the map used by channel security. This
|
|
|
* will be empty unless the <tt>requires-channel</tt> attribute has been used on a URL
|
|
|
* path.
|
|
|
+ * @deprecated please use {@link #createHttpsRedirectFilter} instead
|
|
|
*/
|
|
|
+ @Deprecated
|
|
|
private ManagedMap<BeanMetadataElement, BeanDefinition> parseInterceptUrlsForChannelSecurity() {
|
|
|
ManagedMap<BeanMetadataElement, BeanDefinition> channelRequestMap = new ManagedMap<>();
|
|
|
for (Element urlElt : this.interceptUrls) {
|
|
@@ -897,6 +916,9 @@ class HttpConfigurationBuilder {
|
|
|
if (this.disableUrlRewriteFilter != null) {
|
|
|
filters.add(new OrderDecorator(this.disableUrlRewriteFilter, SecurityFilters.DISABLE_ENCODE_URL_FILTER));
|
|
|
}
|
|
|
+ if (this.httpsRedirectFilter != null) {
|
|
|
+ filters.add(new OrderDecorator(this.httpsRedirectFilter, SecurityFilters.HTTPS_REDIRECT_FILTER));
|
|
|
+ }
|
|
|
if (this.cpf != null) {
|
|
|
filters.add(new OrderDecorator(this.cpf, SecurityFilters.CHANNEL_FILTER));
|
|
|
}
|