package com.zhgd.xmgl.security; import com.zhgd.xmgl.modules.basicdata.entity.SystemUser; import com.zhgd.xmgl.modules.basicdata.mapper.SystemUserMapper; 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 **/ @Component(value="CustomUserDetailsService") 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 grantedAuthorityList = new ArrayList<>(); grantedAuthorityList.add(new GrantedAuthority() { @Override public String getAuthority() { return "admin"; } }); return org.springframework.security.core.userdetails.User// .withUsername(username)// .password(user.getPassword())// .accountExpired(false)// .accountLocked(false)// .credentialsExpired(false)// .authorities(grantedAuthorityList) .disabled(false)// .build(); } }