Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
ioc_sixiang_license
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zengtianlai3
ioc_sixiang_license
Commits
ed2ae4c9
Commit
ed2ae4c9
authored
Jun 13, 2022
by
AfirSraftGarrier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接口文档
parent
6b1dd560
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
182 additions
and
23 deletions
+182
-23
pom.xml
license/pom.xml
+7
-1
CorsConfig.java
.../src/main/java/iot/sixiang/license/config/CorsConfig.java
+23
-20
BaseSwaggerConfig.java
...iot/sixiang/license/config/swagger/BaseSwaggerConfig.java
+76
-0
SwaggerConfig.java
...ava/iot/sixiang/license/config/swagger/SwaggerConfig.java
+25
-0
SwaggerProperties.java
...iot/sixiang/license/config/swagger/SwaggerProperties.java
+43
-0
JwtFilter.java
license/src/main/java/iot/sixiang/license/jwt/JwtFilter.java
+8
-2
No files found.
license/pom.xml
View file @
ed2ae4c9
...
...
@@ -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>
...
...
@@ -78,7 +85,6 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
...
...
license/src/main/java/iot/sixiang/license/config/CorsConfig.java
View file @
ed2ae4c9
package
iot
.
sixiang
.
license
.
config
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.config.annotation.CorsRegistry
;
import
org.springframework.web.servlet.config.annotation.EnableWebMvc
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
org.springframework.web.cors.CorsConfiguration
;
import
org.springframework.web.cors.UrlBasedCorsConfigurationSource
;
import
org.springframework.web.filter.CorsFilter
;
@Configuration
@EnableWebMvc
public
class
CorsConfig
implements
WebMvcConfigurer
{
public
class
CorsConfig
{
@Override
public
void
addCorsMappings
(
CorsRegistry
registry
)
{
registry
.
addMapping
(
"/**"
)
.
allowedOriginPatterns
(
"*"
)
.
allowedMethods
(
"*"
)
.
allowCredentials
(
true
)
.
maxAge
(
3600
)
.
allowedHeaders
(
"*"
);
/**
* 允许跨域调用的过滤器
*/
@Bean
public
CorsFilter
corsFilter
()
{
CorsConfiguration
config
=
new
CorsConfiguration
();
//允许所有域名进行跨域调用
//config.addAllowedOrigin("*");
config
.
addAllowedOriginPattern
(
"*"
);
//允许跨越发送cookie
config
.
setAllowCredentials
(
true
);
//放行全部原始头信息
config
.
addAllowedHeader
(
"*"
);
//允许所有请求方法跨域调用
config
.
addAllowedMethod
(
"*"
);
UrlBasedCorsConfigurationSource
source
=
new
UrlBasedCorsConfigurationSource
();
source
.
registerCorsConfiguration
(
"/**"
,
config
);
return
new
CorsFilter
(
source
);
}
@Override
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
// TODO Auto-generated method stub
}
}
license/src/main/java/iot/sixiang/license/config/swagger/BaseSwaggerConfig.java
0 → 100644
View file @
ed2ae4c9
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
();
}
license/src/main/java/iot/sixiang/license/config/swagger/SwaggerConfig.java
0 → 100644
View file @
ed2ae4c9
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
();
}
}
license/src/main/java/iot/sixiang/license/config/swagger/SwaggerProperties.java
0 → 100644
View file @
ed2ae4c9
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
;
}
license/src/main/java/iot/sixiang/license/jwt/JwtFilter.java
View file @
ed2ae4c9
...
...
@@ -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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment