<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                # security-core在項目中的位置 ![](https://img.kancloud.cn/43/3a/433a1aa4c85d69f6cf32671c8c6fbf54_1055x734.png) ## security-core的作用 包裝資源服務器,作為獨立單元為api-gateway,user-center等提供安全保障。 # 資源服務器 * 要訪問資源服務器受保護的資源需要攜帶令牌(從授權服務器獲得) * **客戶端往往同時也是一個資源服務器,各個服務之間的通信(訪問需要權限的資源)時需攜帶訪問令牌** #### Spring Cloud Oauth 如何開啟資源服務器 * 資源服務器通過 @EnableResourceServer 注解來開啟一個 **OAuth2AuthenticationProcessingFilter** 類型的過濾器 * 通過繼承 ResourceServerConfigurerAdapter 類來配置資源服務器 OAuth2AuthenticationProcessingFilter代碼如何查看 #### ![](https://box.kancloud.cn/a11aeff8aefd6fe6cdacf138e30bd923_839x493.png) (Ctrl +shift+T) ## ResourceServerSecurityConfigurer 可配置屬性 * tokenServices:ResourceServerTokenServices 類的實例,用來實現令牌業務邏輯服務 * resourceId:這個資源服務的ID,這個屬性是可選的,但是推薦設置并在授權服務中進行驗證 * tokenExtractor 令牌提取器用來提取請求中的令牌 * 請求匹配器,用來設置需要進行保護的資源路徑,默認的情況下是受保護資源服務的全部路徑 * 受保護資源的訪問規則,默認的規則是簡單的身份驗證(plain authenticated) * 其他的自定義權限保護規則通過 HttpSecurity 來進行配置 * 使用 DefaultTokenServices 在資源服務器本地配置令牌存儲、解碼、解析方式 # security-core代碼清單詳解 認證授權分離架構的oauth資源服務器,需要在代碼中設置一個門崗,驗證認證中心的token ,門崗代碼如下 ![](https://box.kancloud.cn/a6c1382d621a4bcf34c53ab56e6a8459_1769x776.png) 注意以下被注解,生產需要打開,配置用戶的api權限,注釋后有token即可訪問 `// 開啟spring security 注解 // @EnableGlobalMethodSecurity(prePostEnabled = true)` # token票據驗證 ![](https://box.kancloud.cn/7eea410bb58d317640e825e7a3e7c20e_588x703.png) 票據 redis持久化 ![](https://box.kancloud.cn/805bc758967ef81ecc4e9162b64e7653_1729x547.png) ![](https://box.kancloud.cn/8c489bf1042aa130aeb7068c379fb1fd_1765x768.png) 作為一個認證授權分離的架構,采用此種門崗+票據驗證方式是一種效率最高的方式.讀相關源碼可以驗證此結論,此方案已生產驗證。 ![](https://box.kancloud.cn/1c347e7b86407be804f33384ee113f5f_963x218.png) # oauth白名單配置 ![](https://box.kancloud.cn/7faa18b6385750842142845d7bd413d3_1757x641.png) # 網關api權限設計 相同用戶,不同應用的權限隔離 客戶端模式 : 客戶端A 申請的token ,可以訪問/api-user/menu/current , 客戶端B 申請的token,不讓訪問/api-user/menu/current 密碼模式: 客戶端模式 : 客戶端A admin用戶 申請的token ,可以訪問/api-user/menu/current , 客戶端B admin用戶 申請的token,不讓訪問/api-user/menu/current 參考issue:[https://gitee.com/owenwangwen/open-capacity-platform/issues/IRG23]() oauth引入自定義權限rbacservice前置支持處理 ![](https://box.kancloud.cn/6568e378c65f872f7f47e36aea776e97_1764x774.png) 開啟自定義rbacservice應用api權限隔離 ![](https://box.kancloud.cn/dbf40bee327e8fc38c7118720923c7b4_1761x689.png) ![](https://box.kancloud.cn/f573cab1f1e5e546e6a1e929ac8beedb_1781x752.png) 如果需要細粒度的控制網關api權限,請將注釋放開 通過clientID隔離API權限 ![](https://box.kancloud.cn/0d3f34894c316058e1085ae8fe9dc910_1737x603.png) # 自定義授權失敗接口 ![](https://box.kancloud.cn/845f24860699c7be9ef34cf537f7863c_1774x748.png) ![](https://box.kancloud.cn/9d4f1d8d8b92b9d52976b8d5171550ed_1808x788.png)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看