Upgrade load user json dto if it is OAuth2Authentication

0.3
lishengzhao 2015-05-20 16:46:49 +08:00
parent b637fb08ec
commit d01c8d0113
1 changed files with 4 additions and 2 deletions

View File

@ -38,11 +38,13 @@ public class UserServiceImpl implements UserService {
@Override
public UserJsonDto loadCurrentUserJsonDto() {
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
final Object principal = authentication.getPrincipal();
if (authentication instanceof OAuth2Authentication && authentication.getPrincipal() instanceof String) {
if (authentication instanceof OAuth2Authentication &&
(principal instanceof String || principal instanceof org.springframework.security.core.userdetails.User)) {
return loadOauthUserJsonDto((OAuth2Authentication) authentication);
} else {
final WdcyUserDetails userDetails = (WdcyUserDetails) authentication.getPrincipal();
final WdcyUserDetails userDetails = (WdcyUserDetails) principal;
return new UserJsonDto(userRepository.findByGuid(userDetails.user().guid()));
}
}