Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.tamnd.app.config.security; import com.tamnd.app.core.entities.Account; import com.tamnd.app.core.services.AccountService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Component; /** * * @author tamnd */ @Component public class UserDetailServiceImpl implements UserDetailsService { @Autowired private AccountService service; @Override public UserDetails loadUserByUsername(String name) throws UsernameNotFoundException { Account account = service.findByAccountName(name); if (account == null) { throw new UsernameNotFoundException("No user found with " + name); } return new AccountUserDetails(account); } }