package nlib.security;

import java.util.HashMap;

import javax.annotation.Resource;

import org.springframework.security.core.userdetails.User.UserBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;

/**
 * <pre>
 * @Class Name : NlibUserDetailsService.java
 * 
 * @Description : 스프링 시큐리티용으로, 통합자료시스템으로 부터 사용자 정보를 조회하여 UserDetails 형식으로 제공하는 클래스  
 * 
 * 
 * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
 *
 * </pre>
 *
 * @ ------------    --------    ---------------------------
 * @ 수정일                     수정자             수정내용
 * @ ------------    --------    ---------------------------
 * @ 2021. 7. 7.     KNKIM       최초 생성
 *
 * 
 * @author 이씨플라자 * DIGITALSHIP KNKIM
 * @since 2021. 7. 7.
 * @version 1.0
 *
 */
@Service("userDetailsService")
public class SecUserDetailsService implements UserDetailsService {
	
	private static final Logger log = LoggerFactory.getLogger(SecUserDetailsService.class);
	
	@Resource (name = "secUserDAO")
	private SecUserDAO secUserDAO;
	

    /* 사용자명(ID)으로 사용자정보를 조회해 온다.
     * (non-Javadoc)
     * @see org.springframework.security.core.userdetails.UserDetailsService#loadUserByUsername(java.lang.String)
     */
    @Override
    public UserDetails loadUserByUsername(String loginUserId) throws UsernameNotFoundException {
    	
    	SecUserVO secUserVO = secUserDAO.loadUserByUsername(loginUserId);
    	
        if(secUserVO == null) {
            throw new UsernameNotFoundException(loginUserId);
        }
        return secUserVO;
    }
    
}
