我正在使用远程应用程序中的弹簧开发工具进行弹簧重新加载。我遇到了 HttpSecurity 配置的错误。
正如在这里解释的那样,我把它放在配置http
安全中:
http.requestMatchers("/.~~spring-boot!~/restart").anyRequest().anonymous()
.and().csrf().disable();
第一个 requestMatchers 在 2.2.4.RELEASE 版本中不存在,所以我用 antMatcher 替换了它。但是应用程序必须验证其他 url。我尝试了多种不同的配置,但从未奏效。
第一的
http.csrf().disable().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.antMatcher("/.~~spring-boot!~/restart").anonymous().and().
authorizeRequests(aR -> aR
.antMatchers("/.~~spring-boot!~/restart").anonymous()
.anyRequest().authenticated()
)
.logout().disable()
.addFilterBefore(new AuthTokenFilter(userRepository, env), UsernamePasswordAuthenticationFilter.class);
第二
http.csrf().disable().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.antMatcher("/.~~spring-boot!~/**").authorizeRequests().anyRequest().anonymous()
.and()
.authorizeRequests().anyRequest().authenticated()
.and()
.logout().disable()
.addFilterBefore(new AuthTokenFilter(userRepository, env), UsernamePasswordAuthenticationFilter.class);
第三
http.csrf().disable().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.antMatcher("/.~~spring-boot!~/restart").anonymous().and().authorizeRequests().anyRequest().authenticated().and().logout().disable()
.addFilterBefore(new AuthTokenFilter(userRepository, env), UsernamePasswordAuthenticationFilter.class);
你可以帮帮我吗?一些conf的结果是例外:
线程“File Watcher”中的异常 java.lang.IllegalStateException:上传类文件时出现意外的 401 UNAUTHORIZED 响应。有些是:不能在其自身之后配置任何请求。
我很迷茫,因为认为 antMatcher 会起作用。有任何想法吗?