package net.webxtreme.bridge.datalayer.proxy.hibernate; import java.io.Serializable; import net.webxtreme.bridge.datalayer.model.Utente; import net.webxtreme.bridge.datalayer.proxy.UtenteDao; import net.webxtreme.bridge.hibernate.daosupport.GenericHibernateDao; import org.hibernate.criterion.Restrictions; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; public class UtenteDaoImpl extends GenericHibernateDao implements UtenteDao, UserDetailsService { @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { return (Utente) findUserByUsername(username); } public UserDetails findUserByUsername(String username) throws UsernameNotFoundException { this.getSession().beginTransaction(); Utente utente = (Utente) this.findByCriteria().add(Restrictions.eq("username", username)).uniqueResult(); this.getSession().getTransaction().commit(); if (utente == null) { throw new UsernameNotFoundException("utente '" + username + "' non trovato."); } else { return (UserDetails) utente; } } }