我已经构建了一个网络服务器,并试图对其进行密码保护。我正在尝试使用 Spring Boot 设置基本身份验证。到目前为止,这是我的配置文件:
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/", "/v1/occupancy/*")
.permitAll()
.anyRequest()
.authenticated()
.and()
.httpBasic();
}
}
Run Code Online (Sandbox Code Playgroud)
这按预期工作并保护我的 GET 端点之一,使我能够进行身份验证。
但是,对于 POST 端点,这不起作用。端点看起来像这样:
@RequestMapping(path = "/v1/admin/repository")
public class RepositoryOptionsController {
private final EstablishmentOptionsRepositoryService establishmentOptionsRepositoryService;
private final SubAreaOptionsRepositoryService subAreaOptionsRepositoryService;
@PostMapping("/establishment/options")
public ResponseEntity<String> postEstablishmentOption(@RequestBody OptionsRequestDto body) {
Run Code Online (Sandbox Code Playgroud)
当我做
curl -X POST "http://localhost:8080/v1/admin/repository/establishment/options" -u root -v -d "{...}"
Run Code Online (Sandbox Code Playgroud)
我明白了
Enter host password for user 'root':
Note: Unnecessary use of -X …Run Code Online (Sandbox Code Playgroud)