修复文档页面不可用BUG,支持设置认证消息头来方便调用其他接口
parent
33fba05a38
commit
7c07ae9421
15
pom.xml
15
pom.xml
|
@ -162,22 +162,17 @@
|
||||||
<version>1.4.6</version>
|
<version>1.4.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!--在线文档 -->
|
||||||
<!--在线文档 -->
|
<!--在线文档 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springdoc</groupId>
|
<groupId>org.springdoc</groupId>
|
||||||
<artifactId>springdoc-openapi-ui</artifactId>
|
<artifactId>springdoc-openapi-ui</artifactId>
|
||||||
<version>1.7.0</version>
|
<version>1.6.10</version>
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.yaml</groupId>
|
|
||||||
<artifactId>snakeyaml</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.yaml</groupId>
|
<groupId>org.springdoc</groupId>
|
||||||
<artifactId>snakeyaml</artifactId>
|
<artifactId>springdoc-openapi-security</artifactId>
|
||||||
<version>2.2</version>
|
<version>1.6.10</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
package com.genersoft.iot.vmp.conf;
|
package com.genersoft.iot.vmp.conf;
|
||||||
|
|
||||||
|
import com.genersoft.iot.vmp.conf.security.JwtUtils;
|
||||||
|
import io.swagger.v3.oas.models.Components;
|
||||||
import io.swagger.v3.oas.models.OpenAPI;
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
import io.swagger.v3.oas.models.info.Contact;
|
import io.swagger.v3.oas.models.info.Contact;
|
||||||
import io.swagger.v3.oas.models.info.Info;
|
import io.swagger.v3.oas.models.info.Info;
|
||||||
import io.swagger.v3.oas.models.info.License;
|
import io.swagger.v3.oas.models.info.License;
|
||||||
|
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springdoc.core.GroupedOpenApi;
|
import org.springdoc.core.GroupedOpenApi;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
@ -26,10 +29,14 @@ public class SpringDocConfig {
|
||||||
contact.setName("pan");
|
contact.setName("pan");
|
||||||
contact.setEmail("648540858@qq.com");
|
contact.setEmail("648540858@qq.com");
|
||||||
return new OpenAPI()
|
return new OpenAPI()
|
||||||
|
.components(new Components()
|
||||||
|
.addSecuritySchemes(JwtUtils.HEADER, new SecurityScheme()
|
||||||
|
.type(SecurityScheme.Type.HTTP)
|
||||||
|
.bearerFormat("JWT")))
|
||||||
.info(new Info().title("WVP-PRO 接口文档")
|
.info(new Info().title("WVP-PRO 接口文档")
|
||||||
.contact(contact)
|
.contact(contact)
|
||||||
.description("开箱即用的28181协议视频平台")
|
.description("开箱即用的28181协议视频平台")
|
||||||
.version("v2.0")
|
.version("v3.1.0")
|
||||||
.license(new License().name("Apache 2.0").url("http://springdoc.org")));
|
.license(new License().name("Apache 2.0").url("http://springdoc.org")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class JwtUtils implements InitializingBean {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(JwtUtils.class);
|
private static final Logger logger = LoggerFactory.getLogger(JwtUtils.class);
|
||||||
|
|
||||||
private static final String HEADER = "access-token";
|
public static final String HEADER = "access-token";
|
||||||
|
|
||||||
private static final String AUDIENCE = "Audience";
|
private static final String AUDIENCE = "Audience";
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||||
matchers.add("/");
|
matchers.add("/");
|
||||||
matchers.add("/#/**");
|
matchers.add("/#/**");
|
||||||
matchers.add("/static/**");
|
matchers.add("/static/**");
|
||||||
|
matchers.add("/swagger-ui.html");
|
||||||
|
matchers.add("/swagger-ui/");
|
||||||
matchers.add("/index.html");
|
matchers.add("/index.html");
|
||||||
matchers.add("/doc.html");
|
matchers.add("/doc.html");
|
||||||
matchers.add("/webjars/**");
|
matchers.add("/webjars/**");
|
||||||
|
@ -77,6 +79,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||||
matchers.add("/api/device/query/snap/**");
|
matchers.add("/api/device/query/snap/**");
|
||||||
matchers.add("/record_proxy/*/**");
|
matchers.add("/record_proxy/*/**");
|
||||||
matchers.add("/api/emit");
|
matchers.add("/api/emit");
|
||||||
|
matchers.add("/favicon.ico");
|
||||||
// 可以直接访问的静态数据
|
// 可以直接访问的静态数据
|
||||||
web.ignoring().antMatchers(matchers.toArray(new String[0]));
|
web.ignoring().antMatchers(matchers.toArray(new String[0]));
|
||||||
}
|
}
|
||||||
|
@ -113,7 +116,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||||
.authorizeRequests()
|
.authorizeRequests()
|
||||||
.requestMatchers(CorsUtils::isPreFlightRequest).permitAll()
|
.requestMatchers(CorsUtils::isPreFlightRequest).permitAll()
|
||||||
.antMatchers(userSetting.getInterfaceAuthenticationExcludes().toArray(new String[0])).permitAll()
|
.antMatchers(userSetting.getInterfaceAuthenticationExcludes().toArray(new String[0])).permitAll()
|
||||||
.antMatchers("/api/user/login", "/index/hook/**").permitAll()
|
.antMatchers("/api/user/login", "/index/hook/**", "/swagger-ui/**", "/doc.html").permitAll()
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
// 异常处理器
|
// 异常处理器
|
||||||
.and()
|
.and()
|
||||||
|
|
|
@ -14,6 +14,7 @@ import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
|
@ -95,7 +96,7 @@ public class UserController {
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/add")
|
@PostMapping("/add")
|
||||||
@Operation(summary = "添加用户")
|
@Operation(summary = "添加用户", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||||
@Parameter(name = "username", description = "用户名", required = true)
|
@Parameter(name = "username", description = "用户名", required = true)
|
||||||
@Parameter(name = "password", description = "密码(未md5加密的密码)", required = true)
|
@Parameter(name = "password", description = "密码(未md5加密的密码)", required = true)
|
||||||
@Parameter(name = "roleId", description = "角色ID", required = true)
|
@Parameter(name = "roleId", description = "角色ID", required = true)
|
||||||
|
|
Loading…
Reference in New Issue