Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
apollo
Commits
a416903d
Commit
a416903d
authored
Sep 13, 2017
by
lepdou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add principal type check when get user info
parent
00184457
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
3 deletions
+16
-3
SpringSecurityUserInfoHolder.java
...rtal/spi/springsecurity/SpringSecurityUserInfoHolder.java
+16
-3
No files found.
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserInfoHolder.java
View file @
a416903d
...
@@ -4,15 +4,28 @@ import com.ctrip.framework.apollo.portal.entity.bo.UserInfo;
...
@@ -4,15 +4,28 @@ import com.ctrip.framework.apollo.portal.entity.bo.UserInfo;
import
com.ctrip.framework.apollo.portal.spi.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.spi.UserInfoHolder
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.core.userdetails.User
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
java.security.Principal
;
public
class
SpringSecurityUserInfoHolder
implements
UserInfoHolder
{
public
class
SpringSecurityUserInfoHolder
implements
UserInfoHolder
{
@Override
@Override
public
UserInfo
getUser
()
{
public
UserInfo
getUser
()
{
UserInfo
userInfo
=
new
UserInfo
();
UserInfo
userInfo
=
new
UserInfo
();
String
userId
=
((
User
)
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
()).
getUsername
();
userInfo
.
setUserId
(
getCurrentUsername
());
userInfo
.
setUserId
(
userId
);
return
userInfo
;
return
userInfo
;
}
}
private
String
getCurrentUsername
()
{
Object
principal
=
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
();
if
(
principal
instanceof
UserDetails
)
{
return
((
UserDetails
)
principal
).
getUsername
();
}
if
(
principal
instanceof
Principal
)
{
return
((
Principal
)
principal
).
getName
();
}
return
String
.
valueOf
(
principal
);
}
}
}
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