效果

实现

SwaggerAutoConfiguration里新增配置:

package com.fxkj.common.config;

import com.google.common.base.Predicates;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List; /**
* @author Jackson
*/
@Profile({"default", "dev", "test"})
@Configuration
@EnableConfigurationProperties({SwaggerProperties.class})
@ConditionalOnProperty(prefix = "swagger",value = "enable")
@EnableSwagger2
public class SwaggerAutoConfiguration {
@Resource
private SecurityConfig securityConfig; @Bean
public Docket swaggerSpringMvcPlugin(@Autowired SwaggerProperties swaggerConfigProps) {
return new Docket(DocumentationType.SWAGGER_2)
.enable(swaggerConfigProps.isEnable())
.useDefaultResponseMessages(false)
.apiInfo(apiInfo(swaggerConfigProps))
.securitySchemes(getSecuritySchemes())
.securityContexts(getSecurityContexts())
.select()
.paths(Predicates.not(PathSelectors.regex("/error.*")))
.build();
} private ApiInfo apiInfo(SwaggerProperties properties) {
return new ApiInfoBuilder()
.title(properties.getTitle())
.version(properties.getVersion())
.description(properties.getDescription())
.contact(new Contact(properties.getContactName(),
properties.getContactUrl(),
properties.getContactEmail()))
.license("Apache License Version 2.0")
.licenseUrl("https://github.com/springfox/springfox/blob/master/LICENSE")
.version("2.0")
.build();
} @Bean
public Docket api_system(@Autowired SwaggerProperties swaggerConfigProps) {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfoSystem(swaggerConfigProps))
.securitySchemes(getSecuritySchemes())
.securityContexts(getSecurityContexts())
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.ant("/system/**"))
.build()
.groupName("系统设置")
.pathMapping("/");
} @Bean
public Docket api_role(@Autowired SwaggerProperties swaggerConfigProps) {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfoSystem(swaggerConfigProps))
.securitySchemes(getSecuritySchemes())
.securityContexts(getSecurityContexts())
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.ant("/roles/**"))
.build()
.groupName("角色设置")
.pathMapping("/");
} @Bean
public Docket api_dict(@Autowired SwaggerProperties swaggerConfigProps) {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfoSystem(swaggerConfigProps))
.securitySchemes(getSecuritySchemes())
.securityContexts(getSecurityContexts())
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.ant("/dict/**"))
.build()
.groupName("字典维护")
.pathMapping("/");
} private ApiInfo apiInfoSystem(SwaggerProperties properties) {
return new ApiInfoBuilder()
.title("系统设置相关API")
.version(properties.getVersion())
.description(properties.getDescription())
.contact(new Contact(properties.getContactName(),
properties.getContactUrl(),
properties.getContactEmail()))
.license("Apache License Version 2.0")
.licenseUrl("https://github.com/springfox/springfox/blob/master/LICENSE")
.version("2.0")
.build();
} private ArrayList<ApiKey> getSecuritySchemes() {
return Lists.newArrayList(
new ApiKey("token", "token", "header")
);
} private List<SecurityContext> getSecurityContexts() {
AuthorizationScope[] scopes = {
new AuthorizationScope("global", "accessEverything")
};
List<SecurityReference> securityReferences = Lists.newArrayList(
new SecurityReference("token", scopes)
);
return Lists.newArrayList(SecurityContext.builder()
.securityReferences(securityReferences)
.forPaths(Predicates.not(Predicates.in(securityConfig.getIgnoreUrls())))
.build());
}
}

  

swagger菜单分级的更多相关文章

  1. python学习入门第一天总结

    虽然之前自己也看过许多关于python的视频,但一直没有动力与勇气,所以未能坚持且也没有学得这么深刻,这次希望通过python自动化培训,能够彻底改变自己,通过第一天的python学习,自己学到了许多 ...

  2. 我的第一个python web开发框架(34)——后台管理系统权限设计

    框架底层和接口终于改造完成了,小白再次找到老菜. 小白:老大,上次你对后台权限系统简单的讲了一下,我一点头绪都没有,现在有空完整的说一说吗? 老菜:说到权限系统,要讲明白真不容易,权限系统并不是越复杂 ...

  3. Django框架----权限管理(设计分析以及具体细节)

    说起权限我们大家都知道,不一样的角色会有不一样的权限.比如就像学生管理系统一样,管理员,老师,学生之间的权限都是不一样的,那么展示的页面也是不一样的.所以,我们现在来看看具体操作. 目标:生成一个独立 ...

  4. 基于角色权限管理:rbac设计分析以及具体细节

    权限管理---设计分析以及具体细节 说起权限我们大家都知道,不一样的角色会有不一样的权限. 比如就像学生管理系统一样,管理员,老师,学生之间的权限都是不一样的,那么展示的页面也是不一样的. 所以,我们 ...

  5. jQuery知识点小结

    博主之前学习一段时间后做了点Demo,借此机会发出来分享,其实学jQuery只要简单看看文档即可,但有些细枝末节的东西文档会默认使用者是了解的,所以还是得系统学习系统训练:Talk is cheap, ...

  6. 基于react实现无限分级菜单

    在开发CMS(内容管理系统)系统时,一般都会用到一个侧边栏或者顶部的二级或者三级菜单,当点击或者鼠标悬浮时,菜单能够随之展开或收起. 本文纯粹为了练习一下react,因此我会在react环境下实现这么 ...

  7. JS及Dom示例 | 分级菜单折叠

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. jQuery示例 | 分级菜单

    <!DOCTYPE html> Title .header{ background-color: black; color: wheat; } .content{ min-height: ...

  9. 无限分级和tree结构数据增删改【提供Demo下载】

    无限分级 很多时候我们不确定等级关系的层级,这个时候就需要用到无限分级了. 说到无限分级,又要扯到递归调用了.(据说频繁递归是很耗性能的),在此我们需要先设计好表机构,用来存储无限分级的数据.当然,以 ...

随机推荐

  1. SpringMVC(6)数据验证

    在系列SpringMVC(4)数据绑定-1.SpringMVC(5)数据绑定-2中我们展示了如何绑定数据,绑定完数据之后如何确保我们得到的数据的正确性?这就是我们本篇要说的内容 -> 数据验证. ...

  2. MyEclipse中,编写properties文件,输入中文显示乱码

    我在properties文件中输出中文,结果显示的是乱码,额......好吧,其实不是乱码,哪有这么规范的乱码 其实是在输入中文时发生了转码,就是下面这个样子: 字符集不支持中文,修改方法: 选中你工 ...

  3. JUnit5的条件测试、嵌套测试、重复测试

    条件测试 JUnit5支持条件注解,根据布尔值判断是否执行测试. 自定义条件 @EnabledIf和@DisabledIf注解用来设置自定义条件,示例: @Test @EnabledIf(" ...

  4. jar\war\SpringBoot加载包内外资源的方式,告别FileNotFoundException吧

    工作中常常会用到文件加载,然后又经常忘记,印象不深,没有系统性研究过,从最初的war包项目到现在的springboot项目,从加载外部文件到加载自身jar包内文件,也发生了许多变化,这里开一贴,作为自 ...

  5. 手写笔记变PDF-几行代码变命令行程序为图形化界面

    前言 最近发现了一个非常不错的Python类库----Gooey, https://github.com/chriskiehl/Gooey 在它的帮助下我们可以非常方便的将一个命令行程序升级成一个图形 ...

  6. Caffeine缓存的简单介绍

    1.简介 在本文中,我们将了解Caffeine,一个用于Java的高性能缓存库. 缓存和Map之间的一个根本区别是缓存会清理存储的项目. 一个清理策略会决定在某个给定时间哪些对象应该被删除,这个策略直 ...

  7. VisualEffectGraph基础操作 --创建VEG项目步骤讲解

    一:建立VEG项目步骤 首先打开Unity Hub,  使用unity2020.1 新建项目(本技术博客,默认使用unity2020.1 版本演示),选择HDRP 高清渲染管线,确定项目目录与名称. ...

  8. dart pub上传失败如何解决

    问题: Flutter Exception: Pub will wait for a while before trying to connect again. 解决 1.设置终端代理 export ...

  9. 【洛谷P1962 斐波那契数列】矩阵快速幂+数学推导

    来提供两个正确的做法: 斐波那契数列双倍项的做法(附加证明) 矩阵快速幂 一.双倍项做法 在偶然之中,在百度中翻到了有关于斐波那契数列的词条(传送门),那么我们可以发现一个这个规律$ \frac{F_ ...

  10. 记一次Hvv中遇到的API接口泄露而引起的一系列漏洞

    引言 最近朋友跟我一起把之前废弃的公众号做起来了,更名为鹿鸣安全团队,后面陆续会更新个人笔记,有趣的渗透经历,内网渗透相关话题等,欢迎大家关注 前言 Hvv中的一个很有趣的漏洞挖掘过程,从一个简单的A ...