springdoc
This commit is contained in:
parent
0a6ff25875
commit
c65919c600
8
pom.xml
8
pom.xml
@ -29,6 +29,7 @@
|
|||||||
<commons.io.version>2.13.0</commons.io.version>
|
<commons.io.version>2.13.0</commons.io.version>
|
||||||
<poi.version>4.1.2</poi.version>
|
<poi.version>4.1.2</poi.version>
|
||||||
<velocity.version>2.3</velocity.version>
|
<velocity.version>2.3</velocity.version>
|
||||||
|
<springdoc.version>2.5.0</springdoc.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<!-- 依赖声明 -->
|
<!-- 依赖声明 -->
|
||||||
@ -142,6 +143,13 @@
|
|||||||
<version>${oshi.version}</version>
|
<version>${oshi.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- spring-doc -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springdoc</groupId>
|
||||||
|
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||||
|
<version>${springdoc.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- io常用工具类 -->
|
<!-- io常用工具类 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-io</groupId>
|
<groupId>commons-io</groupId>
|
||||||
|
@ -30,6 +30,12 @@
|
|||||||
<optional>true</optional> <!-- 表示依赖不会传递 -->
|
<optional>true</optional> <!-- 表示依赖不会传递 -->
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- spring-doc -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springdoc</groupId>
|
||||||
|
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Mysql驱动包 -->
|
<!-- Mysql驱动包 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mysql</groupId>
|
<groupId>com.mysql</groupId>
|
||||||
|
@ -1,183 +1,175 @@
|
|||||||
//package com.ruoyi.web.controller.tool;
|
package com.ruoyi.web.controller.tool;
|
||||||
//
|
|
||||||
//import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
//import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
//import java.util.List;
|
import java.util.List;
|
||||||
//import java.util.Map;
|
import java.util.Map;
|
||||||
//import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
//import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
//import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
//import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
//import org.springframework.web.bind.annotation.PutMapping;
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
//import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
//import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
//import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
//import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
//import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
//import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
//import io.swagger.annotations.Api;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
//import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
//import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
//import io.swagger.annotations.ApiModel;
|
|
||||||
//import io.swagger.annotations.ApiModelProperty;
|
/**
|
||||||
//import io.swagger.annotations.ApiOperation;
|
* swagger 用户测试方法
|
||||||
//
|
*
|
||||||
///**
|
* @author ruoyi
|
||||||
// * swagger 用户测试方法
|
*/
|
||||||
// *
|
@Tag(name = "用户信息管理")
|
||||||
// * @author ruoyi
|
@RestController
|
||||||
// */
|
@RequestMapping("/test/user")
|
||||||
//@Api("用户信息管理")
|
public class TestController extends BaseController
|
||||||
//@RestController
|
{
|
||||||
//@RequestMapping("/test/user")
|
private final static Map<Integer, UserEntity> users = new LinkedHashMap<Integer, UserEntity>();
|
||||||
//public class TestController extends BaseController
|
{
|
||||||
//{
|
users.put(1, new UserEntity(1, "admin", "admin123", "15888888888"));
|
||||||
// private final static Map<Integer, UserEntity> users = new LinkedHashMap<Integer, UserEntity>();
|
users.put(2, new UserEntity(2, "ry", "admin123", "15666666666"));
|
||||||
// {
|
}
|
||||||
// users.put(1, new UserEntity(1, "admin", "admin123", "15888888888"));
|
|
||||||
// users.put(2, new UserEntity(2, "ry", "admin123", "15666666666"));
|
@Operation(summary = "获取用户列表")
|
||||||
// }
|
@GetMapping("/list")
|
||||||
//
|
public R<List<UserEntity>> userList()
|
||||||
// @ApiOperation("获取用户列表")
|
{
|
||||||
// @GetMapping("/list")
|
List<UserEntity> userList = new ArrayList<UserEntity>(users.values());
|
||||||
// public R<List<UserEntity>> userList()
|
return R.ok(userList);
|
||||||
// {
|
}
|
||||||
// List<UserEntity> userList = new ArrayList<UserEntity>(users.values());
|
|
||||||
// return R.ok(userList);
|
@Operation(summary = "获取用户详细")
|
||||||
// }
|
@GetMapping("/{userId}")
|
||||||
//
|
public R<UserEntity> getUser(@PathVariable(name = "userId")
|
||||||
// @ApiOperation("获取用户详细")
|
Integer userId)
|
||||||
// @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class)
|
{
|
||||||
// @GetMapping("/{userId}")
|
if (!users.isEmpty() && users.containsKey(userId))
|
||||||
// public R<UserEntity> getUser(@PathVariable Integer userId)
|
{
|
||||||
// {
|
return R.ok(users.get(userId));
|
||||||
// if (!users.isEmpty() && users.containsKey(userId))
|
}
|
||||||
// {
|
else
|
||||||
// return R.ok(users.get(userId));
|
{
|
||||||
// }
|
return R.fail("用户不存在");
|
||||||
// else
|
}
|
||||||
// {
|
}
|
||||||
// return R.fail("用户不存在");
|
|
||||||
// }
|
@Operation(summary = "新增用户")
|
||||||
// }
|
@PostMapping("/save")
|
||||||
//
|
public R<String> save(UserEntity user)
|
||||||
// @ApiOperation("新增用户")
|
{
|
||||||
// @ApiImplicitParams({
|
if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId()))
|
||||||
// @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Integer", dataTypeClass = Integer.class),
|
{
|
||||||
// @ApiImplicitParam(name = "username", value = "用户名称", dataType = "String", dataTypeClass = String.class),
|
return R.fail("用户ID不能为空");
|
||||||
// @ApiImplicitParam(name = "password", value = "用户密码", dataType = "String", dataTypeClass = String.class),
|
}
|
||||||
// @ApiImplicitParam(name = "mobile", value = "用户手机", dataType = "String", dataTypeClass = String.class)
|
users.put(user.getUserId(), user);
|
||||||
// })
|
return R.ok();
|
||||||
// @PostMapping("/save")
|
}
|
||||||
// public R<String> save(UserEntity user)
|
|
||||||
// {
|
@Operation(summary = "更新用户")
|
||||||
// if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId()))
|
@PutMapping("/update")
|
||||||
// {
|
public R<String> update(@RequestBody
|
||||||
// return R.fail("用户ID不能为空");
|
UserEntity user)
|
||||||
// }
|
{
|
||||||
// users.put(user.getUserId(), user);
|
if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId()))
|
||||||
// return R.ok();
|
{
|
||||||
// }
|
return R.fail("用户ID不能为空");
|
||||||
//
|
}
|
||||||
// @ApiOperation("更新用户")
|
if (users.isEmpty() || !users.containsKey(user.getUserId()))
|
||||||
// @PutMapping("/update")
|
{
|
||||||
// public R<String> update(@RequestBody UserEntity user)
|
return R.fail("用户不存在");
|
||||||
// {
|
}
|
||||||
// if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId()))
|
users.remove(user.getUserId());
|
||||||
// {
|
users.put(user.getUserId(), user);
|
||||||
// return R.fail("用户ID不能为空");
|
return R.ok();
|
||||||
// }
|
}
|
||||||
// if (users.isEmpty() || !users.containsKey(user.getUserId()))
|
|
||||||
// {
|
@Operation(summary = "删除用户信息")
|
||||||
// return R.fail("用户不存在");
|
@DeleteMapping("/{userId}")
|
||||||
// }
|
public R<String> delete(@PathVariable(name = "userId")
|
||||||
// users.remove(user.getUserId());
|
Integer userId)
|
||||||
// users.put(user.getUserId(), user);
|
{
|
||||||
// return R.ok();
|
if (!users.isEmpty() && users.containsKey(userId))
|
||||||
// }
|
{
|
||||||
//
|
users.remove(userId);
|
||||||
// @ApiOperation("删除用户信息")
|
return R.ok();
|
||||||
// @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class)
|
}
|
||||||
// @DeleteMapping("/{userId}")
|
else
|
||||||
// public R<String> delete(@PathVariable Integer userId)
|
{
|
||||||
// {
|
return R.fail("用户不存在");
|
||||||
// if (!users.isEmpty() && users.containsKey(userId))
|
}
|
||||||
// {
|
}
|
||||||
// users.remove(userId);
|
}
|
||||||
// return R.ok();
|
|
||||||
// }
|
@Schema(description = "用户实体")
|
||||||
// else
|
class UserEntity
|
||||||
// {
|
{
|
||||||
// return R.fail("用户不存在");
|
@Schema(title = "用户ID")
|
||||||
// }
|
private Integer userId;
|
||||||
// }
|
|
||||||
//}
|
@Schema(title = "用户名称")
|
||||||
//
|
private String username;
|
||||||
//@ApiModel(value = "UserEntity", description = "用户实体")
|
|
||||||
//class UserEntity
|
@Schema(title = "用户密码")
|
||||||
//{
|
private String password;
|
||||||
// @ApiModelProperty("用户ID")
|
|
||||||
// private Integer userId;
|
@Schema(title = "用户手机")
|
||||||
//
|
private String mobile;
|
||||||
// @ApiModelProperty("用户名称")
|
|
||||||
// private String username;
|
public UserEntity()
|
||||||
//
|
{
|
||||||
// @ApiModelProperty("用户密码")
|
|
||||||
// private String password;
|
}
|
||||||
//
|
|
||||||
// @ApiModelProperty("用户手机")
|
public UserEntity(Integer userId, String username, String password, String mobile)
|
||||||
// private String mobile;
|
{
|
||||||
//
|
this.userId = userId;
|
||||||
// public UserEntity()
|
this.username = username;
|
||||||
// {
|
this.password = password;
|
||||||
//
|
this.mobile = mobile;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public UserEntity(Integer userId, String username, String password, String mobile)
|
public Integer getUserId()
|
||||||
// {
|
{
|
||||||
// this.userId = userId;
|
return userId;
|
||||||
// this.username = username;
|
}
|
||||||
// this.password = password;
|
|
||||||
// this.mobile = mobile;
|
public void setUserId(Integer userId)
|
||||||
// }
|
{
|
||||||
//
|
this.userId = userId;
|
||||||
// public Integer getUserId()
|
}
|
||||||
// {
|
|
||||||
// return userId;
|
public String getUsername()
|
||||||
// }
|
{
|
||||||
//
|
return username;
|
||||||
// public void setUserId(Integer userId)
|
}
|
||||||
// {
|
|
||||||
// this.userId = userId;
|
public void setUsername(String username)
|
||||||
// }
|
{
|
||||||
//
|
this.username = username;
|
||||||
// public String getUsername()
|
}
|
||||||
// {
|
|
||||||
// return username;
|
public String getPassword()
|
||||||
// }
|
{
|
||||||
//
|
return password;
|
||||||
// public void setUsername(String username)
|
}
|
||||||
// {
|
|
||||||
// this.username = username;
|
public void setPassword(String password)
|
||||||
// }
|
{
|
||||||
//
|
this.password = password;
|
||||||
// public String getPassword()
|
}
|
||||||
// {
|
|
||||||
// return password;
|
public String getMobile()
|
||||||
// }
|
{
|
||||||
//
|
return mobile;
|
||||||
// public void setPassword(String password)
|
}
|
||||||
// {
|
|
||||||
// this.password = password;
|
public void setMobile(String mobile)
|
||||||
// }
|
{
|
||||||
//
|
this.mobile = mobile;
|
||||||
// public String getMobile()
|
}
|
||||||
// {
|
}
|
||||||
// return mobile;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void setMobile(String mobile)
|
|
||||||
// {
|
|
||||||
// this.mobile = mobile;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
@ -1,67 +1,65 @@
|
|||||||
//package com.ruoyi.web.core.config;
|
package com.ruoyi.web.core.config;
|
||||||
//
|
|
||||||
//import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
//import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
//import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
//import com.ruoyi.common.config.RuoYiConfig;
|
import com.ruoyi.common.config.RuoYiConfig;
|
||||||
//import io.swagger.annotations.ApiOperation;
|
import io.swagger.v3.oas.models.Components;
|
||||||
//import springfox.documentation.builders.ApiInfoBuilder;
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
//import springfox.documentation.builders.PathSelectors;
|
import io.swagger.v3.oas.models.info.Contact;
|
||||||
//import springfox.documentation.builders.RequestHandlerSelectors;
|
import io.swagger.v3.oas.models.info.Info;
|
||||||
//import springfox.documentation.service.ApiInfo;
|
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||||
//import springfox.documentation.service.Contact;
|
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||||
//import springfox.documentation.spi.DocumentationType;
|
|
||||||
//import springfox.documentation.spring.web.plugins.Docket;
|
/**
|
||||||
//
|
* Swagger2的接口配置
|
||||||
///**
|
*
|
||||||
// * Swagger2的接口配置
|
* @author ruoyi
|
||||||
// *
|
*/
|
||||||
// * @author ruoyi
|
@Configuration
|
||||||
// */
|
public class SwaggerConfig
|
||||||
//@Configuration
|
{
|
||||||
//public class SwaggerConfig
|
/** 系统基础配置 */
|
||||||
//{
|
@Autowired
|
||||||
// /** 是否开启swagger */
|
private RuoYiConfig ruoyiConfig;
|
||||||
// @Value("${swagger.enabled}")
|
|
||||||
// private boolean enabled;
|
/**
|
||||||
//
|
* 自定义的 OpenAPI 对象
|
||||||
// /**
|
*/
|
||||||
// * 创建API
|
@Bean
|
||||||
// */
|
public OpenAPI customOpenApi()
|
||||||
// @Bean
|
{
|
||||||
// public Docket createRestApi()
|
return new OpenAPI().components(new Components()
|
||||||
// {
|
// 设置认证的请求头
|
||||||
// return new Docket(DocumentationType.OAS_30)
|
.addSecuritySchemes("apikey", securityScheme()))
|
||||||
// // 是否启用Swagger
|
.addSecurityItem(new SecurityRequirement().addList("apikey"))
|
||||||
// .enable(enabled)
|
.info(getApiInfo());
|
||||||
// // 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息)
|
}
|
||||||
// .apiInfo(apiInfo())
|
|
||||||
// // 设置哪些接口暴露给Swagger展示
|
@Bean
|
||||||
// .select()
|
public SecurityScheme securityScheme()
|
||||||
// // 扫描所有有注解的api,用这种方式更灵活
|
{
|
||||||
// .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
|
return new SecurityScheme()
|
||||||
// // 扫描指定包中的swagger注解
|
.type(SecurityScheme.Type.APIKEY)
|
||||||
// //.apis(RequestHandlerSelectors.basePackage("com.ruoyi.project.tool.swagger"))
|
.name("Authorization")
|
||||||
// // 扫描所有 .apis(RequestHandlerSelectors.any())
|
.in(SecurityScheme.In.HEADER)
|
||||||
// .paths(PathSelectors.any())
|
.scheme("Bearer");
|
||||||
// .build();
|
}
|
||||||
// }
|
|
||||||
//
|
/**
|
||||||
// /**
|
* 添加摘要信息
|
||||||
// * 添加摘要信息
|
*/
|
||||||
// */
|
@SuppressWarnings("static-access")
|
||||||
// private ApiInfo apiInfo()
|
public Info getApiInfo()
|
||||||
// {
|
{
|
||||||
// // 用ApiInfoBuilder进行定制
|
return new Info()
|
||||||
// return new ApiInfoBuilder()
|
// 设置标题
|
||||||
// // 设置标题
|
.title("标题:若依管理系统_接口文档")
|
||||||
// .title("标题:若依管理系统_接口文档")
|
// 描述
|
||||||
// // 描述
|
.description("描述:用于管理集团旗下公司的人员信息,具体包括XXX,XXX模块...")
|
||||||
// .description("描述:用于管理集团旗下公司的人员信息,具体包括XXX,XXX模块...")
|
// 作者信息
|
||||||
// // 作者信息
|
.contact(new Contact().name(ruoyiConfig.getName()))
|
||||||
// .contact(new Contact(RuoYiConfig.getName(), null, null))
|
// 版本
|
||||||
// // 版本
|
.version("版本号:" + ruoyiConfig.getVersion());
|
||||||
// .version("版本号:" + RuoYiConfig.getVersion())
|
}
|
||||||
// .build();
|
}
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
@ -127,6 +127,20 @@ shiro:
|
|||||||
# 是否开启记住我
|
# 是否开启记住我
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
||||||
|
# Springdoc配置
|
||||||
|
springdoc:
|
||||||
|
api-docs:
|
||||||
|
path: /v3/api-docs
|
||||||
|
swagger-ui:
|
||||||
|
enabled: true
|
||||||
|
path: /swagger-ui.html
|
||||||
|
tags-sorter: alpha
|
||||||
|
group-configs:
|
||||||
|
- group: 'default'
|
||||||
|
display-name: '测试模块'
|
||||||
|
paths-to-match: '/**'
|
||||||
|
packages-to-scan: com.ruoyi.web.controller.tool
|
||||||
|
|
||||||
# 防止XSS攻击
|
# 防止XSS攻击
|
||||||
xss:
|
xss:
|
||||||
# 过滤开关
|
# 过滤开关
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<artifactId>servlet-api</artifactId>
|
<artifactId>servlet-api</artifactId>
|
||||||
<groupId>jakarta.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
@ -4,7 +4,6 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.shiro.cache.ehcache.EhCacheManager;
|
import org.apache.shiro.cache.ehcache.EhCacheManager;
|
||||||
@ -25,7 +24,6 @@ import com.ruoyi.common.constant.Constants;
|
|||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.common.utils.security.CipherUtils;
|
import com.ruoyi.common.utils.security.CipherUtils;
|
||||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||||
import com.ruoyi.framework.config.properties.PermitAllUrlProperties;
|
|
||||||
import com.ruoyi.framework.shiro.realm.UserRealm;
|
import com.ruoyi.framework.shiro.realm.UserRealm;
|
||||||
import com.ruoyi.framework.shiro.session.OnlineSessionDAO;
|
import com.ruoyi.framework.shiro.session.OnlineSessionDAO;
|
||||||
import com.ruoyi.framework.shiro.session.OnlineSessionFactory;
|
import com.ruoyi.framework.shiro.session.OnlineSessionFactory;
|
||||||
@ -290,12 +288,6 @@ public class ShiroConfig
|
|||||||
filterChainDefinitionMap.put("/js/**", "anon");
|
filterChainDefinitionMap.put("/js/**", "anon");
|
||||||
filterChainDefinitionMap.put("/ruoyi/**", "anon");
|
filterChainDefinitionMap.put("/ruoyi/**", "anon");
|
||||||
filterChainDefinitionMap.put("/captcha/captchaImage**", "anon");
|
filterChainDefinitionMap.put("/captcha/captchaImage**", "anon");
|
||||||
// 匿名访问不鉴权注解列表
|
|
||||||
List<String> permitAllUrl = SpringUtils.getBean(PermitAllUrlProperties.class).getUrls();
|
|
||||||
if (StringUtils.isNotEmpty(permitAllUrl))
|
|
||||||
{
|
|
||||||
permitAllUrl.forEach(url -> filterChainDefinitionMap.put(url, "anon"));
|
|
||||||
}
|
|
||||||
// 退出 logout地址,shiro去清除session
|
// 退出 logout地址,shiro去清除session
|
||||||
filterChainDefinitionMap.put("/logout", "logout");
|
filterChainDefinitionMap.put("/logout", "logout");
|
||||||
// 不需要拦截的访问
|
// 不需要拦截的访问
|
||||||
|
@ -1,122 +0,0 @@
|
|||||||
package com.ruoyi.framework.config.properties;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import org.springframework.aop.framework.Advised;
|
|
||||||
import org.springframework.beans.BeansException;
|
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.context.ApplicationContextAware;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import com.ruoyi.common.annotation.Anonymous;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置Anonymous注解允许匿名访问的url
|
|
||||||
*
|
|
||||||
* @author ruoyi
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class PermitAllUrlProperties implements InitializingBean, ApplicationContextAware
|
|
||||||
{
|
|
||||||
private List<String> urls = new ArrayList<>();
|
|
||||||
|
|
||||||
private ApplicationContext applicationContext;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterPropertiesSet() throws Exception
|
|
||||||
{
|
|
||||||
Map<String, Object> controllers = applicationContext.getBeansWithAnnotation(Controller.class);
|
|
||||||
for (Object bean : controllers.values())
|
|
||||||
{
|
|
||||||
if (!(bean instanceof Advised))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Class<?> beanClass = ((Advised) bean).getTargetSource().getTarget().getClass();
|
|
||||||
RequestMapping base = beanClass.getAnnotation(RequestMapping.class);
|
|
||||||
String[] baseUrl = {};
|
|
||||||
if (Objects.nonNull(base))
|
|
||||||
{
|
|
||||||
baseUrl = base.value();
|
|
||||||
}
|
|
||||||
Method[] methods = beanClass.getDeclaredMethods();
|
|
||||||
for (Method method : methods)
|
|
||||||
{
|
|
||||||
if (method.isAnnotationPresent(Anonymous.class) && method.isAnnotationPresent(RequestMapping.class))
|
|
||||||
{
|
|
||||||
RequestMapping requestMapping = method.getAnnotation(RequestMapping.class);
|
|
||||||
String[] uri = requestMapping.value();
|
|
||||||
urls.addAll(rebuildUrl(baseUrl, uri));
|
|
||||||
}
|
|
||||||
else if (method.isAnnotationPresent(Anonymous.class) && method.isAnnotationPresent(GetMapping.class))
|
|
||||||
{
|
|
||||||
GetMapping requestMapping = method.getAnnotation(GetMapping.class);
|
|
||||||
String[] uri = requestMapping.value();
|
|
||||||
urls.addAll(rebuildUrl(baseUrl, uri));
|
|
||||||
}
|
|
||||||
else if (method.isAnnotationPresent(Anonymous.class) && method.isAnnotationPresent(PostMapping.class))
|
|
||||||
{
|
|
||||||
PostMapping requestMapping = method.getAnnotation(PostMapping.class);
|
|
||||||
String[] uri = requestMapping.value();
|
|
||||||
urls.addAll(rebuildUrl(baseUrl, uri));
|
|
||||||
}
|
|
||||||
else if (method.isAnnotationPresent(Anonymous.class) && method.isAnnotationPresent(PutMapping.class))
|
|
||||||
{
|
|
||||||
PutMapping requestMapping = method.getAnnotation(PutMapping.class);
|
|
||||||
String[] uri = requestMapping.value();
|
|
||||||
urls.addAll(rebuildUrl(baseUrl, uri));
|
|
||||||
}
|
|
||||||
else if (method.isAnnotationPresent(Anonymous.class) && method.isAnnotationPresent(DeleteMapping.class))
|
|
||||||
{
|
|
||||||
DeleteMapping requestMapping = method.getAnnotation(DeleteMapping.class);
|
|
||||||
String[] uri = requestMapping.value();
|
|
||||||
urls.addAll(rebuildUrl(baseUrl, uri));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<String> rebuildUrl(String[] bases, String[] uris)
|
|
||||||
{
|
|
||||||
List<String> urls = new ArrayList<>();
|
|
||||||
for (String base : bases)
|
|
||||||
{
|
|
||||||
for (String uri : uris)
|
|
||||||
{
|
|
||||||
urls.add(prefix(base) + prefix(uri));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return urls;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String prefix(String seg)
|
|
||||||
{
|
|
||||||
return seg.startsWith("/") ? seg : "/" + seg;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setApplicationContext(ApplicationContext context) throws BeansException
|
|
||||||
{
|
|
||||||
this.applicationContext = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getUrls()
|
|
||||||
{
|
|
||||||
return urls;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUrls(List<String> urls)
|
|
||||||
{
|
|
||||||
this.urls = urls;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user