2023-02-16 15:28:15 +08:00
|
|
|
package com.zhgd.xmgl.security;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.zhgd.xmgl.modules.basicdata.entity.SystemUser;
|
|
|
|
|
import com.zhgd.xmgl.modules.basicdata.mapper.SystemUserMapper;
|
2023-08-04 09:48:49 +08:00
|
|
|
import com.zhgd.xmgl.security.entity.UserInfo;
|
2023-02-16 15:28:15 +08:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.security.core.GrantedAuthority;
|
|
|
|
|
import org.springframework.security.core.userdetails.UserDetails;
|
|
|
|
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
|
|
|
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
|
|
|
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @program: devManage
|
|
|
|
|
* @description:
|
|
|
|
|
* @author: Mr.Peng
|
|
|
|
|
* @create: 2019-09-24 11:02
|
|
|
|
|
**/
|
|
|
|
|
|
2023-08-04 09:48:49 +08:00
|
|
|
@Component(value = "CustomUserDetailsService")
|
2023-02-16 15:28:15 +08:00
|
|
|
public class MyUserDetailsImpl implements UserDetailsService {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private SystemUserMapper systemUserMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private PasswordEncoder passwordEncoder;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
|
|
|
|
final SystemUser user = systemUserMapper.findByUsername(username);
|
|
|
|
|
if (user == null) {
|
|
|
|
|
throw new UsernameNotFoundException("User '" + username + "' not found");
|
|
|
|
|
}
|
|
|
|
|
List<GrantedAuthority> grantedAuthorityList = new ArrayList<>();
|
|
|
|
|
grantedAuthorityList.add(new GrantedAuthority() {
|
|
|
|
|
@Override
|
|
|
|
|
public String getAuthority() {
|
|
|
|
|
return "admin";
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-11-01 11:37:58 +08:00
|
|
|
return new UserInfo(username, user.getPassword(), true, true, true, true, grantedAuthorityList, user.getUserId(), user.getAccountType(), user.getRealName());
|
2023-02-16 15:28:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|