我想在啟用了 Spring Security 的 Spring Boot 項目中使用 h2-console。我的配置如下所示,但我無法訪問任何未經身份驗證的路徑。如果我打開控制臺路徑,登錄提示符就會出現。是不是順序錯了?我已經用 WebSecurityConfigurerAdapter 以舊方式嘗試過它并且它有效,但我想使用新的東西。@EnableWebFluxSecuritypublic class SecurityConfiguration { @Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { return http .csrf().disable() .headers().frameOptions().disable().and() .authorizeExchange() .anyExchange().permitAll() .and() .httpBasic().and() .build(); }}我將配置更改為以下內容,并且身份驗證像我預期的那樣排除了 h2 控制臺:@Configurationpublic class SecurityConfiguration extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.headers().frameOptions().disable().and() .csrf().disable(); http .authorizeRequests() .antMatchers("/", "/h2-console/**").permitAll() .anyRequest().authenticated() .and() .formLogin() .permitAll() .and() .logout() .permitAll(); }}
添加回答
舉報
0/150
提交
取消
