Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
customer-service
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
QG
customer-service
Commits
f5885c6b
Commit
f5885c6b
authored
Mar 06, 2020
by
xiaozhe.chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
尝试登陆功能
parent
0674ecaf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
2 deletions
+83
-2
IntegerToEnumConverterFactory.java
...fig/http/mvc/converter/IntegerToEnumConverterFactory.java
+37
-0
WebSecurityConfig.java
...roup/customer/config/http/security/WebSecurityConfig.java
+2
-2
WebSessionConfig.java
...group/customer/config/http/security/WebSessionConfig.java
+44
-0
No files found.
src/main/java/cn/quantgroup/customer/config/http/mvc/converter/IntegerToEnumConverterFactory.java
0 → 100644
View file @
f5885c6b
package
cn
.
quantgroup
.
customer
.
config
.
http
.
mvc
.
converter
;
import
org.springframework.core.convert.converter.Converter
;
import
org.springframework.core.convert.converter.ConverterFactory
;
public
class
IntegerToEnumConverterFactory
implements
ConverterFactory
<
String
,
Enum
>
{
public
IntegerToEnumConverterFactory
()
{
}
@Override
public
<
T
extends
Enum
>
Converter
<
String
,
T
>
getConverter
(
Class
<
T
>
targetType
)
{
Class
<?>
enumType
=
targetType
;
while
(
enumType
!=
null
&&
!
enumType
.
isEnum
())
{
enumType
=
enumType
.
getSuperclass
();
}
if
(
enumType
==
null
)
{
throw
new
IllegalArgumentException
(
"The target type "
+
targetType
.
getName
()
+
" does not refer to an enum"
);
}
else
{
return
new
IntegerToEnumConverterFactory
.
IntegerToEnum
(
enumType
);
}
}
private
class
IntegerToEnum
<
T
extends
Enum
>
implements
Converter
<
String
,
T
>
{
private
final
Class
<
T
>
enumType
;
public
IntegerToEnum
(
Class
<
T
>
enumType
)
{
this
.
enumType
=
enumType
;
}
public
T
convert
(
String
source
)
{
T
[]
ts
=
enumType
.
getEnumConstants
();
int
ordinal
=
Integer
.
parseInt
(
source
);
return
ordinal
<
ts
.
length
&&
ordinal
>=
0
?
ts
[
ordinal
]
:
null
;
}
}
}
\ No newline at end of file
src/main/java/cn/quantgroup/customer/config/http/security/WebSecurityConfig.java
View file @
f5885c6b
...
...
@@ -31,9 +31,9 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected
void
configure
(
HttpSecurity
http
)
throws
Exception
{
//String allowedRoutes = "/test/**,/error/**,/user/**,/repay/**";
String
allowedRoutes
=
"/test/**,/error/**"
;
String
allowedRoutes
=
"/test/**,/error/**
,/user/login
"
;
String
[]
allowedRoutesArr
=
allowedRoutes
.
split
(
","
);
http
http
.
httpBasic
().
and
()
.
authorizeRequests
()
.
antMatchers
(
allowedRoutesArr
)
.
permitAll
().
anyRequest
().
authenticated
()
...
...
src/main/java/cn/quantgroup/customer/config/http/security/WebSessionConfig.java
View file @
f5885c6b
package
cn
.
quantgroup
.
customer
.
config
.
http
.
security
;
import
cn.quantgroup.customer.config.http.mvc.converter.IntegerToEnumConverterFactory
;
import
cn.quantgroup.customer.constant.Constant
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.core.convert.converter.ConverterRegistry
;
import
org.springframework.format.support.DefaultFormattingConversionService
;
import
org.springframework.format.support.FormattingConversionService
;
import
org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
;
import
org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession
;
import
org.springframework.session.web.http.HeaderHttpSessionStrategy
;
import
org.springframework.session.web.http.HttpSessionStrategy
;
import
java.text.SimpleDateFormat
;
@EnableRedisHttpSession
(
maxInactiveIntervalInSeconds
=
Constant
.
COOKIE_AND_SESSION_EXPIRE_TIMEOUT_SECONDS
)
public
class
WebSessionConfig
{
...
...
@@ -15,4 +25,38 @@ public class WebSessionConfig {
return
strategy
;
}
@Bean
public
Jackson2ObjectMapperBuilder
jacksonBuilder
()
{
Jackson2ObjectMapperBuilder
builder
=
new
Jackson2ObjectMapperBuilder
();
builder
.
indentOutput
(
false
)
.
dateFormat
(
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
))
.
defaultViewInclusion
(
false
)
.
serializationInclusion
(
JsonInclude
.
Include
.
NON_NULL
)
.
featuresToEnable
(
SerializationFeature
.
WRITE_ENUMS_USING_INDEX
,
DeserializationFeature
.
FAIL_ON_NUMBERS_FOR_ENUMS
);
return
builder
;
}
@Bean
public
ConverterRegistry
defaultConversionService
()
{
FormattingConversionService
conversionService
=
new
DefaultFormattingConversionService
();
addFormatter
(
conversionService
);
return
conversionService
;
}
@Bean
public
ConverterRegistry
integrationConversionService
()
{
FormattingConversionService
conversionService
=
new
DefaultFormattingConversionService
();
addFormatter
(
conversionService
);
return
conversionService
;
}
private
void
addFormatter
(
FormattingConversionService
conversionService
)
{
IntegerToEnumConverterFactory
factory
=
new
IntegerToEnumConverterFactory
();
conversionService
.
removeConvertible
(
String
.
class
,
Enum
.
class
);
conversionService
.
addConverterFactory
(
factory
);
}
}
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