/**
 * 
 */
package org.yacos.auth;

import org.acegisecurity.userdetails.UsernameNotFoundException;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataRetrievalFailureException;
import org.yacos.core.users.User;
import org.yacos.web.system.session.SessionService;

/**
 * User details service
 * 
 * @author christiancorsano
 * 
 */
public class UserDetailsService implements
		org.acegisecurity.userdetails.UserDetailsService {
	/**
	 * 
	 */
	public UserDetails loadUserByUsername(String login)
			throws UsernameNotFoundException, DataAccessException {
		User user;
		try {
			user = SessionService.getInstance().getUserManager().getUser(login);
		} catch (Exception e){
			throw new DataRetrievalFailureException("Couldn't retrieve the User "+login,e);
		}
		
		if(user == null){
			throw new UsernameNotFoundException(login);
		}
		
		return new UserDetails(user);
	}
	

}
