簡體   English   中英

我在 spring boot 中放置了基本身份驗證,但是我們如何在沒有身份驗證登錄的情況下訪問一些 Api

[英]I put basic authentication in spring boot but how we access some Api without authentication login

根據標題,我在 spring boot 中放置了一些基本的身份驗證,但是我們如何在沒有身份驗證登錄的情況下訪問某些 API

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
      .authorizeRequests()
      .anyRequest()
      .authenticated()
      .and()
      .httpBasic();
}
http.ignoring().antMatchers("/authFailure");

我們可以像上面那樣使用來忽略特定的 URL 路徑。

看看這個

過濾掉API並允許所有無需身份驗證

例子

.antMatchers(GET, "/home","/health").permitAll()

這將允許所有請求在 2 個端點上的 GET 請求,即使沒有身份驗證

完整樣品

   http
        .authorizeRequests()
        .antMatchers(GET, "/home","/health").permitAll()
        .anyRequest()
        .authenticated()
        .and()
        .httpBasic();

注:需要下單

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM