LoginService.java 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package com.its.web.service.admin;
  2. import com.its.web.dto.admin.PrincipalDetail;
  3. import com.its.web.dto.admin.TbWwwMemberDto;
  4. import com.its.web.mapper.its.admin.AdminMapper;
  5. import lombok.RequiredArgsConstructor;
  6. import lombok.extern.slf4j.Slf4j;
  7. import org.springframework.security.core.userdetails.UserDetails;
  8. import org.springframework.security.core.userdetails.UserDetailsService;
  9. import org.springframework.security.core.userdetails.UsernameNotFoundException;
  10. import org.springframework.stereotype.Service;
  11. @Slf4j
  12. @Service
  13. @RequiredArgsConstructor
  14. public class LoginService implements UserDetailsService {
  15. private final AdminMapper adminMapper;
  16. @Override
  17. public UserDetails loadUserByUsername(String userId) throws UsernameNotFoundException {
  18. TbWwwMemberDto dto = adminMapper.findMemberWidthId(userId);
  19. if (dto != null) {
  20. PrincipalDetail principal = new PrincipalDetail(dto);
  21. // if (dto.getIpAddress() != null) {
  22. // String[] ipArray = dto.getIpAddress().split(",");
  23. // if (ipArray.length > 0) {
  24. // List<String> ipList = new ArrayList<>(Arrays.asList(ipArray));
  25. // try {
  26. // InetAddress ipAddress = InetAddress.getLocalHost();
  27. // if (ipList.contains("*") || ipList.contains(ipAddress.getHostAddress())) {
  28. // return principal;
  29. // }
  30. // else {
  31. // throw new UsernameNotFoundException("접속 가능 IP를 확인해주세요");
  32. // }
  33. // } catch (UnknownHostException e) {
  34. // log.error("IP 정보를 확인 할수 없습니다.");
  35. // }
  36. // }
  37. // }
  38. return principal;
  39. }
  40. else {
  41. throw new UsernameNotFoundException(userId + " 을(를) 찾을 수 없습니다.");
  42. }
  43. }
  44. }