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
11bf5868
Unverified
Commit
11bf5868
authored
Nov 15, 2020
by
wuyc
Committed by
GitHub
Nov 15, 2020
Browse files
[代码优化](v2.6): 代码优化 (#526)
parent
f56006f6
Changes
1
Hide whitespace changes
Inline
Side-by-side
eladmin-common/src/main/java/me/zhengjie/utils/SecurityUtils.java
View file @
11bf5868
...
...
@@ -41,16 +41,8 @@ public class SecurityUtils {
* @return UserDetails
*/
public
static
UserDetails
getCurrentUser
()
{
final
Authentication
authentication
=
SecurityContextHolder
.
getContext
().
getAuthentication
();
if
(
authentication
==
null
)
{
throw
new
BadRequestException
(
HttpStatus
.
UNAUTHORIZED
,
"当前登录状态过期"
);
}
if
(
authentication
.
getPrincipal
()
instanceof
UserDetails
)
{
UserDetails
userDetails
=
(
UserDetails
)
authentication
.
getPrincipal
();
UserDetailsService
userDetailsService
=
SpringContextHolder
.
getBean
(
UserDetailsService
.
class
);
return
userDetailsService
.
loadUserByUsername
(
userDetails
.
getUsername
());
}
throw
new
BadRequestException
(
HttpStatus
.
UNAUTHORIZED
,
"找不到当前登录的信息"
);
UserDetailsService
userDetailsService
=
SpringContextHolder
.
getBean
(
UserDetailsService
.
class
);
return
userDetailsService
.
loadUserByUsername
(
getCurrentUsername
());
}
/**
...
...
@@ -63,8 +55,11 @@ public class SecurityUtils {
if
(
authentication
==
null
)
{
throw
new
BadRequestException
(
HttpStatus
.
UNAUTHORIZED
,
"当前登录状态过期"
);
}
UserDetails
userDetails
=
(
UserDetails
)
authentication
.
getPrincipal
();
return
userDetails
.
getUsername
();
if
(
authentication
.
getPrincipal
()
instanceof
UserDetails
)
{
UserDetails
userDetails
=
(
UserDetails
)
authentication
.
getPrincipal
();
return
userDetails
.
getUsername
();
}
throw
new
BadRequestException
(
HttpStatus
.
UNAUTHORIZED
,
"找不到当前登录的信息"
);
}
/**
...
...
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