UserDetailServiceImpl.java 973 Bytes
package com.bsth.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
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;

import com.bsth.entity.sys.SecurityUser;
import com.bsth.entity.sys.SysUser;
import com.bsth.service.SysUserService;

@Component
public class UserDetailServiceImpl implements UserDetailsService{

	@Autowired
	SysUserService sysUserService;
	
	public UserDetails loadUserByUsername(String username)throws UsernameNotFoundException, DataAccessException {
			
			SysUser user = sysUserService.findByUserName(username);
			if(null == user){
				throw new UsernameNotFoundException("UserName " + username + " not found");
			}
			return new SecurityUser(user);
	}
}