第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

關(guān)于Rest風(fēng)格的API的如何做權(quán)限控制

關(guān)于Rest風(fēng)格的API的如何做權(quán)限控制

慕勒3428872 2019-03-21 19:15:40
想要實現(xiàn)的效果是比如如下兩個接口GET /order/{orderId}POST /order/{orderId}/abc/{abcId}想通過不同的角色或用戶來分別限制他們能訪問接口的某一個,即擁有權(quán)限的一個現(xiàn)在的問題就是,通過什么樣的方式能夠?qū)RL和上面的接口路徑分別匹配上呢?使用的是SpringMVC。注:上面寫的接口URL只是簡單的,還有復(fù)雜的里面參數(shù)可以是正則表達式,或者兩個參數(shù)通過特定字符串拼接的(如{param1}-{param2},所以匹配路徑不能用正則來做,這塊不太了解SpringMVC的底層是如何實現(xiàn)的,求大神解答。
查看完整描述

3 回答

?
森林海

TA貢獻2011條經(jīng)驗 獲得超2個贊

怎么感覺你的問題內(nèi)容和標(biāo)題不是一個意思。你到底是想問權(quán)限控制還是路徑識別匹配?


查看完整回答
反對 回復(fù) 2019-04-16
?
慕妹3242003

TA貢獻1824條經(jīng)驗 獲得超6個贊

你必須要用實作 WebSecurityConfigurerAdapter 

以我所知Spring security基礎(chǔ)的登入是User跟Role.


每一個URL都可以通過實作 WebSecurityConfigurerAdapter的 configure(WebSecurity web)控制的。


比如以下的例子帳戶在內(nèi)存,登入后各資源根制可以用上hasRole()限制:


        

@EnableWebSecurity

@Configuration

public class CustomWebSecurityConfigurerAdapter extends

   WebSecurityConfigurerAdapter {

  @Autowired

  public void configureGlobal(AuthenticationManagerBuilder auth) {

    auth

      .inMemoryAuthentication()

        .withUser("user")  // #1

          .password("password")

          .roles("USER")

          .and()

        .withUser("admin") // #2

          .password("password")

          .roles("ADMIN","USER");

  }


  @Override

  public void configure(WebSecurity web) throws Exception {

    web

      .ignoring()

         .antMatchers("/resources/**"); // #3

  }


  @Override

  protected void configure(HttpSecurity http) throws Exception {

    http

      .authorizeUrls()

        .antMatchers("/signup","/about").permitAll() // #4

        .antMatchers("/admin/**").hasRole("ADMIN") // #6

        .anyRequest().authenticated() // 7

        .and()

    .formLogin()  // #8

        .loginUrl("/login") // #9

        .permitAll(); // #5

  }

}

參考: 官方文檔

查看完整回答
反對 回復(fù) 2019-04-16
  • 3 回答
  • 0 關(guān)注
  • 762 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號