效果

实现

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. 使用 Cron4j 表达式 在 Solon 里开发定时任务

    cron4j 是一个轻量级的Java任务调度工具.cron4j-solon-plugin 是 solon 对 cron4j 的适配插件 添加 maven 引用 <dependency> & ...

  2. 公钥-私钥 白名单-黑名单 Linux 远程访问及控制(SSH)

    远程访问及控制一.SSH远程管理二.OpenSSH服务器① SSH (Secure Shell)协议② OpenSSH三.配置OpenSSH服务器举例四.sshd 服务支持两种验证方式五.使用SSH客 ...

  3. Linux系统引导过程及排除启动故障

    一.Linux操作系统引导过程二.系统初始化进程1.init进程2.Systemd3.Systemd单元类型三.排除启动类故障[1].修复MBR扇区故障(含实验过程)[2].修复GRUB引导故障●方法 ...

  4. 从零搭建一个IdentityServer——资源与访问控制

    IdentityServer作为授权服务器它的最终目的是用于对资源进行管控,这里所说的资源有两种,其一是API资源,实际上也就是OIDC协议中客户端(RP)所需要访问的一系列受保护的资源(API),授 ...

  5. Wordcloud(词云)安装使用以及vscode搭建虚拟环境

    (电脑烧掉了主板,地方上的所有门店全部关闭了,幸好现在京东还通物流,总算是进行把电脑拿回来了.对于一些东西无法实际操作真的是很难受,言归正传,说一下Wordcloud) Wordcloud安装(全局安 ...

  6. WSL2:Windows 亲生的 Linux 子系统

    作 者:道哥,10+年的嵌入式开发老兵. 公众号:[IOT物联网小镇],专注于:C/C++.Linux操作系统.应用程序设计.物联网.单片机和嵌入式开发等领域. 公众号回复[书籍],获取 Linux. ...

  7. linux xsel命令

    xsel操作在三个寄存器上,其中一个是系统剪切板(-b).一个是默认寄存器(-p).一个是(-s)

  8. 网络损伤仪WANsim中的乱序功能

    乱序 乱序功能需要指定每个帧 发生乱序的概率,以及新的帧的位置相较于原来位置的时间范围. 乱序的概率范围是0%~20%,颗粒度是0.001%.Delay的设置范围为 0s~10s,颗粒度为0.1 ms ...

  9. POJ1456 Supermarket 题解

    思维题. 关键在于如何想到用堆来维护贪心的策略. 首先肯定是卖出的利润越大的越好,但有可能当前这天选定了利润最大的很久才过期而利润第二大的第二天就过期,这时的策略就不优了. 所以我们必须动态改变策略, ...

  10. Receiver class com.mchange.v2.c3p0.impl.NewProxyResultSet does not define or inherit an implementation of the resolved method 'abstract boolean isClosed()' of interface java.sql.ResultSet.

    背景: Mayabtis+springboot项目,连接数据库发生异常 报错内容: java.lang.AbstractMethodError: Receiver class com.mchange. ...