Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workaround for Spring Cloud Gateway from Spring Boot 3.3.5 #27690

Merged
merged 1 commit into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ import tech.jhipster.web.filter.CookieCsrfFilter;
<%_ if (!skipClient) { _%>
import <%= packageName %>.web.filter.SpaWebFilter;
<%_ } _%>
<%_ if (applicationTypeGateway) { _%>
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
<%_ } _%>
<%_ if (authenticationUsesCsrf && !applicationTypeMicroservice) { _%>
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -113,6 +117,10 @@ import <%= packageName %>.security.oauth2.CustomClaimConverter;
<%_ if(!skipClient) { _%>
import org.springframework.security.web.header.writers.ReferrerPolicyHeaderWriter;
<%_ } _%>
<%_ if (applicationTypeGateway) { _%>
import org.springframework.security.web.server.WebFilterChainProxy;
import org.springframework.security.web.server.firewall.ServerWebExchangeFirewall;
<%_ } _%>
<%_ if (authenticationUsesCsrf && !applicationTypeMicroservice) { _%>
import org.springframework.util.StringUtils;
<%_ } _%>
Expand Down Expand Up @@ -416,4 +424,19 @@ public class SecurityConfiguration {
}
}
<%_ } _%>
<%_ if (applicationTypeGateway) { _%>
<!-- Fix for Spring Boot 3.3.5: https://github.com/spring-cloud/spring-cloud-gateway/issues/3568 -->
@Bean
BeanPostProcessor beanPostProcessor() {
return new BeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof WebFilterChainProxy springSecurity) {
springSecurity.setFirewall(ServerWebExchangeFirewall.INSECURE_NOOP);
}
return bean;
}
};
}
<%_ } _%>
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ import org.springframework.boot.autoconfigure.security.SecurityProperties;
<%_ if (!skipClient) { _%>
import <%= packageName %>.web.filter.SpaWebFilter;
<%_ } _%>
<%_ if (applicationTypeGateway) { _%>
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
<%_ } _%>
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
<%_ if (authenticationTypeOauth2) { _%>
Expand Down Expand Up @@ -114,6 +118,10 @@ import org.springframework.security.web.server.savedrequest.NoOpServerRequestCac
<%_ } _%>
import org.springframework.security.web.server.util.matcher.NegatedServerWebExchangeMatcher;
import org.springframework.security.web.server.util.matcher.OrServerWebExchangeMatcher;
<%_ if (applicationTypeGateway) { _%>
import org.springframework.security.web.server.WebFilterChainProxy;
import org.springframework.security.web.server.firewall.ServerWebExchangeFirewall;
<%_ } _%>
<%_ if (authenticationUsesCsrf) { _%>
import reactor.core.publisher.Mono;
<%_ } _%>
Expand Down Expand Up @@ -482,4 +490,19 @@ public class SecurityConfiguration {
return Mono.empty();
}
<%_ } _%>
<%_ if (applicationTypeGateway) { _%>
<!-- Fix for Spring Boot 3.3.5: https://github.com/spring-cloud/spring-cloud-gateway/issues/3568 -->
@Bean
BeanPostProcessor beanPostProcessor() {
return new BeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof WebFilterChainProxy springSecurity) {
springSecurity.setFirewall(ServerWebExchangeFirewall.INSECURE_NOOP);
}
return bean;
}
};
}
<%_ } _%>
}
Loading