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

Support ServerExchangeRejectedHandler @Bean #15975

Closed
rwinch opened this issue Oct 22, 2024 · 1 comment
Closed

Support ServerExchangeRejectedHandler @Bean #15975

rwinch opened this issue Oct 22, 2024 · 1 comment
Assignees
Labels
in: web An issue in web modules (web, webmvc) type: enhancement A general enhancement
Milestone

Comments

@rwinch
Copy link
Member

rwinch commented Oct 22, 2024

Spring Security does not use the ServerExchangeRejectedHandler Bean when exposed.

We should fix this, but in the meantime users can leverage a BeanPostProcessor approach.

@Bean
BeanPostProcessor beanPostProcessor() {
	return new BeanPostProcessor() {
		@Override
		public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
			if (bean instanceof WebFilterChainProxy) {
				WebFilterChainProxy springSecurity = (WebFilterChainProxy) bean;
				springSecurity.setExchangeRejectedHandler((exchange, ex) -> Mono.fromRunnable(() -> exchange.getResponse().setStatusCode(HttpStatus.NOT_ACCEPTABLE)));
			}
			return bean;
		}
	};
}
@rwinch rwinch added in: web An issue in web modules (web, webmvc) type: enhancement A general enhancement labels Oct 22, 2024
@rwinch rwinch added this to the 5.7.14 milestone Oct 22, 2024
@rwinch rwinch self-assigned this Oct 22, 2024
rwinch added a commit that referenced this issue Nov 11, 2024
rwinch added a commit that referenced this issue Nov 11, 2024
@rwinch
Copy link
Member Author

rwinch commented Nov 11, 2024

Closed via e86d88d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web An issue in web modules (web, webmvc) type: enhancement A general enhancement
Projects
Status: No status
Development

No branches or pull requests

1 participant