View Javadoc

1   /*
2    * Created on Jun 20, 2006
3    *
4    */
5   package org.musicontroller.security;
6   
7   import org.acegisecurity.userdetails.UserDetailsService;
8   import org.acegisecurity.userdetails.UsernameNotFoundException;
9   import org.springframework.dao.DataAccessException;
10  
11  /**
12   * Implementation of Acegi's UserDetailsService that uses a UserDao for persistent
13   * storage of Users.
14   * @author Varienaja
15   * @version $Id: DaoUserDetailsService.java,v 1.1 2010/03/16 18:55:42 varienaja Exp $
16   */
17  public class DaoUserDetailsService implements UserDetailsService {
18  	
19  	private static UserDao _dao;
20  	
21  	/**
22  	 * Set the UserDao.
23  	 * @param dao The dao.
24  	 */
25  	public void setDao(UserDao dao) {
26  		_dao = dao;
27  	}
28  	
29  	/**
30  	 * @return the UserDao
31  	 */
32  	public UserDao getDao() {
33  		return _dao;
34  	}
35  
36  	public IUser loadUserByUsername(String loginname) throws UsernameNotFoundException, DataAccessException {
37  		IUser p = getDao().getUserByLoginname(loginname);
38  		if (p==null) throw new UsernameNotFoundException("User not found.");
39     		
40  		return p;
41      }
42  }