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;
/**
* scrm登录体系
*
*/
@Slf4j
@Component
...
...
@@ -47,83 +46,85 @@ public class SSOUserInterceptor implements HandlerInterceptor {
private
long
timeout
=
1800
;
@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
;
// 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;
// }
//
// if (targetBean.isAnnotationPresent(NoLogin.class)) {
// // 如果存在,则根据注解的value()确定是否需要登录访问
// NoLogin noLogin = targetBean.getAnnotation(NoLogin.class);
// needLoginFlag = !noLogin.value();
// }
//
// // 2.再判断调用方法上是否存在@NoLogin注解[默认无需登录注解]
// if (handlerMethod.hasMethodAnnotation(NoLogin.class)) {
// // 如果存在,则根据注解的value()确定是否需要登录访问[方法覆盖类]
// NoLogin noLogin = handlerMethod.getMethod().getAnnotation(NoLogin.class);
// needLoginFlag = !noLogin.value();
// }
// // 3.需要登录访问则去验证token,反之,则通过
// if (!needLoginFlag) {
// return true;
// }
//
// //##判断是否登录
// String token = request.getHeader(HttpHeaders.AUTHORIZATION);
// // 1.判断请求是否携带token
// if (StringUtils.isNotEmpty(token)) {
// Session session = getSession(token);
// if (session != null && session instanceof SimpleSession) {
// SimpleSession simpleSession = SimpleSession.class.cast(session);
// // 非空的情况下解析用户信息放入缓存中
// Object user = simpleSession.getAttribute(USER_KEY);
// if (user != null) {
// try {
// log.info("用户信息{}", JSONObject.toJSONString(user));
// cn.com.glsx.evbusiness.config.RopThreadLocal.setLoginUser(user);
// return true;
// } catch (Exception e) {
// log.error("rop a conversion user error:{}", e.getMessage(), e);
// }
// } else {
// Object wechatUserInfo = simpleSession.getAttribute(WECHAT_USER_KEY);
// if (wechatUserInfo != null) {
// 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);
// }
// } else {
// // 需要登录
// needLogin(response);
// return false;
// }
// }
// }
// }
// // 需要登录
// needLogin(response);
// return false;
// } else {
// return true;
// }
}
if
(
targetBean
.
isAnnotationPresent
(
NoLogin
.
class
))
{
// 如果存在,则根据注解的value()确定是否需要登录访问
NoLogin
noLogin
=
targetBean
.
getAnnotation
(
NoLogin
.
class
);
needLoginFlag
=
!
noLogin
.
value
();
}
// 2.再判断调用方法上是否存在@NoLogin注解[默认无需登录注解]
if
(
handlerMethod
.
hasMethodAnnotation
(
NoLogin
.
class
))
{
// 如果存在,则根据注解的value()确定是否需要登录访问[方法覆盖类]
NoLogin
noLogin
=
handlerMethod
.
getMethod
().
getAnnotation
(
NoLogin
.
class
);
needLoginFlag
=
!
noLogin
.
value
();
}
// 3.需要登录访问则去验证token,反之,则通过
if
(!
needLoginFlag
)
{
return
true
;
}
//##判断是否登录
String
token
=
request
.
getHeader
(
HttpHeaders
.
AUTHORIZATION
);
// 1.判断请求是否携带token
if
(
StringUtils
.
isNotEmpty
(
token
))
{
Session
session
=
getSession
(
token
);
if
(
session
!=
null
&&
session
instanceof
SimpleSession
)
{
SimpleSession
simpleSession
=
SimpleSession
.
class
.
cast
(
session
);
// 非空的情况下解析用户信息放入缓存中
Object
user
=
simpleSession
.
getAttribute
(
USER_KEY
);
if
(
user
!=
null
)
{
try
{
log
.
info
(
"用户信息{}"
,
JSONObject
.
toJSONString
(
user
));
RopThreadLocal
.
setLoginUser
(
user
);
return
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
"rop a conversion user error:{}"
,
e
.
getMessage
(),
e
);
}
}
else
{
Object
wechatUserInfo
=
simpleSession
.
getAttribute
(
WECHAT_USER_KEY
);
if
(
wechatUserInfo
!=
null
)
{
try
{
log
.
info
(
"小程序用户信息{}"
,
JSONObject
.
toJSONString
(
wechatUserInfo
));
RopThreadLocal
.
setWechatLoginUserInfo
(
wechatUserInfo
);
return
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
"rop a conversion user error:{}"
,
e
.
getMessage
(),
e
);
}
}
else
{
// 需要登录
needLogin
(
response
);
return
false
;
}
}
}
}
// 需要登录
needLogin
(
response
);
return
false
;
}
else
{
return
true
;
}
}
@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 {
response
.
setCharacterEncoding
(
"UTF-8"
);
response
.
setContentType
(
"application/json; charset=utf-8"
);
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
();
}
}
...
...
@@ -142,8 +144,8 @@ public class SSOUserInterceptor implements HandlerInterceptor {
template
.
setConnectionFactory
(
redisConnectionFactory
);
template
.
setKeySerializer
(
new
StringRedisSerializer
());
template
.
setHashKeySerializer
(
new
StringRedisSerializer
());
//
template.setValueSerializer(new KryoRedisSerializer<>());
//
template.setHashValueSerializer(new KryoRedisSerializer<>());
template
.
setValueSerializer
(
new
KryoRedisSerializer
<>());
template
.
setHashValueSerializer
(
new
KryoRedisSerializer
<>());
template
.
afterPropertiesSet
();
Assert
.
notNull
(
template
,
"Redis Template Is Null"
);
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 {
.
excludePathPatterns
(
"/"
)
.
excludePathPatterns
(
"/login"
)
.
excludePathPatterns
(
"/actuator/**"
)
.
excludePathPatterns
(
"/api/**"
)
.
excludePathPatterns
(
"/platform-evbusiness/api/gbt/ocpp16/tcp/**"
)
.
excludePathPatterns
(
uploadProperties
.
getFilepath
())
.
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 {
startBo
.
setAccountBalance
(
2000.00
);
startBo
.
setPhysicalCardNumber
(
"00000000D14B0A54"
);
startBo
.
setLogicalCardNumber
(
"00000000D14B0A54"
);
insertOrder
(
orderCreateBO
,
orderCode
);
Result
<
Boolean
>
start
=
pileControlFeignClient
.
start
(
JSONObject
.
toJSONString
(
startBo
));
if
(
start
.
getData
())
{
// 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