packagenet.shornepla.auth;importorg.acegisecurity.userdetails.UserDetails;importorg.acegisecurity.userdetails.UserDetailsService;importorg.acegisecurity.userdetails.UsernameNotFoundException;importorg.hibernate.Session;importorg.springframework.dao.DataAccessException;importorg.springframework.orm.hibernate3.support.HibernateDaoSupport;/**
* Provides an UserDesailsService implementation based on Hibernate.
* This ties hibernate and acegi together.
*
* @author shorne
* @since Feb 13, 2009
*/publicclassUserDetailProviderextendsHibernateDaoSupportimplementsUserDetailsService{publicUserDetailsloadUserByUsername(Stringusername)throwsUsernameNotFoundException,DataAccessException{Objectobject=null;Sessionsession=this.getSession();session.beginTransaction();object=session.createQuery("from User o where o.username=:username").setString("username",username).uniqueResult();session.getTransaction().commit();if(object==null){thrownewUsernameNotFoundException("User "+username+"was not found");}else{return(UserDetails)object;}}}