Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
schbrain-parent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
framework
schbrain-parent
Commits
dd827731
"...git@gitlab.schbrain.com:panwangnan/schbrain-parent.git" did not exist on "792f2539c3f2d5aa5a69e6c33a84288da0a75304"
Commit
dd827731
authored
May 08, 2023
by
liaozan
🏀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move WebCommonAutoConfiguration configurations
parent
079b20a9
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
172 additions
and
74 deletions
+172
-74
commons/web-common/src/main/java/com/schbrain/common/web/AuthenticationConfiguration.java
.../com/schbrain/common/web/AuthenticationConfiguration.java
+24
-0
commons/web-common/src/main/java/com/schbrain/common/web/ExceptionHandingConfiguration.java
...om/schbrain/common/web/ExceptionHandingConfiguration.java
+30
-0
commons/web-common/src/main/java/com/schbrain/common/web/ServletComponentConfiguration.java
...om/schbrain/common/web/ServletComponentConfiguration.java
+39
-0
commons/web-common/src/main/java/com/schbrain/common/web/WebCommonAutoConfiguration.java
...a/com/schbrain/common/web/WebCommonAutoConfiguration.java
+10
-42
commons/web-common/src/main/java/com/schbrain/common/web/argument/BodyParamMethodArgumentResolver.java
.../common/web/argument/BodyParamMethodArgumentResolver.java
+13
-16
commons/web-common/src/main/java/com/schbrain/common/web/log/RequestLoggingFilter.java
...ava/com/schbrain/common/web/log/RequestLoggingFilter.java
+5
-10
commons/web-common/src/main/java/com/schbrain/common/web/servlet/AllowAnyOriginWithoutCredentialsCorsConfigurer.java
...rvlet/AllowAnyOriginWithoutCredentialsCorsConfigurer.java
+1
-1
commons/web-common/src/main/java/com/schbrain/common/web/servlet/TraceIdInitializeServletListener.java
.../common/web/servlet/TraceIdInitializeServletListener.java
+2
-4
commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/AuthenticationInterceptor.java
...web/support/authentication/AuthenticationInterceptor.java
+7
-1
commons/web-common/src/main/java/com/schbrain/common/web/utils/ContentCachingServletUtils.java
...schbrain/common/web/utils/ContentCachingServletUtils.java
+40
-0
support/schbrain-spring-support/src/main/java/com/schbrain/framework/support/spring/defaults/DefaultPropertiesEnvironmentPostProcessor.java
...g/defaults/DefaultPropertiesEnvironmentPostProcessor.java
+1
-0
No files found.
commons/web-common/src/main/java/com/schbrain/common/web/AuthenticationConfiguration.java
0 → 100644
View file @
dd827731
package
com.schbrain.common.web
;
import
com.schbrain.common.web.support.authentication.AuthenticationInterceptor
;
import
com.schbrain.common.web.support.authentication.Authenticator
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* @author liaozan
* @since 2023-05-08
*/
@Configuration
(
proxyBeanMethods
=
false
)
public
class
AuthenticationConfiguration
{
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean
(
Authenticator
.
class
)
public
AuthenticationInterceptor
defaultAuthenticationInterceptor
(
Authenticator
authenticator
)
{
return
new
AuthenticationInterceptor
(
authenticator
);
}
}
\ No newline at end of file
commons/web-common/src/main/java/com/schbrain/common/web/ExceptionHandingConfiguration.java
0 → 100644
View file @
dd827731
package
com.schbrain.common.web
;
import
com.schbrain.common.web.exception.*
;
import
com.schbrain.common.web.properties.WebProperties
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* @author liaozan
* @since 2023-05-08
*/
@Configuration
(
proxyBeanMethods
=
false
)
public
class
ExceptionHandingConfiguration
{
@Bean
@ConditionalOnMissingBean
public
GlobalExceptionHandler
defaultGlobalExceptionHandler
()
{
return
new
DefaultGlobalExceptionHandler
();
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean
(
GlobalExceptionHandler
.
class
)
public
ExceptionHandlerWebMcvConfigurer
defaultExceptionHandlerWebMcvConfigurer
(
WebProperties
webProperties
,
GlobalExceptionHandler
exceptionHandler
)
{
return
new
ExceptionHandlerWebMcvConfigurer
(
webProperties
,
exceptionHandler
);
}
}
\ No newline at end of file
commons/web-common/src/main/java/com/schbrain/common/web/ServletComponentConfiguration.java
0 → 100644
View file @
dd827731
package
com.schbrain.common.web
;
import
com.schbrain.common.web.log.RequestLoggingFilter
;
import
com.schbrain.common.web.properties.WebProperties
;
import
com.schbrain.common.web.servlet.CharacterEncodingServletContextInitializer
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.web.servlet.filter.OrderedRequestContextFilter
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.filter.RequestContextFilter
;
/**
* @author liaozan
* @since 2023-05-08
*/
@Configuration
(
proxyBeanMethods
=
false
)
public
class
ServletComponentConfiguration
{
@Bean
@ConditionalOnMissingBean
public
CharacterEncodingServletContextInitializer
characterEncodingServletContextInitializer
(
WebProperties
webProperties
)
{
return
new
CharacterEncodingServletContextInitializer
(
webProperties
.
getEncoding
());
}
@Bean
@ConditionalOnMissingBean
public
RequestContextFilter
requestContextFilter
()
{
OrderedRequestContextFilter
requestContextFilter
=
new
OrderedRequestContextFilter
();
requestContextFilter
.
setThreadContextInheritable
(
true
);
return
requestContextFilter
;
}
@Bean
@ConditionalOnMissingBean
public
RequestLoggingFilter
requestLoggingFilter
(
WebProperties
properties
)
{
return
new
RequestLoggingFilter
(
properties
);
}
}
\ No newline at end of file
commons/web-common/src/main/java/com/schbrain/common/web/WebCommonAutoConfiguration.java
View file @
dd827731
package
com.schbrain.common.web
;
package
com.schbrain.common.web
;
import
com.schbrain.common.web.argument.BodyParamArgumentResolverWebMvcConfigurer
;
import
com.schbrain.common.web.argument.BodyParamArgumentResolverWebMvcConfigurer
;
import
com.schbrain.common.web.exception.*
;
import
com.schbrain.common.web.log.RequestLoggingFilter
;
import
com.schbrain.common.web.properties.WebProperties
;
import
com.schbrain.common.web.properties.WebProperties
;
import
com.schbrain.common.web.result.ResponseBodyHandler
;
import
com.schbrain.common.web.result.ResponseBodyHandler
;
import
com.schbrain.common.web.servlet.*
;
import
com.schbrain.common.web.servlet.AllowAnyOriginWithoutCredentialsCorsConfigurer
;
import
com.schbrain.common.web.support.authentication.AuthenticationInterceptor
;
import
com.schbrain.common.web.servlet.TraceIdInitializeServletListener
;
import
com.schbrain.common.web.support.authentication.Authenticator
;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.boot.autoconfigure.AutoConfiguration
;
import
org.springframework.boot.autoconfigure.AutoConfiguration
;
import
org.springframework.boot.autoconfigure.AutoConfigurationPackages
;
import
org.springframework.boot.autoconfigure.AutoConfigurationPackages
;
import
org.springframework.boot.autoconfigure.condition.*
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.web.client.RestTemplateBuilder
;
import
org.springframework.boot.web.client.RestTemplateBuilder
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.*
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
import
java.util.List
;
import
java.util.List
;
...
@@ -26,29 +24,11 @@ import java.util.List;
...
@@ -26,29 +24,11 @@ import java.util.List;
* @since 2021/11/19
* @since 2021/11/19
*/
*/
@AutoConfiguration
@AutoConfiguration
@ConditionalOnWebApplication
@ConditionalOnWebApplication
(
type
=
Type
.
SERVLET
)
@EnableConfigurationProperties
(
WebProperties
.
class
)
@EnableConfigurationProperties
(
WebProperties
.
class
)
@Import
({
AuthenticationConfiguration
.
class
,
ExceptionHandingConfiguration
.
class
,
ServletComponentConfiguration
.
class
})
public
class
WebCommonAutoConfiguration
{
public
class
WebCommonAutoConfiguration
{
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean
(
Authenticator
.
class
)
public
AuthenticationInterceptor
defaultAuthenticationInterceptor
(
Authenticator
authenticator
)
{
return
new
AuthenticationInterceptor
(
authenticator
);
}
@Bean
@ConditionalOnMissingBean
public
GlobalExceptionHandler
defaultGlobalExceptionHandler
()
{
return
new
DefaultGlobalExceptionHandler
();
}
@Bean
@ConditionalOnMissingBean
public
ExceptionHandlerWebMcvConfigurer
defaultExceptionHandlerWebMcvConfigurer
(
WebProperties
webProperties
,
GlobalExceptionHandler
exceptionHandler
)
{
return
new
ExceptionHandlerWebMcvConfigurer
(
webProperties
,
exceptionHandler
);
}
@Bean
@Bean
@ConditionalOnMissingBean
@ConditionalOnMissingBean
public
BodyParamArgumentResolverWebMvcConfigurer
defaultBodyParamArgumentResolverWebMvcConfigurer
()
{
public
BodyParamArgumentResolverWebMvcConfigurer
defaultBodyParamArgumentResolverWebMvcConfigurer
()
{
...
@@ -81,20 +61,8 @@ public class WebCommonAutoConfiguration {
...
@@ -81,20 +61,8 @@ public class WebCommonAutoConfiguration {
@Bean
@Bean
@ConditionalOnMissingBean
@ConditionalOnMissingBean
public
CharacterEncodingServletContextInitializer
characterEncodingServletContextInitializer
(
WebProperties
webProperties
)
{
public
AllowAnyOriginWithoutCredentialsCorsConfigurer
allowAnyOriginWithoutCredentialsCorsConfigurer
()
{
return
new
CharacterEncodingServletContextInitializer
(
webProperties
.
getEncoding
());
return
new
AllowAnyOriginWithoutCredentialsCorsConfigurer
();
}
@Bean
@ConditionalOnMissingBean
public
RequestLoggingFilter
requestLoggingFilter
(
WebProperties
properties
)
{
return
new
RequestLoggingFilter
(
properties
);
}
@Bean
@ConditionalOnMissingBean
public
AllowAllCorsConfigurer
allowAllCorsConfigurer
()
{
return
new
AllowAllCorsConfigurer
();
}
}
}
}
\ No newline at end of file
commons/web-common/src/main/java/com/schbrain/common/web/argument/BodyParamMethodArgumentResolver.java
View file @
dd827731
...
@@ -7,14 +7,14 @@ import com.schbrain.common.web.annotation.BodyParam;
...
@@ -7,14 +7,14 @@ import com.schbrain.common.web.annotation.BodyParam;
import
lombok.Setter
;
import
lombok.Setter
;
import
org.springframework.core.MethodParameter
;
import
org.springframework.core.MethodParameter
;
import
org.springframework.util.Assert
;
import
org.springframework.util.Assert
;
import
org.springframework.util.StreamUtils
;
import
org.springframework.web.context.request.NativeWebRequest
;
import
org.springframework.web.context.request.NativeWebRequest
;
import
org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver
;
import
org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver
;
import
javax.annotation.Nullable
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
static
com
.
schbrain
.
common
.
web
.
utils
.
ContentCachingServletUtils
.
wrapRequestIfRequired
;
import
static
org
.
springframework
.
web
.
context
.
request
.
RequestAttributes
.
SCOPE_REQUEST
;
/**
/**
* @author liaozan
* @author liaozan
...
@@ -23,7 +23,7 @@ import java.io.InputStream;
...
@@ -23,7 +23,7 @@ import java.io.InputStream;
@Setter
@Setter
public
class
BodyParamMethodArgumentResolver
extends
AbstractNamedValueMethodArgumentResolver
{
public
class
BodyParamMethodArgumentResolver
extends
AbstractNamedValueMethodArgumentResolver
{
private
static
final
String
METHOD_BODY_CACHE_KEY
=
BodyParamMethodArgumentResolver
.
class
.
getName
()
+
".bodyParam
Cache"
;
private
static
final
String
REQUEST_BODY_CACHE
=
BodyParamMethodArgumentResolver
.
class
.
getName
()
+
".requestBody
Cache"
;
private
ObjectMapper
objectMapper
;
private
ObjectMapper
objectMapper
;
...
@@ -48,10 +48,9 @@ public class BodyParamMethodArgumentResolver extends AbstractNamedValueMethodArg
...
@@ -48,10 +48,9 @@ public class BodyParamMethodArgumentResolver extends AbstractNamedValueMethodArg
}
}
@Override
@Override
@Nullable
protected
Object
resolveName
(
String
name
,
MethodParameter
parameter
,
NativeWebRequest
request
)
throws
Exception
{
protected
Object
resolveName
(
String
name
,
MethodParameter
parameter
,
NativeWebRequest
request
)
throws
Exception
{
JsonNode
paramNode
=
getParamNode
(
request
);
JsonNode
requestBody
=
getRequestBody
(
request
);
JsonNode
parameterValue
=
paramNode
.
get
(
name
);
JsonNode
parameterValue
=
requestBody
.
get
(
name
);
if
(
parameterValue
==
null
||
parameterValue
.
isNull
())
{
if
(
parameterValue
==
null
||
parameterValue
.
isNull
())
{
return
null
;
return
null
;
}
}
...
@@ -59,16 +58,14 @@ public class BodyParamMethodArgumentResolver extends AbstractNamedValueMethodArg
...
@@ -59,16 +58,14 @@ public class BodyParamMethodArgumentResolver extends AbstractNamedValueMethodArg
return
objectMapper
.
convertValue
(
parameterValue
,
parameterType
);
return
objectMapper
.
convertValue
(
parameterValue
,
parameterType
);
}
}
private
JsonNode
getParamNode
(
NativeWebRequest
nativeWebRequest
)
throws
IOException
{
private
JsonNode
getRequestBody
(
NativeWebRequest
nativeWebRequest
)
throws
IOException
{
HttpServletRequest
request
=
nativeWebRequest
.
getNativeRequest
(
HttpServletRequest
.
class
);
JsonNode
requestBody
=
(
JsonNode
)
nativeWebRequest
.
getAttribute
(
REQUEST_BODY_CACHE
,
SCOPE_REQUEST
);
Assert
.
state
(
request
!=
null
,
"request must not be null"
);
if
(
requestBody
==
null
)
{
JsonNode
paramNode
=
(
JsonNode
)
request
.
getAttribute
(
METHOD_BODY_CACHE_KEY
);
HttpServletRequest
request
=
wrapRequestIfRequired
(
nativeWebRequest
.
getNativeRequest
(
HttpServletRequest
.
class
));
if
(
paramNode
==
null
)
{
requestBody
=
objectMapper
.
readTree
(
request
.
getInputStream
());
InputStream
inputStream
=
StreamUtils
.
nonClosing
(
request
.
getInputStream
());
nativeWebRequest
.
setAttribute
(
REQUEST_BODY_CACHE
,
requestBody
,
SCOPE_REQUEST
);
paramNode
=
objectMapper
.
readTree
(
inputStream
);
request
.
setAttribute
(
METHOD_BODY_CACHE_KEY
,
paramNode
);
}
}
return
paramNode
;
return
requestBody
;
}
}
}
}
\ No newline at end of file
commons/web-common/src/main/java/com/schbrain/common/web/log/RequestLoggingFilter.java
View file @
dd827731
package
com.schbrain.common.web.log
;
package
com.schbrain.common.web.log
;
import
cn.hutool.core.text.
St
rPool
;
import
cn.hutool.core.text.
Cha
rPool
;
import
cn.hutool.core.util.ArrayUtil
;
import
cn.hutool.core.util.ArrayUtil
;
import
com.schbrain.common.web.properties.WebProperties
;
import
com.schbrain.common.web.properties.WebProperties
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -19,6 +19,8 @@ import javax.servlet.http.HttpServletResponse;
...
@@ -19,6 +19,8 @@ import javax.servlet.http.HttpServletResponse;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.io.UnsupportedEncodingException
;
import
static
com
.
schbrain
.
common
.
web
.
utils
.
ContentCachingServletUtils
.
wrapRequestIfRequired
;
/**
/**
* 请求日志拦截器
* 请求日志拦截器
*/
*/
...
@@ -44,6 +46,7 @@ public class RequestLoggingFilter extends OncePerRequestFilter implements Ordere
...
@@ -44,6 +46,7 @@ public class RequestLoggingFilter extends OncePerRequestFilter implements Ordere
}
}
request
=
wrapRequestIfRequired
(
request
);
request
=
wrapRequestIfRequired
(
request
);
long
startTime
=
System
.
currentTimeMillis
();
long
startTime
=
System
.
currentTimeMillis
();
try
{
try
{
chain
.
doFilter
(
request
,
response
);
chain
.
doFilter
(
request
,
response
);
...
@@ -67,7 +70,7 @@ public class RequestLoggingFilter extends OncePerRequestFilter implements Ordere
...
@@ -67,7 +70,7 @@ public class RequestLoggingFilter extends OncePerRequestFilter implements Ordere
String
queryString
=
request
.
getQueryString
();
String
queryString
=
request
.
getQueryString
();
String
body
=
getRequestBody
(
request
);
String
body
=
getRequestBody
(
request
);
StringBuilder
builder
=
new
StringBuilder
();
StringBuilder
builder
=
new
StringBuilder
();
builder
.
append
(
"requestUri: "
).
append
(
method
).
append
(
StrPool
.
C_
SPACE
).
append
(
requestUri
);
builder
.
append
(
"requestUri: "
).
append
(
method
).
append
(
CharPool
.
SPACE
).
append
(
requestUri
);
if
(
StringUtils
.
hasText
(
queryString
))
{
if
(
StringUtils
.
hasText
(
queryString
))
{
builder
.
append
(
", queryString: "
).
append
(
queryString
);
builder
.
append
(
", queryString: "
).
append
(
queryString
);
}
}
...
@@ -98,12 +101,4 @@ public class RequestLoggingFilter extends OncePerRequestFilter implements Ordere
...
@@ -98,12 +101,4 @@ public class RequestLoggingFilter extends OncePerRequestFilter implements Ordere
}
}
}
}
protected
HttpServletRequest
wrapRequestIfRequired
(
HttpServletRequest
request
)
{
if
(
request
instanceof
ContentCachingRequestWrapper
)
{
return
request
;
}
else
{
return
new
ContentCachingRequestWrapper
(
request
);
}
}
}
}
\ No newline at end of file
commons/web-common/src/main/java/com/schbrain/common/web/servlet/AllowA
ll
CorsConfigurer.java
→
commons/web-common/src/main/java/com/schbrain/common/web/servlet/AllowA
nyOriginWithoutCredentials
CorsConfigurer.java
View file @
dd827731
...
@@ -10,7 +10,7 @@ import java.time.Duration;
...
@@ -10,7 +10,7 @@ import java.time.Duration;
* @author liaozan
* @author liaozan
* @since 2022/11/19
* @since 2022/11/19
*/
*/
public
class
AllowA
ll
CorsConfigurer
implements
WebMvcConfigurer
{
public
class
AllowA
nyOriginWithoutCredentials
CorsConfigurer
implements
WebMvcConfigurer
{
@Override
@Override
public
void
addCorsMappings
(
CorsRegistry
registry
)
{
public
void
addCorsMappings
(
CorsRegistry
registry
)
{
...
...
commons/web-common/src/main/java/com/schbrain/common/web/servlet/TraceIdInitializeServletListener.java
View file @
dd827731
package
com.schbrain.common.web.servlet
;
package
com.schbrain.common.web.servlet
;
import
com.schbrain.common.util.TraceIdUtils
;
import
com.schbrain.common.util.TraceIdUtils
;
import
org.springframework.web.context.request.RequestContextListener
;
import
javax.servlet.ServletRequestEvent
;
import
javax.servlet.ServletRequestEvent
;
import
javax.servlet.ServletRequestListener
;
/**
/**
* @author liaozan
* @author liaozan
* @since 2021/12/8
* @since 2021/12/8
*/
*/
public
class
TraceIdInitializeServletListener
extends
RequestContex
tListener
{
public
class
TraceIdInitializeServletListener
implements
ServletReques
tListener
{
@Override
@Override
public
void
requestInitialized
(
ServletRequestEvent
event
)
{
public
void
requestInitialized
(
ServletRequestEvent
event
)
{
super
.
requestInitialized
(
event
);
// Make sure the traceId is initialized
// Make sure the traceId is initialized
TraceIdUtils
.
get
();
TraceIdUtils
.
get
();
}
}
@Override
@Override
public
void
requestDestroyed
(
ServletRequestEvent
event
)
{
public
void
requestDestroyed
(
ServletRequestEvent
event
)
{
super
.
requestDestroyed
(
event
);
// Make sure the traceId can be cleared
// Make sure the traceId can be cleared
TraceIdUtils
.
clear
();
TraceIdUtils
.
clear
();
}
}
...
...
commons/web-common/src/main/java/com/schbrain/common/web/support/authentication/AuthenticationInterceptor.java
View file @
dd827731
...
@@ -6,6 +6,7 @@ import com.schbrain.common.web.result.ResponseDTO;
...
@@ -6,6 +6,7 @@ import com.schbrain.common.web.result.ResponseDTO;
import
com.schbrain.common.web.support.BaseHandlerInterceptor
;
import
com.schbrain.common.web.support.BaseHandlerInterceptor
;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
lombok.EqualsAndHashCode
;
import
org.springframework.core.Ordered
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.MediaType
;
import
org.springframework.util.Assert
;
import
org.springframework.util.Assert
;
import
org.springframework.web.method.HandlerMethod
;
import
org.springframework.web.method.HandlerMethod
;
...
@@ -22,7 +23,7 @@ import static com.schbrain.common.constants.ResponseCodeConstants.LOGIN_REQUIRED
...
@@ -22,7 +23,7 @@ import static com.schbrain.common.constants.ResponseCodeConstants.LOGIN_REQUIRED
*/
*/
@Data
@Data
@EqualsAndHashCode
(
callSuper
=
true
)
@EqualsAndHashCode
(
callSuper
=
true
)
public
class
AuthenticationInterceptor
extends
BaseHandlerInterceptor
{
public
class
AuthenticationInterceptor
extends
BaseHandlerInterceptor
implements
Ordered
{
private
Authenticator
authenticator
;
private
Authenticator
authenticator
;
...
@@ -31,6 +32,11 @@ public class AuthenticationInterceptor extends BaseHandlerInterceptor {
...
@@ -31,6 +32,11 @@ public class AuthenticationInterceptor extends BaseHandlerInterceptor {
this
.
authenticator
=
authenticator
;
this
.
authenticator
=
authenticator
;
}
}
@Override
public
int
getOrder
()
{
return
Ordered
.
LOWEST_PRECEDENCE
;
}
@Override
@Override
protected
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
HandlerMethod
handler
)
{
protected
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
HandlerMethod
handler
)
{
boolean
validated
=
authenticator
.
validate
(
request
,
response
,
handler
);
boolean
validated
=
authenticator
.
validate
(
request
,
response
,
handler
);
...
...
commons/web-common/src/main/java/com/schbrain/common/web/utils/ContentCachingServletUtils.java
0 → 100644
View file @
dd827731
package
com.schbrain.common.web.utils
;
import
org.springframework.util.Assert
;
import
org.springframework.web.util.ContentCachingRequestWrapper
;
import
org.springframework.web.util.ContentCachingResponseWrapper
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
/**
* @author liaozan
* @since 2023-05-08
*/
public
class
ContentCachingServletUtils
{
/**
* Make request content cacheable to avoid stream closed error after inputStream closed
*/
public
static
HttpServletRequest
wrapRequestIfRequired
(
HttpServletRequest
request
)
{
Assert
.
notNull
(
request
,
"request must not be null"
);
if
(
request
instanceof
ContentCachingRequestWrapper
)
{
return
request
;
}
else
{
return
new
ContentCachingRequestWrapper
(
request
);
}
}
/**
* Make response content cacheable to avoid stream closed error after outputStream closed
*/
public
static
HttpServletResponse
wrapResponseIfRequired
(
HttpServletResponse
response
)
{
Assert
.
notNull
(
response
,
"response must not be null"
);
if
(
response
instanceof
ContentCachingResponseWrapper
)
{
return
response
;
}
else
{
return
new
ContentCachingResponseWrapper
(
response
);
}
}
}
\ No newline at end of file
support/schbrain-spring-support/src/main/java/com/schbrain/framework/support/spring/defaults/DefaultPropertiesEnvironmentPostProcessor.java
View file @
dd827731
...
@@ -42,6 +42,7 @@ public class DefaultPropertiesEnvironmentPostProcessor extends LoggerAwareEnviro
...
@@ -42,6 +42,7 @@ public class DefaultPropertiesEnvironmentPostProcessor extends LoggerAwareEnviro
public
void
postProcessEnvironment
(
ConfigurableEnvironment
environment
,
SpringApplication
application
)
{
public
void
postProcessEnvironment
(
ConfigurableEnvironment
environment
,
SpringApplication
application
)
{
Map
<
String
,
Object
>
defaultProperties
=
new
HashMap
<>();
Map
<
String
,
Object
>
defaultProperties
=
new
HashMap
<>();
// management
// management
defaultProperties
.
put
(
"management.trace.http.enabled"
,
false
);
defaultProperties
.
put
(
"management.endpoints.web.exposure.include"
,
"*"
);
defaultProperties
.
put
(
"management.endpoints.web.exposure.include"
,
"*"
);
defaultProperties
.
put
(
"management.endpoints.enabled-by-default"
,
true
);
defaultProperties
.
put
(
"management.endpoints.enabled-by-default"
,
true
);
defaultProperties
.
put
(
"management.endpoint.health.show-details"
,
Show
.
ALWAYS
);
defaultProperties
.
put
(
"management.endpoint.health.show-details"
,
Show
.
ALWAYS
);
...
...
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