Skip to content

Instantly share code, notes, and snippets.

@mh-github
Created August 13, 2012 12:16
Show Gist options
  • Save mh-github/3340095 to your computer and use it in GitHub Desktop.
Save mh-github/3340095 to your computer and use it in GitHub Desktop.
@Service
public class UserServiceImpl implements UserDetailsService {
@Autowired
private UserDao userDao;
@Autowired
private RoleDao roleDao;
/*
* (non-Javadoc)
*
* @see org.springframework.security.core.userdetails.UserDetailsService#
* loadUserByUsername(java.lang.String)
*/
@Transactional
public UserDetails loadUserByUsername(String userName)
throws UsernameNotFoundException, DataAccessException {
User user = userDao.getUserByUserName(userName);
if (user == null)
throw new UsernameNotFoundException(
"getUserByUserName returned null.");
else {
List<Role> roles = roleDao.getRolesByUsername(userName);
user.setUserAuthorities(roles);
}
return user;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment