根据用户名获取第三方登录对象
This commit is contained in:
+25
-3
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user