Commit 035f9501 authored by zengtianlai3's avatar zengtianlai3

Merge branch 'master' into 'm33'

# Conflicts:
#   license/pom.xml
parents 68341bf9 9fabaa02
.idea
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: com.auth0:java-jwt:3.8.2">
<CLASSES>
<root url="jar://C:/tools/Spring/mvn_repository/com/auth0/java-jwt/3.8.2/java-jwt-3.8.2.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://C:/tools/Spring/mvn_repository/com/auth0/java-jwt/3.8.2/java-jwt-3.8.2-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://C:/tools/Spring/mvn_repository/com/auth0/java-jwt/3.8.2/java-jwt-3.8.2-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: commons-codec:commons-codec:1.15">
<CLASSES>
<root url="jar://C:/tools/Spring/mvn_repository/commons-codec/commons-codec/1.15/commons-codec-1.15.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://C:/tools/Spring/mvn_repository/commons-codec/commons-codec/1.15/commons-codec-1.15-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://C:/tools/Spring/mvn_repository/commons-codec/commons-codec/1.15/commons-codec-1.15-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: org.apache.commons:commons-collections4:4.1">
<CLASSES>
<root url="jar://C:/tools/Spring/mvn_repository/org/apache/commons/commons-collections4/4.1/commons-collections4-4.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://C:/tools/Spring/mvn_repository/org/apache/commons/commons-collections4/4.1/commons-collections4-4.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://C:/tools/Spring/mvn_repository/org/apache/commons/commons-collections4/4.1/commons-collections4-4.1-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: org.apache.poi:poi:3.17">
<CLASSES>
<root url="jar://C:/tools/Spring/mvn_repository/org/apache/poi/poi/3.17/poi-3.17.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://C:/tools/Spring/mvn_repository/org/apache/poi/poi/3.17/poi-3.17-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://C:/tools/Spring/mvn_repository/org/apache/poi/poi/3.17/poi-3.17-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
......@@ -65,6 +65,13 @@
<version>2.0</version>
</dependency>
<!--Knife4j API文档生产工具-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
......
......@@ -24,8 +24,8 @@ public class CorsConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// TODO Auto-generated method stub
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
@Override
......@@ -33,5 +33,4 @@ public class CorsConfig implements WebMvcConfigurer {
registry.addInterceptor(authenticationInterceptor)
.addPathPatterns("/**");
}
}
package iot.sixiang.license.config.swagger;
import org.springframework.context.annotation.Bean;
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 java.util.ArrayList;
import java.util.List;
public abstract class BaseSwaggerConfig {
@Bean
public Docket createRestApi() {
SwaggerProperties swaggerProperties = swaggerProperties();
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo(swaggerProperties))
.select()
.apis(RequestHandlerSelectors.basePackage(swaggerProperties.getApiBasePackage()))
.paths(PathSelectors.any())
.build();
if (swaggerProperties.isEnableSecurity()) {
docket.securitySchemes(securitySchemes()).securityContexts(securityContexts());
}
return docket;
}
private ApiInfo apiInfo(SwaggerProperties swaggerProperties) {
return new ApiInfoBuilder()
.title(swaggerProperties.getTitle())
.description(swaggerProperties.getDescription())
.contact(new Contact(swaggerProperties.getContactName(), swaggerProperties.getContactUrl(), swaggerProperties.getContactEmail()))
.version(swaggerProperties.getVersion())
.build();
}
private List<ApiKey> securitySchemes() {
//设置请求头信息
List<ApiKey> result = new ArrayList<>();
ApiKey apiKey = new ApiKey("Authorization", "Authorization", "header");
result.add(apiKey);
return result;
}
private List<SecurityContext> securityContexts() {
//设置需要登录认证的路径
List<SecurityContext> result = new ArrayList<>();
result.add(getContextByPath("/*/.*"));
return result;
}
private SecurityContext getContextByPath(String pathRegex) {
return SecurityContext.builder()
.securityReferences(defaultAuth())
.forPaths(PathSelectors.regex(pathRegex))
.build();
}
private List<SecurityReference> defaultAuth() {
List<SecurityReference> result = new ArrayList<>();
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
authorizationScopes[0] = authorizationScope;
result.add(new SecurityReference("Authorization", authorizationScopes));
return result;
}
/**
* 自定义Swagger配置
*/
public abstract SwaggerProperties swaggerProperties();
}
package iot.sixiang.license.config.swagger;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
/**
* Created by M=54G
* Date 4/27/21 9:37 AM
* Description API文档相关配置
*/
@Configuration
@EnableSwagger2WebMvc
public class SwaggerConfig extends BaseSwaggerConfig {
@Override
public SwaggerProperties swaggerProperties() {
return SwaggerProperties.builder()
.apiBasePackage("iot.sixiang.license.controller")
.title("实名制接口")
.description("实名制接口文档")
.contactName("ACC")
.version("1.0")
.enableSecurity(true)
.build();
}
}
package iot.sixiang.license.config.swagger;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
@Builder
public class SwaggerProperties {
/**
* API文档生成基础路径
*/
private String apiBasePackage;
/**
* 是否要启用登录认证
*/
private boolean enableSecurity;
/**
* 文档标题
*/
private String title;
/**
* 文档描述
*/
private String description;
/**
* 文档版本
*/
private String version;
/**
* 文档联系人姓名
*/
private String contactName;
/**
* 文档联系人网址
*/
private String contactUrl;
/**
* 文档联系人邮箱
*/
private String contactEmail;
}
......@@ -5,7 +5,6 @@ import com.auth0.jwt.interfaces.Claim;
import com.auth0.jwt.interfaces.DecodedJWT;
import iot.sixiang.license.model.ResResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
......@@ -20,6 +19,13 @@ public class JwtFilter implements Filter {
private static final String url1 = "/login";
private static final String url2 = "/resource";
private static final String url3 = "/doc.html";
private static final String url4 = "/v3/swagger-login";
private static final String url5 = "/swagger-ui.html";
private static final String url6 = "/static";
private static final String url7 = "/swagger-resources";
private static final String url8 = "/webjars/";
@Override
public void init(FilterConfig filterConfig) throws ServletException {
......@@ -40,7 +46,7 @@ public class JwtFilter implements Filter {
String token = request.getHeader("authorization");
boolean check = true;
String uri = request.getRequestURI();
if (uri.contains(url1) || uri.contains(url2)) {
if (uri.contains(url1) || uri.contains(url2) || uri.contains(url3) || uri.contains(url4) || uri.contains(url5) || uri.contains(url6) || uri.contains(url7) || uri.contains(url8)) {
check = false;
}
if (!check) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment