Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
platform
/
platform-evbusiness-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 511edf3f
authored
Nov 17, 2023
by
zhouhaibao
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]登录信息添加
1 parent
626f6f62
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
79 deletions
platform-evbusiness/src/main/java/cn/com/glsx/evbusiness/config/SSOUserInterceptor.java
platform-evbusiness/src/main/java/cn/com/glsx/evbusiness/config/WebConfig.java
platform-evbusiness/src/main/java/cn/com/glsx/evbusiness/modules/service/OrderService.java
platform-evbusiness/src/main/java/cn/com/glsx/evbusiness/config/SSOUserInterceptor.java
View file @
511edf3
...
@@ -27,7 +27,6 @@ import java.util.concurrent.TimeUnit;
...
@@ -27,7 +27,6 @@ import java.util.concurrent.TimeUnit;
/**
/**
* scrm登录体系
* scrm登录体系
*
*/
*/
@Slf4j
@Slf4j
@Component
@Component
...
@@ -47,83 +46,85 @@ public class SSOUserInterceptor implements HandlerInterceptor {
...
@@ -47,83 +46,85 @@ public class SSOUserInterceptor implements HandlerInterceptor {
private
long
timeout
=
1800
;
private
long
timeout
=
1800
;
@Override
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
throws
Exception
{
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
throws
Exception
{
if
(
handler
instanceof
HandlerMethod
)
{
boolean
needLoginFlag
=
true
;
// 默认需要登录
HandlerMethod
handlerMethod
=
(
HandlerMethod
)
handler
;
//##判断是否需要登录
// 1.先判断类上是否存在@NoLogin,@CheckSign注解[默认无需登录注解]
Class
<?>
targetBean
=
handlerMethod
.
getBeanType
();
//验签无需登录校验
if
(
targetBean
.
isAnnotationPresent
(
CheckSign
.
class
)
||
handlerMethod
.
hasMethodAnnotation
(
CheckSign
.
class
))
{
return
true
;
return
true
;
// if (handler instanceof HandlerMethod) {
}
// boolean needLoginFlag = true; // 默认需要登录
//
if
(
targetBean
.
isAnnotationPresent
(
NoLogin
.
class
))
{
// HandlerMethod handlerMethod = (HandlerMethod) handler;
// 如果存在,则根据注解的value()确定是否需要登录访问
// //##判断是否需要登录
NoLogin
noLogin
=
targetBean
.
getAnnotation
(
NoLogin
.
class
);
// // 1.先判断类上是否存在@NoLogin,@CheckSign注解[默认无需登录注解]
needLoginFlag
=
!
noLogin
.
value
();
// Class<?> targetBean = handlerMethod.getBeanType();
}
//
// //验签无需登录校验
// 2.再判断调用方法上是否存在@NoLogin注解[默认无需登录注解]
// if (targetBean.isAnnotationPresent(CheckSign.class) || handlerMethod.hasMethodAnnotation(CheckSign.class)) {
if
(
handlerMethod
.
hasMethodAnnotation
(
NoLogin
.
class
))
{
// return true;
// 如果存在,则根据注解的value()确定是否需要登录访问[方法覆盖类]
// }
NoLogin
noLogin
=
handlerMethod
.
getMethod
().
getAnnotation
(
NoLogin
.
class
);
//
needLoginFlag
=
!
noLogin
.
value
();
// if (targetBean.isAnnotationPresent(NoLogin.class)) {
}
// // 如果存在,则根据注解的value()确定是否需要登录访问
// 3.需要登录访问则去验证token,反之,则通过
// NoLogin noLogin = targetBean.getAnnotation(NoLogin.class);
if
(!
needLoginFlag
)
{
// needLoginFlag = !noLogin.value();
return
true
;
// }
}
//
// // 2.再判断调用方法上是否存在@NoLogin注解[默认无需登录注解]
//##判断是否登录
// if (handlerMethod.hasMethodAnnotation(NoLogin.class)) {
String
token
=
request
.
getHeader
(
HttpHeaders
.
AUTHORIZATION
);
// // 如果存在,则根据注解的value()确定是否需要登录访问[方法覆盖类]
// 1.判断请求是否携带token
// NoLogin noLogin = handlerMethod.getMethod().getAnnotation(NoLogin.class);
if
(
StringUtils
.
isNotEmpty
(
token
))
{
// needLoginFlag = !noLogin.value();
Session
session
=
getSession
(
token
);
// }
if
(
session
!=
null
&&
session
instanceof
SimpleSession
)
{
// // 3.需要登录访问则去验证token,反之,则通过
SimpleSession
simpleSession
=
SimpleSession
.
class
.
cast
(
session
);
// if (!needLoginFlag) {
// 非空的情况下解析用户信息放入缓存中
// return true;
Object
user
=
simpleSession
.
getAttribute
(
USER_KEY
);
// }
if
(
user
!=
null
)
{
//
try
{
// //##判断是否登录
log
.
info
(
"用户信息{}"
,
JSONObject
.
toJSONString
(
user
));
// String token = request.getHeader(HttpHeaders.AUTHORIZATION);
RopThreadLocal
.
setLoginUser
(
user
);
// // 1.判断请求是否携带token
return
true
;
// if (StringUtils.isNotEmpty(token)) {
}
catch
(
Exception
e
)
{
// Session session = getSession(token);
log
.
error
(
"rop a conversion user error:{}"
,
e
.
getMessage
(),
e
);
// if (session != null && session instanceof SimpleSession) {
}
// SimpleSession simpleSession = SimpleSession.class.cast(session);
}
else
{
// // 非空的情况下解析用户信息放入缓存中
Object
wechatUserInfo
=
simpleSession
.
getAttribute
(
WECHAT_USER_KEY
);
// Object user = simpleSession.getAttribute(USER_KEY);
if
(
wechatUserInfo
!=
null
)
{
// if (user != null) {
try
{
// try {
log
.
info
(
"小程序用户信息{}"
,
JSONObject
.
toJSONString
(
wechatUserInfo
));
// log.info("用户信息{}", JSONObject.toJSONString(user));
RopThreadLocal
.
setWechatLoginUserInfo
(
wechatUserInfo
);
// cn.com.glsx.evbusiness.config.RopThreadLocal.setLoginUser(user);
return
true
;
// return true;
}
catch
(
Exception
e
)
{
// } catch (Exception e) {
log
.
error
(
"rop a conversion user error:{}"
,
e
.
getMessage
(),
e
);
// log.error("rop a conversion user error:{}", e.getMessage(), e);
}
// }
}
else
{
// } else {
// 需要登录
// Object wechatUserInfo = simpleSession.getAttribute(WECHAT_USER_KEY);
needLogin
(
response
);
// if (wechatUserInfo != null) {
return
false
;
// try {
}
// log.info("小程序用户信息{}", JSONObject.toJSONString(wechatUserInfo));
}
// cn.com.glsx.evbusiness.config.RopThreadLocal.setWechatLoginUserInfo(wechatUserInfo);
}
// return true;
}
// } catch (Exception e) {
// 需要登录
// log.error("rop a conversion user error:{}", e.getMessage(), e);
needLogin
(
response
);
// }
return
false
;
// } else {
}
else
{
// // 需要登录
return
true
;
// needLogin(response);
}
// return false;
// }
// }
// }
// }
// // 需要登录
// needLogin(response);
// return false;
// } else {
// return true;
// }
}
}
@Override
@Override
public
void
afterCompletion
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
Exception
ex
)
throws
Exception
{
public
void
afterCompletion
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
Exception
ex
)
throws
Exception
{
}
}
...
@@ -131,7 +132,8 @@ public class SSOUserInterceptor implements HandlerInterceptor {
...
@@ -131,7 +132,8 @@ public class SSOUserInterceptor implements HandlerInterceptor {
response
.
setCharacterEncoding
(
"UTF-8"
);
response
.
setCharacterEncoding
(
"UTF-8"
);
response
.
setContentType
(
"application/json; charset=utf-8"
);
response
.
setContentType
(
"application/json; charset=utf-8"
);
try
(
PrintWriter
writer
=
response
.
getWriter
())
{
try
(
PrintWriter
writer
=
response
.
getWriter
())
{
writer
.
write
(
JSON
.
toJSONString
(
R
.
error
(
SystemMessage
.
NOT_LOGIN
.
getCode
(),
SystemMessage
.
NOT_LOGIN
.
getMsg
())));
writer
.
write
(
JSON
.
toJSONString
(
R
.
error
(
SystemMessage
.
NOT_LOGIN
.
getCode
(),
SystemMessage
.
NOT_LOGIN
.
getMsg
())));
writer
.
flush
();
writer
.
flush
();
}
}
}
}
...
@@ -142,8 +144,8 @@ public class SSOUserInterceptor implements HandlerInterceptor {
...
@@ -142,8 +144,8 @@ public class SSOUserInterceptor implements HandlerInterceptor {
template
.
setConnectionFactory
(
redisConnectionFactory
);
template
.
setConnectionFactory
(
redisConnectionFactory
);
template
.
setKeySerializer
(
new
StringRedisSerializer
());
template
.
setKeySerializer
(
new
StringRedisSerializer
());
template
.
setHashKeySerializer
(
new
StringRedisSerializer
());
template
.
setHashKeySerializer
(
new
StringRedisSerializer
());
//
template.setValueSerializer(new KryoRedisSerializer<>());
template
.
setValueSerializer
(
new
KryoRedisSerializer
<>());
//
template.setHashValueSerializer(new KryoRedisSerializer<>());
template
.
setHashValueSerializer
(
new
KryoRedisSerializer
<>());
template
.
afterPropertiesSet
();
template
.
afterPropertiesSet
();
Assert
.
notNull
(
template
,
"Redis Template Is Null"
);
Assert
.
notNull
(
template
,
"Redis Template Is Null"
);
String
sessionKey
=
getSessionKey
(
sessionId
);
String
sessionKey
=
getSessionKey
(
sessionId
);
...
...
platform-evbusiness/src/main/java/cn/com/glsx/evbusiness/config/WebConfig.java
View file @
511edf3
...
@@ -64,7 +64,6 @@ public class WebConfig implements WebMvcConfigurer {
...
@@ -64,7 +64,6 @@ public class WebConfig implements WebMvcConfigurer {
.
excludePathPatterns
(
"/"
)
.
excludePathPatterns
(
"/"
)
.
excludePathPatterns
(
"/login"
)
.
excludePathPatterns
(
"/login"
)
.
excludePathPatterns
(
"/actuator/**"
)
.
excludePathPatterns
(
"/actuator/**"
)
.
excludePathPatterns
(
"/api/**"
)
.
excludePathPatterns
(
"/platform-evbusiness/api/gbt/ocpp16/tcp/**"
)
.
excludePathPatterns
(
"/platform-evbusiness/api/gbt/ocpp16/tcp/**"
)
.
excludePathPatterns
(
uploadProperties
.
getFilepath
())
.
excludePathPatterns
(
uploadProperties
.
getFilepath
())
.
excludePathPatterns
(
"/swagger-resources/**"
,
"/swagger-ui/**"
,
"/v3/**"
,
"/doc.html"
);
.
excludePathPatterns
(
"/swagger-resources/**"
,
"/swagger-ui/**"
,
"/v3/**"
,
"/doc.html"
);
...
...
platform-evbusiness/src/main/java/cn/com/glsx/evbusiness/modules/service/OrderService.java
View file @
511edf3
...
@@ -71,7 +71,6 @@ public class OrderService {
...
@@ -71,7 +71,6 @@ public class OrderService {
startBo
.
setAccountBalance
(
2000.00
);
startBo
.
setAccountBalance
(
2000.00
);
startBo
.
setPhysicalCardNumber
(
"00000000D14B0A54"
);
startBo
.
setPhysicalCardNumber
(
"00000000D14B0A54"
);
startBo
.
setLogicalCardNumber
(
"00000000D14B0A54"
);
startBo
.
setLogicalCardNumber
(
"00000000D14B0A54"
);
insertOrder
(
orderCreateBO
,
orderCode
);
Result
<
Boolean
>
start
=
pileControlFeignClient
.
start
(
JSONObject
.
toJSONString
(
startBo
));
Result
<
Boolean
>
start
=
pileControlFeignClient
.
start
(
JSONObject
.
toJSONString
(
startBo
));
if
(
start
.
getData
())
{
if
(
start
.
getData
())
{
// 4.创建待支付的订单
// 4.创建待支付的订单
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment