Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
civil-bigdata
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
civil
civil-bigdata
Commits
07d4a7b6
Commit
07d4a7b6
authored
Nov 22, 2021
by
韦华德
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新
parent
bbe87011
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
8 deletions
+17
-8
single-server/src/main/java/com/zq/single/config/WebMvcConfig.java
+2
-1
single-server/src/main/java/com/zq/single/config/interceptor/ApiInterceptor.java
+7
-2
single-server/src/main/java/com/zq/single/controller/SysUserController.java
+8
-5
No files found.
single-server/src/main/java/com/zq/single/config/WebMvcConfig.java
View file @
07d4a7b6
...
@@ -15,7 +15,8 @@ public class WebMvcConfig implements WebMvcConfigurer {
...
@@ -15,7 +15,8 @@ public class WebMvcConfig implements WebMvcConfigurer {
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
registry
.
addInterceptor
(
apiInterceptor
)
registry
.
addInterceptor
(
apiInterceptor
)
.
addPathPatterns
(
"/single/**"
)
.
addPathPatterns
(
"/single/**"
)
// .excludePathPatterns("/xxxx/**")
.
excludePathPatterns
(
"/single/auth/login"
)
.
excludePathPatterns
(
"/single/user/login"
)
;
;
}
}
...
...
single-server/src/main/java/com/zq/single/config/interceptor/ApiInterceptor.java
View file @
07d4a7b6
...
@@ -10,8 +10,10 @@ import com.zq.common.config.security.SecurityProperties;
...
@@ -10,8 +10,10 @@ import com.zq.common.config.security.SecurityProperties;
import
com.zq.common.context.ContextUtils
;
import
com.zq.common.context.ContextUtils
;
import
com.zq.common.vo.ApiTokenVo
;
import
com.zq.common.vo.ApiTokenVo
;
import
com.zq.common.vo.ResultVo
;
import
com.zq.common.vo.ResultVo
;
import
com.zq.single.vo.UserInfoVo
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.servlet.HandlerInterceptor
;
import
org.springframework.web.servlet.HandlerInterceptor
;
...
@@ -32,10 +34,13 @@ public class ApiInterceptor implements HandlerInterceptor {
...
@@ -32,10 +34,13 @@ public class ApiInterceptor implements HandlerInterceptor {
log
.
debug
(
"{}请求URI: {}"
,
ip
,
request
.
getRequestURL
());
log
.
debug
(
"{}请求URI: {}"
,
ip
,
request
.
getRequestURL
());
String
token
=
request
.
getHeader
(
properties
.
getHeader
());
String
token
=
request
.
getHeader
(
properties
.
getHeader
());
ApiTokenVo
tokenVo
=
redisUtils
.
getObj
(
BaseCacheKeys
.
appTokenKey
(
token
),
ApiTokenVo
.
class
);
if
(
StringUtils
.
isNotBlank
(
token
))
{
token
=
token
.
replace
(
properties
.
getTokenStartWith
(),
""
);
}
UserInfoVo
tokenVo
=
(
UserInfoVo
)
redisUtils
.
getObj
(
BaseCacheKeys
.
appTokenKey
(
token
),
ApiTokenVo
.
class
);
if
(
tokenVo
==
null
)
{
if
(
tokenVo
==
null
)
{
response
.
setStatus
(
HttpStatus
.
HTTP_UNAUTHORIZED
);
response
.
setStatus
(
HttpStatus
.
HTTP_UNAUTHORIZED
);
ServletUtil
.
write
(
response
,
JSONUtil
.
toJsonStr
(
ResultVo
.
fail
(
401
,
"
认证失败
"
)),
ContentType
.
JSON
.
getValue
());
ServletUtil
.
write
(
response
,
JSONUtil
.
toJsonStr
(
ResultVo
.
fail
(
401
,
"
Unauthorized
"
)),
ContentType
.
JSON
.
getValue
());
return
false
;
return
false
;
}
}
...
...
single-server/src/main/java/com/zq/single/controller/SysUserController.java
View file @
07d4a7b6
...
@@ -115,7 +115,6 @@ public class SysUserController {
...
@@ -115,7 +115,6 @@ public class SysUserController {
userToken
.
setUsername
(
thisUser
.
getUsername
());
userToken
.
setUsername
(
thisUser
.
getUsername
());
String
token
=
ApiTokenUtils
.
createToken
(
userToken
,
BaseCacheKeys
.
APP_TOKEN_EXPIRE_MINUTES
);
String
token
=
ApiTokenUtils
.
createToken
(
userToken
,
BaseCacheKeys
.
APP_TOKEN_EXPIRE_MINUTES
);
response
.
setHeader
(
properties
.
getHeader
(),
token
);
response
.
setHeader
(
properties
.
getHeader
(),
token
);
String
s
=
BaseCacheKeys
.
appTokenKey
(
token
);
redisUtils
.
setObj
(
BaseCacheKeys
.
appTokenKey
(
token
),
userToken
,
BaseCacheKeys
.
APP_TOKEN_EXPIRE_MINUTES
);
redisUtils
.
setObj
(
BaseCacheKeys
.
appTokenKey
(
token
),
userToken
,
BaseCacheKeys
.
APP_TOKEN_EXPIRE_MINUTES
);
return
ResultVo
.
success
();
return
ResultVo
.
success
();
...
@@ -133,13 +132,17 @@ public class SysUserController {
...
@@ -133,13 +132,17 @@ public class SysUserController {
@ApiOperation
(
"单点登录用户管理列表"
)
@ApiOperation
(
"单点登录用户管理列表"
)
@PostMapping
(
"/manageList"
)
@PostMapping
(
"/manageList"
)
public
ResultVo
manageList
(
@RequestBody
SysUser
sysUser
)
{
public
ResultVo
manageList
(
@RequestBody
SysUser
sysUser
)
{
SysUser
thisUser
=
sysUserService
.
getById
(
sysUser
.
getUserId
());
LambdaQueryWrapper
<
SysUser
>
lambdaQueryWrapper
=
new
LambdaQueryWrapper
<>();
lambdaQueryWrapper
.
eq
(
SysUser:
:
getUsername
,
sysUser
.
getUsername
());
List
<
SysUser
>
users
=
sysUserService
.
list
(
lambdaQueryWrapper
);
AssertUtils
.
isTrue
(
users
!=
null
&&
users
.
size
()>
0
,
"服务器繁忙请稍后再试"
);
SysUser
thisUser
=
users
.
get
(
0
);
if
(!
thisUser
.
getIsAdmin
()){
if
(!
thisUser
.
getIsAdmin
()){
return
ResultVo
.
fail
(
"不是管理员"
);
return
ResultVo
.
fail
(
"不是管理员"
);
}
}
LambdaQueryWrapper
<
SysUser
>
lambdaQueryWrapper
=
new
LambdaQueryWrapper
<>();
List
<
SysUser
>
userList
=
sysUserService
.
list
(
lambdaQueryWrapper
.
eq
(
SysUser:
:
getEnabled
,
1L
)
);
List
<
SysUser
>
userList
=
sysUserService
.
list
();
// AssertUtils.isTrue(blind > 0, "服务器繁忙请稍后再试");
return
ResultVo
.
success
(
userList
);
return
ResultVo
.
success
(
userList
);
}
}
...
...
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