Skip to content

Commit

Permalink
Add workaround for Spring Cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
mraible committed Oct 26, 2024
1 parent 4dfb0e0 commit dc7c5aa
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
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;
}
};
}
<%_ } _%>
}

0 comments on commit dc7c5aa

Please sign in to comment.