Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Eladmin
Commits
ef03d1c8
Commit
ef03d1c8
authored
Nov 04, 2019
by
dqjdda
Browse files
自定义权限验证逻辑优化
parent
fd9fb2a6
Changes
2
Hide whitespace changes
Inline
Side-by-side
eladmin-common/src/main/java/me/zhengjie/config/ElPermissionConfig.java
View file @
ef03d1c8
...
...
@@ -19,7 +19,6 @@ public class ElPermissionConfig {
// 获取当前用户的所有权限
List
<
String
>
elPermissions
=
SecurityUtils
.
getUserDetails
().
getAuthorities
().
stream
().
map
(
GrantedAuthority:
:
getAuthority
).
collect
(
Collectors
.
toList
());
// 判断当前用户的所有权限是否包含接口上定义的权限
List
<
String
>
list
=
Arrays
.
stream
(
permissions
).
filter
(
elPermissions:
:
contains
).
collect
(
Collectors
.
toList
());
return
elPermissions
.
contains
(
"admin"
)
||
list
.
size
()
!=
0
;
return
elPermissions
.
contains
(
"admin"
)
||
Arrays
.
stream
(
permissions
).
anyMatch
(
elPermissions:
:
contains
);
}
}
eladmin-system/src/main/java/me/zhengjie/modules/security/rest/AuthenticationController.java
View file @
ef03d1c8
...
...
@@ -61,21 +61,21 @@ public class AuthenticationController {
@ApiOperation
(
"登录授权"
)
@AnonymousAccess
@PostMapping
(
value
=
"/login"
)
public
ResponseEntity
login
(
@Validated
@RequestBody
AuthUser
auth
orization
User
,
HttpServletRequest
request
){
public
ResponseEntity
login
(
@Validated
@RequestBody
AuthUser
authUser
,
HttpServletRequest
request
){
// 查询验证码
String
code
=
redisService
.
getCodeVal
(
auth
orization
User
.
getUuid
());
String
code
=
redisService
.
getCodeVal
(
authUser
.
getUuid
());
// 清除验证码
redisService
.
delete
(
auth
orization
User
.
getUuid
());
redisService
.
delete
(
authUser
.
getUuid
());
if
(
StringUtils
.
isBlank
(
code
))
{
throw
new
BadRequestException
(
"验证码已过期"
);
}
if
(
StringUtils
.
isBlank
(
auth
orization
User
.
getCode
())
||
!
auth
orization
User
.
getCode
().
equalsIgnoreCase
(
code
))
{
if
(
StringUtils
.
isBlank
(
authUser
.
getCode
())
||
!
authUser
.
getCode
().
equalsIgnoreCase
(
code
))
{
throw
new
BadRequestException
(
"验证码错误"
);
}
final
JwtUser
jwtUser
=
(
JwtUser
)
userDetailsService
.
loadUserByUsername
(
auth
orization
User
.
getUsername
());
final
JwtUser
jwtUser
=
(
JwtUser
)
userDetailsService
.
loadUserByUsername
(
authUser
.
getUsername
());
if
(!
jwtUser
.
getPassword
().
equals
(
EncryptUtils
.
encryptPassword
(
auth
orization
User
.
getPassword
()))){
if
(!
jwtUser
.
getPassword
().
equals
(
EncryptUtils
.
encryptPassword
(
authUser
.
getPassword
()))){
throw
new
AccountExpiredException
(
"密码错误"
);
}
...
...
Write
Preview
Supports
Markdown
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