SpringBoot2.x系列教程(五十二)Spring Boot基於SpringSecurity設置swagger2訪問權限

前面我們學習了Spring Boot集成swagger2的具體操作,但swagger2默認是沒有權限控制的,也就是說如果是在內網還好,要是在公網上使用,那麼對應接口文檔信息將出現安全問題。

這篇文章我們就結合SpringBoot中SpringSecurity來進行設置,讓通過swagger2生成的接口文檔也擁有訪問權限,並且不影響其他業務的正常使用。

SpringSecurity

目前Web開發常用的兩個安全框架:Apache Shiro和Spring Security,Spring Security本身是Spring社區的一個子架構,相對而言對Spring有更好的支持。

默認情況下,Spring Security提供了權限、角色、登錄等功能。關於Spring Security的詳細功能我們後面會專門用來介紹。這裏我們直接按照步驟集成使用即可。

功能實現

在swagger2集成項目的基礎上引入Spring Security的依賴:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <optional>true</optional>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章