我有一份申请,当时我正在使用春天的安保和奥安特2的标识。 一切都在发挥作用。 如果用户没有登录在册,则按预期将用户重新定位为登录页。 然而,这一重新定位造成了
@Bean
public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
return http
.authorizeExchange(authorizeExchangeSpec -> {
authorizeExchangeSpec.anyExchange().authenticated();
})
.csrf(csrfSpec -> {
csrfSpec.csrfTokenRepository(CookieServerCsrfTokenRepository.withHttpOnlyFalse());
})
.logout(logoutSpec -> {
logoutSpec.logoutSuccessHandler(oidcLogoutSuccessHandler(this.clientRegistrationRepository));
})
.oauth2Login(Customizer.withDefaults())
.exceptionHandling(exceptionHandlingSpec -> {
exceptionHandlingSpec.authenticationEntryPoint((swe, e) -> {
// It seems its too late here to do such check none of the header have this? Eventhough `AJAX` request triggered this.
if (swe.getRequest().getHeaders().containsKey("X-Requested-With")) {
return Mono.fromRunnable(() -> swe.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED));
}
});
})
.build();
}