mirror of https://gitee.com/maxjhandsome/pig
【优化】 公共部分、细节优化
This commit is contained in:
parent
39469e857a
commit
a065e34309
|
@ -1,10 +1,16 @@
|
|||
package com.github.pig.auth.serivce;
|
||||
|
||||
import com.github.pig.auth.mapper.SysUserMapper;
|
||||
import com.github.pig.common.vo.SysRole;
|
||||
import com.github.pig.common.vo.UserVo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
@ -19,25 +25,33 @@ import java.util.List;
|
|||
*/
|
||||
@Service("userDetailService")
|
||||
public class UserDetailServiceImpl implements UserDetailsService, Serializable {
|
||||
@Autowired
|
||||
private SysUserMapper sysUserMapper;
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
UserVo userVo = sysUserMapper.selectUserVoByUsername(username);
|
||||
if (userVo != null) {
|
||||
return new UserDetails() {
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
|
||||
GrantedAuthority grantedAuthority = (GrantedAuthority) () -> "ROLE_ADMIN";
|
||||
grantedAuthorities.add(grantedAuthority);
|
||||
return grantedAuthorities;
|
||||
List<GrantedAuthority> authorityList = new ArrayList<>();
|
||||
if (!CollectionUtils.isEmpty(userVo.getRoleList())) {
|
||||
for (SysRole role : userVo.getRoleList()) {
|
||||
authorityList.add(new SimpleGrantedAuthority(role.getRoleCode()));
|
||||
}
|
||||
}
|
||||
return authorityList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return "admin";
|
||||
return userVo.getPassword();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return "admin";
|
||||
return userVo.getUsername();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -61,4 +75,6 @@ public class UserDetailServiceImpl implements UserDetailsService, Serializable {
|
|||
}
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue