From 4a946ead6849d48a1ea5ab387978e9c040664c4f Mon Sep 17 00:00:00 2001 From: winLsy <18332763730@163.com> Date: Tue, 16 Jan 2018 15:44:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E7=94=A8=E6=88=B7=E5=90=8D?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=AC=AC=E4=B8=89=E6=96=B9=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UpmsUserAuthenticationServiceImpl.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/ms/upms/src/main/java/com/micro/fast/upms/service/impl/UpmsUserAuthenticationServiceImpl.java b/ms/upms/src/main/java/com/micro/fast/upms/service/impl/UpmsUserAuthenticationServiceImpl.java index 35b4f81..67afce8 100644 --- a/ms/upms/src/main/java/com/micro/fast/upms/service/impl/UpmsUserAuthenticationServiceImpl.java +++ b/ms/upms/src/main/java/com/micro/fast/upms/service/impl/UpmsUserAuthenticationServiceImpl.java @@ -6,6 +6,10 @@ import com.micro.fast.upms.pojo.UpmsUser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.authority.AuthorityUtils; import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.social.security.SocialUser; +import org.springframework.social.security.SocialUserDetails; +import org.springframework.social.security.SocialUserDetailsService; import org.springframework.stereotype.Service; /** @@ -13,11 +17,16 @@ import org.springframework.stereotype.Service; * @author lsy */ @Service("userServiceImpl") -public class UpmsUserAuthenticationServiceImpl implements UserService{ +public class UpmsUserAuthenticationServiceImpl implements UserService,SocialUserDetailsService{ @Autowired private UpmsUserMapper upmsUserMapper; + /** + * 安全框架根据用户的名称获取用户的信息 + * @param username + * @return + */ @Override public User getUserByUsername(String username) { UpmsUser upmsUser = upmsUserMapper.selectByUsername(username); @@ -26,6 +35,19 @@ public class UpmsUserAuthenticationServiceImpl implements UserService{ return user; } - - + /** + * springSocial根据用户的id获取用户的信息 + * @param username 这里只要是用户的唯一标识就可以 + * @return + * @throws UsernameNotFoundException + */ + @Override + public SocialUserDetails loadUserByUserId(String username) throws UsernameNotFoundException { + //使用upmsUserMapper获取到用户的 + UpmsUser upmsUser = upmsUserMapper.selectByUsername(username); + SocialUser socialUser = new SocialUser(username, upmsUser.getPassword() + , true, true, true, true + , AuthorityUtils.commaSeparatedStringToAuthorityList("admin")); + return socialUser; + } }