我正在配置一個具有 2 個安全入口點的 springboot 應用程式,并且我配置了第一個是 Basic Auth 以匹配 ant 模式“/synchro/task/**”。但是當我測驗它時,當我嘗試使用juste“/synchro/task”的URL時它可以作業,但當我獲得諸如“/synchro/task/1”之類的任務ID時卻不行。
我的代碼如下:
http.csrf().disable().antMatcher( "/synchro/task/**").authorizeRequests()
.anyRequest()
.hasRole("APP").and().httpBasic();
我還嘗試使用 requestMatchers 和兩個 antmatchers 來匹配“/synchro/task/*”和“/synchro/task/**”,但它只需要“/synchro/task”,但在有 id 時不需要。
有趣的事實是,當我設定如下:
http.csrf().disable().antMatcher( "/synchro/task/*").authorizeRequests()
.anyRequest()
.hasRole("APP").and().httpBasic();
例如,它僅適用于“/synchro/task/1”,但不適用于“/synchro/task”。
那么,即使我真的認為 antMatcher("/synchro/task/**") 會覆寫帶 id 和不帶 id 的路徑,我怎么能將兩者結合起來。
這是我的控制器類:
Here is the controller :
@RestController
@RequestMapping(value = "/synchro")
public class SynchroResource extends GenericResource {
@Autowired
private IndexationService indexationService;
@Autowired
private SynchroService synchroService;
@RequestMapping(value = "/task", method = RequestMethod.GET)
public IndexationTaskResponse getNextTask() {
return this.indexationService.getNextTask();
}
@RequestMapping(value = "/task/{taskId}", method = RequestMethod.PUT)
public void updateTaskState(@PathVariable long taskId,
@RequestBody(required = false) String errorMessage) {
this.indexationService.updateTaskState(taskId, errorMessage);
}
}
uj5u.com熱心網友回復:
對于不同的 URL,您可以指定多個 antMatcher,如下所示:-
http.csrf().disable().antMatcher("/URL1").antMatcher("/URL2").authorizeRequests()
.anyRequest()
.hasRole("APP").and().httpBasic();
uj5u.com熱心網友回復:
http.csrf().disable()
.antMatchers("/synchro/task/**")
.authorizeRequests()
.anyRequest()
.hasRole("APP").and().httpBasic();
洗掉 antMatcher() 和 authorizeRequests() 方法之間的 .and()。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/408177.html
標籤:
上一篇:For回圈:保留精確的字串(帶空格和引號)以識別單詞出現(python)
下一篇:如何在驗證中包含一組整數
