【发布时间】:2010-05-15 12:25:15
【问题描述】:
使用自定义属性创建新用户时,Spring 中的最佳实践是什么...扩展 org.springframework.security.core.userdetails.User 或在 UserDetailsService 中创建用户(这是 IceFaces 中采用的方法教程)。
public UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException, DataAccessException {
AppUser user = userDAO.findUser(username);
if (user == null)
throw new UsernameNotFoundException("User not found: " + username);
else {
return makeUser(user);
}
}
private User makeUser(AppUser user) {
return new User(user.getLogin(), user
.getPassword(), true, true, true, true,
makeGrantedAuthorities(user));
}
【问题讨论】:
标签: spring-security