From d01c8d011375a416f3a985aeda7656d35f1c867c Mon Sep 17 00:00:00 2001 From: lishengzhao Date: Wed, 20 May 2015 16:46:49 +0800 Subject: [PATCH] Upgrade load user json dto if it is OAuth2Authentication --- src/main/java/cc/wdcy/service/impl/UserServiceImpl.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/cc/wdcy/service/impl/UserServiceImpl.java b/src/main/java/cc/wdcy/service/impl/UserServiceImpl.java index f03abe7..43d8935 100644 --- a/src/main/java/cc/wdcy/service/impl/UserServiceImpl.java +++ b/src/main/java/cc/wdcy/service/impl/UserServiceImpl.java @@ -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())); } }