Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sureness
Sureness
提交
3c314bed
Sureness
项目概览
sureness
/
Sureness
9 个月 前同步成功
通知
32
Star
813
Fork
161
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Sureness
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
3c314bed
编写于
9月 29, 2021
作者:
C
ChineseTony
提交者:
GitHub
9月 29, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #141 from ChineseTony/master
fix
上级
43f7ffeb
f7be318c
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
336 addition
and
122 deletion
+336
-122
samples/sureness-spring-boot-starter-example/pom.xml
samples/sureness-spring-boot-starter-example/pom.xml
+1
-1
samples/sureness-spring-boot-starter-example/src/main/java/com/usthe/sureness/bootstrap/BootstrapApplication.java
...va/com/usthe/sureness/bootstrap/BootstrapApplication.java
+0
-1
samples/sureness-spring-boot-starter-example/src/main/resources/application.yml
...g-boot-starter-example/src/main/resources/application.yml
+7
-5
support/spring-boot-starter-sureness/pom.xml
support/spring-boot-starter-sureness/pom.xml
+1
-1
support/spring-boot-starter-sureness/src/main/java/com/usthe/sureness/configuration/SurenessAutoConfiguration.java
...the/sureness/configuration/SurenessAutoConfiguration.java
+80
-94
support/spring-boot-starter-sureness/src/main/java/com/usthe/sureness/configuration/SurenessFilter.java
...java/com/usthe/sureness/configuration/SurenessFilter.java
+2
-2
support/spring-boot-starter-sureness/src/main/java/com/usthe/sureness/configuration/SurenessProperties.java
.../com/usthe/sureness/configuration/SurenessProperties.java
+29
-18
support/sureness-spring-boot-starter/src/main/java/com/usthe/sureness/configuration/SurenessAutoConfiguration.java
...the/sureness/configuration/SurenessAutoConfiguration.java
+216
-0
未找到文件。
samples/sureness-spring-boot-starter-example/pom.xml
浏览文件 @
3c314bed
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.reporting.outputEncoding>
UTF-8
</project.reporting.outputEncoding>
<project.reporting.outputEncoding>
UTF-8
</project.reporting.outputEncoding>
<java.version>
1.8
</java.version>
<java.version>
1.8
</java.version>
<spring-boot-starter-sureness.version>
1.0.0-beta.
1
</spring-boot-starter-sureness.version>
<spring-boot-starter-sureness.version>
1.0.0-beta.
2
</spring-boot-starter-sureness.version>
</properties>
</properties>
<dependencies>
<dependencies>
...
...
samples/sureness-spring-boot-starter-example/src/main/java/com/usthe/sureness/bootstrap/BootstrapApplication.java
浏览文件 @
3c314bed
...
@@ -8,7 +8,6 @@ import org.springframework.boot.web.servlet.ServletComponentScan;
...
@@ -8,7 +8,6 @@ import org.springframework.boot.web.servlet.ServletComponentScan;
* @author wangtao
* @author wangtao
*/
*/
@SpringBootApplication
@SpringBootApplication
@ServletComponentScan
public
class
BootstrapApplication
{
public
class
BootstrapApplication
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
...
...
samples/sureness-spring-boot-starter-example/src/main/resources/application.yml
浏览文件 @
3c314bed
...
@@ -10,14 +10,16 @@ logging:
...
@@ -10,14 +10,16 @@ logging:
root
:
info
root
:
info
sureness
:
sureness
:
enabled
:
true
container
:
servlet
auth
T
ypes
:
auth
-t
ypes
:
-
Jw
t
-
diges
t
-
B
asic
-
b
asic
-
Diges
t
-
jw
t
support-types
:
support-types
:
-
Servlet
-
Servlet
-
Websocket
-
Websocket
session-enabled
:
true
websocket-enabled
:
true
jwt
:
jwt
:
secret-key
:
?::4s9ssf2sf4sed45pf):RnLN7XNn4wARoQXizIv6MHUsIV+EFfiMw/x7R0ntu4aWr/CWuApcFajCyaFv0bwq2Eik0jdrKUtsA6bx3sDJeFV643R+YYzGMRIqcBIp6AKA98GM2RIqcBIp6-?::4390fsf4sdl6opf)4ZI:tdQMtcQQ14pkOAQdQ546
secret-key
:
?::4s9ssf2sf4sed45pf):RnLN7XNn4wARoQXizIv6MHUsIV+EFfiMw/x7R0ntu4aWr/CWuApcFajCyaFv0bwq2Eik0jdrKUtsA6bx3sDJeFV643R+YYzGMRIqcBIp6AKA98GM2RIqcBIp6-?::4390fsf4sdl6opf)4ZI:tdQMtcQQ14pkOAQdQ546
annotation
:
annotation
:
...
...
support/spring-boot-starter-sureness/pom.xml
浏览文件 @
3c314bed
...
@@ -53,7 +53,7 @@
...
@@ -53,7 +53,7 @@
<maven.compiler.source>
1.8
</maven.compiler.source>
<maven.compiler.source>
1.8
</maven.compiler.source>
<maven.compiler.target>
1.8
</maven.compiler.target>
<maven.compiler.target>
1.8
</maven.compiler.target>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<sureness-core.version>
1.0.
4-beta.2
</sureness-core.version>
<sureness-core.version>
1.0.
5
</sureness-core.version>
<spring-boot.version>
2.4.5
</spring-boot.version>
<spring-boot.version>
2.4.5
</spring-boot.version>
</properties>
</properties>
...
...
support/spring-boot-starter-sureness/src/main/java/com/usthe/sureness/configuration/SurenessAutoConfiguration.java
浏览文件 @
3c314bed
...
@@ -54,6 +54,7 @@ import org.springframework.context.annotation.Configuration;
...
@@ -54,6 +54,7 @@ import org.springframework.context.annotation.Configuration;
import
javax.servlet.Filter
;
import
javax.servlet.Filter
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.LinkedList
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.List
;
...
@@ -75,8 +76,6 @@ public class SurenessAutoConfiguration {
...
@@ -75,8 +76,6 @@ public class SurenessAutoConfiguration {
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
SurenessAutoConfiguration
.
class
);
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
SurenessAutoConfiguration
.
class
);
private
static
final
int
NUM_2
=
2
;
private
ApplicationContext
applicationContext
;
private
ApplicationContext
applicationContext
;
private
SurenessProperties
surenessProperties
;
private
SurenessProperties
surenessProperties
;
...
@@ -94,11 +93,8 @@ public class SurenessAutoConfiguration {
...
@@ -94,11 +93,8 @@ public class SurenessAutoConfiguration {
@Bean
@Bean
@ConditionalOnMissingBean
(
PathTreeProvider
.
class
)
@ConditionalOnMissingBean
(
PathTreeProvider
.
class
)
PathTreeProvider
pathTreeProvider
(
DefaultPathRoleMatcher
pathRoleMatcher
){
PathTreeProvider
pathTreeProvider
(){
PathTreeProvider
pathTreeProvider
=
new
DocumentPathTreeProvider
();
return
new
DocumentPathTreeProvider
();
pathRoleMatcher
.
setPathTreeProvider
(
pathTreeProvider
);
pathRoleMatcher
.
buildTree
();
return
pathTreeProvider
;
}
}
@Bean
@Bean
...
@@ -107,76 +103,73 @@ public class SurenessAutoConfiguration {
...
@@ -107,76 +103,73 @@ public class SurenessAutoConfiguration {
SubjectFactory
subjectFactory
()
{
SubjectFactory
subjectFactory
()
{
SubjectFactory
subjectFactory
=
new
SurenessSubjectFactory
();
SubjectFactory
subjectFactory
=
new
SurenessSubjectFactory
();
List
<
SubjectCreate
>
subjectCreates
=
new
ArrayList
<>();
List
<
SubjectCreate
>
subjectCreates
=
new
ArrayList
<>();
Set
<
AuthType
>
authTypes
=
surenessProperties
.
getAuthTypes
();
AuthType
[]
authTypeArr
=
surenessProperties
.
getAuthTypes
();
if
(
authTypes
==
null
||
authTypes
.
isEmpty
())
{
Set
<
AuthType
>
authTypes
=
authTypeArr
==
null
?
new
HashSet
<>()
:
new
HashSet
<>(
Arrays
.
asList
(
authTypeArr
));
if
(
authTypes
.
isEmpty
())
{
// if is null, default config is basic auth, jwt auth
// if is null, default config is basic auth, jwt auth
LOGGER
.
info
(
"[sureness-starter] - use default authTypes: Basic, Jwt"
);
LOGGER
.
info
(
"[sureness-starter] - use default authTypes: Basic, Jwt"
);
authTypes
=
new
HashSet
<>(
2
);
authTypes
=
new
HashSet
<>(
2
);
authTypes
.
add
(
AuthType
.
BASIC
);
authTypes
.
add
(
AuthType
.
BASIC
);
authTypes
.
add
(
AuthType
.
JWT
);
authTypes
.
add
(
AuthType
.
JWT
);
surenessProperties
.
setAuthTypes
(
authTypes
);
}
}
Set
<
SupportType
>
supportTypes
=
surenessProperties
.
getSupportTypes
();
ContainerType
containerType
=
surenessProperties
.
getContainer
();
if
(
supportTypes
==
null
||
supportTypes
.
isEmpty
()
)
{
if
(
containerType
==
null
)
{
// if is null, default config is servlet
, websocket
// if is null, default config is servlet
LOGGER
.
info
(
"[sureness-starter] - use default supportTypes: Servlet, Websocket"
);
LOGGER
.
info
(
"[sureness-starter] - use default supportTypes: Servlet, Websocket"
);
supportTypes
=
new
HashSet
<>(
2
);
containerType
=
ContainerType
.
Servlet
;
supportTypes
.
add
(
SupportType
.
Servlet
);
supportTypes
.
add
(
SupportType
.
WebSocket
);
surenessProperties
.
setSupportTypes
(
supportTypes
);
}
}
if
(
supportTypes
.
size
()
>=
NUM_2
&&
!
supportTypes
.
contains
(
SupportType
.
WebSocket
))
{
boolean
enableWebsocket
=
surenessProperties
.
isWebsocketEnabled
();
LOGGER
.
error
(
"[sureness-starter] - supportTypes: Servlet, JAX-RS or Spring-Reactor neither can exist at the same time"
);
switch
(
containerType
)
{
throw
new
SurenessInitException
(
"[sureness-starter] - supportTypes: Servlet, JAX-RS or Spring-Reactor neither can exist at the same time"
);
case
Servlet:
}
subjectCreates
.
add
(
new
NoneSubjectServletCreator
());
if
(
supportTypes
.
contains
(
SupportType
.
Servlet
)
)
{
if
(
enableWebsocket
)
{
subjectCreates
.
add
(
new
NoneSubject
ServletCreator
());
subjectCreates
.
add
(
new
JwtSubjectWs
ServletCreator
());
if
(
supportTypes
.
contains
(
SupportType
.
WebSocket
))
{
}
subjectCreates
.
add
(
new
JwtSubjectWsServletCreator
());
if
(
authTypes
.
contains
(
AuthType
.
BASIC
)){
}
subjectCreates
.
add
(
new
BasicSubjectServletCreator
());
if
(
authTypes
.
contains
(
AuthType
.
BASIC
)){
}
subjectCreates
.
add
(
new
BasicSubjectServletCreator
());
if
(
authTypes
.
contains
(
AuthType
.
JWT
)){
}
subjectCreates
.
add
(
new
JwtSubjectServletCreator
());
if
(
authTypes
.
contains
(
AuthType
.
JWT
)){
subjectCreates
.
add
(
new
JwtSubjectWsServletCreator
());
subjectCreates
.
add
(
new
JwtSubjectServletCreator
());
}
subjectCreates
.
add
(
new
JwtSubjectWsServletCreator
());
if
(
authTypes
.
contains
(
AuthType
.
DIGEST
)){
}
subjectCreates
.
add
(
new
DigestSubjectServletCreator
());
if
(
authTypes
.
contains
(
AuthType
.
DIGEST
)){
}
subjectCreates
.
add
(
new
DigestSubjectServletCreator
());
if
(
surenessProperties
.
isSessionEnabled
())
{
}
subjectCreates
.
add
(
new
SessionSubjectServletCreator
());
if
(
surenessProperties
.
isSessionEnabled
())
{
}
subjectCreates
.
add
(
new
SessionSubjectServletCreator
())
;
break
;
}
case
JAX_RS:
}
else
if
(
supportTypes
.
contains
(
SupportType
.
JAX_RS
)){
subjectCreates
.
add
(
new
NoneSubjectJaxRsCreator
());
// other is JAX-RS
if
(
enableWebsocket
)
{
subjectCreates
.
add
(
new
NoneSubject
JaxRsCreator
());
subjectCreates
.
add
(
new
JwtSubjectWs
JaxRsCreator
());
if
(
supportTypes
.
contains
(
SupportType
.
WebSocket
))
{
}
subjectCreates
.
add
(
new
JwtSubjectWsJaxRsCreator
());
if
(
authTypes
.
contains
(
AuthType
.
BASIC
)){
}
subjectCreates
.
add
(
new
BasicSubjectJaxRsCreator
());
if
(
authTypes
.
contains
(
AuthType
.
BASIC
)){
}
subjectCreates
.
add
(
new
BasicSubjectJaxRsCreator
());
if
(
authTypes
.
contains
(
AuthType
.
JWT
)){
}
subjectCreates
.
add
(
new
JwtSubjectJaxRsCreator
());
if
(
authTypes
.
contains
(
AuthType
.
JWT
)){
subjectCreates
.
add
(
new
JwtSubjectWsJaxRsCreator
());
subjectCreates
.
add
(
new
JwtSubjectJaxRsCreator
());
}
subjectCreates
.
add
(
new
JwtSubjectWsJaxRsCreator
());
if
(
authTypes
.
contains
(
AuthType
.
DIGEST
)){
}
subjectCreates
.
add
(
new
DigestSubjectJaxRsCreator
());
if
(
authTypes
.
contains
(
AuthType
.
DIGEST
)){
}
subjectCreates
.
add
(
new
DigestSubjectJaxRsCreator
())
;
break
;
}
case
Spring_Reactor:
}
else
if
(
supportTypes
.
contains
(
SupportType
.
Spring_Reactor
))
{
subjectCreates
.
add
(
new
NoneSubjectSpringReactiveCreator
());
subjectCreates
.
add
(
new
NoneSubjectSpringReactiveCreator
());
if
(
enableWebsocket
)
{
if
(
supportTypes
.
contains
(
SupportType
.
WebSocket
))
{
subjectCreates
.
add
(
new
JwtSubjectWsSpringReactiveCreator
());
subjectCreates
.
add
(
new
JwtSubjectWsSpringReactiveCreator
());
}
}
if
(
authTypes
.
contains
(
AuthType
.
BASIC
))
{
if
(
authTypes
.
contains
(
AuthType
.
BASIC
))
{
subjectCreates
.
add
(
new
BasicSubjectSpringReactiveCreator
());
subjectCreates
.
add
(
new
BasicSubjectSpringReactiveCreator
());
}
}
if
(
authTypes
.
contains
(
AuthType
.
JWT
))
{
if
(
authTypes
.
contains
(
AuthType
.
JWT
))
{
subjectCreates
.
add
(
new
JwtSubjectSpringReactiveCreator
());
subjectCreates
.
add
(
new
JwtSubjectSpringReactiveCreator
());
}
}
if
(
authTypes
.
contains
(
AuthType
.
DIGEST
))
{
if
(
authTypes
.
contains
(
AuthType
.
DIGEST
))
{
subjectCreates
.
add
(
new
DigestSubjectSpringReactiveCreator
());
subjectCreates
.
add
(
new
DigestSubjectSpringReactiveCreator
());
}
}
default
:
break
;
}
}
subjectFactory
.
registerSubjectCreator
(
subjectCreates
);
subjectFactory
.
registerSubjectCreator
(
subjectCreates
);
LOGGER
.
info
(
"[sureness-starter] - SurenessSubjectFactory init success"
);
LOGGER
.
info
(
"[sureness-starter] - SurenessSubjectFactory init success"
);
...
@@ -209,14 +202,14 @@ public class SurenessAutoConfiguration {
...
@@ -209,14 +202,14 @@ public class SurenessAutoConfiguration {
List
<
Processor
>
processorList
=
new
LinkedList
<>();
List
<
Processor
>
processorList
=
new
LinkedList
<>();
NoneProcessor
noneProcessor
=
new
NoneProcessor
();
NoneProcessor
noneProcessor
=
new
NoneProcessor
();
processorList
.
add
(
noneProcessor
);
processorList
.
add
(
noneProcessor
);
Set
<
AuthType
>
authTypes
=
surenessProperties
.
getAuthTypes
();
AuthType
[]
authTypeArr
=
surenessProperties
.
getAuthTypes
();
if
(
authTypes
==
null
||
authTypes
.
isEmpty
())
{
Set
<
AuthType
>
authTypes
=
authTypeArr
==
null
?
new
HashSet
<>()
:
new
HashSet
<>(
Arrays
.
asList
(
authTypeArr
));
if
(
authTypes
.
isEmpty
())
{
// if is null, default config is basic auth, jwt auth
// if is null, default config is basic auth, jwt auth
LOGGER
.
info
(
"[sureness-starter] - use default authTypes: Basic, Jwt"
);
LOGGER
.
info
(
"[sureness-starter] - use default authTypes: Basic, Jwt"
);
authTypes
=
new
HashSet
<>(
2
);
authTypes
=
new
HashSet
<>(
2
);
authTypes
.
add
(
AuthType
.
BASIC
);
authTypes
.
add
(
AuthType
.
BASIC
);
authTypes
.
add
(
AuthType
.
JWT
);
authTypes
.
add
(
AuthType
.
JWT
);
surenessProperties
.
setAuthTypes
(
authTypes
);
}
}
if
(
authTypes
.
contains
(
AuthType
.
JWT
))
{
if
(
authTypes
.
contains
(
AuthType
.
JWT
))
{
JwtProcessor
jwtProcessor
=
new
JwtProcessor
();
JwtProcessor
jwtProcessor
=
new
JwtProcessor
();
...
@@ -241,12 +234,15 @@ public class SurenessAutoConfiguration {
...
@@ -241,12 +234,15 @@ public class SurenessAutoConfiguration {
@Bean
@Bean
@ConditionalOnMissingBean
(
TreePathRoleMatcher
.
class
)
@ConditionalOnMissingBean
(
TreePathRoleMatcher
.
class
)
TreePathRoleMatcher
pathRoleMatcher
(
PathTreeProvider
pathTreeProvider
,
TreePathRoleMatcher
pathRoleMatcher
(
List
<
PathTreeProvider
>
pathTreeProviders
)
{
DefaultPathRoleMatcher
pathRoleMatcher
)
{
DefaultPathRoleMatcher
pathRoleMatcher
=
new
DefaultPathRoleMatcher
();
List
<
PathTreeProvider
>
providers
=
new
ArrayList
<>();
if
(
pathTreeProviders
==
null
)
{
providers
.
add
(
pathTreeProvider
);
pathTreeProviders
=
new
ArrayList
<>();
// add documentProvider default
}
providers
.
add
(
new
DocumentPathTreeProvider
());
if
(
pathTreeProviders
.
isEmpty
())
{
// add documentProvider default
pathTreeProviders
.
add
(
new
DocumentPathTreeProvider
());
}
AnnotationProperties
annotationProperties
=
surenessProperties
.
getAnnotation
();
AnnotationProperties
annotationProperties
=
surenessProperties
.
getAnnotation
();
if
(
annotationProperties
!=
null
&&
annotationProperties
.
isEnable
())
{
if
(
annotationProperties
!=
null
&&
annotationProperties
.
isEnable
())
{
List
<
String
>
scanPackages
=
annotationProperties
.
getScanPackages
();
List
<
String
>
scanPackages
=
annotationProperties
.
getScanPackages
();
...
@@ -255,32 +251,21 @@ public class SurenessAutoConfiguration {
...
@@ -255,32 +251,21 @@ public class SurenessAutoConfiguration {
}
else
{
}
else
{
AnnotationPathTreeProvider
annotationPathTreeProvider
=
new
AnnotationPathTreeProvider
();
AnnotationPathTreeProvider
annotationPathTreeProvider
=
new
AnnotationPathTreeProvider
();
annotationPathTreeProvider
.
setScanPackages
(
scanPackages
);
annotationPathTreeProvider
.
setScanPackages
(
scanPackages
);
providers
.
add
(
annotationPathTreeProvider
);
p
athTreeP
roviders
.
add
(
annotationPathTreeProvider
);
}
}
}
}
pathRoleMatcher
.
setPathTreeProviderList
(
providers
);
pathRoleMatcher
.
setPathTreeProviderList
(
p
athTreeP
roviders
);
pathRoleMatcher
.
buildTree
();
pathRoleMatcher
.
buildTree
();
return
pathRoleMatcher
;
return
pathRoleMatcher
;
}
}
@Bean
@ConditionalOnMissingBean
(
DefaultPathRoleMatcher
.
class
)
public
DefaultPathRoleMatcher
defaultPathRoleMatcher
(){
return
new
DefaultPathRoleMatcher
();
}
@Bean
@Bean
@ConditionalOnWebApplication
@ConditionalOnWebApplication
@ConditionalOnMissingBean
(
value
=
FilterRegistrationBean
.
class
)
@ConditionalOnExpression
(
"'${sureness.container}'.equalsIgnoreCase('servlet')"
)
@ConditionalOnExpression
(
"'${sureness.support-types}'.contains('com.usthe.sureness.configuration.SupportType.Servlet')"
)
public
FilterRegistrationBean
filterRegistration
()
{
public
FilterRegistrationBean
filterRegistration
(
SecurityManager
securityManager
)
{
FilterRegistrationBean
registration
=
new
FilterRegistrationBean
();
FilterRegistrationBean
registration
=
new
FilterRegistrationBean
();
registration
.
setFilter
(
new
SurenessFilter
(
securityManager
));
registration
.
addUrlPatterns
(
"/*"
);
registration
.
addUrlPatterns
(
"/*"
);
registration
.
setFilter
((
Filter
)
registration
.
setFilter
((
Filter
)
applicationContext
.
getBean
(
"surenessFilter"
));
applicationContext
.
getBean
(
"surenessFilter"
));
registration
.
setName
(
"surenessFilter"
);
registration
.
setName
(
"surenessFilter"
);
registration
.
setOrder
(
1
);
registration
.
setOrder
(
1
);
return
registration
;
return
registration
;
...
@@ -288,6 +273,7 @@ public class SurenessAutoConfiguration {
...
@@ -288,6 +273,7 @@ public class SurenessAutoConfiguration {
@Bean
@Bean
@ConditionalOnMissingBean
(
name
=
"surenessFilter"
)
@ConditionalOnMissingBean
(
name
=
"surenessFilter"
)
@ConditionalOnExpression
(
"'${sureness.container}'.equalsIgnoreCase('servlet')"
)
public
Filter
surenessFilter
(
SecurityManager
securityManager
){
public
Filter
surenessFilter
(
SecurityManager
securityManager
){
return
new
SurenessFilter
(
securityManager
);
return
new
SurenessFilter
(
securityManager
);
}
}
...
...
support/spring-boot-starter-sureness/src/main/java/com/usthe/sureness/configuration/SurenessFilter.java
浏览文件 @
3c314bed
...
@@ -71,7 +71,7 @@ public class SurenessFilter implements Filter {
...
@@ -71,7 +71,7 @@ public class SurenessFilter implements Filter {
logger
.
debug
(
"this request account info is illegal, {}"
,
e1
.
getMessage
());
logger
.
debug
(
"this request account info is illegal, {}"
,
e1
.
getMessage
());
responseWrite
(
ResponseEntity
responseWrite
(
ResponseEntity
.
status
(
HttpStatus
.
UNAUTHORIZED
)
.
status
(
HttpStatus
.
UNAUTHORIZED
)
.
body
(
"Username or password is incorrect or expired"
),
servletResponse
);
.
body
(
"Username or password is incorrect or
token
expired"
),
servletResponse
);
return
;
return
;
}
catch
(
DisabledAccountException
|
ExcessiveAttemptsException
e2
)
{
}
catch
(
DisabledAccountException
|
ExcessiveAttemptsException
e2
)
{
logger
.
debug
(
"the account is disabled, {}"
,
e2
.
getMessage
());
logger
.
debug
(
"the account is disabled, {}"
,
e2
.
getMessage
());
...
@@ -96,7 +96,7 @@ public class SurenessFilter implements Filter {
...
@@ -96,7 +96,7 @@ public class SurenessFilter implements Filter {
servletResponse
);
servletResponse
);
return
;
return
;
}
}
try
{
try
{
// if ok, doFilter and add subject in request
// if ok, doFilter and add subject in request
filterChain
.
doFilter
(
servletRequest
,
servletResponse
);
filterChain
.
doFilter
(
servletRequest
,
servletResponse
);
...
...
support/spring-boot-starter-sureness/src/main/java/com/usthe/sureness/configuration/SurenessProperties.java
浏览文件 @
3c314bed
...
@@ -4,7 +4,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
...
@@ -4,7 +4,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Set
;
/**
/**
* @author wangtao
* @author wangtao
...
@@ -20,20 +19,25 @@ public class SurenessProperties {
...
@@ -20,20 +19,25 @@ public class SurenessProperties {
private
boolean
enabled
=
true
;
private
boolean
enabled
=
true
;
/**
/**
* 可配置 支持
websocket, servlet, jax-rs或者其它
容器协议
* 可配置 支持
Servlet, JAX_RS, Spring_Reactor
容器协议
*/
*/
private
Set
<
SupportType
>
supportTypes
;
private
ContainerType
container
=
ContainerType
.
Servlet
;
/**
/**
* 支持的认证方式 Jwt, basic auth, digest auth等其它认证方式
* 支持的认证方式 Jwt, basic auth, digest auth等其它认证方式
*/
*/
private
Set
<
AuthType
>
authTypes
;
private
AuthType
[]
authTypes
=
new
AuthType
[]
{
AuthType
.
BASIC
,
AuthType
.
JWT
,
AuthType
.
DIGEST
}
;
/**
/**
* 当 authType 为
jwt
时设置的属性
* 当 authType 为
JWT
时设置的属性
*/
*/
private
JwtProperties
jwt
;
private
JwtProperties
jwt
;
/**
* 是否开启 websocket 的认证鉴权
*/
private
boolean
websocketEnabled
=
true
;
/**
/**
* 是否开启 session
* 是否开启 session
*/
*/
...
@@ -44,19 +48,11 @@ public class SurenessProperties {
...
@@ -44,19 +48,11 @@ public class SurenessProperties {
*/
*/
private
AnnotationProperties
annotation
;
private
AnnotationProperties
annotation
;
public
Set
<
SupportType
>
getSupportTypes
()
{
public
AuthType
[]
getAuthTypes
()
{
return
supportTypes
;
}
public
void
setSupportTypes
(
Set
<
SupportType
>
supportTypes
)
{
this
.
supportTypes
=
supportTypes
;
}
public
Set
<
AuthType
>
getAuthTypes
()
{
return
authTypes
;
return
authTypes
;
}
}
public
void
setAuthTypes
(
Set
<
AuthType
>
authTypes
)
{
public
void
setAuthTypes
(
AuthType
[]
authTypes
)
{
this
.
authTypes
=
authTypes
;
this
.
authTypes
=
authTypes
;
}
}
...
@@ -92,6 +88,23 @@ public class SurenessProperties {
...
@@ -92,6 +88,23 @@ public class SurenessProperties {
this
.
annotation
=
annotation
;
this
.
annotation
=
annotation
;
}
}
public
ContainerType
getContainer
()
{
return
container
;
}
public
void
setContainer
(
ContainerType
container
)
{
this
.
container
=
container
;
}
public
boolean
isWebsocketEnabled
()
{
return
websocketEnabled
;
}
public
void
setWebsocketEnabled
(
boolean
websocketEnabled
)
{
this
.
websocketEnabled
=
websocketEnabled
;
}
public
static
enum
AuthType
{
public
static
enum
AuthType
{
/** json web token auth **/
/** json web token auth **/
JWT
,
JWT
,
...
@@ -101,15 +114,13 @@ public class SurenessProperties {
...
@@ -101,15 +114,13 @@ public class SurenessProperties {
DIGEST
DIGEST
}
}
public
static
enum
Support
Type
{
public
static
enum
Container
Type
{
/** http servlet **/
/** http servlet **/
Servlet
,
Servlet
,
/** jax-rs **/
/** jax-rs **/
JAX_RS
,
JAX_RS
,
/** spring reactor stream **/
/** spring reactor stream **/
Spring_Reactor
,
Spring_Reactor
,
/** websocket **/
WebSocket
}
}
public
static
class
AnnotationProperties
{
public
static
class
AnnotationProperties
{
...
...
support/sureness-spring-boot-starter/src/main/java/com/usthe/sureness/configuration/SurenessAutoConfiguration.java
0 → 100644
浏览文件 @
3c314bed
package
com.usthe.sureness.configuration
;
import
com.usthe.sureness.matcher.DefaultPathRoleMatcher
;
import
com.usthe.sureness.matcher.PathTreeProvider
;
import
com.usthe.sureness.matcher.TreePathRoleMatcher
;
import
com.usthe.sureness.mgt.SecurityManager
;
import
com.usthe.sureness.mgt.SurenessSecurityManager
;
import
com.usthe.sureness.processor.DefaultProcessorManager
;
import
com.usthe.sureness.processor.Processor
;
import
com.usthe.sureness.processor.ProcessorManager
;
import
com.usthe.sureness.processor.support.JwtProcessor
;
import
com.usthe.sureness.processor.support.NoneProcessor
;
import
com.usthe.sureness.processor.support.PasswordProcessor
;
import
com.usthe.sureness.provider.SurenessAccountProvider
;
import
com.usthe.sureness.provider.annotation.AnnotationPathTreeProvider
;
import
com.usthe.sureness.provider.ducument.DocumentAccountProvider
;
import
com.usthe.sureness.provider.ducument.DocumentPathTreeProvider
;
import
com.usthe.sureness.subject.SubjectCreate
;
import
com.usthe.sureness.subject.SubjectFactory
;
import
com.usthe.sureness.subject.SurenessSubjectFactory
;
import
com.usthe.sureness.subject.creater.BasicSubjectJaxRsCreator
;
import
com.usthe.sureness.subject.creater.BasicSubjectServletCreator
;
import
com.usthe.sureness.subject.creater.DigestSubjectJaxRsCreator
;
import
com.usthe.sureness.subject.creater.DigestSubjectServletCreator
;
import
com.usthe.sureness.subject.creater.JwtSubjectJaxRsCreator
;
import
com.usthe.sureness.subject.creater.JwtSubjectServletCreator
;
import
com.usthe.sureness.subject.creater.JwtSubjectWsJaxRsCreator
;
import
com.usthe.sureness.subject.creater.JwtSubjectWsServletCreator
;
import
com.usthe.sureness.subject.creater.NoneSubjectJaxRsCreator
;
import
com.usthe.sureness.subject.creater.NoneSubjectServletCreator
;
import
com.usthe.sureness.util.JsonWebTokenUtil
;
import
com.usthe.sureness.util.SurenessConstant
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.BeansException
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnResource
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.util.CollectionUtils
;
import
javax.servlet.Filter
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Set
;
import
static
com
.
usthe
.
sureness
.
DefaultSurenessConfig
.
SUPPORT_JAX_RS
;
/**
* @author wangtao
* @date 2021/7/3
*/
@Configuration
@ConditionalOnProperty
(
prefix
=
"sureness"
,
name
=
"enabled"
,
havingValue
=
"true"
,
matchIfMissing
=
true
)
@ConditionalOnResource
(
resources
=
"META-INF/spring.factories"
)
@AutoConfigureAfter
(
value
=
{
SurenessProperties
.
class
})
public
class
SurenessAutoConfiguration
implements
ApplicationContextAware
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
SurenessAutoConfiguration
.
class
);
private
ApplicationContext
applicationContext
;
@Bean
@ConditionalOnMissingBean
(
SurenessAccountProvider
.
class
)
SurenessAccountProvider
accountProvider
(){
return
new
DocumentAccountProvider
();
}
@Bean
@ConditionalOnMissingBean
(
PathTreeProvider
.
class
)
PathTreeProvider
pathTreeProvider
(
DefaultPathRoleMatcher
pathRoleMatcher
){
PathTreeProvider
pathTreeProvider
=
new
DocumentPathTreeProvider
();
pathRoleMatcher
.
setPathTreeProvider
(
pathTreeProvider
);
pathRoleMatcher
.
buildTree
();
return
pathTreeProvider
;
}
@Bean
@ConditionalOnMissingBean
(
SubjectFactory
.
class
)
SubjectFactory
subjectFactory
(
SurenessProperties
surenessProperties
)
{
SubjectFactory
subjectFactory
=
new
SurenessSubjectFactory
();
List
<
SubjectCreate
>
subjectCreates
=
new
ArrayList
<>();
Set
<
String
>
sets
=
new
HashSet
<>();
if
(!
CollectionUtils
.
isEmpty
(
surenessProperties
.
getAuthTypes
())){
sets
=
surenessProperties
.
getAuthTypes
();
}
if
(
SUPPORT_JAX_RS
.
equals
(
surenessProperties
.
getSupportType
()))
{
subjectCreates
.
add
(
new
NoneSubjectJaxRsCreator
());
if
(
sets
.
contains
(
SurenessConstant
.
BASIC
)){
subjectCreates
.
add
(
new
BasicSubjectJaxRsCreator
());
}
if
(
sets
.
contains
(
SurenessConstant
.
JWT
)){
subjectCreates
.
add
(
new
JwtSubjectJaxRsCreator
());
subjectCreates
.
add
(
new
JwtSubjectWsJaxRsCreator
());
}
if
(
sets
.
contains
(
SurenessConstant
.
DIGEST
)){
subjectCreates
.
add
(
new
DigestSubjectJaxRsCreator
());
}
}
else
{
subjectCreates
.
add
(
new
NoneSubjectServletCreator
());
if
(
sets
.
contains
(
SurenessConstant
.
BASIC
)){
subjectCreates
.
add
(
new
BasicSubjectServletCreator
());
}
if
(
sets
.
contains
(
SurenessConstant
.
JWT
)){
subjectCreates
.
add
(
new
JwtSubjectServletCreator
());
subjectCreates
.
add
(
new
JwtSubjectWsServletCreator
());
}
if
(
sets
.
contains
(
SurenessConstant
.
DIGEST
)){
subjectCreates
.
add
(
new
DigestSubjectServletCreator
());
}
}
subjectFactory
.
registerSubjectCreator
(
subjectCreates
);
LOGGER
.
info
(
"SurenessSubjectFactory init"
);
return
subjectFactory
;
}
@Bean
@ConditionalOnMissingBean
(
SecurityManager
.
class
)
SecurityManager
securityManager
(
SurenessProperties
surenessProperties
,
ProcessorManager
processorManager
,
TreePathRoleMatcher
pathRoleMatcher
,
SubjectFactory
subjectFactory
)
{
if
(!
CollectionUtils
.
isEmpty
(
surenessProperties
.
getAuthTypes
())
&&
surenessProperties
.
getSupportType
().
contains
(
SurenessConstant
.
JWT
)){
JsonWebTokenUtil
.
setDefaultSecretKey
(
surenessProperties
.
getToken
());
}
SurenessSecurityManager
securityManager
=
SurenessSecurityManager
.
getInstance
();
securityManager
.
setPathRoleMatcher
(
pathRoleMatcher
);
securityManager
.
setSubjectFactory
(
subjectFactory
);
securityManager
.
setProcessorManager
(
processorManager
);
return
securityManager
;
}
@Bean
@ConditionalOnMissingBean
(
ProcessorManager
.
class
)
ProcessorManager
processorManager
(
SurenessAccountProvider
accountProvider
,
SurenessProperties
surenessProperties
)
{
List
<
Processor
>
processorList
=
new
LinkedList
<>();
NoneProcessor
noneProcessor
=
new
NoneProcessor
();
processorList
.
add
(
noneProcessor
);
if
(!
CollectionUtils
.
isEmpty
(
surenessProperties
.
getAuthTypes
())
&&
surenessProperties
.
getSupportType
().
contains
(
SurenessConstant
.
JWT
)){
JwtProcessor
jwtProcessor
=
new
JwtProcessor
();
processorList
.
add
(
jwtProcessor
);
}
PasswordProcessor
passwordProcessor
=
new
PasswordProcessor
();
passwordProcessor
.
setAccountProvider
(
accountProvider
);
processorList
.
add
(
passwordProcessor
);
return
new
DefaultProcessorManager
(
processorList
);
}
@Bean
@ConditionalOnMissingBean
(
TreePathRoleMatcher
.
class
)
TreePathRoleMatcher
pathRoleMatcher
(
PathTreeProvider
pathTreeProvider
,
DefaultPathRoleMatcher
pathRoleMatcher
,
SurenessProperties
surenessProperties
)
{
List
<
PathTreeProvider
>
tmp
=
new
ArrayList
<>();
tmp
.
add
(
pathTreeProvider
);
if
(!
CollectionUtils
.
isEmpty
(
surenessProperties
.
getScanPackages
()))
{
AnnotationPathTreeProvider
annotationPathTreeProvider
=
new
AnnotationPathTreeProvider
();
annotationPathTreeProvider
.
setScanPackages
(
surenessProperties
.
getScanPackages
());
tmp
.
add
(
annotationPathTreeProvider
);
}
pathRoleMatcher
.
setPathTreeProviderList
(
tmp
);
pathRoleMatcher
.
buildTree
();
return
pathRoleMatcher
;
}
@Bean
@ConditionalOnMissingBean
(
DefaultPathRoleMatcher
.
class
)
public
DefaultPathRoleMatcher
defaultPathRoleMatcher
(){
return
new
DefaultPathRoleMatcher
();
}
@Bean
@ConditionalOnWebApplication
@ConditionalOnMissingBean
(
value
=
FilterRegistrationBean
.
class
,
name
=
"surenessFilter"
)
@ConditionalOnProperty
(
name
=
"sureness.supportType"
,
havingValue
=
"servlet"
)
public
FilterRegistrationBean
testFilterRegistration
(
SecurityManager
securityManager
)
{
FilterRegistrationBean
registration
=
new
FilterRegistrationBean
();
registration
.
setFilter
(
new
SurenessFilter
(
securityManager
));
registration
.
addUrlPatterns
(
"/*"
);
registration
.
setFilter
((
Filter
)
applicationContext
.
getBean
(
"surenessFilter"
));
registration
.
setName
(
"surenessFilter"
);
registration
.
setOrder
(
1
);
return
registration
;
}
@Bean
@ConditionalOnMissingBean
(
name
=
"surenessFilter"
)
public
Filter
surenessFilter
(
SecurityManager
securityManager
){
return
new
SurenessFilter
(
securityManager
);
}
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
this
.
applicationContext
=
applicationContext
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录