首页>代码>SSM和Spring Security的整合后台权限基础框架>/mis/src/main/java/com/haoyu/security/MyUserDetailsService.java
package com.haoyu.security;
import javax.annotation.Resource;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import com.haoyu.system.dao.UserMapper;
import com.haoyu.system.domain.Authorities;
public class MyUserDetailsService implements UserDetailsService {
@Resource
private UserMapper userMapper;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//替换为数据库访问就可以了
// User user = new User("tester", "1", AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER,ROLE_ADMIN"));
com.haoyu.system.domain.User u = userMapper.findByUserName(username);
Authorities authorities = userMapper.findAuthoritiesByUserName(username);
User user = new User(username, u.getPassword(), AuthorityUtils.commaSeparatedStringToAuthorityList(authorities.getAuthority()));
return user;
}
}
最近下载更多
15719908287 LV10
2024年11月1日
微信网友_7134912998903808 LV15
2024年9月14日
taoshen95 LV16
2024年5月15日
ewan007 LV30
2023年7月4日
liaozhenlei LV8
2022年6月7日
ssnqqq LV3
2022年4月10日
wubinbin LV11
2022年4月3日
jay1992 LV14
2022年1月17日
tiansitong LV14
2021年12月5日
17704627276 LV17
2021年11月30日
最近浏览更多
微信网友_7826662819680256
2025年12月24日
暂无贡献等级
15719908287 LV10
2024年11月1日
微信网友_7134912998903808 LV15
2024年9月14日
TY0165 LV20
2024年6月24日
taoshen95 LV16
2024年5月15日
minjing123 LV8
2024年1月4日
iiiiiiixiiiiii LV1
2023年12月31日
shuangfu LV25
2023年12月2日
Hachi6 LV13
2023年8月17日
ewan007 LV30
2023年7月4日

